Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

verify that conflicts with Space names are being checked for compliantUsername #798

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test/e2e/parallel/registration_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, userSignup.Status.CompliantUsername))

// Now check that the reg-service treats the deactivated usersignup as nonexistent and returns 404
assertGetSignupReturnsNotFound(t, await, token)
Expand Down
1 change: 1 addition & 0 deletions test/e2e/user_management_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
71 changes: 71 additions & 0 deletions test/e2e/usersignup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit lost: why is the usersignup's CompliantUserName already set to something like conflicting-2 at the beginning of the test?

Copy link
Collaborator Author

@MatousJobanek MatousJobanek Sep 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

look at the // given part - it creates a Space with "conflicting" name there.


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).
Expand Down