Skip to content

Commit

Permalink
fix: name length validation (#33615)
Browse files Browse the repository at this point in the history
* test: test for length validation
  • Loading branch information
Inferato authored Dec 4, 2023
1 parent 97b8cb9 commit 19844b9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions openedx/core/djangoapps/user_api/accounts/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,10 @@ def get_name_validation_error(name):
"""
if name:
# Validation for the name length
if len(name) > 255:
return _("Full name can't be longer than 255 symbols")

regex = re.findall(r'https|http?://(?:[-\w.]|(?:%[\da-fA-F]{2}))+', name)
return _('Enter a valid name') if bool(regex) else ''
else:
Expand Down
10 changes: 9 additions & 1 deletion openedx/core/djangoapps/user_api/accounts/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
from openedx.core.djangoapps.user_api.accounts import PRIVATE_VISIBILITY
from openedx.core.djangoapps.user_api.accounts.api import (
get_account_settings,
update_account_settings
update_account_settings,
get_name_validation_error
)
from openedx.core.djangoapps.user_api.accounts.tests.retirement_helpers import ( # pylint: disable=unused-import
RetirementTestCase,
Expand Down Expand Up @@ -570,6 +571,13 @@ def test_change_country_removes_state(self):
assert account_settings['country'] is None
assert account_settings['state'] is None

def test_get_name_validation_error_too_long(self):
"""
Test validation error when the name is too long.
"""
result = get_name_validation_error("A" * 256)
assert result == "Full name can't be longer than 255 symbols"


@patch('openedx.core.djangoapps.user_api.accounts.image_helpers._PROFILE_IMAGE_SIZES', [50, 10])
@patch.dict(
Expand Down

0 comments on commit 19844b9

Please sign in to comment.