[VAN-332] Full name validation on registration page. (#28444)
This commit is contained in:
@@ -89,6 +89,14 @@ def contains_html(value):
|
||||
return bool(regex.search(value))
|
||||
|
||||
|
||||
def contains_url(value):
|
||||
"""
|
||||
Validator method to check whether full name contains url
|
||||
"""
|
||||
regex = re.findall(r'https|http?://(?:[-\w.]|(?:%[\da-fA-F]{2}))+', value)
|
||||
return bool(regex)
|
||||
|
||||
|
||||
def validate_name(name):
|
||||
"""
|
||||
Verifies a Full_Name is valid, raises a ValidationError otherwise.
|
||||
@@ -97,6 +105,8 @@ def validate_name(name):
|
||||
"""
|
||||
if contains_html(name):
|
||||
raise forms.ValidationError(_('Full Name cannot contain the following characters: < >'))
|
||||
if contains_url(name):
|
||||
raise forms.ValidationError(_('Enter a valid name'))
|
||||
|
||||
|
||||
class UsernameField(forms.CharField):
|
||||
|
||||
@@ -237,6 +237,27 @@ class RegistrationViewValidationErrorTest(ThirdPartyAuthTestMixin, UserAPITestCa
|
||||
}
|
||||
)
|
||||
|
||||
def test_register_fullname_url_validation_error(self):
|
||||
"""
|
||||
Test for catching invalid full name errors
|
||||
"""
|
||||
response = self.client.post(self.url, {
|
||||
"email": "bob@example.com",
|
||||
"name": "Bob Smith http://test.com",
|
||||
"username": "bob",
|
||||
"password": "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": 'Enter a valid name'}],
|
||||
"error_code": "validation-error"
|
||||
}
|
||||
)
|
||||
|
||||
@override_waffle_flag(REGISTRATION_FAILURE_LOGGING_FLAG, True)
|
||||
def test_registration_failure_logging(self):
|
||||
# Register a user
|
||||
|
||||
Reference in New Issue
Block a user