Merge pull request #2283 from coreos-inc/namespace-messaging
More detailed namespace validation
This commit is contained in:
commit
1bbb69367a
7 changed files with 11 additions and 14 deletions
|
@ -19,11 +19,8 @@ def create_organization(name, email, creating_user, email_required=True):
|
||||||
team.add_user_to_team(creating_user, owners_team)
|
team.add_user_to_team(creating_user, owners_team)
|
||||||
|
|
||||||
return new_org
|
return new_org
|
||||||
except InvalidUsernameException:
|
except InvalidUsernameException as iue:
|
||||||
msg = ('Invalid organization name: %s Organization names must consist ' +
|
raise InvalidOrganizationException(iue.message)
|
||||||
'solely of lower case letters, numbers, and underscores. ' +
|
|
||||||
'[a-z0-9_]') % name
|
|
||||||
raise InvalidOrganizationException(msg)
|
|
||||||
|
|
||||||
|
|
||||||
def get_organization(name):
|
def get_organization(name):
|
||||||
|
|
|
@ -57,7 +57,7 @@ def create_user_noverify(username, email, email_required=True, prompts=tuple()):
|
||||||
|
|
||||||
(username_valid, username_issue) = validate_username(username)
|
(username_valid, username_issue) = validate_username(username)
|
||||||
if not username_valid:
|
if not username_valid:
|
||||||
raise InvalidUsernameException('Invalid username %s: %s' % (username, username_issue))
|
raise InvalidUsernameException('Invalid namespace %s: %s' % (username, username_issue))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
existing = User.get((User.username == username) | (User.email == email))
|
existing = User.get((User.username == username) | (User.email == email))
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
Usernames with dots or dashes are incompatible with Docker version 1.8 or older
|
Usernames with dots or dashes are incompatible with Docker version 1.8 or older
|
||||||
</div>
|
</div>
|
||||||
<div class="co-alert co-alert-danger thin" ng-show="!signupForm.namespaceField.$error.required && signupForm.namespaceField.$invalid">
|
<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>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
var TEAM_PATTERN = '^[a-z][a-z0-9]+$';
|
var TEAM_PATTERN = '^[a-z][a-z0-9]+$';
|
||||||
var ROBOT_PATTERN = '^[a-z][a-z0-9_]{3,29}$';
|
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.
|
// Define the pages module.
|
||||||
quayPages = angular.module('quayPages', [], function(){});
|
quayPages = angular.module('quayPages', [], function(){});
|
||||||
|
|
|
@ -48,10 +48,10 @@
|
||||||
Organization names with dots or dashes are incompatible with Docker version 1.8 or older
|
Organization names with dots or dashes are incompatible with Docker version 1.8 or older
|
||||||
</span>
|
</span>
|
||||||
<span class="co-alert co-alert-danger thin" ng-show="!newOrgForm.namespaceField.$error.required && newOrgForm.namespaceField.$invalid">
|
<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>
|
</span>
|
||||||
</div>
|
</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>
|
||||||
|
|
||||||
<div class="form-group nested" quay-require="['MAILING']">
|
<div class="form-group nested" quay-require="['MAILING']">
|
||||||
|
|
|
@ -651,7 +651,7 @@ class TestCreateNewUser(ApiTestCase):
|
||||||
email='test@example.com'),
|
email='test@example.com'),
|
||||||
expected_code=400)
|
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'])
|
json['detail'])
|
||||||
|
|
||||||
def test_trycreateregexmismatch(self):
|
def test_trycreateregexmismatch(self):
|
||||||
|
@ -661,7 +661,7 @@ class TestCreateNewUser(ApiTestCase):
|
||||||
email='test@example.com'),
|
email='test@example.com'),
|
||||||
expected_code=400)
|
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'])
|
json['detail'])
|
||||||
|
|
||||||
def test_createuser(self):
|
def test_createuser(self):
|
||||||
|
|
|
@ -35,11 +35,11 @@ def validate_email(email_address):
|
||||||
def validate_username(username):
|
def validate_username(username):
|
||||||
# Based off the restrictions defined in the Docker Registry API spec
|
# Based off the restrictions defined in the Docker Registry API spec
|
||||||
if not re.match(VALID_USERNAME_REGEX, username):
|
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)
|
length_match = (len(username) >= MIN_USERNAME_LENGTH and len(username) <= MAX_USERNAME_LENGTH)
|
||||||
if not length_match:
|
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))
|
(MIN_USERNAME_LENGTH, MAX_USERNAME_LENGTH))
|
||||||
|
|
||||||
return (True, '')
|
return (True, '')
|
||||||
|
|
Reference in a new issue