fix(cli): avoid panic when external auth name isn't provided (#12177)

Fixes https://github.com/coder/coder/issues/10216
This commit is contained in:
Colin Adler
2024-02-15 15:17:16 -06:00
committed by GitHub
parent 4c3d44658d
commit 8a9f59a4bb
2 changed files with 16 additions and 0 deletions
+3
View File
@@ -52,6 +52,9 @@ fi
Command: "coder external-auth access-token slack --extra \"authed_user.id\"",
},
),
Middleware: clibase.Chain(
clibase.RequireNArgs(1),
),
Options: clibase.OptionSet{{
Name: "Extra",
Flag: "extra",
+13
View File
@@ -46,6 +46,19 @@ func TestExternalAuth(t *testing.T) {
clitest.Start(t, inv)
pty.ExpectMatch("bananas")
})
t.Run("NoArgs", func(t *testing.T) {
t.Parallel()
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
httpapi.Write(context.Background(), w, http.StatusOK, agentsdk.ExternalAuthResponse{
AccessToken: "bananas",
})
}))
t.Cleanup(srv.Close)
url := srv.URL
inv, _ := clitest.New(t, "--agent-url", url, "external-auth", "access-token")
watier := clitest.StartWithWaiter(t, inv)
watier.RequireContains("wanted 1 args but got 0")
})
t.Run("SuccessWithExtra", func(t *testing.T) {
t.Parallel()
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {