MCPcopy Index your code
hub / github.com/coder/coder / TestExternalAuth

Function TestExternalAuth

cli/externalauth_test.go:16–80  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestExternalAuth(t *testing.T) {
17 t.Parallel()
18 t.Run("CanceledWithURL", func(t *testing.T) {
19 t.Parallel()
20 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
21 httpapi.Write(context.Background(), w, http.StatusOK, agentsdk.ExternalAuthResponse{
22 URL: "https://github.com",
23 })
24 }))
25 t.Cleanup(srv.Close)
26 url := srv.URL
27 inv, _ := clitest.New(t, "--agent-url", url, "--agent-token", "foo", "external-auth", "access-token", "github")
28 pty := ptytest.New(t)
29 inv.Stdout = pty.Output()
30 waiter := clitest.StartWithWaiter(t, inv)
31 pty.ExpectMatch("https://github.com")
32 waiter.RequireIs(cliui.ErrCanceled)
33 })
34 t.Run("SuccessWithToken", func(t *testing.T) {
35 t.Parallel()
36 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
37 httpapi.Write(context.Background(), w, http.StatusOK, agentsdk.ExternalAuthResponse{
38 AccessToken: "bananas",
39 })
40 }))
41 t.Cleanup(srv.Close)
42 url := srv.URL
43 inv, _ := clitest.New(t, "--agent-url", url, "--agent-token", "foo", "external-auth", "access-token", "github")
44 pty := ptytest.New(t)
45 inv.Stdout = pty.Output()
46 clitest.Start(t, inv)
47 pty.ExpectMatch("bananas")
48 })
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, "--agent-token", "foo", "external-auth", "access-token")
59 watier := clitest.StartWithWaiter(t, inv)
60 watier.RequireContains("wanted 1 args but got 0")
61 })
62 t.Run("SuccessWithExtra", func(t *testing.T) {
63 t.Parallel()
64 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
65 httpapi.Write(context.Background(), w, http.StatusOK, agentsdk.ExternalAuthResponse{
66 AccessToken: "bananas",
67 TokenExtra: map[string]interface{}{
68 "hey": "there",
69 },
70 })
71 }))
72 t.Cleanup(srv.Close)
73 url := srv.URL

Callers

nothing calls this directly

Calls 11

WriteFunction · 0.92
NewFunction · 0.92
NewFunction · 0.92
StartWithWaiterFunction · 0.92
StartFunction · 0.92
RequireIsMethod · 0.80
RequireContainsMethod · 0.80
RunMethod · 0.65
CleanupMethod · 0.65
OutputMethod · 0.65
ExpectMatchMethod · 0.45

Tested by

no test coverage detected