backups: Allow remote repository usernames to start with numbers

Although useradd recommends starting with either a lowercase letter or an
underscore, there is nothing that consistently adheres to this recommendation
across systems. Because some systems do not follow this recommendation and this
recommendation is not a hard requirement, we should not prevent connections at
the validation stage.

Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
Benjamin Ortiz 2020-07-10 04:05:46 +00:00 committed by Sunil Mohan Adapa
parent b9fe3fb491
commit 5e6a661648
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2
2 changed files with 5 additions and 3 deletions

View File

@ -95,7 +95,7 @@ def repository_validator(path):
hostname = hostname.split('%')[0]
# Validate username using Unix username regex
if not re.match(r'[a-z_][a-z0-9_-]*$', username):
if not re.match(r'[a-z0-9_][a-z0-9_-]*$', username):
raise ValidationError(_(f'Invalid username: {username}'))
# The hostname should either be a valid IP address or hostname

View File

@ -34,8 +34,10 @@ def test_repository_paths_validation():
def test_repository_username_validation():
"""Test that usernames in repository string are validated properly."""
valid_usernames = ['sshuser', 'cypher_punk-2077', '_user', '_-_']
invalid_usernames = ['1two', 'somebody else']
valid_usernames = [
'sshuser', 'cypher_punk-2077', '_user', '_-_', '1two', '1234'
]
invalid_usernames = ['somebody else']
path_string = '{}@example.org:~/backups'
_validate_repository(valid_usernames, invalid_usernames, path_string)