Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the user validation regex and message #120

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions invenio_userprofiles/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@

from flask_babelex import lazy_gettext as _

username_regex = re.compile('^[a-zA-Z][a-zA-Z0-9-_]{2}[a-zA-Z0-9-_]*$')
username_regex = re.compile('^[a-zA-Z0-9-_]{3,}$')
"""Username rules."""

USERNAME_RULES = _(
'Username must start with a letter, be at least three characters long and'
' only contain alphanumeric characters, dashes and underscores.')
'Username must be at least three characters long and only contain'
' alphanumeric characters, dashes and underscores.')
"""Description of username validation rules.

.. note:: Used for both form help text and for form validation error."""
Expand Down
9 changes: 3 additions & 6 deletions tests/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,17 @@

test_usernames = {
'valid': 'Good-Name_9',
'invalid_begins_with_number': '9CantStartWithNumber',
'valid_begins_with_number': '9CanStartWithNumber',
'invalid_characters': '_Containsi!!ega!Char acters*',
'invalid_short': 'ab',
}


def test_validate_username(app):
"""Test username validator."""
# Goodname can contain letters, numbers and starts with a letter
# Goodname can contain letters and numbers
validate_username(test_usernames['valid'])

# Can't start with a number
with pytest.raises(ValueError):
validate_username(test_usernames['invalid_begins_with_number'])
validate_username(test_usernames['valid_begins_with_number'])

# Can only contain latin letters and numbers
with pytest.raises(ValueError):
Expand Down