(t *testing.T)
| 572 | } |
| 573 | |
| 574 | func TestAuthenticatingGitCredentials(t *testing.T) { |
| 575 | // Given we have no host or global credential helpers configured |
| 576 | // And given they have chosen https as their git protocol |
| 577 | // When they choose to authenticate git with their GitHub credentials |
| 578 | // Then gh is configured as their credential helper for that host |
| 579 | ios, _, _, _ := iostreams.Test() |
| 580 | |
| 581 | reg := &httpmock.Registry{} |
| 582 | defer reg.Verify(t) |
| 583 | reg.Register( |
| 584 | httpmock.REST("GET", "api/v3/"), |
| 585 | httpmock.ScopesResponder("repo,read:org")) |
| 586 | reg.Register( |
| 587 | httpmock.GraphQL(`query UserCurrent\b`), |
| 588 | httpmock.StringResponse(`{"data":{"viewer":{ "login": "monalisa" }}}`)) |
| 589 | |
| 590 | opts := &LoginOptions{ |
| 591 | IO: ios, |
| 592 | Config: tinyConfig{}, |
| 593 | HTTPClient: &http.Client{Transport: reg}, |
| 594 | Hostname: "example.com", |
| 595 | Interactive: true, |
| 596 | GitProtocol: "https", |
| 597 | Prompter: &prompter.PrompterMock{ |
| 598 | SelectFunc: func(prompt, _ string, opts []string) (int, error) { |
| 599 | if prompt == "How would you like to authenticate GitHub CLI?" { |
| 600 | return prompter.IndexFor(opts, "Paste an authentication token") |
| 601 | } |
| 602 | return -1, prompter.NoSuchPromptErr(prompt) |
| 603 | }, |
| 604 | AuthTokenFunc: func() (string, error) { |
| 605 | return "ATOKEN", nil |
| 606 | }, |
| 607 | }, |
| 608 | CredentialFlow: &GitCredentialFlow{ |
| 609 | Prompter: &prompter.PrompterMock{ |
| 610 | ConfirmFunc: func(prompt string, _ bool) (bool, error) { |
| 611 | return true, nil |
| 612 | }, |
| 613 | }, |
| 614 | HelperConfig: &gitcredentials.FakeHelperConfig{ |
| 615 | SelfExecutablePath: "/path/to/gh", |
| 616 | Helpers: map[string]gitcredentials.Helper{}, |
| 617 | }, |
| 618 | // Updater not required for this test as we will be setting gh as the helper |
| 619 | }, |
| 620 | } |
| 621 | |
| 622 | require.NoError(t, Login(opts)) |
| 623 | |
| 624 | helper, err := opts.CredentialFlow.HelperConfig.ConfiguredHelper("example.com") |
| 625 | require.NoError(t, err) |
| 626 | require.True(t, helper.IsOurs(), "expected gh to be the configured helper") |
| 627 | } |
| 628 | |
| 629 | func TestLogin_pastedTokenIgnoresConfiguredExpiringPreference(t *testing.T) { |
| 630 | // A config-derived expiring preference must not leak into a login where the user pastes a token, which can never |
nothing calls this directly
no test coverage detected