(t *testing.T)
| 596 | } |
| 597 | |
| 598 | func TestAuthListRemoveTokensListDelete_JSON(t *testing.T) { |
| 599 | store := newMemSecretsStore() |
| 600 | |
| 601 | runtime := &app.Runtime{ |
| 602 | Auth: app.AuthOperations{ |
| 603 | OpenSecretsStore: func() (secrets.Store, error) { return store, nil }, |
| 604 | CheckRefreshToken: func(_ context.Context, _ string, refreshToken string, _ []string, _ time.Duration) error { |
| 605 | if refreshToken == "rt2" { |
| 606 | return errors.New("invalid_grant") |
| 607 | } |
| 608 | return nil |
| 609 | }, |
| 610 | }, |
| 611 | } |
| 612 | |
| 613 | _ = store.SetToken(config.DefaultClientName, "b@b.com", secrets.Token{RefreshToken: "rt2"}) |
| 614 | _ = store.SetToken(config.DefaultClientName, "a@b.com", secrets.Token{RefreshToken: "rt1"}) |
| 615 | |
| 616 | listOut := captureStdout(t, func() { |
| 617 | _ = captureStderr(t, func() { |
| 618 | if err := executeWithRuntime([]string{"--json", "auth", "list"}, runtime); err != nil { |
| 619 | t.Fatalf("Execute list: %v", err) |
| 620 | } |
| 621 | }) |
| 622 | }) |
| 623 | var listResp struct { |
| 624 | Accounts []struct { |
| 625 | Email string `json:"email"` |
| 626 | } `json:"accounts"` |
| 627 | } |
| 628 | if err := json.Unmarshal([]byte(listOut), &listResp); err != nil { |
| 629 | t.Fatalf("list json: %v\nout=%q", err, listOut) |
| 630 | } |
| 631 | if len(listResp.Accounts) != 2 || listResp.Accounts[0].Email != "a@b.com" || listResp.Accounts[1].Email != "b@b.com" { |
| 632 | t.Fatalf("unexpected accounts: %#v", listResp.Accounts) |
| 633 | } |
| 634 | |
| 635 | listChecked := executeWithTestRuntime(t, []string{"--json", "auth", "list", "--check"}, runtime) |
| 636 | if listChecked.err != nil { |
| 637 | t.Fatalf("Execute list --check: %v", listChecked.err) |
| 638 | } |
| 639 | var listCheckedResp struct { |
| 640 | Accounts []struct { |
| 641 | Email string `json:"email"` |
| 642 | Valid *bool `json:"valid,omitempty"` |
| 643 | Error string `json:"error,omitempty"` |
| 644 | } `json:"accounts"` |
| 645 | } |
| 646 | if err := json.Unmarshal([]byte(listChecked.stdout), &listCheckedResp); err != nil { |
| 647 | t.Fatalf("list --check json: %v\nout=%q", err, listChecked.stdout) |
| 648 | } |
| 649 | if len(listCheckedResp.Accounts) != 2 { |
| 650 | t.Fatalf("unexpected accounts: %#v", listCheckedResp.Accounts) |
| 651 | } |
| 652 | if listCheckedResp.Accounts[0].Email != "a@b.com" || listCheckedResp.Accounts[0].Valid == nil || !*listCheckedResp.Accounts[0].Valid { |
| 653 | t.Fatalf("expected a@b.com valid, got: %#v", listCheckedResp.Accounts[0]) |
| 654 | } |
| 655 | if listCheckedResp.Accounts[1].Email != "b@b.com" || listCheckedResp.Accounts[1].Valid == nil || *listCheckedResp.Accounts[1].Valid || !strings.Contains(listCheckedResp.Accounts[1].Error, "invalid_grant") { |
nothing calls this directly
no test coverage detected