Skip to content

Commit 8a9f59a

Browse files
authored
fix(cli): avoid panic when external auth name isn't provided (#12177)
Fixes #10216
1 parent 4c3d446 commit 8a9f59a

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

cli/externalauth.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ fi
5252
Command: "coder external-auth access-token slack --extra \"authed_user.id\"",
5353
},
5454
),
55+
Middleware: clibase.Chain(
56+
clibase.RequireNArgs(1),
57+
),
5558
Options: clibase.OptionSet{{
5659
Name: "Extra",
5760
Flag: "extra",

cli/externalauth_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,19 @@ func TestExternalAuth(t *testing.T) {
4646
clitest.Start(t, inv)
4747
pty.ExpectMatch("bananas")
4848
})
49+
t.Run("NoArgs", func(t *testing.T) {
50+
t.Parallel()
51+
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
52+
httpapi.Write(context.Background(), w, http.StatusOK, agentsdk.ExternalAuthResponse{
53+
AccessToken: "bananas",
54+
})
55+
}))
56+
t.Cleanup(srv.Close)
57+
url := srv.URL
58+
inv, _ := clitest.New(t, "--agent-url", url, "external-auth", "access-token")
59+
watier := clitest.StartWithWaiter(t, inv)
60+
watier.RequireContains("wanted 1 args but got 0")
61+
})
4962
t.Run("SuccessWithExtra", func(t *testing.T) {
5063
t.Parallel()
5164
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

0 commit comments

Comments
 (0)