(t *testing.T)
| 29 | ) |
| 30 | |
| 31 | func (s) TestClientConnAuthority(t *testing.T) { |
| 32 | serverNameOverride := "over.write.server.name" |
| 33 | creds, err := credentials.NewClientTLSFromFile(testdata.Path("x509/server_ca_cert.pem"), serverNameOverride) |
| 34 | if err != nil { |
| 35 | t.Fatalf("credentials.NewClientTLSFromFile(_, %q) failed: %v", err, serverNameOverride) |
| 36 | } |
| 37 | |
| 38 | tests := []struct { |
| 39 | name string |
| 40 | target string |
| 41 | opts []DialOption |
| 42 | wantAuthority string |
| 43 | }{ |
| 44 | { |
| 45 | name: "default", |
| 46 | target: "Non-Existent.Server:8080", |
| 47 | opts: []DialOption{WithTransportCredentials(insecure.NewCredentials())}, |
| 48 | wantAuthority: "Non-Existent.Server:8080", |
| 49 | }, |
| 50 | { |
| 51 | name: "override-via-creds", |
| 52 | target: "Non-Existent.Server:8080", |
| 53 | opts: []DialOption{WithTransportCredentials(creds)}, |
| 54 | wantAuthority: serverNameOverride, |
| 55 | }, |
| 56 | { |
| 57 | name: "override-via-WithAuthority", |
| 58 | target: "Non-Existent.Server:8080", |
| 59 | opts: []DialOption{WithTransportCredentials(insecure.NewCredentials()), WithAuthority("authority-override")}, |
| 60 | wantAuthority: "authority-override", |
| 61 | }, |
| 62 | { |
| 63 | name: "override-via-creds-and-WithAuthority", |
| 64 | target: "Non-Existent.Server:8080", |
| 65 | opts: []DialOption{WithTransportCredentials(creds), WithAuthority(serverNameOverride)}, |
| 66 | wantAuthority: serverNameOverride, |
| 67 | }, |
| 68 | { |
| 69 | name: "unix relative", |
| 70 | target: "unix:sock.sock", |
| 71 | opts: []DialOption{WithTransportCredentials(insecure.NewCredentials())}, |
| 72 | wantAuthority: "localhost", |
| 73 | }, |
| 74 | { |
| 75 | name: "unix relative with custom dialer", |
| 76 | target: "unix:sock.sock", |
| 77 | opts: []DialOption{WithTransportCredentials(insecure.NewCredentials()), WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) { |
| 78 | return (&net.Dialer{}).DialContext(ctx, "", addr) |
| 79 | })}, |
| 80 | wantAuthority: "localhost", |
| 81 | }, |
| 82 | { |
| 83 | name: "unix absolute", |
| 84 | target: "unix:/sock.sock", |
| 85 | opts: []DialOption{WithTransportCredentials(insecure.NewCredentials())}, |
| 86 | wantAuthority: "localhost", |
| 87 | }, |
| 88 | { |
nothing calls this directly
no test coverage detected