mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-09 11:46:49 +00:00
fix(accounts): a username longer than the field is refused by the login form
Django's login form gives the username its max_length after the field is built, so a longer username was not refused and reached authentication. django-axes then stored it in its 255-character column, which PostgreSQL refuses: a login with a 300-character username was a 500 (SQLite does not enforce the length). Both login forms, with and without OTP, now check the length, so such a username is a form error and never reaches authentication, the lockout or the Logs page. This also turns the PostgreSQL leg of CI green again: the S-16 test from #167 hit exactly this.
This commit is contained in:
parent
6c080aa4a3
commit
3210ef2eee
5 changed files with 36 additions and 5 deletions
|
|
@ -58,9 +58,13 @@ class LoginRowInputTests(TestCase):
|
|||
def login(self, username):
|
||||
return self.client.post(reverse("accounts:login"), {"username": username, "password": "wrong"})
|
||||
|
||||
def test_an_oversized_username_is_cut_to_the_field(self):
|
||||
self.assertEqual(self.login("x" * 300).status_code, 200)
|
||||
self.assertEqual(rows(), [("x" * 150, "-", "Login failed", False, "127.0.0.1")])
|
||||
def test_an_oversized_username_is_refused_by_the_form(self):
|
||||
# longer than the username field: no login attempt, so nothing for
|
||||
# django-axes to store (its 255-character column refused it on PostgreSQL)
|
||||
response = self.login("x" * 300)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertIn("username", response.context["form"].errors)
|
||||
self.assertFalse(Logs.objects.exists())
|
||||
|
||||
def test_a_crlf_username_stays_in_its_row(self):
|
||||
forged = "bob\r\nadmin - Login"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue