From 452a144dc1caf3335229c861e3de6cbb00c0bbad Mon Sep 17 00:00:00 2001 From: Kilian Seizinger Date: Fri, 22 May 2020 18:07:48 +0200 Subject: [PATCH 1/2] :bug: Fix username RegEx --- openbook_auth/validators.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/openbook_auth/validators.py b/openbook_auth/validators.py index 5ac1e3fa..d77ee56b 100644 --- a/openbook_auth/validators.py +++ b/openbook_auth/validators.py @@ -6,9 +6,11 @@ def username_characters_validator(username): - if not re.match('^[a-zA-Z0-9_.]*$', username): + if not re.match("^[a-zA-Z0-9](?:[._]?[a-z-A-Z0-9])*$", username): raise ValidationError( - _('Usernames can only contain alphanumeric characters, periods and underscores.'), + _( + 'Usernames can only contain alphanumeric characters, periods and underscores. They must not begin or end with a period or underscore.' + ) ) From 8addfae3afe935b20038c02ba3d12b1e2a321fd1 Mon Sep 17 00:00:00 2001 From: Kilian Seizinger Date: Fri, 22 May 2020 18:08:05 +0200 Subject: [PATCH 2/2] :white_check_mark: Extend the tests --- openbook_auth/tests/views/test_auth.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openbook_auth/tests/views/test_auth.py b/openbook_auth/tests/views/test_auth.py index 6cc3a937..d30eea17 100644 --- a/openbook_auth/tests/views/test_auth.py +++ b/openbook_auth/tests/views/test_auth.py @@ -96,7 +96,7 @@ def test_invalid_username(self): should return 400 if the username is not valid """ url = self._get_url() - invalid_usernames = ('joel<;<', '<>', ' shantanu space ', 'greater_than_30_characters_username_is_not_valid',) + invalid_usernames = ('joel<;<', '<>', ' shantanu space ', 'greater_than_30_characters_username_is_not_valid','.start_with_period','more_than__one_special_char','end_with_period.') token = self._make_user_invite_token() for username in invalid_usernames: data = {