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

Function TestPatchRoleSyncMapping

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

Source from the content-addressed store, hash-verified

468}
469
470func TestPatchRoleSyncMapping(t *testing.T) {
471 t.Parallel()
472
473 t.Run("OK", func(t *testing.T) {
474 t.Parallel()
475
476 owner, user := coderdenttest.New(t, &coderdenttest.Options{
477 LicenseOptions: &coderdenttest.LicenseOptions{
478 Features: license.Features{
479 codersdk.FeatureCustomRoles: 1,
480 codersdk.FeatureMultipleOrganizations: 1,
481 },
482 },
483 })
484
485 orgID := user.OrganizationID
486 orgAdmin, _ := coderdtest.CreateAnotherUser(t, owner, orgID, rbac.ScopedRoleOrgAdmin(user.OrganizationID))
487
488 ctx := testutil.Context(t, testutil.WaitShort)
489 _, err := orgAdmin.PatchRoleIDPSyncSettings(ctx, orgID.String(), codersdk.RoleSyncSettings{
490 Field: "wibble",
491 Mapping: map[string][]string{"wobble": {"group-00"}},
492 })
493 require.NoError(t, err)
494
495 ctx = testutil.Context(t, testutil.WaitShort)
496 settings, err := orgAdmin.PatchRoleIDPSyncMapping(ctx, orgID.String(), codersdk.PatchRoleIDPSyncMappingRequest{
497 Add: []codersdk.IDPSyncMapping[string]{
498 {Given: "wibble", Gets: "group-00"},
499 {Given: "wobble", Gets: "group-01"},
500 {Given: "wobble", Gets: "group-02"},
501 },
502 // Remove takes priority over Add, so "3" should not actually be added to wooble.
503 Remove: []codersdk.IDPSyncMapping[string]{
504 {Given: "wobble", Gets: "group-01"},
505 },
506 })
507
508 expected := map[string][]string{
509 "wibble": {"group-00"},
510 "wobble": {"group-00", "group-02"},
511 }
512
513 require.NoError(t, err)
514 require.Equal(t, expected, settings.Mapping)
515
516 fetchedSettings, err := orgAdmin.RoleIDPSyncSettings(ctx, orgID.String())
517 require.NoError(t, err)
518 require.Equal(t, "wibble", fetchedSettings.Field)
519 require.Equal(t, expected, fetchedSettings.Mapping)
520 })
521
522 t.Run("NotAuthorized", func(t *testing.T) {
523 t.Parallel()
524
525 owner, user := coderdenttest.New(t, &coderdenttest.Options{
526 LicenseOptions: &coderdenttest.LicenseOptions{
527 Features: license.Features{

Callers

nothing calls this directly

Calls 12

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