Skip to content

Commit 4d62eba

Browse files
committed
Fix WithExtra
1 parent f18900c commit 4d62eba

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

coderd/coderdtest/oidctest/idp.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ type FakeIDP struct {
6868
// "Authorized Redirect URLs". This can be used to emulate that.
6969
hookValidRedirectURL func(redirectURL string) error
7070
hookUserInfo func(email string) (jwt.MapClaims, error)
71-
hookExtra func(email string) map[string]interface{}
71+
hookMutateToken func(token map[string]interface{})
7272
fakeCoderd func(req *http.Request) (*http.Response, error)
7373
hookOnRefresh func(email string) error
7474
// Custom authentication for the client. This is useful if you want
@@ -115,9 +115,9 @@ func WithRefresh(hook func(email string) error) func(*FakeIDP) {
115115

116116
// WithExtra returns extra fields that be accessed on the returned Oauth Token.
117117
// These extra fields can override the default fields (id_token, access_token, etc).
118-
func WithExtra(extra func(email string) map[string]interface{}) func(*FakeIDP) {
118+
func WithMutateToken(mutateToken func(token map[string]interface{})) func(*FakeIDP) {
119119
return func(f *FakeIDP) {
120-
f.hookExtra = extra
120+
f.hookMutateToken = mutateToken
121121
}
122122
}
123123

@@ -630,10 +630,8 @@ func (f *FakeIDP) httpHandler(t testing.TB) http.Handler {
630630
"expires_in": int64((time.Minute * 5).Seconds()),
631631
"id_token": f.encodeClaims(t, claims),
632632
}
633-
if f.hookExtra != nil {
634-
for k, v := range f.hookExtra(email) {
635-
token[k] = v
636-
}
633+
if f.hookMutateToken != nil {
634+
f.hookMutateToken(token)
637635
}
638636
// Store the claims for the next refresh
639637
f.refreshIDTokenClaims.Store(refreshToken, claims)

coderd/externalauth/externalauth_test.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,9 @@ func TestRefreshToken(t *testing.T) {
267267
db := dbfake.New()
268268
fake, config, link := setupOauth2Test(t, testConfig{
269269
FakeIDPOpts: []oidctest.FakeIDPOpt{
270-
oidctest.WithExtra(func(email string) map[string]interface{} {
271-
return map[string]interface{}{
272-
"authed_user": map[string]interface{}{
273-
"access_token": "slack-user-token",
274-
},
270+
oidctest.WithMutateToken(func(token map[string]interface{}) {
271+
token["authed_user"] = map[string]interface{}{
272+
"access_token": "slack-user-token",
275273
}
276274
}),
277275
},

0 commit comments

Comments
 (0)