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

Commit7f51005

Browse files
refactor: increase group name limit to 255 (#15377)
Close#15184
1 parent1736309 commit7f51005

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

‎codersdk/name.go‎

Lines changed: 7 additions & 3 deletions
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
funcGroupNameValid(strstring)error {
101-
// 36 is to support using UUIDs as the group name.
102-
iflen(str)>36 {
103-
returnxerrors.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+
iflen(str)>limit {
107+
returnxerrors.New(fmt.Sprintf("must be <= %d characters",limit))
104108
}
105109
// Avoid conflicts with routes like /groups/new and /groups/create.
106110
ifstr=="new"||str=="create" {

‎codersdk/name_test.go‎

Lines changed: 39 additions & 0 deletions
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+
funcTestGroupNameValid(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+
Namestring
269+
Validbool
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:=rangetestCases {
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)

[8]ページ先頭

©2009-2025 Movatter.jp