@@ -70,10 +70,7 @@ type FakeIDP struct {
70
70
// Custom authentication for the client. This is useful if you want
71
71
// to test something like PKI auth vs a client_secret.
72
72
hookAuthenticateClient func (t testing.TB , req * http.Request ) (url.Values , error )
73
- // Optional if you want to use a real http network request assuming
74
- // it is not directed to the IDP.
75
- defaultClient * http.Client
76
- serve bool
73
+ serve bool
77
74
}
78
75
79
76
type FakeIDPOpt func (idp * FakeIDP )
@@ -135,8 +132,9 @@ func WithIssuer(issuer string) func(*FakeIDP) {
135
132
}
136
133
137
134
const (
138
- authorizePath = "/oauth2/authorize"
135
+ // nolint:gosec // It thinks this is a secret lol
139
136
tokenPath = "/oauth2/token"
137
+ authorizePath = "/oauth2/authorize"
140
138
keysPath = "/oauth2/keys"
141
139
userInfoPath = "/oauth2/userinfo"
142
140
)
@@ -237,15 +235,15 @@ func (f *FakeIDP) AttemptLogin(t testing.TB, client *codersdk.Client, idTokenCla
237
235
var err error
238
236
239
237
cli := f .HTTPClient (client .HTTPClient )
240
- shallowCpyCli := & ( * cli )
238
+ shallowCpyCli := * cli
241
239
242
240
if shallowCpyCli .Jar == nil {
243
241
shallowCpyCli .Jar , err = cookiejar .New (nil )
244
242
require .NoError (t , err , "failed to create cookie jar" )
245
243
}
246
244
247
245
unauthenticated := codersdk .New (client .URL )
248
- unauthenticated .HTTPClient = shallowCpyCli
246
+ unauthenticated .HTTPClient = & shallowCpyCli
249
247
250
248
return f .LoginWithClient (t , unauthenticated , idTokenClaims , opts ... )
251
249
}
@@ -296,7 +294,7 @@ func (f *FakeIDP) LoginWithClient(t testing.TB, client *codersdk.Client, idToken
296
294
297
295
t .Cleanup (func () {
298
296
if res .Body != nil {
299
- res .Body .Close ()
297
+ _ = res .Body .Close ()
300
298
}
301
299
})
302
300
@@ -326,7 +324,7 @@ func (f *FakeIDP) OIDCCallback(t testing.TB, state string, idTokenClaims jwt.Map
326
324
327
325
t .Cleanup (func () {
328
326
if resp .Body != nil {
329
- resp .Body .Close ()
327
+ _ = resp .Body .Close ()
330
328
}
331
329
})
332
330
return resp , nil
@@ -444,7 +442,7 @@ func (f *FakeIDP) httpHandler(t testing.TB) http.Handler {
444
442
// w/e and clicking "Allow". They will be redirected back to the redirect
445
443
// when this is done.
446
444
mux .Handle (authorizePath , http .HandlerFunc (func (rw http.ResponseWriter , r * http.Request ) {
447
- f .logger .Info (r .Context (), "HTTP Call Authorize " , slog .F ("url" , r .URL .String ()))
445
+ f .logger .Info (r .Context (), "http call authorize " , slog .F ("url" , r .URL .String ()))
448
446
449
447
clientID := r .URL .Query ().Get ("client_id" )
450
448
if ! assert .Equal (t , f .clientID , clientID , "unexpected client_id" ) {
@@ -495,7 +493,7 @@ func (f *FakeIDP) httpHandler(t testing.TB) http.Handler {
495
493
496
494
mux .Handle (tokenPath , http .HandlerFunc (func (rw http.ResponseWriter , r * http.Request ) {
497
495
values , err := f .authenticateOIDCClientRequest (t , r )
498
- f .logger .Info (r .Context (), "HTTP Call Token " ,
496
+ f .logger .Info (r .Context (), "http call token " ,
499
497
slog .Error (err ),
500
498
slog .F ("values" , values .Encode ()),
501
499
)
@@ -508,10 +506,11 @@ func (f *FakeIDP) httpHandler(t testing.TB) http.Handler {
508
506
if ! ok {
509
507
return "unknown"
510
508
}
511
- if _ , ok := email .(string ); ! ok {
509
+ emailStr , ok := email .(string )
510
+ if ! ok {
512
511
return "wrong-type"
513
512
}
514
- return email .( string )
513
+ return emailStr
515
514
}
516
515
517
516
var claims jwt.MapClaims
@@ -593,7 +592,7 @@ func (f *FakeIDP) httpHandler(t testing.TB) http.Handler {
593
592
594
593
mux .Handle (userInfoPath , http .HandlerFunc (func (rw http.ResponseWriter , r * http.Request ) {
595
594
token , err := f .authenticateBearerTokenRequest (t , r )
596
- f .logger .Info (r .Context (), "HTTP Call UserInfo " ,
595
+ f .logger .Info (r .Context (), "http call user info " ,
597
596
slog .Error (err ),
598
597
slog .F ("url" , r .URL .String ()),
599
598
)
@@ -612,7 +611,7 @@ func (f *FakeIDP) httpHandler(t testing.TB) http.Handler {
612
611
}))
613
612
614
613
mux .Handle (keysPath , http .HandlerFunc (func (rw http.ResponseWriter , r * http.Request ) {
615
- f .logger .Info (r .Context (), "HTTP Call Keys " )
614
+ f .logger .Info (r .Context (), "http call keys " )
616
615
set := jose.JSONWebKeySet {
617
616
Keys : []jose.JSONWebKey {
618
617
{
@@ -626,7 +625,7 @@ func (f *FakeIDP) httpHandler(t testing.TB) http.Handler {
626
625
}))
627
626
628
627
mux .NotFound (func (rw http.ResponseWriter , r * http.Request ) {
629
- f .logger .Error (r .Context (), "HTTP Call NotFound " , slog .F ("path" , r .URL .Path ))
628
+ f .logger .Error (r .Context (), "http call not found " , slog .F ("path" , r .URL .Path ))
630
629
t .Errorf ("unexpected request to IDP at path %q. Not supported" , r .URL .Path )
631
630
})
632
631
0 commit comments