Strengths invalid characters detection in username

By doing re.fullmatch per ogayot's recommendation.
Added a test case to validate it.
The added test would fail without the fullmatch.
This commit is contained in:
Carlos Nihelton 2022-05-11 12:58:13 -03:00
parent 79205ed3ea
commit 888eb344a2
No known key found for this signature in database
GPG Key ID: 6FE346D245197E9A
2 changed files with 5 additions and 1 deletions

View File

@ -160,7 +160,7 @@ class IdentityController(SubiquityController):
if username in self._system_reserved_names:
return UsernameValidation.SYSTEM_RESERVED
if not re.match(USERNAME_REGEX, username):
if not re.fullmatch(USERNAME_REGEX, username):
return UsernameValidation.INVALID_CHARS
if len(username) > USERNAME_MAXLEN:

View File

@ -1083,3 +1083,7 @@ class TestIdentityValidation(TestAPI):
resp = await inst.get('/identity/validate_username',
username='01root')
self.assertEqual(resp, 'INVALID_CHARS')
resp = await inst.get('/identity/validate_username',
username='o#$%^&')
self.assertEqual(resp, 'INVALID_CHARS')