-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/cue: fix "login" on a clean environment, and add tests
`cue login` broke as it treated a missing $CUE_CONFIG_DIR/logins.cue as a fatal error, which is bad as new users are in this situation. We never noticed as we didn't have integration tests for this command. Write the first integration tests with a mock httptest server which only implements the two OAuth2 endpoints with simple logic. Rather than having to write the testscripts to emulate a user going to the /login/device page to insert the user_code string, run the oauth registry in various modes with predefined behaviors. Note that I had to teach `cue login` to perform the OAuth2 device flow over HTTP rather than HTTPS when using an insecure CUE registry. This required changing the AllHosts method from returning []string, which was done to avoid exposing the Host type, to returning []Host. Both the Oauth2 config and the logins.json transport are updated. Fixes #2925. Signed-off-by: Daniel Martí <[email protected]> Change-Id: Ib793fb73c921cd68038645d072271fbe9e8ee0ec Dispatch-Trailer: {"type":"trybot","CL":1178176,"patchset":2,"ref":"refs/changes/76/1178176/2","targetBranch":"master"}
- Loading branch information
Showing
8 changed files
with
172 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Test that `cue login` fails when given an error | ||
# such as a device_code being expired. | ||
|
||
env CUE_CONFIG_DIR=$WORK/cueconfig | ||
oauthregistry device-code-expired | ||
|
||
! exec cue login | ||
stdout 'open:.*user_code=user-code' | ||
stderr 'cannot obtain the OAuth2 token.*expired_token' | ||
! exists cueconfig/logins.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Test that `cue login` succeeds with the device flow | ||
# when the device login is immediately authorized and successful. | ||
|
||
env CUE_CONFIG_DIR=$WORK/cueconfig | ||
oauthregistry immediate-success | ||
|
||
exec cue login | ||
stdout 'open:.*user_code=user-code' | ||
grep 'secret-access-token' cueconfig/logins.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Test that `cue login` succeeds with the device flow | ||
# when the device login is authorized after the first polling request. | ||
|
||
env CUE_CONFIG_DIR=$WORK/cueconfig | ||
oauthregistry pending-success | ||
|
||
exec cue login | ||
stdout 'open:.*user_code=user-code' | ||
grep 'secret-access-token' cueconfig/logins.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters