Merge pull request #12587 from edx/PLAT-1004-Email-field-lenght
Set the Email field length is 254 characters.
This commit is contained in:
@@ -131,7 +131,7 @@ class AccountCreationForm(forms.Form):
|
||||
}
|
||||
)
|
||||
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={
|
||||
"required": _EMAIL_INVALID_MSG,
|
||||
"invalid": _EMAIL_INVALID_MSG,
|
||||
|
||||
@@ -388,8 +388,19 @@ class TestCreateAccountValidation(TestCase):
|
||||
assert_email_error("A properly formatted e-mail is required")
|
||||
|
||||
# Too long
|
||||
params["email"] = "this_email_address_has_76_characters_in_it_so_it_is_unacceptable@example.com"
|
||||
assert_email_error("Email cannot be more than 75 characters long")
|
||||
params["email"] = '{email}@example.com'.format(
|
||||
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
|
||||
params["email"] = "not_an_email_address"
|
||||
|
||||
@@ -38,17 +38,20 @@ class TestLongUsernameEmail(TestCase):
|
||||
|
||||
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)
|
||||
|
||||
# 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.
|
||||
self.assertEqual(response.status_code, 400)
|
||||
|
||||
obj = json.loads(response.content)
|
||||
self.assertEqual(
|
||||
obj['value'],
|
||||
"Email cannot be more than 75 characters long",
|
||||
"Email cannot be more than 254 characters long",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user