Skip to content

Commit

Permalink
Reject usernames with a length > 36
Browse files Browse the repository at this point in the history
  • Loading branch information
David Cooke committed Feb 13, 2022
1 parent f8717d0 commit ffa24b0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/authentication/basic_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def validate(self, data):

self.validate_email(data["email"])
self.check_email_or_username_in_use(email=data["email"], username=data["username"])
if len(data["username"]) > 36:
raise ValidationError("username_too_long")

return {key: data[key] for key in self.required_fields}

Expand Down
9 changes: 9 additions & 0 deletions src/authentication/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,15 @@ def test_register_with_mail_failing_domain(self):
config.set("email_domain", None)
self.assertEqual(response.status_code, HTTP_400_BAD_REQUEST)

def test_register_long_username(self):
data = {
"username": "a" * 37,
"password": "uO7*$E@0ngqL",
"email": "user11@example.org",
}
response = self.client.post(reverse("register"), data)
self.assertEqual(response.status_code, HTTP_400_BAD_REQUEST)


class EmailResendTestCase(APITestCase):
def test_email_resend(self):
Expand Down

0 comments on commit ffa24b0

Please sign in to comment.