Skip to content

Commit 56fa2cf

Browse files
mfranciscDevtools
andauthored
add check for account number set in signup response (codeready-toolchain#1196)
* add check for account number set in --------- Co-authored-by: Devtools <devtools@redhat.com>
1 parent b44c578 commit 56fa2cf

File tree

5 files changed

+54
-6
lines changed

5 files changed

+54
-6
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module github.com/codeready-toolchain/toolchain-e2e
22

33
require (
4-
github.com/codeready-toolchain/api v0.0.0-20250605152105-383ffe6cac27
5-
github.com/codeready-toolchain/toolchain-common v0.0.0-20250506093954-2b65ad3a2e12
4+
github.com/codeready-toolchain/api v0.0.0-20250909075145-ca043a618f0f
5+
github.com/codeready-toolchain/toolchain-common v0.0.0-20250910131836-b410cd4ca53d
66
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
77
github.com/fatih/color v1.18.0
88
github.com/ghodss/yaml v1.0.0

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk
3030
github.com/cloudflare/circl v1.1.0/go.mod h1:prBCrKB9DV4poKZY1l9zBXg2QJY7mvgRvtMxxK7fi4I=
3131
github.com/cloudflare/circl v1.6.1 h1:zqIqSPIndyBh1bjLVVDHMPpVKqp8Su/V+6MeDzzQBQ0=
3232
github.com/cloudflare/circl v1.6.1/go.mod h1:uddAzsPgqdMAYatqJ0lsjX1oECcQLIlRpzZh3pJrofs=
33-
github.com/codeready-toolchain/api v0.0.0-20250605152105-383ffe6cac27 h1:g1ivSPPHTC96RHp8S/gRmqODWgoHyivq+/d5kSI0pEs=
34-
github.com/codeready-toolchain/api v0.0.0-20250605152105-383ffe6cac27/go.mod h1:20258od6i5+jP406Z76YaI2ow/vc7URwsDU2bokpkRE=
35-
github.com/codeready-toolchain/toolchain-common v0.0.0-20250506093954-2b65ad3a2e12 h1:w54sojJJ8PsHZzK1mC+/EUBrQ9F2sC/k7JUVc8LSqK4=
36-
github.com/codeready-toolchain/toolchain-common v0.0.0-20250506093954-2b65ad3a2e12/go.mod h1:TrMvD0sP69wI6Rouzfs7OsOUSj4CGn/ZiIdiDBAFQjk=
33+
github.com/codeready-toolchain/api v0.0.0-20250909075145-ca043a618f0f h1:IZ3Wq4iC0765HP369U3+08NFb0rK/NJCKfRjj8OdPVo=
34+
github.com/codeready-toolchain/api v0.0.0-20250909075145-ca043a618f0f/go.mod h1:20258od6i5+jP406Z76YaI2ow/vc7URwsDU2bokpkRE=
35+
github.com/codeready-toolchain/toolchain-common v0.0.0-20250910131836-b410cd4ca53d h1:wu30udLhwynhfb5w+G+fKjsQfn0hW18llOjh0ZYh62c=
36+
github.com/codeready-toolchain/toolchain-common v0.0.0-20250910131836-b410cd4ca53d/go.mod h1:nQ2naidFtgGv+BofbwsiZWvQLdQ2O9ICR2uxf67oYmA=
3737
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
3838
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3939
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

test/e2e/parallel/registration_service_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,32 @@ func TestSignupOK(t *testing.T) {
468468
// Re-activate the usersignup by calling the signup endpoint with the same token/user again
469469
signupUser(token, emailAddress, identity.Username, identity)
470470
})
471+
472+
t.Run("test get signup returns expected response", func(t *testing.T) {
473+
// Get valid generated token for e2e tests.
474+
emailAddress := uuid.Must(uuid.NewV4()).String() + "@acme.com"
475+
identity, token, err := authsupport.NewToken(authsupport.WithEmail(emailAddress), commonauth.WithUserIDClaim("123"), commonauth.WithAccountIDClaim("456"), commonauth.WithAccountNumberClaim("789"))
476+
require.NoError(t, err)
477+
478+
// Signup a new user
479+
userSignup := signupUser(token, emailAddress, identity.Username, identity)
480+
481+
t.Logf("Signed up new user %+v", userSignup)
482+
483+
// call GET /signup and verify expected response body fields are there
484+
now := time.Now()
485+
NewGetSignupClient(t, await, identity.Username, token).Invoke(signupIsProvisioned,
486+
signupHasExpectedDates(now, now.Add(time.Hour*24*30)),
487+
signupHasExpectedClaims(map[string]string{
488+
"name": userSignup.Name,
489+
"username": userSignup.Spec.IdentityClaims.PreferredUsername,
490+
"givenName": userSignup.Spec.IdentityClaims.GivenName,
491+
"familyName": userSignup.Spec.IdentityClaims.FamilyName,
492+
"userID": "123",
493+
"accountID": "456",
494+
"accountNumber": "789",
495+
}))
496+
})
471497
}
472498

