TestExternalAuthManagement is for testing the apis interacting with external auths from the user perspective. We assume the external auth will always work, so we can test the managing apis like unlinking and listing.
(t *testing.T)
| 174 | // will always work, so we can test the managing apis like unlinking and |
| 175 | // listing. |
| 176 | func TestExternalAuthManagement(t *testing.T) { |
| 177 | t.Parallel() |
| 178 | t.Run("ListProviders", func(t *testing.T) { |
| 179 | t.Parallel() |
| 180 | const githubID = "fake-github" |
| 181 | const gitlabID = "fake-gitlab" |
| 182 | const slackID = "fake-slack" |
| 183 | const azureID = "fake-azure" |
| 184 | ghRevokeCalled := false |
| 185 | slRevokeCalled := false |
| 186 | azRevokeCalled := false |
| 187 | |
| 188 | ghRevoke := func() (int, error) { |
| 189 | ghRevokeCalled = true |
| 190 | return http.StatusNoContent, nil |
| 191 | } |
| 192 | slRevoke := func() (int, error) { |
| 193 | slRevokeCalled = true |
| 194 | return http.StatusOK, nil |
| 195 | } |
| 196 | azRevoke := func() (int, error) { |
| 197 | azRevokeCalled = true |
| 198 | return http.StatusForbidden, xerrors.New("some error") |
| 199 | } |
| 200 | |
| 201 | github := oidctest.NewFakeIDP(t, oidctest.WithServing(), oidctest.WithRevokeTokenGitHub(ghRevoke)) |
| 202 | gitlab := oidctest.NewFakeIDP(t, oidctest.WithServing()) |
| 203 | slack := oidctest.NewFakeIDP(t, oidctest.WithServing(), oidctest.WithRevokeTokenRFC(slRevoke)) |
| 204 | azure := oidctest.NewFakeIDP(t, oidctest.WithServing(), oidctest.WithRevokeTokenRFC(azRevoke)) |
| 205 | |
| 206 | owner := coderdtest.New(t, &coderdtest.Options{ |
| 207 | ExternalAuthConfigs: []*externalauth.Config{ |
| 208 | github.ExternalAuthConfig(t, githubID, nil, func(cfg *externalauth.Config) { |
| 209 | cfg.Type = codersdk.EnhancedExternalAuthProviderGitHub.String() |
| 210 | }), |
| 211 | gitlab.ExternalAuthConfig(t, gitlabID, nil, func(cfg *externalauth.Config) { |
| 212 | cfg.Type = codersdk.EnhancedExternalAuthProviderGitLab.String() |
| 213 | }), |
| 214 | slack.ExternalAuthConfig(t, slackID, nil, func(cfg *externalauth.Config) { |
| 215 | cfg.Type = codersdk.EnhancedExternalAuthProviderSlack.String() |
| 216 | cfg.RevokeURL = "" |
| 217 | }), |
| 218 | azure.ExternalAuthConfig(t, azureID, nil, func(cfg *externalauth.Config) { |
| 219 | cfg.Type = codersdk.EnhancedExternalAuthProviderAzureDevopsEntra.String() |
| 220 | }), |
| 221 | }, |
| 222 | }) |
| 223 | ownerUser := coderdtest.CreateFirstUser(t, owner) |
| 224 | // Just a regular user |
| 225 | client, _ := coderdtest.CreateAnotherUser(t, owner, ownerUser.OrganizationID) |
| 226 | ctx := testutil.Context(t, testutil.WaitLong) |
| 227 | |
| 228 | // List auths without any links. |
| 229 | list, err := client.ListExternalAuths(ctx) |
| 230 | require.NoError(t, err) |
| 231 | require.Len(t, list.Providers, 4) |
| 232 | require.Len(t, list.Links, 0) |
| 233 |
nothing calls this directly
no test coverage detected