(t *testing.T)
| 20 | ) |
| 21 | |
| 22 | func TestGitAskpass(t *testing.T) { |
| 23 | t.Parallel() |
| 24 | t.Run("UsernameAndPassword", func(t *testing.T) { |
| 25 | t.Parallel() |
| 26 | srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 27 | httpapi.Write(context.Background(), w, http.StatusOK, agentsdk.ExternalAuthResponse{ |
| 28 | Username: "something", |
| 29 | Password: "bananas", |
| 30 | }) |
| 31 | })) |
| 32 | t.Cleanup(srv.Close) |
| 33 | url := srv.URL |
| 34 | inv, _ := clitest.New(t, "--agent-url", url, "Username for 'https://github.com':") |
| 35 | inv.Environ.Set("GIT_PREFIX", "/") |
| 36 | inv.Environ.Set("CODER_AGENT_TOKEN", "fake-token") |
| 37 | pty := ptytest.New(t) |
| 38 | inv.Stdout = pty.Output() |
| 39 | clitest.Start(t, inv) |
| 40 | pty.ExpectMatch("something") |
| 41 | |
| 42 | inv, _ = clitest.New(t, "--agent-url", url, "Password for 'https://potato@github.com':") |
| 43 | inv.Environ.Set("GIT_PREFIX", "/") |
| 44 | inv.Environ.Set("CODER_AGENT_TOKEN", "fake-token") |
| 45 | pty = ptytest.New(t) |
| 46 | inv.Stdout = pty.Output() |
| 47 | clitest.Start(t, inv) |
| 48 | pty.ExpectMatch("bananas") |
| 49 | }) |
| 50 | |
| 51 | t.Run("NoHost", func(t *testing.T) { |
| 52 | t.Parallel() |
| 53 | srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 54 | httpapi.Write(context.Background(), w, http.StatusNotFound, codersdk.Response{ |
| 55 | Message: "Nope!", |
| 56 | }) |
| 57 | })) |
| 58 | t.Cleanup(srv.Close) |
| 59 | url := srv.URL |
| 60 | inv, _ := clitest.New(t, "--agent-url", url, "--no-open", "Username for 'https://github.com':") |
| 61 | inv.Environ.Set("GIT_PREFIX", "/") |
| 62 | inv.Environ.Set("CODER_AGENT_TOKEN", "fake-token") |
| 63 | pty := ptytest.New(t) |
| 64 | inv.Stderr = pty.Output() |
| 65 | err := inv.Run() |
| 66 | require.ErrorIs(t, err, cliui.ErrCanceled) |
| 67 | pty.ExpectMatch("Nope!") |
| 68 | }) |
| 69 | |
| 70 | t.Run("Poll", func(t *testing.T) { |
| 71 | t.Parallel() |
| 72 | ctx := testutil.Context(t, testutil.WaitShort) |
| 73 | resp := atomic.Pointer[agentsdk.ExternalAuthResponse]{} |
| 74 | resp.Store(&agentsdk.ExternalAuthResponse{ |
| 75 | URL: "https://something.org", |
| 76 | }) |
| 77 | poll := make(chan struct{}, 10) |
| 78 | srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 79 | val := resp.Load() |
nothing calls this directly
no test coverage detected