(t *testing.T)
| 336 | } |
| 337 | |
| 338 | func TestAuthenticatingGitCredentials(t *testing.T) { |
| 339 | // Given we have no host or global credential helpers configured |
| 340 | // And given they have chosen https as their git protocol |
| 341 | // When they choose to authenticate git with their GitHub credentials |
| 342 | // Then gh is configured as their credential helper for that host |
| 343 | ios, _, _, _ := iostreams.Test() |
| 344 | |
| 345 | reg := &httpmock.Registry{} |
| 346 | defer reg.Verify(t) |
| 347 | reg.Register( |
| 348 | httpmock.REST("GET", "api/v3/"), |
| 349 | httpmock.ScopesResponder("repo,read:org")) |
| 350 | reg.Register( |
| 351 | httpmock.GraphQL(`query UserCurrent\b`), |
| 352 | httpmock.StringResponse(`{"data":{"viewer":{ "login": "monalisa" }}}`)) |
| 353 | |
| 354 | opts := &LoginOptions{ |
| 355 | IO: ios, |
| 356 | Config: tinyConfig{}, |
| 357 | HTTPClient: &http.Client{Transport: reg}, |
| 358 | Hostname: "example.com", |
| 359 | Interactive: true, |
| 360 | GitProtocol: "https", |
| 361 | Prompter: &prompter.PrompterMock{ |
| 362 | SelectFunc: func(prompt, _ string, opts []string) (int, error) { |
| 363 | if prompt == "How would you like to authenticate GitHub CLI?" { |
| 364 | return prompter.IndexFor(opts, "Paste an authentication token") |
| 365 | } |
| 366 | return -1, prompter.NoSuchPromptErr(prompt) |
| 367 | }, |
| 368 | AuthTokenFunc: func() (string, error) { |
| 369 | return "ATOKEN", nil |
| 370 | }, |
| 371 | }, |
| 372 | CredentialFlow: &GitCredentialFlow{ |
| 373 | Prompter: &prompter.PrompterMock{ |
| 374 | ConfirmFunc: func(prompt string, _ bool) (bool, error) { |
| 375 | return true, nil |
| 376 | }, |
| 377 | }, |
| 378 | HelperConfig: &gitcredentials.FakeHelperConfig{ |
| 379 | SelfExecutablePath: "/path/to/gh", |
| 380 | Helpers: map[string]gitcredentials.Helper{}, |
| 381 | }, |
| 382 | // Updater not required for this test as we will be setting gh as the helper |
| 383 | }, |
| 384 | } |
| 385 | |
| 386 | require.NoError(t, Login(opts)) |
| 387 | |
| 388 | helper, err := opts.CredentialFlow.HelperConfig.ConfiguredHelper("example.com") |
| 389 | require.NoError(t, err) |
| 390 | require.True(t, helper.IsOurs(), "expected gh to be the configured helper") |
| 391 | } |
| 392 | |
| 393 | func Test_scopesSentence(t *testing.T) { |
| 394 | type args struct { |
nothing calls this directly
no test coverage detected