Skip to content

Commit

Permalink
:authority should include port number (#1123)
Browse files Browse the repository at this point in the history
  • Loading branch information
menghanl authored Mar 28, 2017
1 parent 14a6be4 commit 0df08a7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
7 changes: 1 addition & 6 deletions clientconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import (
"fmt"
"math"
"net"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -360,11 +359,7 @@ func DialContext(ctx context.Context, target string, opts ...DialOption) (conn *
} else if cc.dopts.insecure && cc.dopts.copts.Authority != "" {
cc.authority = cc.dopts.copts.Authority
} else {
colonPos := strings.LastIndex(target, ":")
if colonPos == -1 {
colonPos = len(target)
}
cc.authority = target[:colonPos]
cc.authority = target
}
waitC := make(chan error, 1)
go func() {
Expand Down
12 changes: 12 additions & 0 deletions clientconn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ func TestTLSDialTimeout(t *testing.T) {
}
}

func TestDefaultAuthority(t *testing.T) {
target := "Non-Existent.Server:8080"
conn, err := Dial(target, WithInsecure())
if err != nil {
t.Fatalf("Dial(_, _) = _, %v, want _, <nil>", err)
}
conn.Close()
if conn.authority != target {
t.Fatalf("%v.authority = %v, want %v", conn, conn.authority, target)
}
}

func TestTLSServerNameOverwrite(t *testing.T) {
overwriteServerName := "over.write.server.name"
creds, err := credentials.NewClientTLSFromFile(tlsDir+"ca.pem", overwriteServerName)
Expand Down

0 comments on commit 0df08a7

Please sign in to comment.