From 47f2f7de0f14065ffdaacb9ef0d0a5709a8b87ce Mon Sep 17 00:00:00 2001 From: attiyaishaque Date: Tue, 31 May 2016 15:59:23 +0500 Subject: [PATCH] Set the Email field length is 254 characters. --- common/djangoapps/student/forms.py | 2 +- .../student/tests/test_create_account.py | 15 +++++++++++++-- .../student/tests/test_long_username_email.py | 9 ++++++--- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/common/djangoapps/student/forms.py b/common/djangoapps/student/forms.py index e9bce5a025..095b7cc21c 100644 --- a/common/djangoapps/student/forms.py +++ b/common/djangoapps/student/forms.py @@ -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, diff --git a/common/djangoapps/student/tests/test_create_account.py b/common/djangoapps/student/tests/test_create_account.py index 3f9aa3f3c1..fec922ab44 100644 --- a/common/djangoapps/student/tests/test_create_account.py +++ b/common/djangoapps/student/tests/test_create_account.py @@ -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" diff --git a/common/djangoapps/student/tests/test_long_username_email.py b/common/djangoapps/student/tests/test_long_username_email.py index 7bfc02ca4a..4bdd7f6fba 100644 --- a/common/djangoapps/student/tests/test_long_username_email.py +++ b/common/djangoapps/student/tests/test_long_username_email.py @@ -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", )