(t *testing.T)
| 760 | } |
| 761 | |
| 762 | func TestLogin_recordsAuthTelemetryOnFailure(t *testing.T) { |
| 763 | // Telemetry must reflect how far the login got: an issued expiring token is recorded even when storing it fails, |
| 764 | // and a stored credential counts as a successful sign-in even when a later side effect fails. |
| 765 | tests := []struct { |
| 766 | name string |
| 767 | config iconfig |
| 768 | gitProtocol string |
| 769 | helperErr error |
| 770 | setup func(t *testing.T, opts *LoginOptions, reg *httpmock.Registry) |
| 771 | wantSuccess string |
| 772 | }{ |
| 773 | { |
| 774 | name: "storage fails after an expiring token is issued", |
| 775 | config: failingStorageConfig{tinyConfig{}}, |
| 776 | gitProtocol: "https", |
| 777 | wantSuccess: "false", |
| 778 | }, |
| 779 | { |
| 780 | name: "credential helper setup fails after storage", |
| 781 | config: tinyConfig{}, |
| 782 | gitProtocol: "https", |
| 783 | helperErr: errors.New("helper setup failed"), |
| 784 | wantSuccess: "true", |
| 785 | }, |
| 786 | { |
| 787 | name: "SSH key upload fails after storage", |
| 788 | config: tinyConfig{}, |
| 789 | gitProtocol: "ssh", |
| 790 | setup: func(t *testing.T, opts *LoginOptions, reg *httpmock.Registry) { |
| 791 | dir := t.TempDir() |
| 792 | require.NoError(t, os.WriteFile(filepath.Join(dir, "id_ed25519.pub"), []byte("PUBKEY asdf"), 0600)) |
| 793 | opts.sshContext = ssh.NewContextForTests(dir, "") |
| 794 | reg.Register(httpmock.REST("GET", "user/keys"), httpmock.StatusStringResponse(500, "{}")) |
| 795 | }, |
| 796 | wantSuccess: "true", |
| 797 | }, |
| 798 | } |
| 799 | |
| 800 | for _, tt := range tests { |
| 801 | t.Run(tt.name, func(t *testing.T) { |
| 802 | ios, _, _, _ := iostreams.Test() |
| 803 | recorder := &telemetry.InvocationRecorderSpy{} |
| 804 | reg := &httpmock.Registry{} |
| 805 | defer reg.Verify(t) |
| 806 | |
| 807 | opts := &LoginOptions{ |
| 808 | IO: ios, |
| 809 | Config: tt.config, |
| 810 | HTTPClient: &http.Client{Transport: reg}, |
| 811 | Hostname: "github.com", |
| 812 | Interactive: true, |
| 813 | GitProtocol: tt.gitProtocol, |
| 814 | Telemetry: recorder, |
| 815 | Prompter: &prompter.PrompterMock{ |
| 816 | SelectFunc: func(prompt, _ string, opts []string) (int, error) { |
| 817 | switch prompt { |
| 818 | case "How would you like to authenticate GitHub CLI?": |
| 819 | return prompter.IndexFor(opts, "Login with a web browser") |
nothing calls this directly
no test coverage detected