Skip to content

Commit

Permalink
cmd/cue: test storing access token expiry in login
Browse files Browse the repository at this point in the history
`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]>
  • Loading branch information
mvdan committed Oct 1, 2024
1 parent 791420a commit 25e0884
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/cue/cmd/script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ func newMockRegistryOauth(mode string) *httptest.Server {
writeJSON(w, http.StatusOK, oauth2.Token{
AccessToken: staticAccessToken,
TokenType: "Bearer",
Expiry: time.Now().Add(time.Hour),
ExpiresIn: int64(time.Hour / time.Second), // 1h in seconds
})
default:
panic(fmt.Sprintf("unknown mode: %q", mode))
Expand Down
4 changes: 2 additions & 2 deletions cmd/cue/cmd/testdata/script/login_immediate.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ grep -count=1 '"access_token"' cueconfig/logins.json
# Ensure the contents of the token look correct.
grep -count=1 '"access_token": "secret-access-token"' cueconfig/logins.json
grep -count=1 '"token_type": "Bearer"' cueconfig/logins.json
# TODO(mvdan): oauthregistry does not provide expires_in correctly.
! grep '"expiry": ' cueconfig/logins.json
# TODO(mvdan): store expiry timestamps in UTC for consistency.
grep '"expiry": "20..-..-..T' cueconfig/logins.json
# oauthregistry does not give a refresh token, and we use encoding/json's omitempty.
! grep '"refresh_token"' cueconfig/logins.json

0 comments on commit 25e0884

Please sign in to comment.