(t *testing.T)
| 591 | } |
| 592 | |
| 593 | func TestAuthenticatingGitCredentials(t *testing.T) { |
| 594 | // Given we have no host or global credential helpers configured |
| 595 | // And given they have chosen https as their git protocol |
| 596 | // When they choose to authenticate git with their GitHub credentials |
| 597 | // Then gh is configured as their credential helper for that host |
| 598 | ios, _, _, _ := iostreams.Test() |
| 599 | |
| 600 | reg := &httpmock.Registry{} |
| 601 | defer reg.Verify(t) |
| 602 | reg.Register( |
| 603 | httpmock.REST("GET", "api/v3/"), |
| 604 | httpmock.ScopesResponder("repo,read:org")) |
| 605 | reg.Register( |
| 606 | httpmock.GraphQL(`query UserCurrent\b`), |
| 607 | httpmock.StringResponse(`{"data":{"viewer":{ "login": "monalisa" }}}`)) |
| 608 | |
| 609 | opts := &LoginOptions{ |
| 610 | IO: ios, |
| 611 | Config: tinyConfig{}, |
| 612 | HTTPClient: &http.Client{Transport: reg}, |
| 613 | Hostname: "example.com", |
| 614 | Interactive: true, |
| 615 | GitProtocol: "https", |
| 616 | Prompter: &prompter.PrompterMock{ |
| 617 | SelectFunc: func(prompt, _ string, opts []string) (int, error) { |
| 618 | if prompt == "How would you like to authenticate GitHub CLI?" { |
| 619 | return prompter.IndexFor(opts, "Paste an authentication token") |
| 620 | } |
| 621 | return -1, prompter.NoSuchPromptErr(prompt) |
| 622 | }, |
| 623 | AuthTokenFunc: func() (string, error) { |
| 624 | return "ATOKEN", nil |
| 625 | }, |
| 626 | }, |
| 627 | CredentialFlow: &GitCredentialFlow{ |
| 628 | Prompter: &prompter.PrompterMock{ |
| 629 | ConfirmFunc: func(prompt string, _ bool) (bool, error) { |
| 630 | return true, nil |
| 631 | }, |
| 632 | }, |
| 633 | HelperConfig: &gitcredentials.FakeHelperConfig{ |
| 634 | SelfExecutablePath: "/path/to/gh", |
| 635 | Helpers: map[string]gitcredentials.Helper{}, |
| 636 | }, |
| 637 | // Updater not required for this test as we will be setting gh as the helper |
| 638 | }, |
| 639 | } |
| 640 | |
| 641 | require.NoError(t, Login(opts)) |
| 642 | |
| 643 | helper, err := opts.CredentialFlow.HelperConfig.ConfiguredHelper("example.com") |
| 644 | require.NoError(t, err) |
| 645 | require.True(t, helper.IsOurs(), "expected gh to be the configured helper") |
| 646 | } |
| 647 | |
| 648 | func TestLogin_pastedTokenIgnoresConfiguredExpiringPreference(t *testing.T) { |
| 649 | // 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