Skip to content

Commit 7d1216c

Browse files
author
Devtools
committed
handle account_number
1 parent 4e4b0b2 commit 7d1216c

File tree

5 files changed

+31
-3
lines changed

5 files changed

+31
-3
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ require (
2626
)
2727

2828
require (
29-
github.com/codeready-toolchain/api v0.0.0-20250506092100-39b4862e1271
29+
github.com/codeready-toolchain/api v0.0.0-20250909075145-ca043a618f0f
3030
github.com/ghodss/yaml v1.0.0
3131
github.com/google/go-cmp v0.6.0
3232
github.com/google/go-github/v52 v52.0.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk
2727
github.com/cloudflare/circl v1.1.0/go.mod h1:prBCrKB9DV4poKZY1l9zBXg2QJY7mvgRvtMxxK7fi4I=
2828
github.com/cloudflare/circl v1.6.1 h1:zqIqSPIndyBh1bjLVVDHMPpVKqp8Su/V+6MeDzzQBQ0=
2929
github.com/cloudflare/circl v1.6.1/go.mod h1:uddAzsPgqdMAYatqJ0lsjX1oECcQLIlRpzZh3pJrofs=
30-
github.com/codeready-toolchain/api v0.0.0-20250506092100-39b4862e1271 h1:AHrFr/aPuJ4+0zHw4sFXcfMA92kChy12JAPS5bLODlw=
31-
github.com/codeready-toolchain/api v0.0.0-20250506092100-39b4862e1271/go.mod h1:20258od6i5+jP406Z76YaI2ow/vc7URwsDU2bokpkRE=
30+
github.com/codeready-toolchain/api v0.0.0-20250909075145-ca043a618f0f h1:IZ3Wq4iC0765HP369U3+08NFb0rK/NJCKfRjj8OdPVo=
31+
github.com/codeready-toolchain/api v0.0.0-20250909075145-ca043a618f0f/go.mod h1:20258od6i5+jP406Z76YaI2ow/vc7URwsDU2bokpkRE=
3232
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
3333
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3434
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

pkg/test/auth/tokenmanager.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,13 @@ func WithAccountIDClaim(accountID string) ExtraClaim {
151151
}
152152
}
153153

154+
// WithAccountNumberClaim sets the `account_number` claim in the token to generate
155+
func WithAccountNumberClaim(accountNumber string) ExtraClaim {
156+
return func(token *jwt.Token) {
157+
token.Claims.(*MyClaims).AccountNumber = accountNumber
158+
}
159+
}
160+
154161
// WithAudClaim sets the `aud` claim in the token to generate
155162
func WithAudClaim(aud []string) ExtraClaim {
156163
return func(token *jwt.Token) {
@@ -234,6 +241,7 @@ type MyClaims struct {
234241
OriginalSub string `json:"original_sub"`
235242
UserID string `json:"user_id"`
236243
AccountID string `json:"account_id"`
244+
AccountNumber string `json:"account_number,omitempty"`
237245
}
238246

239247
// GenerateToken generates a default token.

pkg/test/auth/tokenmanager_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,25 @@ func TestTokenManagerTokens(t *testing.T) {
356356
require.True(t, ok)
357357
require.Equal(t, "987654321", claims.AccountID)
358358
})
359+
t.Run("create token with account_number extra claim", func(t *testing.T) {
360+
username := uuid.NewString()
361+
identity0 := &Identity{
362+
ID: uuid.New(),
363+
Username: username,
364+
}
365+
// generate the token
366+
encodedToken, err := tokenManager.GenerateSignedToken(*identity0, kid0, WithAccountNumberClaim("987654320"))
367+
require.NoError(t, err)
368+
// unmarshall it again
369+
decodedToken, err := jwt.ParseWithClaims(encodedToken, &MyClaims{}, func(token *jwt.Token) (interface{}, error) {
370+
return &(key0.PublicKey), nil
371+
})
372+
require.NoError(t, err)
373+
require.True(t, decodedToken.Valid)
374+
claims, ok := decodedToken.Claims.(*MyClaims)
375+
require.True(t, ok)
376+
require.Equal(t, "987654320", claims.AccountNumber)
377+
})
359378
}
360379

361380
func TestTokenManagerKeyService(t *testing.T) {

pkg/test/usersignup/usersignup.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ func NewUserSignup(modifiers ...Modifier) *toolchainv1alpha1.UserSignup {
281281
GivenName: "Foo",
282282
FamilyName: "Bar",
283283
Company: "Red Hat",
284+
AccountNumber: "4242",
284285
},
285286
},
286287
}

0 commit comments

Comments
 (0)