Commit f7659c8b by Attiya Ishaque

Merge pull request #12587 from edx/PLAT-1004-Email-field-lenght

Set the Email field length is 254 characters.
parents 9d3365f0 62b431ea
...@@ -131,7 +131,7 @@ class AccountCreationForm(forms.Form): ...@@ -131,7 +131,7 @@ class AccountCreationForm(forms.Form):
} }
) )
email = forms.EmailField( email = forms.EmailField(
max_length=75, # Limit per RFCs is 254, but User's email field in django 1.4 only takes 75 max_length=254, # Limit per RFCs is 254
error_messages={ error_messages={
"required": _EMAIL_INVALID_MSG, "required": _EMAIL_INVALID_MSG,
"invalid": _EMAIL_INVALID_MSG, "invalid": _EMAIL_INVALID_MSG,
......
...@@ -388,8 +388,19 @@ class TestCreateAccountValidation(TestCase): ...@@ -388,8 +388,19 @@ class TestCreateAccountValidation(TestCase):
assert_email_error("A properly formatted e-mail is required") assert_email_error("A properly formatted e-mail is required")
# Too long # Too long
params["email"] = "this_email_address_has_76_characters_in_it_so_it_is_unacceptable@example.com" params["email"] = '{email}@example.com'.format(
assert_email_error("Email cannot be more than 75 characters long") email='this_email_address_has_254_characters_in_it_so_it_is_unacceptable' * 4
)
# Assert that we get error when email has more than 254 characters.
self.assertGreater(len(params['email']), 254)
assert_email_error("Email cannot be more than 254 characters long")
# Valid Email
params["email"] = "student@edx.com"
# Assert success on valid email
self.assertLess(len(params["email"]), 254)
self.assert_success(params)
# Invalid # Invalid
params["email"] = "not_an_email_address" params["email"] = "not_an_email_address"
......
...@@ -38,17 +38,20 @@ class TestLongUsernameEmail(TestCase): ...@@ -38,17 +38,20 @@ class TestLongUsernameEmail(TestCase):
def test_long_email(self): def test_long_email(self):
""" """
Test email cannot be more than 75 characters long. Test email cannot be more than 254 characters long.
""" """
self.url_params['email'] = '{0}@bar.com'.format('foo_bar' * 15) self.url_params['email'] = '{email}@bar.com'.format(email='foo_bar' * 36)
response = self.client.post(self.url, self.url_params) response = self.client.post(self.url, self.url_params)
# Assert that we get error when email has more than 254 characters.
self.assertGreater(len(self.url_params['email']), 254)
# Status code should be 400. # Status code should be 400.
self.assertEqual(response.status_code, 400) self.assertEqual(response.status_code, 400)
obj = json.loads(response.content) obj = json.loads(response.content)
self.assertEqual( self.assertEqual(
obj['value'], obj['value'],
"Email cannot be more than 75 characters long", "Email cannot be more than 254 characters long",
) )
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment