(t *testing.T)
| 699 | } |
| 700 | |
| 701 | func TestOAuth2ProviderRevoke(t *testing.T) { |
| 702 | t.Parallel() |
| 703 | |
| 704 | client := coderdtest.New(t, nil) |
| 705 | owner := coderdtest.CreateFirstUser(t, client) |
| 706 | |
| 707 | tests := []struct { |
| 708 | name string |
| 709 | // fn performs some action that removes the user's code and token. |
| 710 | fn func(context.Context, *codersdk.Client, exchangeSetup) |
| 711 | // replacesToken specifies whether the action replaces the token or only |
| 712 | // deletes it. |
| 713 | replacesToken bool |
| 714 | }{ |
| 715 | { |
| 716 | name: "DeleteApp", |
| 717 | fn: func(ctx context.Context, _ *codersdk.Client, s exchangeSetup) { |
| 718 | //nolint:gocritic // OAauth2 app management requires owner permission. |
| 719 | err := client.DeleteOAuth2ProviderApp(ctx, s.app.ID) |
| 720 | require.NoError(t, err) |
| 721 | }, |
| 722 | }, |
| 723 | { |
| 724 | name: "DeleteSecret", |
| 725 | fn: func(ctx context.Context, _ *codersdk.Client, s exchangeSetup) { |
| 726 | //nolint:gocritic // OAauth2 app management requires owner permission. |
| 727 | err := client.DeleteOAuth2ProviderAppSecret(ctx, s.app.ID, s.secret.ID) |
| 728 | require.NoError(t, err) |
| 729 | }, |
| 730 | }, |
| 731 | { |
| 732 | name: "DeleteApp", |
| 733 | fn: func(ctx context.Context, client *codersdk.Client, s exchangeSetup) { |
| 734 | err := client.RevokeOAuth2ProviderApp(ctx, s.app.ID) |
| 735 | require.NoError(t, err) |
| 736 | }, |
| 737 | }, |
| 738 | { |
| 739 | name: "OverrideCodeAndToken", |
| 740 | fn: func(ctx context.Context, client *codersdk.Client, s exchangeSetup) { |
| 741 | // Generating a new code should wipe out the old code. |
| 742 | code, verifier, err := authorizationFlow(ctx, client, s.cfg) |
| 743 | require.NoError(t, err) |
| 744 | |
| 745 | // Generating a new token should wipe out the old token. |
| 746 | _, err = s.cfg.Exchange(ctx, code, |
| 747 | oauth2.SetAuthURLParam("code_verifier", verifier), |
| 748 | ) |
| 749 | require.NoError(t, err) |
| 750 | }, |
| 751 | replacesToken: true, |
| 752 | }, |
| 753 | } |
| 754 | |
| 755 | setup := func(ctx context.Context, testClient *codersdk.Client, name string) exchangeSetup { |
| 756 | // We need a new app each time because we only allow one code and token per |
| 757 | // app and user at the moment and because the test might delete the app. |
| 758 | //nolint:gocritic // OAauth2 app management requires owner permission. |
nothing calls this directly
no test coverage detected