473499
func TestUserSignupFoundWhenNamedWithEncodedUsername(t *testing.T) {
@@ -1005,6 +1031,16 @@ func signupHasExpectedDates(startDate, endDate time.Time) func(c *GetSignupClien
10051031
}
10061032
}
10071033

1034+
func signupHasExpectedClaims(claims map[string]string) func(c *GetSignupClient) {
1035+
return func(c *GetSignupClient) {
1036+
for expectedClaim, expectedClaimValue := range claims {
1037+
actualClaimValue, claimFound := c.responseBody[expectedClaim]
1038+
require.True(c.t, claimFound, "unable to find expected claim [%s]. Claims found %v", expectedClaim, claims)
1039+
require.Equal(c.t, expectedClaimValue, actualClaimValue, "expected claim value [%s] doesn't match actual claim value [%s]", expectedClaimValue, actualClaimValue)
1040+
}
1041+
}
1042+
}
1043+
10081044
func signupIsProvisioned(client *GetSignupClient) {
10091045
hostAwait := client.await.Host()
10101046
memberAwait := client.await.Member1()

test/e2e/usersignup_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ func (s *userSignupIntegrationTest) TestGetSignupEndpointUpdatesIdentityClaims()
356356
IdentityID(id).
357357
UserID("000999").
358358
AccountID("111999").
359+
AccountNumber("4242").
359360
EnsureMUR().
360361
RequireConditions(wait.ConditionSet(wait.Default(), wait.ApprovedAutomatically())...).
361362
Execute(s.T())
@@ -376,6 +377,7 @@ func (s *userSignupIntegrationTest) TestGetSignupEndpointUpdatesIdentityClaims()
376377
claims = append(claims, commonauth.WithGivenNameClaim("Jane"))
377378
claims = append(claims, commonauth.WithFamilyNameClaim("Turner"))
378379
claims = append(claims, commonauth.WithCompanyClaim("Acme"))
380+
claims = append(claims, commonauth.WithAccountNumberClaim("2222"))
379381

380382
token, err := authsupport.NewTokenFromIdentity(userIdentity, claims...)
381383
require.NoError(s.T(), err)
@@ -394,6 +396,7 @@ func (s *userSignupIntegrationTest) TestGetSignupEndpointUpdatesIdentityClaims()
394396
require.Equal(s.T(), "Jane", userSignup.Spec.IdentityClaims.GivenName)
395397
require.Equal(s.T(), "Turner", userSignup.Spec.IdentityClaims.FamilyName)
396398
require.Equal(s.T(), "Acme", userSignup.Spec.IdentityClaims.Company)
399+
require.Equal(s.T(), "2222", userSignup.Spec.IdentityClaims.AccountNumber)
397400
}
398401

399402
// TestUserResourcesCreatedWhenOriginalSubIsSet tests the case where:

testsupport/signup_request.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ type SignupRequest struct {
5353
originalSub string
5454
userID string
5555
accountID string
56+
accountNumber string
5657
cleanupDisabled bool
5758
noSpace bool
5859
activationCode string
@@ -115,6 +116,11 @@ func (r *SignupRequest) AccountID(accountID string) *SignupRequest {
115116
return r
116117
}
117118

119+
func (r *SignupRequest) AccountNumber(accountNumber string) *SignupRequest {
120+
r.accountNumber = accountNumber
121+
return r
122+
}
123+
118124
// EnsureMUR will ensure that a MasterUserRecord is created. It is necessary to call this function in order for
119125
// the Execute function to return a non-nil value for its second return parameter.
120126
func (r *SignupRequest) EnsureMUR() *SignupRequest {
@@ -232,6 +238,9 @@ func (r *SignupRequest) Execute(t *testing.T) *SignupResult {
232238
if r.accountID != "" {
233239
claims = append(claims, commonauth.WithAccountIDClaim(r.accountID))
234240
}
241+
if r.accountNumber != "" {
242+
claims = append(claims, commonauth.WithAccountNumberClaim(r.accountNumber))
243+
}
235244
r.token, err = authsupport.NewTokenFromIdentity(userIdentity, claims...)
236245
require.NoError(t, err)
237246

0 commit comments

Comments
 (0)