Skip to content

Commit 3be7d31

Browse files
committed
Fix comments
1 parent dffeb16 commit 3be7d31

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

coderd/coderdtest/oidctest/helper.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ func (h *LoginHelper) ExpireOauthToken(t *testing.T, db database.Store, user *co
6767
})
6868
require.NoError(t, err, "get user link")
6969

70-
// Fetch the oauth link for the given user.
70+
// Expire the oauth link for the given user.
7171
_, err = db.UpdateUserLink(ctx, database.UpdateUserLinkParams{
7272
OAuthAccessToken: link.OAuthAccessToken,
7373
OAuthRefreshToken: link.OAuthRefreshToken,
7474
OAuthExpiry: time.Now().Add(time.Hour * -1),
75-
UserID: key.UserID,
76-
LoginType: database.LoginTypeOIDC,
75+
UserID: link.UserID,
76+
LoginType: link.LoginType,
7777
})
7878
require.NoError(t, err, "expire user link")
7979

coderd/coderdtest/oidctest/idp.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func NewFakeIDP(t testing.TB, opts ...FakeIDPOpt) *FakeIDP {
149149

150150
idp.updateIssuerURL(t, idp.issuer)
151151
if idp.serve {
152-
idp.Serve(t)
152+
idp.realServer(t)
153153
}
154154

155155
return idp
@@ -176,8 +176,8 @@ func (f *FakeIDP) updateIssuerURL(t testing.TB, issuer string) {
176176
}
177177
}
178178

179-
// Serve is optional, but turns the FakeIDP into a real http server.
180-
func (f *FakeIDP) Serve(t testing.TB) *httptest.Server {
179+
// realServer turns the FakeIDP into a real http server.
180+
func (f *FakeIDP) realServer(t testing.TB) *httptest.Server {
181181
t.Helper()
182182

183183
ctx, cancel := context.WithCancel(context.Background())
@@ -222,14 +222,14 @@ func (f *FakeIDP) AttemptLogin(t testing.TB, client *codersdk.Client, idTokenCla
222222
unauthenticated := codersdk.New(client.URL)
223223
unauthenticated.HTTPClient = shallowCpyCli
224224

225-
return f.LoginClient(t, unauthenticated, idTokenClaims, opts...)
225+
return f.LoginWithClient(t, unauthenticated, idTokenClaims, opts...)
226226
}
227227

228-
// LoginClient reuses the context of the passed in client. This means the same
228+
// LoginWithClient reuses the context of the passed in client. This means the same
229229
// cookies will be used. This should be an unauthenticated client in most cases.
230230
//
231231
// This is a niche case, but it is needed for testing ConvertLoginType.
232-
func (f *FakeIDP) LoginClient(t testing.TB, client *codersdk.Client, idTokenClaims jwt.MapClaims, opts ...func(r *http.Request)) (*codersdk.Client, *http.Response) {
232+
func (f *FakeIDP) LoginWithClient(t testing.TB, client *codersdk.Client, idTokenClaims jwt.MapClaims, opts ...func(r *http.Request)) (*codersdk.Client, *http.Response) {
233233
t.Helper()
234234

235235
coderOauthURL, err := client.URL.Parse("/api/v2/users/oidc/callback")
@@ -285,6 +285,10 @@ func (f *FakeIDP) LoginClient(t testing.TB, client *codersdk.Client, idTokenClai
285285
// The flow starts at the user hitting the OIDC login page.
286286
func (f *FakeIDP) OIDCCallback(t testing.TB, state string, idTokenClaims jwt.MapClaims) (*http.Response, error) {
287287
t.Helper()
288+
if f.serve {
289+
panic("cannot use OIDCCallback with WithServing. This is only for the in memory usage")
290+
}
291+
288292
f.stateToIDTokenClaims.Store(state, idTokenClaims)
289293

290294
cli := f.HTTPClient(nil)

coderd/userauth_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ func TestUserOIDC(t *testing.T) {
881881
})
882882
require.NoError(t, err)
883883

884-
fake.LoginClient(t, user, claims, func(r *http.Request) {
884+
fake.LoginWithClient(t, user, claims, func(r *http.Request) {
885885
r.URL.RawQuery = url.Values{
886886
"oidc_merge_state": {convertResponse.StateString},
887887
}.Encode()

0 commit comments

Comments
 (0)