Skip to content

Commit

Permalink
Add username validation for names (#41)
Browse files Browse the repository at this point in the history
Adds a regex pattern match for usernames "^[a-z][a-z0-9-]*[a-z0-9]$".
Must start with a lowercase letter, only consist of alpha numerics or
hypens and doesn't end with a hypen. Bumped the min length to 2 as the
RE2 syntax doesn't support lookback syntax.
  • Loading branch information
emcfarlane authored Nov 30, 2023
1 parent 97498ee commit 371f64e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
7 changes: 5 additions & 2 deletions buf/registry/owner/v1beta1/organization.proto
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ message Organization {
// A name uniquely identifies an Organization, however name is mutable.
string name = 4 [
(buf.validate.field).required = true,
(buf.validate.field).string.max_len = 32
(buf.validate.field).string.min_len = 2,
(buf.validate.field).string.max_len = 32,
(buf.validate.field).string.pattern = "^[a-z][a-z0-9-]*[a-z0-9]$"
];
// The configurable description of the Organization.
string description = 5 [(buf.validate.field).string.max_len = 350];
Expand Down Expand Up @@ -82,8 +84,9 @@ message OrganizationRef {
string id = 1 [(buf.validate.field).string.uuid = true];
// The name of the Organization.
string name = 2 [(buf.validate.field).string = {
min_len: 1;
min_len: 2;
max_len: 32;
pattern: "^[a-z][a-z0-9-]*[a-z0-9]$";
}];
}
}
4 changes: 3 additions & 1 deletion buf/registry/owner/v1beta1/organization_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ message CreateOrganizationsRequest {
// The name of the Organization.
string name = 1 [
(buf.validate.field).required = true,
(buf.validate.field).string.max_len = 32
(buf.validate.field).string.min_len = 2,
(buf.validate.field).string.max_len = 32,
(buf.validate.field).string.pattern = "^[a-z][a-z0-9-]*[a-z0-9]$"
];
// The configurable description of the Organization.
string description = 2 [(buf.validate.field).string.max_len = 350];
Expand Down
3 changes: 2 additions & 1 deletion buf/registry/owner/v1beta1/owner.proto
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ message OwnerRef {
string id = 1 [(buf.validate.field).string.uuid = true];
// The name of the User or Organization.
string name = 2 [(buf.validate.field).string = {
min_len: 1;
min_len: 2;
max_len: 32;
pattern: "^[a-z][a-z0-9-]*[a-z0-9]$";
}];
}
}
7 changes: 5 additions & 2 deletions buf/registry/owner/v1beta1/user.proto
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ message User {
// A name uniquely identifies a User, however name is mutable.
string name = 4 [
(buf.validate.field).required = true,
(buf.validate.field).string.max_len = 32
(buf.validate.field).string.min_len = 2,
(buf.validate.field).string.max_len = 32,
(buf.validate.field).string.pattern = "^[a-z][a-z0-9-]*[a-z0-9]$"
];
// The type of the User.
UserType type = 5 [
Expand Down Expand Up @@ -111,8 +113,9 @@ message UserRef {
string id = 1 [(buf.validate.field).string.uuid = true];
// The name of the User.
string name = 2 [(buf.validate.field).string = {
min_len: 1;
min_len: 2;
max_len: 32;
pattern: "^[a-z][a-z0-9-]*[a-z0-9]$";
}];
}
}
4 changes: 3 additions & 1 deletion buf/registry/owner/v1beta1/user_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ message CreateUsersRequest {
// The name of the User.
string name = 1 [
(buf.validate.field).required = true,
(buf.validate.field).string.max_len = 32
(buf.validate.field).string.min_len = 2,
(buf.validate.field).string.max_len = 32,
(buf.validate.field).string.pattern = "^[a-z][a-z0-9-]*[a-z0-9]$"
];
// The type of the User.
//
Expand Down

0 comments on commit 371f64e

Please sign in to comment.