Skip to content

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 19 commits into from
Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge main
  • Loading branch information
bryphe-coder committed Feb 17, 2022
commit 0a43941d3bd030883d6d0d480b4b2f0674841de9
2 changes: 1 addition & 1 deletion cli/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func login() *cobra.Command {
},
})
if err != nil {
return xerrors.Errorf("specify email prompt: %w", err)
return xerrors.Errorf("paste token prompt: %w", err)
}

err = saveSessionToken(cmd, client, apiKey, serverURL)
Expand Down
29 changes: 14 additions & 15 deletions cli/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/coder/coder/cli/clitest"
"github.com/coder/coder/coderd"
"github.com/coder/coder/coderd/coderdtest"
"github.com/coder/coder/console"
"github.com/coder/coder/pty/ptytest"
)

func TestLogin(t *testing.T) {
Expand Down Expand Up @@ -70,18 +70,17 @@ func TestLogin(t *testing.T) {
require.NoError(t, err)

root, _ := clitest.New(t, "login", client.URL.String(), "--force-tty")
cons := console.New(t, root)
pty := ptytest.New(t)
root.SetIn(pty.Input())
root.SetOut(pty.Output())
go func() {
err := root.Execute()
require.NoError(t, err)
}()

_, err = cons.ExpectString("Paste your token here:")
require.NoError(t, err)
_, err = cons.SendLine(token.SessionToken)
require.NoError(t, err)
_, err = cons.ExpectString("Welcome to Coder")
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) {
Expand All @@ -96,17 +95,17 @@ func TestLogin(t *testing.T) {
require.NoError(t, err)

root, _ := clitest.New(t, "login", client.URL.String(), "--force-tty")
cons := console.New(t, root)
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)
}()

_, err = cons.ExpectString("Paste your token here:")
require.NoError(t, err)
_, err = cons.SendLine("an-invalid-token")
require.NoError(t, err)
_, err = cons.ExpectString("That's not a valid token!")
require.NoError(t, err)
pty.ExpectMatch("Paste your token here:")
pty.WriteLine("an-invalid-token")
pty.ExpectMatch("That's not a valid token!")
})
}
1 change: 1 addition & 0 deletions cli/workspacecreate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/coder/coder/coderd/coderdtest"
"github.com/coder/coder/provisioner/echo"
"github.com/coder/coder/provisionersdk/proto"
"github.com/coder/coder/pty/ptytest"
)

func TestWorkspaceCreate(t *testing.T) {
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.