From f299a29573678d5f44dbdfb6fb0e77ef3a9abb6d Mon Sep 17 00:00:00 2001 From: Edward McFarlane Date: Wed, 29 Nov 2023 18:30:22 -0500 Subject: [PATCH] Add username validation for names 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. --- buf/registry/owner/v1beta1/organization.proto | 7 +++++-- buf/registry/owner/v1beta1/organization_service.proto | 4 +++- buf/registry/owner/v1beta1/owner.proto | 3 ++- buf/registry/owner/v1beta1/user.proto | 7 +++++-- buf/registry/owner/v1beta1/user_service.proto | 4 +++- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/buf/registry/owner/v1beta1/organization.proto b/buf/registry/owner/v1beta1/organization.proto index 5ea4a4b..8d73a5e 100644 --- a/buf/registry/owner/v1beta1/organization.proto +++ b/buf/registry/owner/v1beta1/organization.proto @@ -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]; @@ -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]$"; }]; } } diff --git a/buf/registry/owner/v1beta1/organization_service.proto b/buf/registry/owner/v1beta1/organization_service.proto index 0987147..3cd50da 100644 --- a/buf/registry/owner/v1beta1/organization_service.proto +++ b/buf/registry/owner/v1beta1/organization_service.proto @@ -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]; diff --git a/buf/registry/owner/v1beta1/owner.proto b/buf/registry/owner/v1beta1/owner.proto index ab45248..63cd935 100644 --- a/buf/registry/owner/v1beta1/owner.proto +++ b/buf/registry/owner/v1beta1/owner.proto @@ -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]$"; }]; } } diff --git a/buf/registry/owner/v1beta1/user.proto b/buf/registry/owner/v1beta1/user.proto index 47074fb..b4fbbad 100644 --- a/buf/registry/owner/v1beta1/user.proto +++ b/buf/registry/owner/v1beta1/user.proto @@ -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 [ @@ -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]$"; }]; } } diff --git a/buf/registry/owner/v1beta1/user_service.proto b/buf/registry/owner/v1beta1/user_service.proto index ca0cf1a..824dcc2 100644 --- a/buf/registry/owner/v1beta1/user_service.proto +++ b/buf/registry/owner/v1beta1/user_service.proto @@ -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. //