Skip to content

Commit

Permalink
xds/cdsbalancer: cleanup security tests
Browse files Browse the repository at this point in the history
  • Loading branch information
easwars committed Aug 17, 2023
1 parent b07bf5d commit 663f6d0
Show file tree
Hide file tree
Showing 3 changed files with 757 additions and 468 deletions.
23 changes: 20 additions & 3 deletions internal/credentials/xds/handshake_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,26 @@ type handshakeAttrKey struct{}
// Equal reports whether the handshake info structs are identical (have the
// same pointer). This is sufficient as all subconns from one CDS balancer use
// the same one.
func (hi *HandshakeInfo) Equal(o any) bool {
oh, ok := o.(*HandshakeInfo)
return ok && oh == hi
func (hi *HandshakeInfo) Equal(other *HandshakeInfo) bool {
if hi == nil && other == nil {
return true
}
if hi == nil || other == nil {
return false
}
if hi.rootProvider != other.rootProvider ||
hi.identityProvider != other.identityProvider ||
hi.requireClientCert != other.requireClientCert ||
len(hi.sanMatchers) != len(other.sanMatchers) {
return false
}
for i := range hi.sanMatchers {
if !hi.sanMatchers[i].Equal(other.sanMatchers[i]) {
return false
}
}
return true

}

// SetHandshakeInfo returns a copy of addr in which the Attributes field is
Expand Down
4 changes: 2 additions & 2 deletions internal/stubserver/stubserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func parseCfg(r *manual.Resolver, s string) *serviceconfig.ParseResult {
// StartTestService spins up a stub server exposing the TestService on a local
// port. If the passed in server is nil, a stub server that implements only the
// EmptyCall and UnaryCall RPCs is started.
func StartTestService(t *testing.T, server *StubServer) *StubServer {
func StartTestService(t *testing.T, server *StubServer, sopts ...grpc.ServerOption) *StubServer {
if server == nil {
server = &StubServer{
EmptyCallF: func(context.Context, *testpb.Empty) (*testpb.Empty, error) { return &testpb.Empty{}, nil },
Expand All @@ -225,7 +225,7 @@ func StartTestService(t *testing.T, server *StubServer) *StubServer {
},
}
}
server.StartServer()
server.StartServer(sopts...)

t.Logf("Started test service backend at %q", server.Address)
return server
Expand Down

0 comments on commit 663f6d0

Please sign in to comment.