Skip to content

Commit 25e0884

Browse files
committed
cmd/cue: test storing access token expiry in login
`cue login` did this correctly, but our test oauth2 server provided an "expiry" JSON field rather than the "expires_in" field which the oauth2 spec mandates for the wire format. Left another TODO as we don't store the timestamp in UTC at rest. Signed-off-by: Daniel Martí <[email protected]> Change-Id: I453a2690cdf742162510a7b571092f3a853524a5 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1202035 Reviewed-by: Roger Peppe <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
1 parent 791420a commit 25e0884

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

cmd/cue/cmd/script_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ func newMockRegistryOauth(mode string) *httptest.Server {
518518
writeJSON(w, http.StatusOK, oauth2.Token{
519519
AccessToken: staticAccessToken,
520520
TokenType: "Bearer",
521-
Expiry: time.Now().Add(time.Hour),
521+
ExpiresIn: int64(time.Hour / time.Second), // 1h in seconds
522522
})
523523
default:
524524
panic(fmt.Sprintf("unknown mode: %q", mode))

cmd/cue/cmd/testdata/script/login_immediate.txtar

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ grep -count=1 '"access_token"' cueconfig/logins.json
1414
# Ensure the contents of the token look correct.
1515
grep -count=1 '"access_token": "secret-access-token"' cueconfig/logins.json
1616
grep -count=1 '"token_type": "Bearer"' cueconfig/logins.json
17-
# TODO(mvdan): oauthregistry does not provide expires_in correctly.
18-
! grep '"expiry": ' cueconfig/logins.json
17+
# TODO(mvdan): store expiry timestamps in UTC for consistency.
18+
grep '"expiry": "20..-..-..T' cueconfig/logins.json
1919
# oauthregistry does not give a refresh token, and we use encoding/json's omitempty.
2020
! grep '"refresh_token"' cueconfig/logins.json

0 commit comments

Comments
 (0)