Skip to content

Commit 5825bb5

Browse files
committed
test(oidc): reword refresh comments and assert no token on persist failure
Comment wording only, plus a nil-token assertion in TestLogin_RefreshPersistFailure. Part of NVIDIA/OpenShell#4514. Signed-off-by: shvma <[email protected]>
1 parent c4fb70b commit 5825bb5

3 files changed

Lines changed: 18 additions & 18 deletions

File tree

‎openshell/v1/oidc/doc.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
// use them. A later Login reuses the stored token only when it is valid
2727
// and was issued for the gateway's issuer and client ID. If that token has
2828
// expired but carries a refresh token, Login refreshes it and rewrites the
29-
// file instead of prompting.
29+
// file without prompting.
3030
//
3131
// # Standalone Login
3232
//

‎openshell/v1/oidc/refresh.go‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ func lockTokenDir(dir string) func() {
5757
// refreshed is used as is. When the refresh is rejected with invalid_grant,
5858
// the file is read once more: a valid token another process wrote for the
5959
// same issuer and client is used as is, and an expired one with a
60-
// different refresh token is refreshed once with that token. Processes
61-
// do not share a file lock; like the Python SDK, this recovers instead
62-
// of locking. The stored argument only decides whether to try; the file
63-
// read under the lock is what gets refreshed.
60+
// different refresh token is refreshed once with that token. Like the
61+
// Python SDK, it takes no file lock across processes. The stored argument
62+
// only decides whether to try; the file read under the lock is what gets
63+
// refreshed.
6464
//
6565
// In-memory mode does not refresh, since a rotated refresh token that is
6666
// not written back would leave the file holding a revoked one. If the
@@ -199,8 +199,8 @@ func refreshToken(ctx context.Context, tokenEndpoint, clientID, refresh string,
199199
}
200200

201201
// An absent expires_in leaves the token without an expiry, as the code
202-
// exchange does; a present but non-positive one is rejected rather
203-
// than stored as a token that never expires.
202+
// exchange does. A present expires_in must be positive; zero or a
203+
// negative value is rejected as malformed.
204204
var fields map[string]json.RawMessage
205205
_ = json.Unmarshal(body, &fields)
206206
if _, present := fields["expires_in"]; present && tokResp.ExpiresIn <= 0 {

‎openshell/v1/oidc/refresh_test.go‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,8 @@ func TestLogin_RefreshFailureFallsBackToFlow(t *testing.T) {
284284
}
285285

286286
// TestLogin_InMemoryDoesNotRefresh verifies that WithInMemory runs the
287-
// interactive flow instead of refreshing, so a rotated refresh token is
288-
// never lost by not being written back.
287+
// interactive flow without refreshing: a rotated refresh token would not be
288+
// written back, and the file would keep a revoked one.
289289
func TestLogin_InMemoryDoesNotRefresh(t *testing.T) {
290290
resetDiscoveryCache()
291291
provider := newRefreshProvider(t, refreshed)
@@ -324,8 +324,8 @@ func TestLogin_RefreshKeepsClientCredentialsMarker(t *testing.T) {
324324
assert.True(t, readStoredBundle(t, dir).ClientCredentials)
325325
}
326326

327-
// TestLogin_RefreshPersistFailure verifies that Login reports a failure to
328-
// write the refreshed token instead of returning a token the file lacks.
327+
// TestLogin_RefreshPersistFailure verifies that Login returns
328+
// ErrTokenPersist and no token when the refreshed token cannot be written.
329329
func TestLogin_RefreshPersistFailure(t *testing.T) {
330330
if runtime.GOOS == "windows" || os.Geteuid() == 0 {
331331
t.Skip("needs a read-only directory")
@@ -337,8 +337,9 @@ func TestLogin_RefreshPersistFailure(t *testing.T) {
337337
require.NoError(t, os.Chmod(dir, 0o500))
338338
t.Cleanup(func() { _ = os.Chmod(dir, 0o700) })
339339

340-
_, _, err := loginNoPrompt(t, provider.URL, dir)
340+
tok, _, err := loginNoPrompt(t, provider.URL, dir)
341341
require.ErrorIs(t, err, ErrTokenPersist)
342+
assert.Nil(t, tok)
342343
}
343344

344345
// TestRefreshToken_ErrorOmitsRefreshToken verifies that a failed refresh
@@ -473,8 +474,7 @@ func TestLogin_RefreshKeepsStoredIssuerForm(t *testing.T) {
473474
}
474475

475476
// TestLogin_RefreshDiscoveryFailure verifies that Login reports a discovery
476-
// failure without prompting, instead of trying discovery again for the
477-
// interactive flow.
477+
// failure after a single discovery request and without prompting.
478478
func TestLogin_RefreshDiscoveryFailure(t *testing.T) {
479479
resetDiscoveryCache()
480480
var discoveries sync.Mutex
@@ -498,7 +498,7 @@ func TestLogin_RefreshDiscoveryFailure(t *testing.T) {
498498
}
499499

500500
// TestLogin_RefreshContextDeadline verifies that a refresh cut short by the
501-
// caller's deadline returns ErrTimeout instead of starting the flow.
501+
// caller's deadline returns ErrTimeout and does not start the flow.
502502
func TestLogin_RefreshContextDeadline(t *testing.T) {
503503
resetDiscoveryCache()
504504
provider := newRefreshProvider(t, func(form url.Values) (int, string) {
@@ -520,9 +520,9 @@ func TestLogin_RefreshContextDeadline(t *testing.T) {
520520
}
521521

522522
// TestLogin_ConcurrentRefreshSpendsRefreshTokenOnce verifies that
523-
// concurrent Login calls in one process refresh once: the second waits,
524-
// re-reads the file and uses the token the first one wrote, instead of
525-
// replaying a refresh token that a rotating provider has already revoked.
523+
// concurrent Login calls in one process refresh once: the others wait,
524+
// re-read the file and use the token the first one wrote. The mock
525+
// provider rejects a reused refresh token, as a rotating provider does.
526526
func TestLogin_ConcurrentRefreshSpendsRefreshTokenOnce(t *testing.T) {
527527
resetDiscoveryCache()
528528
var used sync.Map

0 commit comments

Comments
 (0)