Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: registering a new user with a full name longer than 255 characters #34577

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -167,9 +168,11 @@ class AccountCreationForm(forms.Form):

name = forms.CharField(
min_length=accounts.NAME_MIN_LENGTH,
max_length=accounts.NAME_MAX_LENGTH,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of relying on system generated string we should add our own error message just like _NAME_TOO_SHORT_MSG this will help us to have have translations for them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@farhaanbukhsh done 😉

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]
)
Expand Down
24 changes: 24 additions & 0 deletions openedx/core/djangoapps/user_authn/views/tests/test_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,30 @@ def test_register_fullname_url_validation_error(self):
}
)

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
Expand Down
Loading