MCPcopy Index your code
hub / github.com/coder/coder / TestPatchRoleSyncSettings

Function TestPatchRoleSyncSettings

enterprise/coderd/idpsync_test.go:342–398  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

340}
341
342func TestPatchRoleSyncSettings(t *testing.T) {
343 t.Parallel()
344
345 t.Run("OK", func(t *testing.T) {
346 t.Parallel()
347
348 owner, user := coderdenttest.New(t, &coderdenttest.Options{
349 LicenseOptions: &coderdenttest.LicenseOptions{
350 Features: license.Features{
351 codersdk.FeatureCustomRoles: 1,
352 codersdk.FeatureMultipleOrganizations: 1,
353 },
354 },
355 })
356
357 orgAdmin, _ := coderdtest.CreateAnotherUser(t, owner, user.OrganizationID, rbac.ScopedRoleOrgAdmin(user.OrganizationID))
358
359 // Test as org admin
360 ctx := testutil.Context(t, testutil.WaitShort)
361 settings, err := orgAdmin.PatchRoleIDPSyncSettings(ctx, user.OrganizationID.String(), codersdk.RoleSyncSettings{
362 Field: "august",
363 })
364 require.NoError(t, err)
365 require.Equal(t, "august", settings.Field)
366
367 fetchedSettings, err := orgAdmin.RoleIDPSyncSettings(ctx, user.OrganizationID.String())
368 require.NoError(t, err)
369 require.Equal(t, "august", fetchedSettings.Field)
370 })
371
372 t.Run("NotAuthorized", func(t *testing.T) {
373 t.Parallel()
374
375 owner, user := coderdenttest.New(t, &coderdenttest.Options{
376 LicenseOptions: &coderdenttest.LicenseOptions{
377 Features: license.Features{
378 codersdk.FeatureCustomRoles: 1,
379 codersdk.FeatureMultipleOrganizations: 1,
380 },
381 },
382 })
383
384 member, _ := coderdtest.CreateAnotherUser(t, owner, user.OrganizationID)
385
386 ctx := testutil.Context(t, testutil.WaitShort)
387 _, err := member.PatchRoleIDPSyncSettings(ctx, user.OrganizationID.String(), codersdk.RoleSyncSettings{
388 Field: "august",
389 })
390 var apiError *codersdk.Error
391 require.ErrorAs(t, err, &apiError)
392 require.Equal(t, http.StatusForbidden, apiError.StatusCode())
393
394 _, err = member.RoleIDPSyncSettings(ctx, user.OrganizationID.String())
395 require.ErrorAs(t, err, &apiError)
396 require.Equal(t, http.StatusForbidden, apiError.StatusCode())
397 })
398}
399

Callers

nothing calls this directly

Calls 10

StatusCodeMethod · 0.95
NewFunction · 0.92
CreateAnotherUserFunction · 0.92
ScopedRoleOrgAdminFunction · 0.92
ContextFunction · 0.92
RoleIDPSyncSettingsMethod · 0.80
RunMethod · 0.65
StringMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected