Skip to content

Commit

Permalink
Fixup tests that interact with django-allauth ACCOUNT_PREVENT_ENUMERA…
Browse files Browse the repository at this point in the history
…TION

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
  • Loading branch information
ewdurbin committed Sep 11, 2024
1 parent ab1dc94 commit b3bd496
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
2 changes: 2 additions & 0 deletions pydotorg/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@
ACCOUNT_UNIQUE_EMAIL = True
ACCOUNT_EMAIL_VERIFICATION = 'mandatory'
ACCOUNT_AUTHENTICATION_METHOD = 'username_email'
# TODO: Enable enumeration prevention
ACCOUNT_PREVENT_ENUMERATION = False
SOCIALACCOUNT_EMAIL_REQUIRED = True
SOCIALACCOUNT_EMAIL_VERIFICATION = True
SOCIALACCOUNT_QUERY_EMAIL = True
Expand Down
14 changes: 6 additions & 8 deletions users/tests/test_forms.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from django.contrib.auth import get_user_model
from django.test import TestCase, RequestFactory
from django.test import TestCase

from allauth.account.forms import SignupForm
from allauth.account.models import EmailAddress

from users.forms import UserProfileForm, MembershipForm

Expand Down Expand Up @@ -50,8 +51,8 @@ def test_duplicate_username(self):
self.assertIn('username', form.errors)

def test_duplicate_email(self):
User.objects.create_user('test1', '[email protected]', 'testpass')
request = RequestFactory().get('/')
user = User.objects.create_user('test1', '[email protected]', 'testpass')
EmailAddress.objects.create(user=user, email="[email protected]")

form = SignupForm(data={
'username': 'username2',
Expand All @@ -60,11 +61,8 @@ def test_duplicate_email(self):
'password2': 'password',
})

self.assertTrue(form.is_valid())
with self.assertRaises(ValueError) as e:
form.save(request)

self.assertEqual(str(e.exception), '[email protected]')
self.assertFalse(form.is_valid())
self.assertIn('email', form.errors)

def test_newline_in_username(self):
# Note that since Django 1.9, forms.CharField().strip is True
Expand Down
1 change: 0 additions & 1 deletion users/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ def test_user_new_account(self):
'password2': 'password',
})

@override_settings(ACCOUNT_PREVENT_ENUMERATION=False)
def test_user_duplicate_username_email(self):
post_data = {
'username': 'thisusernamedoesntexist',
Expand Down

0 comments on commit b3bd496

Please sign in to comment.