From 7dea1aba98c973abda170fb85af311d1dea5e2ff Mon Sep 17 00:00:00 2001 From: Guilherme Carvalho Date: Wed, 14 Dec 2022 10:36:37 -0300 Subject: [PATCH] Remove duplicated opts Signed-off-by: Guilherme Carvalho --- pkg/server/endpoints/endpoints_test.go | 53 +++++++------------------- 1 file changed, 14 insertions(+), 39 deletions(-) diff --git a/pkg/server/endpoints/endpoints_test.go b/pkg/server/endpoints/endpoints_test.go index 4321e2bbf52..d0b86c0b80a 100644 --- a/pkg/server/endpoints/endpoints_test.go +++ b/pkg/server/endpoints/endpoints_test.go @@ -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