(t *testing.T)
| 185 | } |
| 186 | |
| 187 | func TestAuthenticateDeviceFlow(t *testing.T) { |
| 188 | f := newFakeGitHub(t) |
| 189 | f.deviceToken = "gho_device_token" |
| 190 | m := newManager(t, f) |
| 191 | // Inside Docker with a random port, PKCE is impossible, so the device flow |
| 192 | // is selected. |
| 193 | m.inDocker = func() bool { return true } |
| 194 | m.openURL = func(string) error { return errors.New("no browser") } |
| 195 | |
| 196 | prompter := &fakePrompter{urlCapable: true} // shows the code, no action needed |
| 197 | |
| 198 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 199 | defer cancel() |
| 200 | |
| 201 | out, err := m.Authenticate(ctx, prompter) |
| 202 | require.NoError(t, err) |
| 203 | assert.Nil(t, out) |
| 204 | assert.Equal(t, "gho_device_token", m.AccessToken()) |
| 205 | assert.Contains(t, f.recordedGrants(), "urn:ietf:params:oauth:grant-type:device_code") |
| 206 | } |
| 207 | |
| 208 | func TestAuthenticateDevicePollingPending(t *testing.T) { |
| 209 | f := newFakeGitHub(t) |
nothing calls this directly
no test coverage detected