(t *testing.T)
| 684 | } |
| 685 | |
| 686 | func TestConfig_IsLoggedInWithTenant(t *testing.T) { |
| 687 | t.Run("it returns true when there is a tenant in the config and its access token is valid", func(t *testing.T) { |
| 688 | tempFile := createTempConfigFile(t, []byte(`{ |
| 689 | "install_id": "3998b053-dd7f-4bfe-bb10-c4f3a96a0180", |
| 690 | "default_tenant": "auth0-cli.eu.auth0.com", |
| 691 | "tenants": { |
| 692 | "auth0-cli.eu.auth0.com": { |
| 693 | "name": "auth0-cli", |
| 694 | "domain": "auth0-cli.eu.auth0.com", |
| 695 | "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJodHRwczovL2F1dGgwLmF1dGgwLmNvbS8iLCJpYXQiOjE2ODExNDcwNjAsImV4cCI6OTY4MTgzMzQ2MH0.DsEpQkL0MIWcGJOIfEY8vr3MVS_E0GYsachNLQwBu5Q", |
| 696 | "expires_at": "2023-04-18T11:18:07.998809Z", |
| 697 | "client_id": "secret" |
| 698 | } |
| 699 | } |
| 700 | }`)) |
| 701 | |
| 702 | config := &Config{path: tempFile} |
| 703 | assert.True(t, config.IsLoggedInWithTenant("auth0-cli.eu.auth0.com")) |
| 704 | }) |
| 705 | |
| 706 | t.Run("it returns false when the config file doesn't exist", func(t *testing.T) { |
| 707 | config := &Config{path: "i-dont-exist.json"} |
| 708 | assert.False(t, config.IsLoggedInWithTenant("auth0-cli.eu.auth0.com")) |
| 709 | }) |
| 710 | |
| 711 | t.Run("it returns false when there is a tenant in the config and its access token is expired", func(t *testing.T) { |
| 712 | tempFile := createTempConfigFile(t, []byte(`{ |
| 713 | "install_id": "3998b053-dd7f-4bfe-bb10-c4f3a96a0180", |
| 714 | "default_tenant": "auth0-cli.eu.auth0.com", |
| 715 | "tenants": { |
| 716 | "auth0-cli.eu.auth0.com": { |
| 717 | "name": "auth0-cli", |
| 718 | "domain": "auth0-cli.eu.auth0.com", |
| 719 | "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJodHRwczovL2F1dGgwLmF1dGgwLmNvbS8iLCJpYXQiOjE2ODExNDcwNjAsImV4cCI6MTY4MTEzMzQ2MH0.dG481CD7v8VCzSsBHdApTiRDUuCZXBgk5LO__q4r2Fg", |
| 720 | "expires_at": "2023-04-10T11:18:07.998809Z", |
| 721 | "client_id": "secret" |
| 722 | } |
| 723 | } |
| 724 | }`)) |
| 725 | |
| 726 | config := &Config{path: tempFile} |
| 727 | assert.False(t, config.IsLoggedInWithTenant("auth0-cli.eu.auth0.com")) |
| 728 | }) |
| 729 | |
| 730 | t.Run("it returns false when there is a tenant in the config and its access token is malformed", func(t *testing.T) { |
| 731 | tempFile := createTempConfigFile(t, []byte(`{ |
| 732 | "install_id": "3998b053-dd7f-4bfe-bb10-c4f3a96a0180", |
| 733 | "default_tenant": "auth0-cli.eu.auth0.com", |
| 734 | "tenants": { |
| 735 | "auth0-cli.eu.auth0.com": { |
| 736 | "name": "auth0-cli", |
| 737 | "domain": "auth0-cli.eu.auth0.com", |
| 738 | "access_token": "dG481CD7v8VCzSsBHdApTiRDUuCZXBgk5LO__q4r2Fg", |
| 739 | "expires_at": "2023-04-10T11:18:07.998809Z", |
| 740 | "client_id": "secret" |
| 741 | } |
| 742 | } |
| 743 | }`)) |
nothing calls this directly
no test coverage detected