Skip to content

verify that reg-service returns 403 when user is banned #1141

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

Merged

Conversation

MatousJobanek
Copy link
Collaborator

@MatousJobanek MatousJobanek commented Mar 27, 2025

Copy link

Comment on lines -559 to -590
s.Run("ban provisioned usersignup", func() {
hostAwait := s.Host()
memberAwait := s.Member1()
hostAwait.UpdateToolchainConfig(s.T(), testconfig.AutomaticApproval().Enabled(false))

// Create a new UserSignup and approve it manually
user := NewSignupRequest(s.Awaitilities).
Username("banprovisioned").
Email("banprovisioned@test.com").
ManuallyApprove().
TargetCluster(memberAwait).
RequireConditions(wait.ConditionSet(wait.Default(), wait.ApprovedByAdmin())...).
Execute(s.T())
userSignup := user.UserSignup

// Create the BannedUser
CreateBannedUser(s.T(), s.Host(), userSignup.Spec.IdentityClaims.Email)

// Confirm the user is banned
_, err := hostAwait.WithRetryOptions(wait.TimeoutOption(time.Second*15)).WaitForUserSignup(s.T(), userSignup.Name,
wait.UntilUserSignupHasConditions(wait.ConditionSet(wait.Default(), wait.ApprovedByAdmin(), wait.Banned())...))
require.NoError(s.T(), err)

// Confirm that a MasterUserRecord is deleted
_, err = hostAwait.WithRetryOptions(wait.TimeoutOption(time.Second*10)).WaitForMasterUserRecord(s.T(), userSignup.Spec.IdentityClaims.PreferredUsername)
require.Error(s.T(), err)
// confirm usersignup
_, err = hostAwait.WaitForUserSignup(s.T(), userSignup.Name,
wait.UntilUserSignupHasConditions(wait.ConditionSet(wait.Default(), wait.ApprovedByAdmin(), wait.Banned())...),
wait.UntilUserSignupHasStateLabel(toolchainv1alpha1.UserSignupStateLabelValueBanned))
require.NoError(s.T(), err)
})
Copy link
Collaborator Author

@MatousJobanek MatousJobanek Mar 27, 2025

Choose a reason for hiding this comment

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

this was a complete duplication of the first test of "ban provisioned usersignup" below

Comment on lines -592 to -618
s.Run("manually created usersignup with preexisting banneduser", func() {
hostAwait := s.Host()
memberAwait := s.Member1()
hostAwait.UpdateToolchainConfig(s.T(), testconfig.AutomaticApproval().Enabled(true))

id := uuid.Must(uuid.NewV4()).String()
email := "testuser" + id + "@test.com"
CreateBannedUser(s.T(), s.Host(), email)

// For this test, we don't want to create the UserSignup via the registration service (the next test does this)
// Instead, we want to confirm the behaviour when a UserSignup with a banned email address is created manually
userSignup := NewUserSignup(hostAwait.Namespace, "testuser"+id, email)
userSignup.Spec.TargetCluster = memberAwait.ClusterName

// Create the UserSignup via the Kubernetes API
err := hostAwait.CreateWithCleanup(s.T(), userSignup)
require.NoError(s.T(), err)
s.T().Logf("user signup '%s' created", userSignup.Name)

// Check the UserSignup is created and confirm that the user is banned
_, err = hostAwait.WaitForUserSignup(s.T(), userSignup.Name, wait.UntilUserSignupHasStateLabel(toolchainv1alpha1.UserSignupStateLabelValueBanned))
require.NoError(s.T(), err)

err = hostAwait.WaitUntilSpaceAndSpaceBindingsDeleted(s.T(), "testuser"+id)
require.NoError(s.T(), err)
})

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this didn't test a real scenario (we don't create UserSignups manually), thus it's better to remove it to not bring any confusion in the future.

Copy link
Contributor

@mfrancisc mfrancisc left a comment

Choose a reason for hiding this comment

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

Looks good 👍

Thanks for the additional cleanup.

@MatousJobanek
Copy link
Collaborator Author

/retest
olm issue

Copy link

openshift-ci bot commented Mar 27, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alexeykazakov, MatousJobanek, metlos, mfrancisc, rajivnathan

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [MatousJobanek,alexeykazakov,metlos,mfrancisc,rajivnathan]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@MatousJobanek MatousJobanek merged commit 1ae278a into codeready-toolchain:master Mar 28, 2025
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants