diff --git a/pkg/configuration/configuration.go b/pkg/configuration/configuration.go index 925fea81..3c81d700 100644 --- a/pkg/configuration/configuration.go +++ b/pkg/configuration/configuration.go @@ -274,7 +274,6 @@ func (r VerificationConfig) CaptchaScoreThreshold() float32 { threshold := commonconfig.GetString(r.c.Captcha.ScoreThreshold, "") thresholdFloat, err := strconv.ParseFloat(threshold, 32) if err != nil { - if threshold != "" { log.Error(nil, err, fmt.Sprintf("unable to parse captcha score threshold, using default value '%.1f'", defaultScoreThreshold)) } @@ -288,7 +287,6 @@ func (r VerificationConfig) CaptchaRequiredScore() float32 { threshold := commonconfig.GetString(r.c.Captcha.RequiredScore, "0") thresholdFloat, err := strconv.ParseFloat(threshold, 32) if err != nil { - if threshold != "" { log.Error(nil, err, fmt.Sprintf("unable to parse automatic verification threshold, using default value '%.1f'", defaultAutomaticVerificationThreshold)) } diff --git a/pkg/controller/analytics_test.go b/pkg/controller/analytics_test.go index d629c2a7..0fb4aaa9 100644 --- a/pkg/controller/analytics_test.go +++ b/pkg/controller/analytics_test.go @@ -33,7 +33,6 @@ func (s *TestAnalyticsSuite) TestAnalyticsHandler() { analyticsCtrl := NewAnalytics() s.Run("valid devspaces segment write key json", func() { - // Create a request to pass to our handler. We don't have any query parameters for now, so we'll // pass 'nil' as the third parameter. req, err := http.NewRequest(http.MethodGet, "/api/v1/segment-write-key", nil) diff --git a/pkg/controller/authconfig_test.go b/pkg/controller/authconfig_test.go index 39a49664..598d1e4e 100644 --- a/pkg/controller/authconfig_test.go +++ b/pkg/controller/authconfig_test.go @@ -43,7 +43,6 @@ func (s *TestAuthConfigSuite) TestAuthClientConfigHandler() { handler := gin.HandlerFunc(authConfigCtrl.GetHandler) s.Run("valid json config", func() { - // We create a ResponseRecorder (which satisfies http.ResponseWriter) to record the response. rr := httptest.NewRecorder() ctx, _ := gin.CreateTestContext(rr) diff --git a/pkg/controller/signup.go b/pkg/controller/signup.go index 3e2b7f4c..a336efce 100644 --- a/pkg/controller/signup.go +++ b/pkg/controller/signup.go @@ -106,7 +106,6 @@ func (s *Signup) InitVerificationHandler(ctx *gin.Context) { // GetHandler returns the Signup resource func (s *Signup) GetHandler(ctx *gin.Context) { - // Get the UserSignup resource from the service by the username username := ctx.GetString(context.UsernameKey) signupResource, err := s.app.SignupService().GetSignup(ctx, username, true) diff --git a/pkg/controller/signup_test.go b/pkg/controller/signup_test.go index e70afde5..1c09a936 100644 --- a/pkg/controller/signup_test.go +++ b/pkg/controller/signup_test.go @@ -506,7 +506,6 @@ func (s *TestSignupSuite) TestVerifyPhoneCodeHandler() { }) s.Run("verifycode returns status error", func() { - userSignup.Annotations[crtapi.UserVerificationAttemptsAnnotationKey] = "9999" userSignup.Annotations[crtapi.UserVerificationExpiryAnnotationKey] = time.Now().Add(10 * time.Second).Format(service.TimestampLayout) userSignup.Annotations[crtapi.UserSignupVerificationTimestampAnnotationKey] = time.Now().Format(service.TimestampLayout) @@ -569,7 +568,6 @@ func initPhoneVerification(t *testing.T, handler gin.HandlerFunc, params gin.Par } func (s *TestSignupSuite) TestVerifyActivationCodeHandler() { - s.Run("verification successful", func() { // given userSignup := testusersignup.NewUserSignup(testusersignup.VerificationRequiredAgo(time.Second)) // just signed up @@ -592,7 +590,6 @@ func (s *TestSignupSuite) TestVerifyActivationCodeHandler() { }) s.Run("verification failed", func() { - s.Run("too many attempts", func() { // given userSignup := testusersignup.NewUserSignup( diff --git a/pkg/controller/usernames_test.go b/pkg/controller/usernames_test.go index 2b5467ca..9b1dcd6d 100644 --- a/pkg/controller/usernames_test.go +++ b/pkg/controller/usernames_test.go @@ -39,7 +39,6 @@ func (s *TestUsernamesSuite) TestUsernamesGetHandler() { ) s.Run("success", func() { - nsClient := namespaced.NewClient(fakeClient, commontest.HostOperatorNs) // Create Usernames controller instance. @@ -94,7 +93,6 @@ func (s *TestUsernamesSuite) TestUsernamesGetHandler() { // Check the status code is what we expect. assert.Equal(s.T(), http.StatusNotFound, rr.Code, "handler returned wrong status code") }) - }) s.Run("error", func() { diff --git a/pkg/log/log.go b/pkg/log/log.go index 7ab56dee..f771a99d 100644 --- a/pkg/log/log.go +++ b/pkg/log/log.go @@ -80,7 +80,6 @@ func Init(withName string, opts ...zap.Opts) { } klogv1.SetOutputBySeverity("INFO", klogWriter{}) // tell klog v1 to use the custom writer // END : hack to redirect klogv1 calls to klog v2 - }) } diff --git a/pkg/middleware/jwt_middleware_test.go b/pkg/middleware/jwt_middleware_test.go index 2a98180f..6b0b94e4 100644 --- a/pkg/middleware/jwt_middleware_test.go +++ b/pkg/middleware/jwt_middleware_test.go @@ -140,7 +140,6 @@ func (s *TestAuthMiddlewareSuite) TestAuthMiddlewareService() { }) s.Run("auth requests", func() { - // do some requests var authtests = []struct { name string diff --git a/pkg/proxy/handlers/spacelister_get_test.go b/pkg/proxy/handlers/spacelister_get_test.go index 0b35487e..38173a87 100644 --- a/pkg/proxy/handlers/spacelister_get_test.go +++ b/pkg/proxy/handlers/spacelister_get_test.go @@ -45,7 +45,6 @@ func TestSpaceListerGet(t *testing.T) { } func testSpaceListerGet(t *testing.T, publicViewerEnabled bool) { - memberFakeClient := test.NewFakeClient(t, // spacebinding requests spacebindingrequesttest.NewSpaceBindingRequest("animelover-sbr", "dancelover-dev", @@ -608,7 +607,6 @@ func testSpaceListerGet(t *testing.T, publicViewerEnabled bool) { } func TestGetUserWorkspace(t *testing.T) { - fakeSignupService := fake.NewSignupService( newSignup("batman", true), newSignup("robin", true), @@ -766,7 +764,6 @@ func TestGetUserWorkspace(t *testing.T) { } func TestSpaceListerGetPublicViewerEnabled(t *testing.T) { - fakeSignupService := fake.NewSignupService( newSignup("batman", true), newSignup("robin", true), @@ -831,7 +828,6 @@ func TestSpaceListerGetPublicViewerEnabled(t *testing.T) { } for k, tc := range tests { - t.Run(k, func(t *testing.T) { // given signupProvider := fakeSignupService.GetSignup @@ -869,7 +865,6 @@ func TestSpaceListerGetPublicViewerEnabled(t *testing.T) { } func TestGetUserWorkspaceWithBindingsWithPublicViewerEnabled(t *testing.T) { - fakeSignupService := fake.NewSignupService( newSignup("batman", true), newSignup("robin", true), @@ -966,7 +961,6 @@ func TestGetUserWorkspaceWithBindingsWithPublicViewerEnabled(t *testing.T) { } for k, tc := range tests { - t.Run(k, func(t *testing.T) { // given signupProvider := fakeSignupService.GetSignup diff --git a/pkg/proxy/handlers/spacelister_list_test.go b/pkg/proxy/handlers/spacelister_list_test.go index f83ec7d2..5f5d1f64 100644 --- a/pkg/proxy/handlers/spacelister_list_test.go +++ b/pkg/proxy/handlers/spacelister_list_test.go @@ -113,7 +113,6 @@ func TestHandleSpaceListRequest(t *testing.T) { } for k, rtc := range tt { - t.Run(k, func(t *testing.T) { // given tests := map[string]struct { diff --git a/pkg/proxy/members.go b/pkg/proxy/members.go index 02c8e472..005dc24b 100644 --- a/pkg/proxy/members.go +++ b/pkg/proxy/members.go @@ -200,5 +200,4 @@ func (s *MemberClusters) getMemberURL(proxyPluginName string, member *cluster.Ca scheme = "https://" } return url.Parse(scheme + proxyRoute.Status.Ingress[0].Host) - } diff --git a/pkg/proxy/members_test.go b/pkg/proxy/members_test.go index 240ab706..4f4419f9 100644 --- a/pkg/proxy/members_test.go +++ b/pkg/proxy/members_test.go @@ -105,7 +105,6 @@ func (s *TestMemberClustersSuite) TestGetClusterAccess() { publicViewerEnabled := tc.publicViewerEnabled s.Run(k, func() { - s.Run("unable to get signup", func() { tt := map[string]struct { workspace string @@ -144,7 +143,6 @@ func (s *TestMemberClustersSuite) TestGetClusterAccess() { // then require.EqualError(s.T(), err, "user is not provisioned (yet)") }) - }) } }) diff --git a/pkg/proxy/metrics/proxy_metrics_test.go b/pkg/proxy/metrics/proxy_metrics_test.go index a71c1de8..0a623577 100644 --- a/pkg/proxy/metrics/proxy_metrics_test.go +++ b/pkg/proxy/metrics/proxy_metrics_test.go @@ -54,7 +54,6 @@ func TestHistogramVec(t *testing.T) { require.Len(t, g[0].GetMetric()[3].GetLabel(), 2) compareLabelPairValues(t, listFailure, g[0].GetMetric()[3].GetLabel()) require.Equal(t, uint64(2), g[0].GetMetric()[3].GetHistogram().GetSampleCount()) - } var expectedResponseMetadata = ` @@ -118,7 +117,6 @@ func createLabelPairs(name, value string) clientmodel.LabelPair { } func getExpectedLabelPairs() ([]clientmodel.LabelPair, []clientmodel.LabelPair, []clientmodel.LabelPair, []clientmodel.LabelPair) { - // labelPairs are ordered alphabetically on name when gathered. getSuccess := []clientmodel.LabelPair{ createLabelPairs("kube_verb", "get"), diff --git a/pkg/proxy/metrics_server_test.go b/pkg/proxy/metrics_server_test.go index 634d1fbc..51f9ed59 100644 --- a/pkg/proxy/metrics_server_test.go +++ b/pkg/proxy/metrics_server_test.go @@ -61,7 +61,6 @@ func TestProxyMetricsServer(t *testing.T) { _, err = buf.ReadFrom(resp.Body) require.NoError(t, err) assert.Equal(t, expectedServerBlankResponse, buf.String()) - } var expectedServerBlankResponse = `# HELP promhttp_metric_handler_errors_total Total number of internal errors encountered by the promhttp metric handler. diff --git a/pkg/proxy/proxy.go b/pkg/proxy/proxy.go index 5fb37f74..3d97e902 100644 --- a/pkg/proxy/proxy.go +++ b/pkg/proxy/proxy.go @@ -449,7 +449,6 @@ func userHasBinding(username string, workspace *toolchainv1alpha1.Workspace) boo } } return false - } // getUserWorkspaceWithBindings retrieves the workspace with the SpaceBindings if the requesting user has access to it. diff --git a/pkg/proxy/proxy_test.go b/pkg/proxy/proxy_test.go index 0ce94a66..36f7db8f 100644 --- a/pkg/proxy/proxy_test.go +++ b/pkg/proxy/proxy_test.go @@ -85,7 +85,6 @@ func (s *TestProxySuite) TestProxy() { for _, environment := range []testconfig.EnvName{testconfig.E2E, testconfig.Dev, testconfig.Prod} { s.Run("for environment "+string(environment), func() { - s.SetConfig(testconfig.RegistrationService(). Environment(string(environment))) @@ -1181,7 +1180,6 @@ func (s *TestProxySuite) TestValidateWorkspaceRequest() { } func (s *TestProxySuite) TestGetTransport() { - s.Run("when not prod", func() { for _, envName := range []testconfig.EnvName{testconfig.E2E, testconfig.Dev} { s.Run("env "+string(envName), func() { diff --git a/pkg/server/routes.go b/pkg/server/routes.go index 07172148..fb44f80f 100644 --- a/pkg/server/routes.go +++ b/pkg/server/routes.go @@ -108,7 +108,6 @@ func (srv *RegistrationServer) SetupRoutes(proxyPort string, reg *prometheus.Reg err = errs.Wrap(err, "unable to setup route to serve static content") } srv.router.Use(static.Serve("/", staticHandler)) - }) return err } diff --git a/pkg/server/routes_test.go b/pkg/server/routes_test.go index a072fb6c..9276d717 100644 --- a/pkg/server/routes_test.go +++ b/pkg/server/routes_test.go @@ -16,7 +16,6 @@ import ( ) func TestStaticContent(t *testing.T) { - log.Init("registration-service-testing") router := gin.Default() staticHandler, err := assets.ServeEmbedContent() diff --git a/pkg/server/server.go b/pkg/server/server.go index 5d6a952e..a35b6253 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -32,7 +32,6 @@ type RegistrationServer struct { // New creates a new RegistrationServer object with reasonable defaults. func New(application application.Application) *RegistrationServer { - gin.SetMode(gin.ReleaseMode) ginRouter := gin.New() ginRouter.Use( diff --git a/pkg/signup/service/signup_service.go b/pkg/signup/service/signup_service.go index 27ef4dd5..52020d27 100644 --- a/pkg/signup/service/signup_service.go +++ b/pkg/signup/service/signup_service.go @@ -447,7 +447,6 @@ func (s *ServiceImpl) DoGetSignup(ctx *gin.Context, cl namespaced.Client, userna // user's access token and updates the UserSignup if necessary. If updates were made, the function returns true // otherwise it returns false. func (s *ServiceImpl) auditUserSignupAgainstClaims(ctx *gin.Context, userSignup *toolchainv1alpha1.UserSignup) bool { - updated := false updateIfRequired := func(ctx *gin.Context, key, existing string, updated bool) (string, bool) { @@ -515,7 +514,6 @@ func GetDefaultUserTarget(cl namespaced.Client, spaceName, murName string) (stri } sort.Strings(spaceNames) spaceName = spaceNames[0] - } space := &toolchainv1alpha1.Space{} if err := cl.Get(gocontext.TODO(), cl.NamespacedName(spaceName), space); err != nil { diff --git a/pkg/signup/service/signup_service_test.go b/pkg/signup/service/signup_service_test.go index c2b4bdce..ed3659ea 100644 --- a/pkg/signup/service/signup_service_test.go +++ b/pkg/signup/service/signup_service_test.go @@ -54,7 +54,6 @@ func TestRunSignupServiceSuite(t *testing.T) { func (s *TestSignupServiceSuite) ServiceConfiguration(verificationEnabled bool, excludedDomains string, verificationCodeExpiresInMin int) { - s.OverrideApplicationDefault( testconfig.RegistrationService(). Verification().Enabled(verificationEnabled). @@ -67,7 +66,6 @@ func (s *TestSignupServiceSuite) TestSignup() { // given requestTime := time.Now() assertUserSignupExists := func(cl client.Client, username string) toolchainv1alpha1.UserSignup { - userSignups := &toolchainv1alpha1.UserSignupList{} err := cl.List(gocontext.TODO(), userSignups, client.InNamespace(commontest.HostOperatorNs)) require.NoError(s.T(), err) @@ -182,7 +180,6 @@ func (s *TestSignupServiceSuite) TestSignup() { }) } func (s *TestSignupServiceSuite) TestSignupFailsWhenClientReturnsError() { - // given rr := httptest.NewRecorder() ctx, _ := gin.CreateTestContext(rr) @@ -205,7 +202,6 @@ func (s *TestSignupServiceSuite) TestSignupFailsWhenClientReturnsError() { } func (s *TestSignupServiceSuite) TestSignupFailsWithNotFoundThenOtherError() { - // given rr := httptest.NewRecorder() ctx, _ := gin.CreateTestContext(rr) @@ -908,7 +904,6 @@ func (s *TestSignupServiceSuite) TestGetSignupReadyConditionStatus() { for tcName, tc := range tests { s.Run(tcName, func() { - // given mur.Status = toolchainv1alpha1.MasterUserRecordStatus{ Conditions: []toolchainv1alpha1.Condition{ @@ -1021,7 +1016,6 @@ func (s *TestSignupServiceSuite) TestGetDefaultUserNamespaceMultiSpace() { // then assert.Equal(s.T(), "userB-dev", defaultUserNamespace) // space2 is prioritized over space1 because it was created by the userB assert.Equal(s.T(), "member-123", targetCluster) - } func (s *TestSignupServiceSuite) TestGetDefaultUserNamespaceFailNoHomeSpaceNoSpaceBinding() { @@ -1167,13 +1161,10 @@ func (s *TestSignupServiceSuite) TestIsPhoneVerificationRequired() { assert.InDelta(s.T(), float32(1.0), score, 0.01) assert.Equal(s.T(), "captcha-assessment-123", assessmentID) }) - }) - } func (s *TestSignupServiceSuite) TestGetSignupUpdatesUserSignupIdentityClaims() { - s.ServiceConfiguration(false, "", 5) // Create a new UserSignup diff --git a/pkg/verification/sender/amazon_sns_sender.go b/pkg/verification/sender/amazon_sns_sender.go index 3f212ed2..3945074b 100644 --- a/pkg/verification/sender/amazon_sns_sender.go +++ b/pkg/verification/sender/amazon_sns_sender.go @@ -28,7 +28,6 @@ func NewAmazonSNSSender(cfg AWSSenderConfiguration) NotificationSender { } func (s *AmazonSNSSender) SendNotification(_ *gin.Context, content, phoneNumber, _ string) error { - // TODO add support for country-specific sender IDs if we ever decide to use Amazon SNS to send notifications awsAccessKeyID := s.Config.AWSAccessKeyID() diff --git a/pkg/verification/sender/twilio_sender_test.go b/pkg/verification/sender/twilio_sender_test.go index 5f6cfe92..e36d131a 100644 --- a/pkg/verification/sender/twilio_sender_test.go +++ b/pkg/verification/sender/twilio_sender_test.go @@ -39,7 +39,6 @@ func (c *MockTwilioConfig) TwilioSenderConfigs() []toolchainv1alpha1.TwilioSende } func TestTwilioSenderID(t *testing.T) { - cfg := &MockTwilioConfig{ AccountSID: "TWILIO_SID_VALUE", AuthToken: "AUTH_TOKEN_VALUE", diff --git a/pkg/verification/service/verification_service.go b/pkg/verification/service/verification_service.go index 8a4a383b..700be730 100644 --- a/pkg/verification/service/verification_service.go +++ b/pkg/verification/service/verification_service.go @@ -218,7 +218,6 @@ func generateVerificationCode() (string, error) { // VerifyPhoneCode validates the user's phone verification code. It updates the specified UserSignup value, so even // if an error is returned by this function the caller should still process changes to it func (s *ServiceImpl) VerifyPhoneCode(ctx *gin.Context, username, code string) (verificationErr error) { - cfg := configuration.GetRegistrationServiceConfig() // If we can't even find the UserSignup, then die here signup := &toolchainv1alpha1.UserSignup{} diff --git a/pkg/verification/service/verification_service_test.go b/pkg/verification/service/verification_service_test.go index 4ac8979d..cb72df63 100644 --- a/pkg/verification/service/verification_service_test.go +++ b/pkg/verification/service/verification_service_test.go @@ -61,7 +61,6 @@ func TestRunVerificationServiceSuite(t *testing.T) { } func (s *TestVerificationServiceSuite) ServiceConfiguration(accountSID, authToken, fromNumber string) { - ns, err := commonconfig.GetWatchNamespace() require.NoError(s.T(), err) @@ -486,7 +485,6 @@ func (s *TestVerificationServiceSuite) TestVerifyPhoneCode() { now := time.Now() s.Run("verification ok", func() { - userSignup := testusersignup.NewUserSignup( testusersignup.WithEncodedName("johny@kubesaw"), testusersignup.WithLabel(toolchainv1alpha1.UserSignupUserPhoneHashLabelKey, "+1NUMBER"), @@ -510,7 +508,6 @@ func (s *TestVerificationServiceSuite) TestVerifyPhoneCode() { }) s.Run("verification ok for usersignup with username identifier", func() { - userSignup := testusersignup.NewUserSignup( testusersignup.WithEncodedName("employee085@kubesaw"), testusersignup.WithLabel(toolchainv1alpha1.UserSignupUserPhoneHashLabelKey, "+1NUMBER"), @@ -534,7 +531,6 @@ func (s *TestVerificationServiceSuite) TestVerifyPhoneCode() { }) s.Run("when verification code is invalid", func() { - userSignup := testusersignup.NewUserSignup( testusersignup.WithEncodedName("johny@kubesaw"), testusersignup.WithLabel(toolchainv1alpha1.UserSignupUserPhoneHashLabelKey, "+1NUMBER"), @@ -555,7 +551,6 @@ func (s *TestVerificationServiceSuite) TestVerifyPhoneCode() { }) s.Run("when verification code has expired", func() { - userSignup := testusersignup.NewUserSignup( testusersignup.WithEncodedName("johny@kubesaw"), testusersignup.WithLabel(toolchainv1alpha1.UserSignupUserPhoneHashLabelKey, "+1NUMBER"), @@ -575,7 +570,6 @@ func (s *TestVerificationServiceSuite) TestVerifyPhoneCode() { }) s.Run("when verifications exceeded maximum attempts", func() { - userSignup := testusersignup.NewUserSignup( testusersignup.WithEncodedName("johny@kubesaw"), testusersignup.WithLabel(toolchainv1alpha1.UserSignupUserPhoneHashLabelKey, "+1NUMBER"), @@ -592,7 +586,6 @@ func (s *TestVerificationServiceSuite) TestVerifyPhoneCode() { }) s.Run("when verifications attempts has invalid value", func() { - userSignup := testusersignup.NewUserSignup( testusersignup.WithEncodedName("johny@kubesaw"), testusersignup.WithLabel(toolchainv1alpha1.UserSignupUserPhoneHashLabelKey, "+1NUMBER"), @@ -615,7 +608,6 @@ func (s *TestVerificationServiceSuite) TestVerifyPhoneCode() { }) s.Run("when verifications expiry is corrupt", func() { - userSignup := testusersignup.NewUserSignup( testusersignup.WithEncodedName("johny@kubesaw"), testusersignup.WithLabel(toolchainv1alpha1.UserSignupUserPhoneHashLabelKey, "+1NUMBER"), @@ -810,7 +802,6 @@ func (s *TestVerificationServiceSuite) testVerifyActivationCode(targetCluster st }) s.Run("when invalid code", func() { - s.Run("first attempt", func() { // given userSignup := testusersignup.NewUserSignup(testusersignup.VerificationRequiredAgo(time.Second)) // just signed up @@ -1021,5 +1012,4 @@ func (s *TestVerificationServiceSuite) TestPhoneNumberAlreadyInUse() { require.EqualError(s.T(), err, "list error: failed listing userSignups") }) }) - } diff --git a/test/fake/utils.go b/test/fake/utils.go index 241f1cf4..70c664d8 100644 --- a/test/fake/utils.go +++ b/test/fake/utils.go @@ -10,7 +10,6 @@ import ( ) func NewSpace(name, targetCluster, compliantUserName string, spaceTestOptions ...spacetest.Option) *toolchainv1alpha1.Space { - spaceTestOptions = append(spaceTestOptions, spacetest.WithLabel(toolchainv1alpha1.SpaceCreatorLabelKey, compliantUserName), spacetest.WithSpecTargetCluster(targetCluster), diff --git a/test/testsuite.go b/test/testsuite.go index a1bbee07..54087f53 100644 --- a/test/testsuite.go +++ b/test/testsuite.go @@ -45,7 +45,6 @@ func (s *UnitTestSuite) OverrideApplicationDefault(opts ...testconfig.ToolchainC } func (s *UnitTestSuite) SetConfig(opts ...testconfig.ToolchainConfigOption) configuration.RegistrationServiceConfig { - current := &toolchainv1alpha1.ToolchainConfig{} err := s.ConfigClient.Get(context.TODO(), types.NamespacedName{Name: "config", Namespace: test.HostOperatorNs}, current)