Skip to content

feat: add api for patching custom org roles #13357

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
May 29, 2024
Prev Previous commit
Next Next commit
add test for mismatched orgID
  • Loading branch information
Emyrk committed May 28, 2024
commit 715efa2b7bf6ffe2c6b273af1acb11ec4a30227f
2 changes: 1 addition & 1 deletion enterprise/coderd/roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (h enterpriseCustomRoleHandler) PatchOrganizationRole(ctx context.Context,
if role.OrganizationID != orgID.String() {
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
Message: "Invalid request, organization in role and url must match",
Detail: fmt.Sprintf("role org %q does not match URL %q", role.OrganizationID, orgID.String()),
Detail: fmt.Sprintf("role organization=%q does not match URL=%q", role.OrganizationID, orgID.String()),
})
return codersdk.Role{}, false
}
Expand Down
24 changes: 23 additions & 1 deletion enterprise/coderd/roles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func TestCustomOrganizationRole(t *testing.T) {

// Revoked licenses cannot modify/create custom roles, but they can
// use the existing roles.
t.Run("Revoked License", func(t *testing.T) {
t.Run("RevokedLicense", func(t *testing.T) {
t.Parallel()
dv := coderdtest.DeploymentValues(t)
dv.Experiments = []string{string(codersdk.ExperimentCustomRoles)}
Expand Down Expand Up @@ -208,4 +208,26 @@ func TestCustomOrganizationRole(t *testing.T) {
})
require.ErrorContains(t, err, "Validation")
})

t.Run("MismatchedOrganizations", func(t *testing.T) {
t.Parallel()
dv := coderdtest.DeploymentValues(t)
dv.Experiments = []string{string(codersdk.ExperimentCustomRoles)}
owner, first := coderdenttest.New(t, &coderdenttest.Options{
Options: &coderdtest.Options{
DeploymentValues: dv,
},
LicenseOptions: &coderdenttest.LicenseOptions{
Features: license.Features{
codersdk.FeatureCustomRoles: 1,
},
},
})

ctx := testutil.Context(t, testutil.WaitMedium)

//nolint:gocritic // owner is required for this
_, err := owner.PatchOrganizationRole(ctx, first.OrganizationID, templateAdminCustom(uuid.New()))
require.ErrorContains(t, err, "does not match")
})
}