add test
This commit is contained in:
@ -187,7 +187,7 @@ func (c *tlsCreds) ServerHandshake(rawConn net.Conn) (net.Conn, AuthInfo, error)
|
|||||||
rawConn.Close()
|
rawConn.Close()
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
return conn, &TLSInfo{conn.ConnectionState()}, nil
|
return conn, TLSInfo{conn.ConnectionState()}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTLS uses c to construct a TransportAuthenticator based on TLS.
|
// NewTLS uses c to construct a TransportAuthenticator based on TLS.
|
||||||
|
|||||||
@ -66,6 +66,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type testServer struct {
|
type testServer struct {
|
||||||
|
security string // indicate the authentication protocol used by this server.
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *testServer) EmptyCall(ctx context.Context, in *testpb.Empty) (*testpb.Empty, error) {
|
func (s *testServer) EmptyCall(ctx context.Context, in *testpb.Empty) (*testpb.Empty, error) {
|
||||||
@ -110,6 +111,24 @@ func (s *testServer) UnaryCall(ctx context.Context, in *testpb.SimpleRequest) (*
|
|||||||
}
|
}
|
||||||
grpc.SetTrailer(ctx, md)
|
grpc.SetTrailer(ctx, md)
|
||||||
}
|
}
|
||||||
|
if s.security != "" {
|
||||||
|
// Check Auth info
|
||||||
|
authInfo, ok := credentials.FromContext(ctx)
|
||||||
|
if !ok {
|
||||||
|
grpclog.Fatalf("Failed to get AuthInfo from ctx.")
|
||||||
|
}
|
||||||
|
var authType string
|
||||||
|
switch info := authInfo.(type) {
|
||||||
|
case credentials.TLSInfo:
|
||||||
|
authType = info.Type()
|
||||||
|
default:
|
||||||
|
grpclog.Fatalf("Unknown AuthInfo type")
|
||||||
|
}
|
||||||
|
if authType != s.security {
|
||||||
|
grpclog.Fatalf("Wrong auth type: got %q, want %q", authType, s.security)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Simulate some service delay.
|
// Simulate some service delay.
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
return &testpb.SimpleResponse{
|
return &testpb.SimpleResponse{
|
||||||
@ -319,7 +338,7 @@ func setUp(hs *health.HealthServer, maxStream uint32, ua string, e env) (s *grpc
|
|||||||
if hs != nil {
|
if hs != nil {
|
||||||
healthpb.RegisterHealthCheckServer(s, hs)
|
healthpb.RegisterHealthCheckServer(s, hs)
|
||||||
}
|
}
|
||||||
testpb.RegisterTestServiceServer(s, &testServer{})
|
testpb.RegisterTestServiceServer(s, &testServer{security: e.security})
|
||||||
go s.Serve(lis)
|
go s.Serve(lis)
|
||||||
addr := la
|
addr := la
|
||||||
switch e.network {
|
switch e.network {
|
||||||
|
|||||||
Reference in New Issue
Block a user