Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: add additional patch routes for group and role idp sync#16351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
aslilac merged 7 commits intomainfromlilac/patch-other-sync-stuff
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
add tests
  • Loading branch information
@aslilac
aslilac committedJan 31, 2025
commit771a1f4e5fd42c4514a3a8e17a4668845f74009a
4 changes: 2 additions & 2 deletionscodersdk/idpsync.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -148,7 +148,7 @@ type PatchRoleIDPSyncConfigRequest struct {
Field string `json:"field"`
}

func (c *Client) PatchRoleIDPSyncConfig(ctx context.Context, orgID string, reqPatchGroupIDPSyncConfigRequest) (RoleSyncSettings, error) {
func (c *Client) PatchRoleIDPSyncConfig(ctx context.Context, orgID string, reqPatchRoleIDPSyncConfigRequest) (RoleSyncSettings, error) {
res, err := c.Request(ctx, http.MethodPatch, fmt.Sprintf("/api/v2/organizations/%s/settings/idpsync/roles/config", orgID), req)
if err != nil {
return RoleSyncSettings{}, xerrors.Errorf("make request: %w", err)
Expand All@@ -168,7 +168,7 @@ type PatchRoleIDPSyncMappingRequest struct {
Remove []IDPSyncMapping[string]
}

func (c *Client) PatchRoleIDPSyncMapping(ctx context.Context, orgID string, reqPatchGroupIDPSyncMappingRequest) (RoleSyncSettings, error) {
func (c *Client) PatchRoleIDPSyncMapping(ctx context.Context, orgID string, reqPatchRoleIDPSyncMappingRequest) (RoleSyncSettings, error) {
res, err := c.Request(ctx, http.MethodPatch, fmt.Sprintf("/api/v2/organizations/%s/settings/idpsync/roles/mapping", orgID), req)
if err != nil {
return RoleSyncSettings{}, xerrors.Errorf("make request: %w", err)
Expand Down
144 changes: 144 additions & 0 deletionsenterprise/coderd/idpsync_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -398,6 +398,150 @@ func TestPatchRoleSyncSettings(t *testing.T) {
})
}

func TestPatchRoleSyncConfig(t *testing.T) {
t.Parallel()

t.Run("OK", func(t *testing.T) {
t.Parallel()

owner, user := coderdenttest.New(t, &coderdenttest.Options{
LicenseOptions: &coderdenttest.LicenseOptions{
Features: license.Features{
codersdk.FeatureCustomRoles: 1,
codersdk.FeatureMultipleOrganizations: 1,
},
},
})

orgID := user.OrganizationID
orgAdmin, _ := coderdtest.CreateAnotherUser(t, owner, orgID, rbac.ScopedRoleOrgAdmin(user.OrganizationID))

mapping := map[string][]string{"wibble": {"group-01"}}

ctx := testutil.Context(t, testutil.WaitShort)
_, err := orgAdmin.PatchRoleIDPSyncSettings(ctx, orgID.String(), codersdk.RoleSyncSettings{
Field: "wibble",
Mapping: mapping,
})

require.NoError(t, err)

fetchedSettings, err := orgAdmin.RoleIDPSyncSettings(ctx, orgID.String())
require.NoError(t, err)
require.Equal(t, "wibble", fetchedSettings.Field)
require.Equal(t, mapping, fetchedSettings.Mapping)

ctx = testutil.Context(t, testutil.WaitShort)
settings, err := orgAdmin.PatchRoleIDPSyncConfig(ctx, orgID.String(), codersdk.PatchRoleIDPSyncConfigRequest{
Field: "wobble",
})

require.NoError(t, err)
require.Equal(t, "wobble", settings.Field)
require.Equal(t, mapping, settings.Mapping)

fetchedSettings, err = orgAdmin.RoleIDPSyncSettings(ctx, orgID.String())
require.NoError(t, err)
require.Equal(t, "wobble", fetchedSettings.Field)
require.Equal(t, mapping, fetchedSettings.Mapping)
})

t.Run("NotAuthorized", func(t *testing.T) {
t.Parallel()

owner, user := coderdenttest.New(t, &coderdenttest.Options{
LicenseOptions: &coderdenttest.LicenseOptions{
Features: license.Features{
codersdk.FeatureCustomRoles: 1,
codersdk.FeatureMultipleOrganizations: 1,
},
},
})

member, _ := coderdtest.CreateAnotherUser(t, owner, user.OrganizationID)

ctx := testutil.Context(t, testutil.WaitShort)
_, err := member.PatchGroupIDPSyncConfig(ctx, user.OrganizationID.String(), codersdk.PatchGroupIDPSyncConfigRequest{})
var apiError *codersdk.Error
require.ErrorAs(t, err, &apiError)
require.Equal(t, http.StatusForbidden, apiError.StatusCode())
})
}

func TestPatchRoleSyncMapping(t *testing.T) {
t.Parallel()

t.Run("OK", func(t *testing.T) {
t.Parallel()

owner, user := coderdenttest.New(t, &coderdenttest.Options{
LicenseOptions: &coderdenttest.LicenseOptions{
Features: license.Features{
codersdk.FeatureCustomRoles: 1,
codersdk.FeatureMultipleOrganizations: 1,
},
},
})

orgID := user.OrganizationID
orgAdmin, _ := coderdtest.CreateAnotherUser(t, owner, orgID, rbac.ScopedRoleOrgAdmin(user.OrganizationID))

ctx := testutil.Context(t, testutil.WaitShort)
_, err := orgAdmin.PatchRoleIDPSyncSettings(ctx, orgID.String(), codersdk.RoleSyncSettings{
Field: "wibble",
Mapping: map[string][]string{"wobble": {"group-00"}},
})
require.NoError(t, err)

ctx = testutil.Context(t, testutil.WaitShort)
settings, err := orgAdmin.PatchRoleIDPSyncMapping(ctx, orgID.String(), codersdk.PatchRoleIDPSyncMappingRequest{
Add: []codersdk.IDPSyncMapping[string]{
{Given: "wibble", Gets: "group-00"},
{Given: "wobble", Gets: "group-01"},
{Given: "wobble", Gets: "group-02"},
},
// Remove takes priority over Add, so "3" should not actually be added to wooble.
Remove: []codersdk.IDPSyncMapping[string]{
{Given: "wobble", Gets: "group-01"},
},
})

expected := map[string][]string{
"wibble": {"group-00"},
"wobble": {"group-00", "group-02"},
}

require.NoError(t, err)
require.Equal(t, expected, settings.Mapping)

fetchedSettings, err := orgAdmin.RoleIDPSyncSettings(ctx, orgID.String())
require.NoError(t, err)
require.Equal(t, "wibble", fetchedSettings.Field)
require.Equal(t, expected, fetchedSettings.Mapping)
})

t.Run("NotAuthorized", func(t *testing.T) {
t.Parallel()

owner, user := coderdenttest.New(t, &coderdenttest.Options{
LicenseOptions: &coderdenttest.LicenseOptions{
Features: license.Features{
codersdk.FeatureCustomRoles: 1,
codersdk.FeatureMultipleOrganizations: 1,
},
},
})

member, _ := coderdtest.CreateAnotherUser(t, owner, user.OrganizationID)

ctx := testutil.Context(t, testutil.WaitShort)
_, err := member.PatchGroupIDPSyncMapping(ctx, user.OrganizationID.String(), codersdk.PatchGroupIDPSyncMappingRequest{})
var apiError *codersdk.Error
require.ErrorAs(t, err, &apiError)
require.Equal(t, http.StatusForbidden, apiError.StatusCode())
})
}

func TestGetOrganizationSyncSettings(t *testing.T) {
t.Parallel()

Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp