Skip to content

Commit 5f83fc4

Browse files
committed
PR Comments, add unit test
1 parent 9fc4ec8 commit 5f83fc4

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

coderd/database/dbmem/dbmem.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,7 @@ func (q *FakeQuerier) CustomRoles(_ context.Context, arg database.CustomRolesPar
11811181

11821182
found := make([]database.CustomRole, 0)
11831183
for _, role := range q.data.customRoles {
1184+
role := role
11841185
if len(arg.LookupRoles) > 0 {
11851186
if !slices.ContainsFunc(arg.LookupRoles, func(s string) bool {
11861187
return strings.EqualFold(s, role.Name)
@@ -1193,7 +1194,6 @@ func (q *FakeQuerier) CustomRoles(_ context.Context, arg database.CustomRolesPar
11931194
continue
11941195
}
11951196

1196-
role := role
11971197
found = append(found, role)
11981198
}
11991199

enterprise/cli/rolescmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
func (r *RootCmd) roles() *serpent.Command {
1919
cmd := &serpent.Command{
2020
Use: "roles",
21-
Short: "Manage roles",
21+
Short: "Manage site-wide roles.",
2222
Aliases: []string{"role"},
2323
Handler: func(inv *serpent.Invocation) error {
2424
return inv.Command.HelpHandler(inv)

enterprise/coderd/roles_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,37 @@ func TestCustomRole(t *testing.T) {
167167
})
168168
require.ErrorContains(t, err, "forbidden")
169169
})
170+
171+
t.Run("InvalidName", func(t *testing.T) {
172+
t.Parallel()
173+
dv := coderdtest.DeploymentValues(t)
174+
dv.Experiments = []string{string(codersdk.ExperimentCustomRoles)}
175+
owner, _ := coderdenttest.New(t, &coderdenttest.Options{
176+
Options: &coderdtest.Options{
177+
DeploymentValues: dv,
178+
},
179+
LicenseOptions: &coderdenttest.LicenseOptions{
180+
Features: license.Features{
181+
codersdk.FeatureCustomRoles: 1,
182+
},
183+
},
184+
})
185+
186+
ctx := testutil.Context(t, testutil.WaitMedium)
187+
188+
//nolint:gocritic // owner is required for this
189+
_, err := owner.PatchRole(ctx, codersdk.Role{
190+
Name: "Bad_Name", // No underscores allowed
191+
DisplayName: "Testing Purposes",
192+
// Basically creating a template admin manually
193+
SitePermissions: codersdk.CreatePermissions(map[codersdk.RBACResource][]codersdk.RBACAction{
194+
codersdk.ResourceTemplate: {codersdk.ActionCreate, codersdk.ActionRead, codersdk.ActionUpdate, codersdk.ActionViewInsights},
195+
codersdk.ResourceFile: {codersdk.ActionCreate, codersdk.ActionRead},
196+
codersdk.ResourceWorkspace: {codersdk.ActionRead},
197+
}),
198+
OrganizationPermissions: nil,
199+
UserPermissions: nil,
200+
})
201+
require.ErrorContains(t, err, "Invalid role name")
202+
})
170203
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy