Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
menghanl committed Oct 20, 2017
1 parent 0f2edb3 commit 2bca6ad
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions test/end2end_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4287,6 +4287,61 @@ func TestServerCredsDispatch(t *testing.T) {
}
}

type authorityCheckCreds struct {
expected string
}

func (c *authorityCheckCreds) ServerHandshake(rawConn net.Conn) (net.Conn, credentials.AuthInfo, error) {
return rawConn, nil, nil
}
func (c *authorityCheckCreds) ClientHandshake(ctx context.Context, authority string, rawConn net.Conn) (net.Conn, credentials.AuthInfo, error) {
if c.expected != authority {
return nil, nil, fmt.Errorf("got unexpected authority %s, want %s", authority, c.expected)
}
return rawConn, nil, nil
}
func (c *authorityCheckCreds) Info() credentials.ProtocolInfo {
return credentials.ProtocolInfo{}
}
func (c *authorityCheckCreds) Clone() credentials.TransportCredentials {
return &*c
}
func (c *authorityCheckCreds) OverrideServerName(s string) error {
return nil
}

const testAuthority = "test.auth.ori.ty"

// This test makes sure that the authority client handshake gets is the endpoint
// in dial target, not the resolved ip address.
func TestCredsHandshakeAuthority(t *testing.T) {
lis, err := net.Listen("tcp", "localhost:0")
if err != nil {
t.Fatalf("Failed to listen: %v", err)
}
cred := &authorityCheckCreds{expected: testAuthority}
s := grpc.NewServer(grpc.Creds(cred))
go s.Serve(lis)
defer s.Stop()

r, rcleanup := manual.GenerateAndRegisterManualResolver()
defer rcleanup()

cc, err := grpc.Dial(r.Scheme()+":///"+testAuthority, grpc.WithTransportCredentials(cred))
if err != nil {
t.Fatalf("grpc.Dial(%q) = %v", lis.Addr().String(), err)
}
defer cc.Close()
r.NewAddress([]resolver.Address{{Addr: lis.Addr().String()}})

tc := testpb.NewTestServiceClient(cc)
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
defer cancel()
if _, err := tc.EmptyCall(ctx, &testpb.Empty{}, grpc.FailFast(false)); grpc.Code(err) != codes.Unimplemented {
t.Fatalf("TestService/EmptyCall(_, _) = _, %v, want <unimplemented>", err)
}
}

func TestFlowControlLogicalRace(t *testing.T) {
// Test for a regression of https://github.com/grpc/grpc-go/issues/632,
// and other flow control bugs.
Expand Down

0 comments on commit 2bca6ad

Please sign in to comment.