File tree 2 files changed +46
-3
lines changed
2 files changed +46
-3
lines changed Original file line number Diff line number Diff line change 1
1
package codersdk
2
2
3
3
import (
4
+ "fmt"
4
5
"regexp"
5
6
"strings"
6
7
@@ -98,9 +99,12 @@ func UserRealNameValid(str string) error {
98
99
99
100
// GroupNameValid returns whether the input string is a valid group name.
100
101
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 ))
104
108
}
105
109
// Avoid conflicts with routes like /groups/new and /groups/create.
106
110
if str == "new" || str == "create" {
Original file line number Diff line number Diff line change 8
8
"github.com/stretchr/testify/require"
9
9
10
10
"github.com/coder/coder/v2/codersdk"
11
+ "github.com/coder/coder/v2/cryptorand"
11
12
"github.com/coder/coder/v2/testutil"
12
13
)
13
14
@@ -254,3 +255,41 @@ func TestUserRealNameValid(t *testing.T) {
254
255
})
255
256
}
256
257
}
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
+ }
You can’t perform that action at this time.
0 commit comments