Skip to content

Commit b3bd496

Browse files
committed
Fixup tests that interact with django-allauth ACCOUNT_PREVENT_ENUMERATION
ACCOUNT_PREVENT_ENUMERATION was introduced in django-allauth 0.52.0, and interferes with our expectations. This should probably be turned on! But for now disable it by default to keep the changeset minimal. Allauth _used_ to iterate over users to check for email uniquenss but stopped at some point, so we have to create an EmailAdress object for the user in the relevant test-case for duplicate emails
1 parent ab1dc94 commit b3bd496

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

pydotorg/settings/base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@
110110
ACCOUNT_UNIQUE_EMAIL = True
111111
ACCOUNT_EMAIL_VERIFICATION = 'mandatory'
112112
ACCOUNT_AUTHENTICATION_METHOD = 'username_email'
113+
# TODO: Enable enumeration prevention
114+
ACCOUNT_PREVENT_ENUMERATION = False
113115
SOCIALACCOUNT_EMAIL_REQUIRED = True
114116
SOCIALACCOUNT_EMAIL_VERIFICATION = True
115117
SOCIALACCOUNT_QUERY_EMAIL = True

users/tests/test_forms.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from django.contrib.auth import get_user_model
2-
from django.test import TestCase, RequestFactory
2+
from django.test import TestCase
33

44
from allauth.account.forms import SignupForm
5+
from allauth.account.models import EmailAddress
56

67
from users.forms import UserProfileForm, MembershipForm
78

@@ -50,8 +51,8 @@ def test_duplicate_username(self):
5051
self.assertIn('username', form.errors)
5152

5253
def test_duplicate_email(self):
53-
User.objects.create_user('test1', '[email protected]', 'testpass')
54-
request = RequestFactory().get('/')
54+
user = User.objects.create_user('test1', '[email protected]', 'testpass')
55+
EmailAddress.objects.create(user=user, email="[email protected]")
5556

5657
form = SignupForm(data={
5758
'username': 'username2',
@@ -60,11 +61,8 @@ def test_duplicate_email(self):
6061
'password2': 'password',
6162
})
6263

63-
self.assertTrue(form.is_valid())
64-
with self.assertRaises(ValueError) as e:
65-
form.save(request)
66-
67-
self.assertEqual(str(e.exception), '[email protected]')
64+
self.assertFalse(form.is_valid())
65+
self.assertIn('email', form.errors)
6866

6967
def test_newline_in_username(self):
7068
# Note that since Django 1.9, forms.CharField().strip is True

users/tests/test_views.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,6 @@ def test_user_new_account(self):
228228
'password2': 'password',
229229
})
230230

231-
@override_settings(ACCOUNT_PREVENT_ENUMERATION=False)
232231
def test_user_duplicate_username_email(self):
233232
post_data = {
234233
'username': 'thisusernamedoesntexist',

0 commit comments

Comments
 (0)