Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7f51005

Browse files
refactor: increase group name limit to 255 (#15377)
Close #15184
1 parent 1736309 commit 7f51005

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

codersdk/name.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package codersdk
22

33
import (
4+
"fmt"
45
"regexp"
56
"strings"
67

@@ -98,9 +99,12 @@ func UserRealNameValid(str string) error {
9899

99100
// GroupNameValid returns whether the input string is a valid group name.
100101
func GroupNameValid(str string) error {
101-
// 36 is to support using UUIDs as the group name.
102-
if len(str) > 36 {
103-
return xerrors.New("must be <= 36 characters")
102+
// We want to support longer names for groups to allow users to sync their
103+
// group names with their identity providers without manual mapping. Related
104+
// to: https://github.com/coder/coder/issues/15184
105+
limit := 255
106+
if len(str) > limit {
107+
return xerrors.New(fmt.Sprintf("must be <= %d characters", limit))
104108
}
105109
// Avoid conflicts with routes like /groups/new and /groups/create.
106110
if str == "new" || str == "create" {

codersdk/name_test.go

+39
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/stretchr/testify/require"
99

1010
"github.com/coder/coder/v2/codersdk"
11+
"github.com/coder/coder/v2/cryptorand"
1112
"github.com/coder/coder/v2/testutil"
1213
)
1314

@@ -254,3 +255,41 @@ func TestUserRealNameValid(t *testing.T) {
254255
})
255256
}
256257
}
258+
259+
func TestGroupNameValid(t *testing.T) {
260+
t.Parallel()
261+
262+
random255String, err := cryptorand.String(255)
263+
require.NoError(t, err, "failed to generate 255 random string")
264+
random256String, err := cryptorand.String(256)
265+
require.NoError(t, err, "failed to generate 256 random string")
266+
267+
testCases := []struct {
268+
Name string
269+
Valid bool
270+
}{
271+
{"", false},
272+
{"my-group", true},
273+
{"create", false},
274+
{"new", false},
275+
{"Lord Voldemort Team", false},
276+
{random255String, true},
277+
{random256String, false},
278+
}
279+
for _, testCase := range testCases {
280+
testCase := testCase
281+
t.Run(testCase.Name, func(t *testing.T) {
282+
t.Parallel()
283+
err := codersdk.GroupNameValid(testCase.Name)
284+
assert.Equal(
285+
t,
286+
testCase.Valid,
287+
err == nil,
288+
"Test case %s failed: expected valid=%t but got error: %v",
289+
testCase.Name,
290+
testCase.Valid,
291+
err,
292+
)
293+
})
294+
}
295+
}

0 commit comments

Comments
 (0)