fix: registering new user with a name longer than 255 characters

This commit is contained in:
Dima Alipov
2024-04-23 14:47:07 +03:00
committed by Farhaan Bukhsh
parent 421f28f25d
commit 15aa04b858
2 changed files with 27 additions and 0 deletions

View File

@@ -148,6 +148,7 @@ class AccountCreationForm(forms.Form):
_EMAIL_INVALID_MSG = _("A properly formatted e-mail is required")
_NAME_TOO_SHORT_MSG = _("Your legal name must be a minimum of one character long")
_NAME_TOO_LONG_MSG = _("Your legal name is too long. It must not exceed %(max_length)s characters")
# TODO: Resolve repetition
@@ -167,9 +168,11 @@ class AccountCreationForm(forms.Form):
name = forms.CharField(
min_length=accounts.NAME_MIN_LENGTH,
max_length=accounts.NAME_MAX_LENGTH,
error_messages={
"required": _NAME_TOO_SHORT_MSG,
"min_length": _NAME_TOO_SHORT_MSG,
"max_length": _NAME_TOO_LONG_MSG % {"max_length": accounts.NAME_MAX_LENGTH},
},
validators=[validate_name]
)

View File

@@ -316,6 +316,30 @@ class RegistrationViewValidationErrorTest(
}
)
def test_register_fullname_max_lenghth_validation_error(self):
"""
Full name error detection test if the length exceeds 255 characters.
"""
expected_error_message = f"Your legal name is too long. It must not exceed {NAME_MAX_LENGTH} characters"
response = self.client.post(self.url, {
"email": self.EMAIL,
"name": "x" * 256,
"username": self.USERNAME,
"password": self.PASSWORD,
"honor_code": "true",
})
assert response.status_code == 400
response_json = json.loads(response.content.decode('utf-8'))
self.assertDictEqual(
response_json,
{
"name": [{"user_message": expected_error_message}],
"error_code": "validation-error"
}
)
def test_register_fullname_html_validation_error(self):
"""
Test for catching invalid full name errors