From 77dd0e4a272cedef3b43847432226616df6f3735 Mon Sep 17 00:00:00 2001 From: "Ja (Thanakul) Wattanawong" Date: Fri, 9 Oct 2020 08:11:28 -0700 Subject: [PATCH 1/6] Allow numbers in usernames --- ocflib/account/validators.py | 4 ++-- tests/account/validators_test.py | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/ocflib/account/validators.py b/ocflib/account/validators.py index 3b776c92..22c28e38 100644 --- a/ocflib/account/validators.py +++ b/ocflib/account/validators.py @@ -344,8 +344,8 @@ def validate_username(username, check_exists=False): if not 3 <= len(username) <= 16: raise ValueError('Username must be between 3 and 16 characters.') - if not all(c.islower() for c in username): - raise ValueError('Username must be all lowercase letters.') + if not all(c.islower() or c.isdigit() for c in username): + raise ValueError('Username must be all lowercase and numeric characters.') if check_exists and not user_exists(username): raise ValueError('Username does not exist.') diff --git a/tests/account/validators_test.py b/tests/account/validators_test.py index 216745cb..b9c6d137 100644 --- a/tests/account/validators_test.py +++ b/tests/account/validators_test.py @@ -25,8 +25,6 @@ class TestValidateUsername: # bad characters 'Ckuehl', 'ckuehl!', - '123123', - 'f00f00', ]) def test_failure(self, username): with pytest.raises(ValueError): From fe06b66526f83f335ccd3b9363b59f3a10cabcf9 Mon Sep 17 00:00:00 2001 From: "Ja (Thanakul) Wattanawong" Date: Fri, 9 Oct 2020 21:46:36 -0700 Subject: [PATCH 2/6] Enforce first character lowercase --- ocflib/account/validators.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ocflib/account/validators.py b/ocflib/account/validators.py index 22c28e38..0e14ea20 100644 --- a/ocflib/account/validators.py +++ b/ocflib/account/validators.py @@ -344,8 +344,11 @@ def validate_username(username, check_exists=False): if not 3 <= len(username) <= 16: raise ValueError('Username must be between 3 and 16 characters.') + if not username[0].islower(): + raise ValueError('Username must begin with a lowercase character') + if not all(c.islower() or c.isdigit() for c in username): - raise ValueError('Username must be all lowercase and numeric characters.') + raise ValueError('Username must be only lowercase and numeric characters.') if check_exists and not user_exists(username): raise ValueError('Username does not exist.') From ae66b47446410c732d2c92df750cec040a8ec406 Mon Sep 17 00:00:00 2001 From: "Ja (Thanakul) Wattanawong" Date: Fri, 9 Oct 2020 21:47:05 -0700 Subject: [PATCH 3/6] Add back all numeric bad case --- tests/account/validators_test.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/account/validators_test.py b/tests/account/validators_test.py index b9c6d137..ac1a4e86 100644 --- a/tests/account/validators_test.py +++ b/tests/account/validators_test.py @@ -25,6 +25,7 @@ class TestValidateUsername: # bad characters 'Ckuehl', 'ckuehl!', + '123123', ]) def test_failure(self, username): with pytest.raises(ValueError): From 0083f290253969aaa46c6b3fad4861502398d45a Mon Sep 17 00:00:00 2001 From: "Ja (Thanakul) Wattanawong" Date: Sat, 10 Oct 2020 13:28:03 -0700 Subject: [PATCH 4/6] Allow usernames with numbers --- ocflib/account/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ocflib/account/utils.py b/ocflib/account/utils.py index ca120211..d2162dba 100644 --- a/ocflib/account/utils.py +++ b/ocflib/account/utils.py @@ -40,7 +40,7 @@ def extract_username_from_principal(principal): 'ckuehl' """ - REGEX = '^([a-z]{3,16})(/[a-z]*)?@OCF\\.BERKELEY\\.EDU$' + REGEX = '^([a-z0-9]{3,16})(/[a-z]*)?@OCF\\.BERKELEY\\.EDU$' match = re.match(REGEX, principal) if not match: From 3adda0e276fe73c003b470cb210700772a11120f Mon Sep 17 00:00:00 2001 From: "Ja (Thanakul) Wattanawong" Date: Wed, 14 Oct 2020 01:47:27 -0700 Subject: [PATCH 5/6] Make regex more strict --- ocflib/account/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ocflib/account/utils.py b/ocflib/account/utils.py index d2162dba..4c4d226c 100644 --- a/ocflib/account/utils.py +++ b/ocflib/account/utils.py @@ -40,7 +40,7 @@ def extract_username_from_principal(principal): 'ckuehl' """ - REGEX = '^([a-z0-9]{3,16})(/[a-z]*)?@OCF\\.BERKELEY\\.EDU$' + REGEX = '^([a-z][a-z0-9]{2,16})(/[a-z]*)?@OCF\\.BERKELEY\\.EDU$' match = re.match(REGEX, principal) if not match: From 8264faa21ff99405cbd677bf10ca0d26d40b0042 Mon Sep 17 00:00:00 2001 From: "Ja (Thanakul) Wattanawong" Date: Wed, 14 Oct 2020 02:16:34 -0700 Subject: [PATCH 6/6] I can't add --- ocflib/account/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ocflib/account/utils.py b/ocflib/account/utils.py index 4c4d226c..e7d8d6e8 100644 --- a/ocflib/account/utils.py +++ b/ocflib/account/utils.py @@ -40,7 +40,7 @@ def extract_username_from_principal(principal): 'ckuehl' """ - REGEX = '^([a-z][a-z0-9]{2,16})(/[a-z]*)?@OCF\\.BERKELEY\\.EDU$' + REGEX = '^([a-z][a-z0-9]{2,15})(/[a-z]*)?@OCF\\.BERKELEY\\.EDU$' match = re.match(REGEX, principal) if not match: