Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions apps/users/tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def test_duplicate_username(self):
self.assertFalse(form.is_valid())
self.assertIn("username", form.errors)

def test_duplicate_email(self):
def test_duplicate_email_does_not_report_the_address_is_taken(self):
"""Enumeration prevention keeps signup from confirming a known address."""
user = User.objects.create_user("test1", "test@example.com", "testpass")
EmailAddress.objects.create(user=user, email="test@example.com")

Expand All @@ -54,8 +55,8 @@ def test_duplicate_email(self):
}
)

self.assertFalse(form.is_valid())
self.assertIn("email", form.errors)
self.assertTrue(form.is_valid())
self.assertNotIn("email", form.errors)

def test_newline_in_username(self):
# Note that since Django 1.9, forms.CharField().strip is True
Expand Down
16 changes: 15 additions & 1 deletion apps/users/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,22 @@ def test_user_duplicate_username_email(self):
}
self.assertUserCreated(data=post_data)
response = self.assertUserCreated(data=post_data, template_name="account/signup.html")
# A taken username still has to be reported. A taken email must not be:
# enumeration prevention sends mail to the address instead.
Comment on lines +243 to +244
self.assertContains(response, "A user with that username already exists.")
self.assertContains(response, "A user is already registered with this email address.")
self.assertNotContains(response, "A user is already registered with this email address.")

def test_password_reset_does_not_reveal_whether_the_email_is_known(self):
Comment on lines +247 to +248
"""An unknown address gets the same page as a known one."""
url = reverse("account_reset_password")

known = self.client.post(url, {"email": self.user.email}, follow=True)
unknown = self.client.post(url, {"email": "nobody@example.com"}, follow=True)

self.assertEqual(known.status_code, 200)
self.assertEqual(unknown.status_code, 200)
self.assertEqual(known.redirect_chain, unknown.redirect_chain)
self.assertNotContains(unknown, "The email address is not assigned to any user account")

def test_usernames(self):
url = reverse("account_signup")
Expand Down
3 changes: 1 addition & 2 deletions pydotorg/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@
ACCOUNT_SIGNUP_FIELDS = ["email*", "username*", "password1*", "password2*"]
ACCOUNT_UNIQUE_EMAIL = True
ACCOUNT_EMAIL_VERIFICATION = "mandatory"
# TODO: Enable enumeration prevention
ACCOUNT_PREVENT_ENUMERATION = False
ACCOUNT_PREVENT_ENUMERATION = True
SOCIALACCOUNT_EMAIL_REQUIRED = True
SOCIALACCOUNT_EMAIL_VERIFICATION = True
SOCIALACCOUNT_QUERY_EMAIL = True
Expand Down