Skip to content

Commit

Permalink
Remove duplicated opts
Browse files Browse the repository at this point in the history
Signed-off-by: Guilherme Carvalho <guilhermbrsp@gmail.com>
  • Loading branch information
guilhermocc committed Dec 14, 2022
1 parent 0be5985 commit 7dea1ab
Showing 1 changed file with 14 additions and 39 deletions.
53 changes: 14 additions & 39 deletions pkg/server/endpoints/endpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,49 +327,24 @@ func TestListenAndServe(t *testing.T) {
testRemoteCaller(ctx, t, target)
})

t.Run("Connection closed to unfederated foreign admin caller", func(t *testing.T) {
config := tlsconfig.MTLSClientConfig(unfederatedForeignAdminSVID, ca.X509Bundle(), tlsconfig.AuthorizeID(serverID))
t.Run("Connection closed to misconfigured foreign admin caller", func(t *testing.T) {
unauthenticatedConfig := tlsconfig.MTLSClientConfig(unauthenticatedForeignAdminSVID, ca.X509Bundle(), tlsconfig.AuthorizeID(serverID))
unauthorizedConfig := tlsconfig.MTLSClientConfig(unauthorizedForeignAdminSVID, ca.X509Bundle(), tlsconfig.AuthorizeID(serverID))
unfederatedConfig := tlsconfig.MTLSClientConfig(unfederatedForeignAdminSVID, ca.X509Bundle(), tlsconfig.AuthorizeID(serverID))

timedContext, cancelFn := context.WithTimeout(ctx, 100*time.Millisecond)
defer cancelFn()
for _, config := range []*tls.Config{unauthenticatedConfig, unauthorizedConfig, unfederatedConfig} {
timedContext, cancelFn := context.WithTimeout(ctx, 100*time.Millisecond)

_, err := grpc.DialContext(timedContext, endpoints.TCPAddr.String(),
grpc.WithBlock(),
grpc.WithTransportCredentials(credentials.NewTLS(config)),
grpc.WithReturnConnectionError(),
grpc.WithBlock(),
)
require.EqualError(t, err, "context deadline exceeded: connection error: desc = \"error reading server preface: remote error: tls: bad certificate\"")
})

t.Run("Connection closed to unauthorized foreign admin caller", func(t *testing.T) {
config := tlsconfig.MTLSClientConfig(unauthorizedForeignAdminSVID, ca.X509Bundle(), tlsconfig.AuthorizeID(serverID))

timedContext, cancelFn := context.WithTimeout(ctx, 100*time.Millisecond)
defer cancelFn()

_, err := grpc.DialContext(timedContext, endpoints.TCPAddr.String(),
grpc.WithBlock(),
grpc.WithTransportCredentials(credentials.NewTLS(config)),
grpc.WithReturnConnectionError(),
grpc.WithBlock(),
)
require.EqualError(t, err, "context deadline exceeded: connection error: desc = \"error reading server preface: remote error: tls: bad certificate\"")
})

t.Run("Connection closed to unauthenticated foreign admin caller", func(t *testing.T) {
config := tlsconfig.MTLSClientConfig(unauthenticatedForeignAdminSVID, ca.X509Bundle(), tlsconfig.AuthorizeID(serverID))
_, err := grpc.DialContext(timedContext, endpoints.TCPAddr.String(),
grpc.WithBlock(),
grpc.WithTransportCredentials(credentials.NewTLS(config)),
grpc.WithReturnConnectionError(),
)

timedContext, cancelFn := context.WithTimeout(ctx, 100*time.Millisecond)
defer cancelFn()
cancelFn()

_, err := grpc.DialContext(timedContext, endpoints.TCPAddr.String(),
grpc.WithBlock(),
grpc.WithTransportCredentials(credentials.NewTLS(config)),
grpc.WithReturnConnectionError(),
grpc.WithBlock(),
)
require.EqualError(t, err, "context deadline exceeded: connection error: desc = \"error reading server preface: remote error: tls: bad certificate\"")
require.EqualError(t, err, "context deadline exceeded: connection error: desc = \"error reading server preface: remote error: tls: bad certificate\"")
}
})

// Assert that the bundle endpoint server was called to listen and serve
Expand Down

0 comments on commit 7dea1ab

Please sign in to comment.