From 5e6a661648f6d9c743f04997defb562d4a5af60a Mon Sep 17 00:00:00 2001 From: Benjamin Ortiz Date: Fri, 10 Jul 2020 04:05:46 +0000 Subject: [PATCH] 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 --- plinth/modules/backups/forms.py | 2 +- plinth/modules/backups/tests/test_validators.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/plinth/modules/backups/forms.py b/plinth/modules/backups/forms.py index 60178e54f..32f4bc23e 100644 --- a/plinth/modules/backups/forms.py +++ b/plinth/modules/backups/forms.py @@ -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 diff --git a/plinth/modules/backups/tests/test_validators.py b/plinth/modules/backups/tests/test_validators.py index 7d3a1f859..394a6d2ae 100644 --- a/plinth/modules/backups/tests/test_validators.py +++ b/plinth/modules/backups/tests/test_validators.py @@ -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)