Skip to content

Add tests for activation code+signup #1158

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
merged 3 commits into from
Jun 13, 2025
Merged
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
66 changes: 52 additions & 14 deletions test/e2e/parallel/registration_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,15 +702,39 @@ func TestActivationCodeVerification(t *testing.T) {
member2Await := await.Member2()
route := hostAwait.RegistrationServiceURL

verifySuccessful := func(t *testing.T, targetCluster string) {
verifySuccessful := func(t *testing.T, targetCluster string, existingUserSignup, deactivateSignup bool) {
// given
event := testsocialevent.NewSocialEvent(hostAwait.Namespace, commonsocialevent.NewName(),
testsocialevent.WithUserTier("deactivate80"),
testsocialevent.WithSpaceTier("base1ns6didler"),
testsocialevent.WithTargetCluster(targetCluster))
err := hostAwait.CreateWithCleanup(t, event)
require.NoError(t, err)
userSignup, token := signup(t, hostAwait)
userSignup := &toolchainv1alpha1.UserSignup{}
token, userName := "", ""
if existingUserSignup {
// create a user signup before using the activation code
userSignup, token = signup(t, hostAwait)
cleanup.AddCleanTasks(t, hostAwait.Client, userSignup)
userName = userSignup.Name

if deactivateSignup {
// deactivate the UserSignup to test the deactivation path
_, err = wait.For(t, hostAwait.Awaitility, &toolchainv1alpha1.UserSignup{}).
Update(userName, hostAwait.Namespace,
func(us *toolchainv1alpha1.UserSignup) {
states.SetDeactivated(us, true)
})
require.NoError(t, err)
t.Logf("user signup '%s' deactivated", userName)
}
} else {
// create only the identity and token for calling the activation-code endpoint.
// the signup should be created by the activation-code endpoint.
identity, _, tokenValue := userToken(t)
token = tokenValue
userName = identity.Username
}

// when call verification endpoint with a valid activation code
NewHTTPRequest(t).
Expand All @@ -719,22 +743,23 @@ func TestActivationCodeVerification(t *testing.T) {
// then
// ensure the UserSignup is in "pending approval" condition,
// because in these series of parallel tests, automatic approval is disabled ¯\_(ツ)_/¯
_, err = hostAwait.WaitForUserSignup(t, userSignup.Name,
userSignup, err = hostAwait.WaitForUserSignup(t, userName,
wait.UntilUserSignupHasLabel(toolchainv1alpha1.SocialEventUserSignupLabelKey, event.Name),
wait.UntilUserSignupHasConditions(wait.ConditionSet(wait.Default(), wait.PendingApproval())...))
cleanup.AddCleanTasks(t, hostAwait.Client, userSignup)
require.NoError(t, err)
// explicitly approve the usersignup (see above, config for parallel test has automatic approval disabled)
userSignup, err = wait.For(t, hostAwait.Awaitility, &toolchainv1alpha1.UserSignup{}).
Update(userSignup.Name, hostAwait.Namespace,
_, err = wait.For(t, hostAwait.Awaitility, &toolchainv1alpha1.UserSignup{}).
Update(userName, hostAwait.Namespace,
func(us *toolchainv1alpha1.UserSignup) {
states.SetApprovedManually(us, true)
})
require.NoError(t, err)
t.Logf("user signup '%s' approved", userSignup.Name)
t.Logf("user signup '%s' approved", userName)

// check that the MUR and Space are configured as expected
// Wait for the UserSignup to have the desired state
userSignup, err = hostAwait.WaitForUserSignup(t, userSignup.Name,
userSignup, err = hostAwait.WaitForUserSignup(t, userName,
wait.UntilUserSignupHasCompliantUsername(),
wait.UntilUserSignupHasTargetCluster(targetCluster))
require.NoError(t, err)
Expand All @@ -761,11 +786,19 @@ func TestActivationCodeVerification(t *testing.T) {
}

t.Run("verification successful with no target cluster", func(t *testing.T) {
verifySuccessful(t, "")
verifySuccessful(t, "", true, false)
})

t.Run("verification successful with target cluster", func(t *testing.T) {
verifySuccessful(t, member2Await.ClusterName)
verifySuccessful(t, member2Await.ClusterName, true, false)
})

t.Run("UserSignup doesn't exist yet it should be created", func(t *testing.T) {
verifySuccessful(t, member2Await.ClusterName, false, false)
})

t.Run("UserSignup is deactivated it should be reactivated", func(t *testing.T) {
verifySuccessful(t, member2Await.ClusterName, true, true)
})

t.Run("verification failed", func(t *testing.T) {
Expand Down Expand Up @@ -930,11 +963,7 @@ func signup(t *testing.T, hostAwait *wait.HostAwaitility) (*toolchainv1alpha1.Us
route := hostAwait.RegistrationServiceURL

// Create a token and identity to sign up with
identity := commonauth.NewIdentity()
emailValue := identity.Username + "@some.domain"
emailClaim := commonauth.WithEmailClaim(emailValue)
token, err := commonauth.GenerateSignedE2ETestToken(*identity, emailClaim)
require.NoError(t, err)
identity, emailValue, token := userToken(t)

// Call the signup endpoint
NewHTTPRequest(t).InvokeEndpoint("POST", route+"/api/v1/signup", token, "", http.StatusAccepted)
Expand All @@ -950,6 +979,15 @@ func signup(t *testing.T, hostAwait *wait.HostAwaitility) (*toolchainv1alpha1.Us
return userSignup, token
}

func userToken(t *testing.T) (*commonauth.Identity, string, string) {
identity := commonauth.NewIdentity()
emailValue := identity.Username + "@some.domain"
emailClaim := commonauth.WithEmailClaim(emailValue)
token, err := commonauth.GenerateSignedE2ETestToken(*identity, emailClaim)
require.NoError(t, err)
return identity, emailValue, token
}

func signupHasExpectedDates(startDate, endDate time.Time) func(c *GetSignupClient) {
return func(c *GetSignupClient) {
responseStartDate, err := time.Parse(time.RFC3339, c.responseBody["startDate"].(string))
Expand Down
Loading