grpc: remove remaining usages of grpc.WithInsecure() (#5246)
This commit is contained in:

committed by
GitHub

parent
fbe4ccbc1e
commit
6c3ccbe89a
@ -24,6 +24,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"google.golang.org/grpc/credentials"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
"google.golang.org/grpc/testdata"
|
||||
)
|
||||
|
||||
@ -43,7 +44,7 @@ func (s) TestClientConnAuthority(t *testing.T) {
|
||||
{
|
||||
name: "default",
|
||||
target: "Non-Existent.Server:8080",
|
||||
opts: []DialOption{WithInsecure()},
|
||||
opts: []DialOption{WithTransportCredentials(insecure.NewCredentials())},
|
||||
wantAuthority: "Non-Existent.Server:8080",
|
||||
},
|
||||
{
|
||||
@ -55,7 +56,7 @@ func (s) TestClientConnAuthority(t *testing.T) {
|
||||
{
|
||||
name: "override-via-WithAuthority",
|
||||
target: "Non-Existent.Server:8080",
|
||||
opts: []DialOption{WithInsecure(), WithAuthority("authority-override")},
|
||||
opts: []DialOption{WithTransportCredentials(insecure.NewCredentials()), WithAuthority("authority-override")},
|
||||
wantAuthority: "authority-override",
|
||||
},
|
||||
{
|
||||
@ -67,13 +68,13 @@ func (s) TestClientConnAuthority(t *testing.T) {
|
||||
{
|
||||
name: "unix relative",
|
||||
target: "unix:sock.sock",
|
||||
opts: []DialOption{WithInsecure()},
|
||||
opts: []DialOption{WithTransportCredentials(insecure.NewCredentials())},
|
||||
wantAuthority: "localhost",
|
||||
},
|
||||
{
|
||||
name: "unix relative with custom dialer",
|
||||
target: "unix:sock.sock",
|
||||
opts: []DialOption{WithInsecure(), WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) {
|
||||
opts: []DialOption{WithTransportCredentials(insecure.NewCredentials()), WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) {
|
||||
return (&net.Dialer{}).DialContext(ctx, "", addr)
|
||||
})},
|
||||
wantAuthority: "localhost",
|
||||
@ -81,13 +82,13 @@ func (s) TestClientConnAuthority(t *testing.T) {
|
||||
{
|
||||
name: "unix absolute",
|
||||
target: "unix:/sock.sock",
|
||||
opts: []DialOption{WithInsecure()},
|
||||
opts: []DialOption{WithTransportCredentials(insecure.NewCredentials())},
|
||||
wantAuthority: "localhost",
|
||||
},
|
||||
{
|
||||
name: "unix absolute with custom dialer",
|
||||
target: "unix:///sock.sock",
|
||||
opts: []DialOption{WithInsecure(), WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) {
|
||||
opts: []DialOption{WithTransportCredentials(insecure.NewCredentials()), WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) {
|
||||
return (&net.Dialer{}).DialContext(ctx, "", addr)
|
||||
})},
|
||||
wantAuthority: "localhost",
|
||||
@ -95,13 +96,13 @@ func (s) TestClientConnAuthority(t *testing.T) {
|
||||
{
|
||||
name: "localhost colon port",
|
||||
target: "localhost:50051",
|
||||
opts: []DialOption{WithInsecure()},
|
||||
opts: []DialOption{WithTransportCredentials(insecure.NewCredentials())},
|
||||
wantAuthority: "localhost:50051",
|
||||
},
|
||||
{
|
||||
name: "colon port",
|
||||
target: ":50051",
|
||||
opts: []DialOption{WithInsecure()},
|
||||
opts: []DialOption{WithTransportCredentials(insecure.NewCredentials())},
|
||||
wantAuthority: "localhost:50051",
|
||||
},
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
|
||||
"google.golang.org/grpc/resolver"
|
||||
)
|
||||
@ -83,7 +84,7 @@ func (s) TestParsedTarget_Success_WithoutCustomDialer(t *testing.T) {
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.target, func(t *testing.T) {
|
||||
cc, err := Dial(test.target, WithInsecure())
|
||||
cc, err := Dial(test.target, WithTransportCredentials(insecure.NewCredentials()))
|
||||
if err != nil {
|
||||
t.Fatalf("Dial(%q) failed: %v", test.target, err)
|
||||
}
|
||||
@ -106,7 +107,7 @@ func (s) TestParsedTarget_Failure_WithoutCustomDialer(t *testing.T) {
|
||||
|
||||
for _, target := range targets {
|
||||
t.Run(target, func(t *testing.T) {
|
||||
if cc, err := Dial(target, WithInsecure()); err == nil {
|
||||
if cc, err := Dial(target, WithTransportCredentials(insecure.NewCredentials())); err == nil {
|
||||
defer cc.Close()
|
||||
t.Fatalf("Dial(%q) succeeded cc.parsedTarget = %+v, expected to fail", target, cc.parsedTarget)
|
||||
}
|
||||
@ -178,7 +179,7 @@ func (s) TestParsedTarget_WithCustomDialer(t *testing.T) {
|
||||
return nil, errors.New("dialer error")
|
||||
}
|
||||
|
||||
cc, err := Dial(test.target, WithInsecure(), WithContextDialer(dialer))
|
||||
cc, err := Dial(test.target, WithTransportCredentials(insecure.NewCredentials()), WithContextDialer(dialer))
|
||||
if err != nil {
|
||||
t.Fatalf("Dial(%q) failed: %v", test.target, err)
|
||||
}
|
||||
|
@ -282,8 +282,8 @@ func WithReturnConnectionError() DialOption {
|
||||
// WithCredentialsBundle or WithPerRPCCredentials) which require transport
|
||||
// security is incompatible and will cause grpc.Dial() to fail.
|
||||
//
|
||||
// Deprecated: use WithTransportCredentials and insecure.NewCredentials() instead.
|
||||
// Will be supported throughout 1.x.
|
||||
// Deprecated: use WithTransportCredentials and insecure.NewCredentials()
|
||||
// instead. Will be supported throughout 1.x.
|
||||
func WithInsecure() DialOption {
|
||||
return newFuncDialOption(func(o *dialOptions) {
|
||||
o.copts.TransportCredentials = insecure.NewCredentials()
|
||||
|
@ -26,6 +26,7 @@ import (
|
||||
"time"
|
||||
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
"google.golang.org/grpc/resolver"
|
||||
"google.golang.org/grpc/resolver/manual"
|
||||
"google.golang.org/grpc/status"
|
||||
@ -46,7 +47,7 @@ func (s) TestOneBackendPickfirst(t *testing.T) {
|
||||
defer scleanup()
|
||||
|
||||
cc, err := Dial(r.Scheme()+":///test.server",
|
||||
WithInsecure(),
|
||||
WithTransportCredentials(insecure.NewCredentials()),
|
||||
WithResolvers(r),
|
||||
WithCodec(testCodec{}))
|
||||
if err != nil {
|
||||
@ -80,7 +81,7 @@ func (s) TestBackendsPickfirst(t *testing.T) {
|
||||
servers, scleanup := startServers(t, numServers, math.MaxInt32)
|
||||
defer scleanup()
|
||||
|
||||
cc, err := Dial(r.Scheme()+":///test.server", WithInsecure(), WithResolvers(r), WithCodec(testCodec{}))
|
||||
cc, err := Dial(r.Scheme()+":///test.server", WithTransportCredentials(insecure.NewCredentials()), WithResolvers(r), WithCodec(testCodec{}))
|
||||
if err != nil {
|
||||
t.Fatalf("failed to dial: %v", err)
|
||||
}
|
||||
@ -112,7 +113,7 @@ func (s) TestNewAddressWhileBlockingPickfirst(t *testing.T) {
|
||||
servers, scleanup := startServers(t, numServers, math.MaxInt32)
|
||||
defer scleanup()
|
||||
|
||||
cc, err := Dial(r.Scheme()+":///test.server", WithInsecure(), WithResolvers(r), WithCodec(testCodec{}))
|
||||
cc, err := Dial(r.Scheme()+":///test.server", WithTransportCredentials(insecure.NewCredentials()), WithResolvers(r), WithCodec(testCodec{}))
|
||||
if err != nil {
|
||||
t.Fatalf("failed to dial: %v", err)
|
||||
}
|
||||
@ -147,7 +148,7 @@ func (s) TestCloseWithPendingRPCPickfirst(t *testing.T) {
|
||||
_, scleanup := startServers(t, numServers, math.MaxInt32)
|
||||
defer scleanup()
|
||||
|
||||
cc, err := Dial(r.Scheme()+":///test.server", WithInsecure(), WithResolvers(r), WithCodec(testCodec{}))
|
||||
cc, err := Dial(r.Scheme()+":///test.server", WithTransportCredentials(insecure.NewCredentials()), WithResolvers(r), WithCodec(testCodec{}))
|
||||
if err != nil {
|
||||
t.Fatalf("failed to dial: %v", err)
|
||||
}
|
||||
@ -182,7 +183,7 @@ func (s) TestOneServerDownPickfirst(t *testing.T) {
|
||||
servers, scleanup := startServers(t, numServers, math.MaxInt32)
|
||||
defer scleanup()
|
||||
|
||||
cc, err := Dial(r.Scheme()+":///test.server", WithInsecure(), WithResolvers(r), WithCodec(testCodec{}))
|
||||
cc, err := Dial(r.Scheme()+":///test.server", WithTransportCredentials(insecure.NewCredentials()), WithResolvers(r), WithCodec(testCodec{}))
|
||||
if err != nil {
|
||||
t.Fatalf("failed to dial: %v", err)
|
||||
}
|
||||
@ -222,7 +223,7 @@ func (s) TestAllServersDownPickfirst(t *testing.T) {
|
||||
servers, scleanup := startServers(t, numServers, math.MaxInt32)
|
||||
defer scleanup()
|
||||
|
||||
cc, err := Dial(r.Scheme()+":///test.server", WithInsecure(), WithResolvers(r), WithCodec(testCodec{}))
|
||||
cc, err := Dial(r.Scheme()+":///test.server", WithTransportCredentials(insecure.NewCredentials()), WithResolvers(r), WithCodec(testCodec{}))
|
||||
if err != nil {
|
||||
t.Fatalf("failed to dial: %v", err)
|
||||
}
|
||||
@ -264,7 +265,7 @@ func (s) TestAddressesRemovedPickfirst(t *testing.T) {
|
||||
servers, scleanup := startServers(t, numServers, math.MaxInt32)
|
||||
defer scleanup()
|
||||
|
||||
cc, err := Dial(r.Scheme()+":///test.server", WithInsecure(), WithResolvers(r), WithCodec(testCodec{}))
|
||||
cc, err := Dial(r.Scheme()+":///test.server", WithTransportCredentials(insecure.NewCredentials()), WithResolvers(r), WithCodec(testCodec{}))
|
||||
if err != nil {
|
||||
t.Fatalf("failed to dial: %v", err)
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ import (
|
||||
|
||||
"google.golang.org/grpc/balancer"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
"google.golang.org/grpc/internal/balancer/stub"
|
||||
"google.golang.org/grpc/resolver"
|
||||
"google.golang.org/grpc/resolver/manual"
|
||||
@ -55,7 +56,7 @@ func (s) TestResolverErrorInBuild(t *testing.T) {
|
||||
r := manual.NewBuilderWithScheme("whatever")
|
||||
r.InitialState(resolver.State{ServiceConfig: &serviceconfig.ParseResult{Err: errors.New("resolver build err")}})
|
||||
|
||||
cc, err := Dial(r.Scheme()+":///test.server", WithInsecure(), WithResolvers(r))
|
||||
cc, err := Dial(r.Scheme()+":///test.server", WithTransportCredentials(insecure.NewCredentials()), WithResolvers(r))
|
||||
if err != nil {
|
||||
t.Fatalf("Dial(_, _) = _, %v; want _, nil", err)
|
||||
}
|
||||
@ -74,7 +75,7 @@ func (s) TestResolverErrorInBuild(t *testing.T) {
|
||||
func (s) TestServiceConfigErrorRPC(t *testing.T) {
|
||||
r := manual.NewBuilderWithScheme("whatever")
|
||||
|
||||
cc, err := Dial(r.Scheme()+":///test.server", WithInsecure(), WithResolvers(r))
|
||||
cc, err := Dial(r.Scheme()+":///test.server", WithTransportCredentials(insecure.NewCredentials()), WithResolvers(r))
|
||||
if err != nil {
|
||||
t.Fatalf("Dial(_, _) = _, %v; want _, nil", err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user