-
Notifications
You must be signed in to change notification settings - Fork 889
feat: Login via CLI #298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: Login via CLI #298
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
6c50b85
Create initial route for generating an API key
bryphe-coder fe55c73
Add cli-auth page
bryphe-coder 3bb3164
Fix lint warnings
bryphe-coder 9ec938e
Add login prompt for non-first-time-user case
bryphe-coder 87fc9e2
Add test case for login
bryphe-coder 6607a5a
Factor out CliAuth token component
bryphe-coder 0e323ce
Add storybook for CliAuthToken
bryphe-coder a33d2c7
Merge main
bryphe-coder 9cc7e94
Add test case for CliAuthToken
bryphe-coder 7774e29
Add codersdk function + test
bryphe-coder 8ea2920
Fix lint issues
bryphe-coder 669f2ca
Discard output of browser pkg
bryphe-coder 0a43941
Merge main
bryphe-coder 5ecba6d
Add mask for session token prompt
bryphe-coder 13696a7
Inline saveSessionToken into both code paths
bryphe-coder dccb009
Move setting browser.Stderr/Stdout to init
bryphe-coder ca1a458
Change route /api-keys -> /users/{user}/keys
bryphe-coder b232d0c
Remove leftover saveSessionToken func
bryphe-coder 0d829b3
Update route in UI for getting new token
bryphe-coder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
@@ -1,11 +1,13 @@ | ||
package cli_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/coder/coder/cli/clitest" | ||
"github.com/coder/coder/coderd" | ||
"github.com/coder/coder/coderd/coderdtest" | ||
"github.com/coder/coder/pty/ptytest" | ||
) | ||
|
@@ -50,4 +52,60 @@ func TestLogin(t *testing.T) { | |
} | ||
pty.ExpectMatch("Welcome to Coder") | ||
}) | ||
|
||
t.Run("ExistingUserValidTokenTTY", func(t *testing.T) { | ||
t.Parallel() | ||
client := coderdtest.New(t) | ||
_, err := client.CreateInitialUser(context.Background(), coderd.CreateInitialUserRequest{ | ||
Username: "test-user", | ||
Email: "[email protected]", | ||
Organization: "acme-corp", | ||
Password: "password", | ||
}) | ||
require.NoError(t, err) | ||
token, err := client.LoginWithPassword(context.Background(), coderd.LoginWithPasswordRequest{ | ||
Email: "[email protected]", | ||
Password: "password", | ||
}) | ||
require.NoError(t, err) | ||
|
||
root, _ := clitest.New(t, "login", client.URL.String(), "--force-tty") | ||
pty := ptytest.New(t) | ||
root.SetIn(pty.Input()) | ||
root.SetOut(pty.Output()) | ||
go func() { | ||
err := root.Execute() | ||
require.NoError(t, err) | ||
}() | ||
|
||
pty.ExpectMatch("Paste your token here:") | ||
pty.WriteLine(token.SessionToken) | ||
pty.ExpectMatch("Welcome to Coder") | ||
}) | ||
|
||
t.Run("ExistingUserInvalidTokenTTY", func(t *testing.T) { | ||
t.Parallel() | ||
client := coderdtest.New(t) | ||
_, err := client.CreateInitialUser(context.Background(), coderd.CreateInitialUserRequest{ | ||
Username: "test-user", | ||
Email: "[email protected]", | ||
Organization: "acme-corp", | ||
Password: "password", | ||
}) | ||
require.NoError(t, err) | ||
|
||
root, _ := clitest.New(t, "login", client.URL.String(), "--force-tty") | ||
pty := ptytest.New(t) | ||
root.SetIn(pty.Input()) | ||
root.SetOut(pty.Output()) | ||
go func() { | ||
err := root.Execute() | ||
// An error is expected in this case, since the login wasn't successful: | ||
require.Error(t, err) | ||
}() | ||
|
||
pty.ExpectMatch("Paste your token here:") | ||
pty.WriteLine("an-invalid-token") | ||
pty.ExpectMatch("That's not a valid token!") | ||
}) | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.