|
4 | 4 | "bytes" |
5 | 5 | "context" |
6 | 6 | "encoding/json" |
| 7 | + "fmt" |
7 | 8 | "net/http" |
8 | 9 | "path/filepath" |
9 | 10 | "strings" |
@@ -339,6 +340,27 @@ func Test_statusRun(t *testing.T) { |
339 | 340 | - Token scopes: 'repo', 'read:org' |
340 | 341 | `), |
341 | 342 | }, |
| 343 | + { |
| 344 | + name: "rejected refresh token surfaces a clear error without a scope request", |
| 345 | + opts: StatusOptions{}, |
| 346 | + cfgStubs: func(t *testing.T, c gh.Config) { |
| 347 | + past := time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC) |
| 348 | + loginRefreshable(t, c, "github.com", "monalisa", "gho_stale", "ghr_abc", &past) |
| 349 | + setRefresher(t, c, &ghmock.TokenRefresherMock{ |
| 350 | + RefreshFunc: func(string, string) (gh.RefreshableCredential, error) { |
| 351 | + return gh.RefreshableCredential{}, fmt.Errorf("server rejected token: %w", gh.ErrRefreshTokenInvalid) |
| 352 | + }, |
| 353 | + }) |
| 354 | + }, |
| 355 | + wantErr: cmdutil.SilentError, |
| 356 | + wantErrOut: heredoc.Doc(` |
| 357 | + github.com |
| 358 | + X Refresh token for github.com account monalisa was rejected |
| 359 | + - Active account: true |
| 360 | + - The stored short-lived credential was removed because its refresh token is no longer valid. |
| 361 | + - To re-authenticate, run: gh auth login -h github.com |
| 362 | + `), |
| 363 | + }, |
342 | 364 | { |
343 | 365 | name: "token from env", |
344 | 366 | opts: StatusOptions{}, |
@@ -786,6 +808,24 @@ func Test_statusRun(t *testing.T) { |
786 | 808 | wantOut: `{"hosts":{"github.com":[{"state":"timeout","error":"Get \"https://api.github.com/\": context deadline exceeded","active":true,"host":"github.com","login":"monalisa","tokenSource":"GH_CONFIG_DIR/hosts.yml","gitProtocol":"https"}]}}` + "\n", |
787 | 809 | wantErr: nil, // should not return error in machine-readable mode |
788 | 810 | }, |
| 811 | + { |
| 812 | + name: "json, rejected refresh token", |
| 813 | + opts: StatusOptions{ |
| 814 | + Hostname: "github.com", |
| 815 | + }, |
| 816 | + jsonFields: []string{"hosts"}, |
| 817 | + cfgStubs: func(t *testing.T, c gh.Config) { |
| 818 | + past := time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC) |
| 819 | + loginRefreshable(t, c, "github.com", "monalisa", "gho_stale", "ghr_abc", &past) |
| 820 | + setRefresher(t, c, &ghmock.TokenRefresherMock{ |
| 821 | + RefreshFunc: func(string, string) (gh.RefreshableCredential, error) { |
| 822 | + return gh.RefreshableCredential{}, fmt.Errorf("server rejected token: %w", gh.ErrRefreshTokenInvalid) |
| 823 | + }, |
| 824 | + }) |
| 825 | + }, |
| 826 | + wantOut: `{"hosts":{"github.com":[{"state":"refresh_expired","error":"refresh token for github.com was rejected; the stored credential was removed","active":true,"host":"github.com","login":"monalisa","tokenSource":"","gitProtocol":"https"}]}}` + "\n", |
| 827 | + wantErr: nil, // should not return error in machine-readable mode |
| 828 | + }, |
789 | 829 | { |
790 | 830 | name: "json, with show token", |
791 | 831 | opts: StatusOptions{ |
|
0 commit comments