From 3adf2b22eacf7bdc52e740a0f4c9805382dfdaef Mon Sep 17 00:00:00 2001 From: Matous Jobanek Date: Fri, 22 Sep 2023 13:11:46 +0200 Subject: [PATCH 1/4] verify that conflicts with Space names are being checked for compliantUsername --- test/e2e/usersignup_test.go | 71 +++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/test/e2e/usersignup_test.go b/test/e2e/usersignup_test.go index bb8f05562..3fa31fca3 100644 --- a/test/e2e/usersignup_test.go +++ b/test/e2e/usersignup_test.go @@ -8,8 +8,12 @@ import ( toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1" "github.com/codeready-toolchain/toolchain-common/pkg/states" testconfig "github.com/codeready-toolchain/toolchain-common/pkg/test/config" + testcommonspace "github.com/codeready-toolchain/toolchain-common/pkg/test/space" . "github.com/codeready-toolchain/toolchain-e2e/testsupport" + . "github.com/codeready-toolchain/toolchain-e2e/testsupport/space" "github.com/codeready-toolchain/toolchain-e2e/testsupport/wait" + "github.com/redhat-cop/operator-utils/pkg/util" + v1 "k8s.io/api/core/v1" "github.com/gofrs/uuid" "github.com/stretchr/testify/assert" @@ -528,6 +532,73 @@ func (s *userSignupIntegrationTest) TestTargetClusterSelectedAutomatically() { VerifyResourcesProvisionedForSignup(s.T(), s.Awaitilities, userSignup, "deactivate30", "base") } +func (s *userSignupIntegrationTest) TestTransformUsernameWithSpaceConflict() { + // given + conflictingSpace, _, _ := CreateSpace(s.T(), s.Awaitilities, testcommonspace.WithName("conflicting")) + + // when + userSignup, _ := NewSignupRequest(s.Awaitilities). + Username(conflictingSpace.Name). + TargetCluster(s.Member1()). + ManuallyApprove(). + EnsureMUR(). + RequireConditions(wait.ConditionSet(wait.Default(), wait.ApprovedByAdmin())...). + Execute(s.T()).Resources() + + // then + compliantUsername := userSignup.Status.CompliantUsername + require.Equal(s.T(), fmt.Sprintf("%s-2", conflictingSpace.Name), compliantUsername) + + s.T().Run("when signup is deactivated, Space is stuck in terminating state, and when it reactivates then it should generate a new name", func(t *testing.T) { + // given + // let's get a namespace of the space + space, err := s.Host().WaitForSpace(t, compliantUsername, wait.UntilSpaceHasAnyProvisionedNamespaces()) + require.NoError(t, err) + namespaceName := space.Status.ProvisionedNamespaces[0].Name + // and add a dummy finalizer there so it will get stuck + _, err = s.Member1().UpdateNamespace(t, namespaceName, func(ns *v1.Namespace) { + util.AddFinalizer(ns, "test/finalizer.toolchain.e2e.tests") + }) + require.NoError(t, err) + + // don't forget to clean the finalizer up + defer func() { + t.Log("cleaning up the finalizer") + _, err = s.Member1().UpdateNamespace(t, namespaceName, func(ns *v1.Namespace) { + util.RemoveFinalizer(ns, "test/finalizer.toolchain.e2e.tests") + }) + require.NoError(t, err) + }() + + // now deactivate the usersignup + _, err = s.Host().UpdateUserSignup(t, userSignup.Name, func(us *toolchainv1alpha1.UserSignup) { + states.SetDeactivated(us, true) + }) + require.NoError(t, err) + + // wait until it is deactivated, SpaceBinding is gone, and Space is in terminating state + _, err = s.Host().WaitForUserSignup(t, userSignup.Name, + wait.UntilUserSignupHasStateLabel(toolchainv1alpha1.UserSignupStateLabelValueDeactivated)) + require.NoError(t, err) + err = s.Host().WaitUntilSpaceBindingsWithLabelDeleted(t, toolchainv1alpha1.SpaceBindingMasterUserRecordLabelKey, compliantUsername) + require.NoError(t, err) + _, err = s.Host().WaitForSpace(t, compliantUsername, wait.UntilSpaceIsBeingDeleted()) + require.NoError(t, err) + + // when + userSignup, err = s.Host().UpdateUserSignup(t, userSignup.Name, func(us *toolchainv1alpha1.UserSignup) { + states.SetApprovedManually(us, true) + }) + require.NoError(t, err) + + // then + userSignup, _ = VerifyUserRelatedResources(t, s.Awaitilities, userSignup, "deactivate30") + VerifySpaceRelatedResources(t, s.Awaitilities, userSignup, "base") + VerifyResourcesProvisionedForSignup(t, s.Awaitilities, userSignup, "deactivate30", "base") + require.Equal(t, fmt.Sprintf("%s-3", conflictingSpace.Name), userSignup.Status.CompliantUsername) + }) +} + func (s *userSignupIntegrationTest) TestTransformUsername() { // Create UserSignup with a username that we don't need to transform userSignup, _ := NewSignupRequest(s.Awaitilities). From 1fba888b6c38ca5777bacb82b24eee3cd2811285 Mon Sep 17 00:00:00 2001 From: Matous Jobanek Date: Fri, 22 Sep 2023 16:36:01 +0200 Subject: [PATCH 2/4] wait until Space is gone --- test/e2e/parallel/registration_service_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/test/e2e/parallel/registration_service_test.go b/test/e2e/parallel/registration_service_test.go index e10f8b546..00b188980 100644 --- a/test/e2e/parallel/registration_service_test.go +++ b/test/e2e/parallel/registration_service_test.go @@ -375,6 +375,7 @@ func TestSignupOK(t *testing.T) { wait.UntilUserSignupHasConditions(wait.ConditionSet(wait.Default(), wait.ApprovedByAdmin(), wait.DeactivatedWithoutPreDeactivation())...), wait.UntilUserSignupHasStateLabel(toolchainv1alpha1.UserSignupStateLabelValueDeactivated)) require.NoError(t, err) + require.NoError(t, hostAwait.WaitUntilSpaceAndSpaceBindingsDeleted(t, identity.Username)) // Now check that the reg-service treats the deactivated usersignup as nonexistent and returns 404 assertGetSignupReturnsNotFound(t, await, token) From aef1a68a5a8182bb908b8e580986225fcf8f5b1c Mon Sep 17 00:00:00 2001 From: Matous Jobanek Date: Fri, 22 Sep 2023 17:04:02 +0200 Subject: [PATCH 3/4] use complaintUsername --- test/e2e/parallel/registration_service_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/parallel/registration_service_test.go b/test/e2e/parallel/registration_service_test.go index 00b188980..9b400cc3c 100644 --- a/test/e2e/parallel/registration_service_test.go +++ b/test/e2e/parallel/registration_service_test.go @@ -375,7 +375,7 @@ func TestSignupOK(t *testing.T) { wait.UntilUserSignupHasConditions(wait.ConditionSet(wait.Default(), wait.ApprovedByAdmin(), wait.DeactivatedWithoutPreDeactivation())...), wait.UntilUserSignupHasStateLabel(toolchainv1alpha1.UserSignupStateLabelValueDeactivated)) require.NoError(t, err) - require.NoError(t, hostAwait.WaitUntilSpaceAndSpaceBindingsDeleted(t, identity.Username)) + require.NoError(t, hostAwait.WaitUntilSpaceAndSpaceBindingsDeleted(t, userSignup.Status.CompliantUsername)) // Now check that the reg-service treats the deactivated usersignup as nonexistent and returns 404 assertGetSignupReturnsNotFound(t, await, token) From 40fdca1386c473c88686c57e9b5cce6fc870bede Mon Sep 17 00:00:00 2001 From: Matous Jobanek Date: Fri, 22 Sep 2023 18:15:12 +0200 Subject: [PATCH 4/4] wait after banning --- test/e2e/user_management_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/test/e2e/user_management_test.go b/test/e2e/user_management_test.go index 97e458f8c..46c6176e9 100644 --- a/test/e2e/user_management_test.go +++ b/test/e2e/user_management_test.go @@ -647,6 +647,7 @@ func (s *userManagementTestSuite) TestUserBanning() { wait.UntilUserSignupHasConditions(wait.ConditionSet(wait.Default(), wait.ApprovedByAdmin(), wait.Banned())...), wait.UntilUserSignupHasStateLabel(toolchainv1alpha1.UserSignupStateLabelValueBanned)) require.NoError(t, err) + require.NoError(t, hostAwait.WaitUntilSpaceAndSpaceBindingsDeleted(t, userSignup.Status.CompliantUsername)) t.Run("unban the banned user", func(t *testing.T) { // Unban the user