Return the reason a username validation failed and add tests to verify we are sending the reason to client
This commit is contained in:
parent
a71c682abe
commit
0e54b0501c
3 changed files with 39 additions and 11 deletions
|
@ -10,10 +10,16 @@ def validate_email(email_address):
|
|||
|
||||
|
||||
def validate_username(username):
|
||||
# Minimum length of 2, maximum length of 255, no url unsafe characters
|
||||
return (re.search(r'[^a-z0-9_]', username) is None and
|
||||
len(username) >= 4 and
|
||||
len(username) <= 30)
|
||||
# Based off the restrictions defined in the Docker Registry API spec
|
||||
regex_match = (re.search(r'[^a-z0-9_]', username) is None)
|
||||
if not regex_match:
|
||||
return (False, 'Username must match expression [a-z0-9_]+')
|
||||
|
||||
length_match = (len(username) >= 4 and len(username) <= 30)
|
||||
if not length_match:
|
||||
return (False, 'Username must be between 4 and 30 characters in length')
|
||||
|
||||
return (True, '')
|
||||
|
||||
|
||||
def validate_password(password):
|
||||
|
|
Reference in a new issue