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

refactor: increase group name limit to 255#15377

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
BrunoQuaresma merged 3 commits intomainfrombq/feat-increase-group-name-length
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletionscodersdk/name.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
package codersdk

import (
"fmt"
"regexp"
"strings"

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

// GroupNameValid returns whether the input string is a valid group name.
func GroupNameValid(str string) error {
// 36 is to support using UUIDs as the group name.
if len(str) > 36 {
return xerrors.New("must be <= 36 characters")
// We want to support longer names for groups to allow users to sync their
// group names with their identity providers without manual mapping. Related
// to: https://github.com/coder/coder/issues/15184
limit := 255
if len(str) > limit {
return xerrors.New(fmt.Sprintf("must be <= %d characters", limit))
}
// Avoid conflicts with routes like /groups/new and /groups/create.
if str == "new" || str == "create" {
Expand Down
39 changes: 39 additions & 0 deletionscodersdk/name_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,6 +8,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/coder/coder/v2/codersdk"
"github.com/coder/coder/v2/cryptorand"
"github.com/coder/coder/v2/testutil"
)

Expand DownExpand Up@@ -254,3 +255,41 @@ func TestUserRealNameValid(t *testing.T) {
})
}
}

func TestGroupNameValid(t *testing.T) {
t.Parallel()

random255String, err := cryptorand.String(255)
require.NoError(t, err, "failed to generate 255 random string")
random256String, err := cryptorand.String(256)
require.NoError(t, err, "failed to generate 256 random string")

testCases := []struct {
Name string
Valid bool
}{
{"", false},
{"my-group", true},
{"create", false},
{"new", false},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Why is this invalid?

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

To avoid route conflicts.

// Avoid conflicts with routes like /templates/new and /groups/create.ifstr=="new"||str=="create" {returnxerrors.Errorf("cannot use %q as a name",str)}

mafredri reacted with thumbs up emoji
{"Lord Voldemort Team", false},
{random255String, true},
{random256String, false},
}
for _, testCase := range testCases {
testCase := testCase
t.Run(testCase.Name, func(t *testing.T) {
t.Parallel()
err := codersdk.GroupNameValid(testCase.Name)
assert.Equal(
t,
testCase.Valid,
err == nil,
"Test case %s failed: expected valid=%t but got error: %v",
testCase.Name,
testCase.Valid,
err,
)
})
}
}
Loading

[8]ページ先頭

©2009-2025 Movatter.jp