More detailed namespace validation

Fixes namespace validation to use the proper regex for checking length, as well as showing the proper messaging if the entered namespace is invalid

[Delivers #137830461]
This commit is contained in:
Joseph Schorr 2017-01-17 17:31:24 -05:00
parent aafcb592a6
commit 462f47924e
7 changed files with 11 additions and 14 deletions

View file

@ -19,11 +19,8 @@ def create_organization(name, email, creating_user, email_required=True):
team.add_user_to_team(creating_user, owners_team)
return new_org
except InvalidUsernameException:
msg = ('Invalid organization name: %s Organization names must consist ' +
'solely of lower case letters, numbers, and underscores. ' +
'[a-z0-9_]') % name
raise InvalidOrganizationException(msg)
except InvalidUsernameException as iue:
raise InvalidOrganizationException(iue.message)
def get_organization(name):

View file

@ -57,7 +57,7 @@ def create_user_noverify(username, email, email_required=True, prompts=tuple()):
(username_valid, username_issue) = validate_username(username)
if not username_valid:
raise InvalidUsernameException('Invalid username %s: %s' % (username, username_issue))
raise InvalidUsernameException('Invalid namespace %s: %s' % (username, username_issue))
try:
existing = User.get((User.username == username) | (User.email == email))

View file

@ -16,7 +16,7 @@
Usernames with dots or dashes are incompatible with Docker version 1.8 or older
</div>
<div class="co-alert co-alert-danger thin" ng-show="!signupForm.namespaceField.$error.required && signupForm.namespaceField.$invalid">
Usernames must be alphanumeric and be at least four characters in length
Usernames must be alphanumeric and between four and thirty characters in length
</div>
</div>

View file

@ -1,6 +1,6 @@
var TEAM_PATTERN = '^[a-z][a-z0-9]+$';
var ROBOT_PATTERN = '^[a-z][a-z0-9_]{3,29}$';
var USERNAME_PATTERN = '^([a-z0-9]+(?:[._-][a-z0-9]+)*){4,30}$';
var USERNAME_PATTERN = '^(?=.{4,30}$)([a-z0-9]+(?:[._-][a-z0-9]+)*)$';
// Define the pages module.
quayPages = angular.module('quayPages', [], function(){});

View file

@ -48,10 +48,10 @@
Organization names with dots or dashes are incompatible with Docker version 1.8 or older
</span>
<span class="co-alert co-alert-danger thin" ng-show="!newOrgForm.namespaceField.$error.required && newOrgForm.namespaceField.$invalid">
Organization names must be alphanumeric and be at least four characters in length
Organization names must be alphanumeric, be at least four characters in length and max thirty characters in length
</span>
</div>
<span class="description">This will also be the namespace for your repositories. Must be alphanumeric, all lowercase and at least four characters long.</span>
<span class="description">This will also be the namespace for your repositories. Must be alphanumeric, all lowercase, at least four characters long and at most thirty characters long.</span>
</div>
<div class="form-group nested" quay-require="['MAILING']">

View file

@ -651,7 +651,7 @@ class TestCreateNewUser(ApiTestCase):
email='test@example.com'),
expected_code=400)
self.assertEquals('Invalid username a: Username must be between 4 and 30 characters in length',
self.assertEquals('Invalid namespace a: Namespace must be between 4 and 30 characters in length',
json['detail'])
def test_trycreateregexmismatch(self):
@ -661,7 +661,7 @@ class TestCreateNewUser(ApiTestCase):
email='test@example.com'),
expected_code=400)
self.assertEquals('Invalid username auserName: Username must match expression ^([a-z0-9]+(?:[._-][a-z0-9]+)*)$',
self.assertEquals('Invalid namespace auserName: Namespace must match expression ^([a-z0-9]+(?:[._-][a-z0-9]+)*)$',
json['detail'])
def test_createuser(self):

View file

@ -35,11 +35,11 @@ def validate_email(email_address):
def validate_username(username):
# Based off the restrictions defined in the Docker Registry API spec
if not re.match(VALID_USERNAME_REGEX, username):
return (False, 'Username must match expression ' + VALID_USERNAME_REGEX)
return (False, 'Namespace must match expression ' + VALID_USERNAME_REGEX)
length_match = (len(username) >= MIN_USERNAME_LENGTH and len(username) <= MAX_USERNAME_LENGTH)
if not length_match:
return (False, 'Username must be between %s and %s characters in length' %
return (False, 'Namespace must be between %s and %s characters in length' %
(MIN_USERNAME_LENGTH, MAX_USERNAME_LENGTH))
return (True, '')