From 558add5513151a973b3ffe454f8b98b213ad60c9 Mon Sep 17 00:00:00 2001 From: Devtools Date: Mon, 16 Jun 2025 16:18:07 +0200 Subject: [PATCH] set user unready when no default ns --- go.mod | 2 ++ go.sum | 4 +-- pkg/signup/service/signup_service.go | 10 ++++++++ pkg/signup/service/signup_service_test.go | 30 +++++++++++++++++++++++ 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index eb78c7fc..68770639 100644 --- a/go.mod +++ b/go.mod @@ -176,3 +176,5 @@ require ( sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect sigs.k8s.io/yaml v1.4.0 // indirect ) + +replace github.com/codeready-toolchain/api => github.com/mfrancisc/api v0.0.0-20250616123239-4c04c1fb9d8f diff --git a/go.sum b/go.sum index 4d07be09..8328535c 100644 --- a/go.sum +++ b/go.sum @@ -51,8 +51,6 @@ github.com/cloudflare/circl v1.1.0/go.mod h1:prBCrKB9DV4poKZY1l9zBXg2QJY7mvgRvtM github.com/cloudflare/circl v1.6.1 h1:zqIqSPIndyBh1bjLVVDHMPpVKqp8Su/V+6MeDzzQBQ0= github.com/cloudflare/circl v1.6.1/go.mod h1:uddAzsPgqdMAYatqJ0lsjX1oECcQLIlRpzZh3pJrofs= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= -github.com/codeready-toolchain/api v0.0.0-20250506183835-ee4a91d0bca4 h1:m2OsrXpH1MieIg65FQQl3EV0oAyqNfIAYhW2TQnOrWY= -github.com/codeready-toolchain/api v0.0.0-20250506183835-ee4a91d0bca4/go.mod h1:20258od6i5+jP406Z76YaI2ow/vc7URwsDU2bokpkRE= github.com/codeready-toolchain/toolchain-common v0.0.0-20250506093954-2b65ad3a2e12 h1:w54sojJJ8PsHZzK1mC+/EUBrQ9F2sC/k7JUVc8LSqK4= github.com/codeready-toolchain/toolchain-common v0.0.0-20250506093954-2b65ad3a2e12/go.mod h1:TrMvD0sP69wI6Rouzfs7OsOUSj4CGn/ZiIdiDBAFQjk= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= @@ -268,6 +266,8 @@ github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27k github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mfrancisc/api v0.0.0-20250616123239-4c04c1fb9d8f h1:TrA2m+lpNhB0Dl483z0thJ1kI42z38i/wzFmbS0v56E= +github.com/mfrancisc/api v0.0.0-20250616123239-4c04c1fb9d8f/go.mod h1:20258od6i5+jP406Z76YaI2ow/vc7URwsDU2bokpkRE= github.com/migueleliasweb/go-github-mock v0.0.18 h1:0lWt9MYmZQGnQE2rFtjlft/YtD6hzxuN6JJRFpujzEI= github.com/migueleliasweb/go-github-mock v0.0.18/go.mod h1:CcgXcbMoRnf3rRVHqGssuBquZDIcaplxL2W6G+xs7kM= github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMKeZ+mmkFQ= diff --git a/pkg/signup/service/signup_service.go b/pkg/signup/service/signup_service.go index 60e37283..2a7324dc 100644 --- a/pkg/signup/service/signup_service.go +++ b/pkg/signup/service/signup_service.go @@ -442,6 +442,16 @@ func (s *ServiceImpl) DoGetSignup(ctx *gin.Context, cl namespaced.Client, userna signupResponse.DefaultUserNamespace = defaultNamespace } + if defaultNamespace == "" { + // default namespace is not set, so we need to set the status to not ready + signupResponse.Status = signup.Status{ + Ready: false, + Reason: toolchainv1alpha1.UserSignupNoDefaultNamespaceReason, + Message: "No default namespace found", + VerificationRequired: states.VerificationRequired(userSignup), + } + } + return signupResponse, nil } diff --git a/pkg/signup/service/signup_service_test.go b/pkg/signup/service/signup_service_test.go index 5fdb41ca..10abfcce 100644 --- a/pkg/signup/service/signup_service_test.go +++ b/pkg/signup/service/signup_service_test.go @@ -1301,6 +1301,36 @@ func (s *TestSignupServiceSuite) TestGetSignupUpdatesUserSignupIdentityClaims() }) } +func (s *TestSignupServiceSuite) TestGetSignupStatusNoDefaultNamespace() { + // given + s.ServiceConfiguration(true, "", 5) + + username, us := s.newUserSignupComplete() + mur := s.newProvisionedMUR("ted") + toolchainStatus := s.newToolchainStatus(".apps.") + // Do NOT create any Space or SpaceBinding for this user + _, application := testutil.PrepareInClusterApp(s.T(), us, mur, toolchainStatus) + + c, _ := gin.CreateTestContext(httptest.NewRecorder()) + + // when + response, err := application.SignupService().GetSignup(c, username, true) + + // then + require.NoError(s.T(), err) + require.NotNil(s.T(), response) + assert.False(s.T(), response.Status.Ready) + assert.Equal(s.T(), toolchainv1alpha1.UserSignupNoDefaultNamespaceReason, response.Status.Reason) + assert.Equal(s.T(), "No default namespace found", response.Status.Message) + assert.Empty(s.T(), response.DefaultUserNamespace) + assert.Empty(s.T(), response.ConsoleURL) + assert.Empty(s.T(), response.CheDashboardURL) + assert.Empty(s.T(), response.APIEndpoint) + assert.Empty(s.T(), response.ClusterName) + assert.Empty(s.T(), response.ProxyURL) + assert.Empty(s.T(), response.RHODSMemberURL) +} + func (s *TestSignupServiceSuite) newUserSignupComplete() (string, *toolchainv1alpha1.UserSignup) { return "ted@kubesaw", testusersignup.NewUserSignup( testusersignup.WithEncodedName("ted@kubesaw"),