Skip to content

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 6, 2024

Conversation

BrunoQuaresma
Copy link
Collaborator

Close #15184

@BrunoQuaresma BrunoQuaresma requested a review from mtojek November 5, 2024 13:17
@BrunoQuaresma BrunoQuaresma self-assigned this Nov 5, 2024
@mtojek mtojek requested a review from mafredri November 5, 2024 13:24
{"", 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
Collaborator Author

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.
if str == "new" || str == "create" {
	return xerrors.Errorf("cannot use %q as a name", str)
}

@BrunoQuaresma
Copy link
Collaborator Author

@ethanndickson @code-asher I see you both worked on this group name validation in the past, so I'm just checking if my changes are ok.

Comment on lines 272 to 273
{randomString(255), true},
{randomString(256), false},
Copy link
Member

Choose a reason for hiding this comment

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

Could you use testutil.GetRandomName(...) ?

Copy link
Member

Choose a reason for hiding this comment

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

I think get random name is limited in length 🤔

Copy link
Member

Choose a reason for hiding this comment

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

oh, then perhaps namesgenerator.GetRandomName(255)?

Copy link
Member

Choose a reason for hiding this comment

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

GetRandomName only checks if the argument is greater than 0, and if it is, appends a random number between 1 and 10

Copy link
Member

Choose a reason for hiding this comment

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

ok, one last guess: cryptorand.String(...)

t.Run(testCase.Name, func(t *testing.T) {
t.Parallel()
err := codersdk.GroupNameValid(testCase.Name)
assert.Equal(t, testCase.Valid, err == nil)
Copy link
Member

Choose a reason for hiding this comment

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

Can you modify this to contain the error if something bad happens:

assert.Equal(t, testCase.Valid, err == nil, "Test case %s failed: expected valid=%t but got error: %v", testCase.Name, testCase.Valid, err)

Copy link
Member

@ethanndickson ethanndickson left a comment

Choose a reason for hiding this comment

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

LGTM once Marcin's feedback is addressed!

Copy link
Member

@code-asher code-asher left a comment

Choose a reason for hiding this comment

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

Yup, the 36 char limit was pretty arbitrary so this makes sense to me.

@BrunoQuaresma BrunoQuaresma changed the title feat(coderd): increase group name limit to 255 feat(api): increase group name limit to 255 Nov 6, 2024
@BrunoQuaresma BrunoQuaresma changed the title feat(api): increase group name limit to 255 refactor: increase group name limit to 255 Nov 6, 2024
@BrunoQuaresma BrunoQuaresma merged commit 7f51005 into main Nov 6, 2024
32 checks passed
@BrunoQuaresma BrunoQuaresma deleted the bq/feat-increase-group-name-length branch November 6, 2024 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support longer group names
5 participants