From 79a8529413f7de1b00d5acda9b5b08d339eeef8a Mon Sep 17 00:00:00 2001 From: Nils VAN ZUIJLEN Date: Sun, 4 Sep 2022 21:37:27 +0200 Subject: [PATCH 1/2] Add regression test for #75 --- accounts/tests.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/accounts/tests.py b/accounts/tests.py index ee8ad172..baecb7eb 100644 --- a/accounts/tests.py +++ b/accounts/tests.py @@ -11,6 +11,7 @@ from uuid import uuid4 from bs4 import BeautifulSoup from django.conf import settings +from django.core import mail from django.contrib.auth.models import Permission from django.contrib.auth.models import User from django.test import TestCase @@ -466,3 +467,18 @@ class ProfilTest(TestCase): self.user.first_name = "last_name" self.user.save() self.assertEqual(str(self.user.profile), "Test") + + +class PasswordResetTest(TestCase): + def setUp(self): + self.password = "AAA" + self.user = User.objects.create_user("AAA", "AAA@exemple.com", self.password) + + def test_password_reset_form(self): + """Check for regression on #75""" + resp = self.client.post("/accounts/password_reset/", data={"email": self.user.email}) + self.assertEqual(resp.status_code, 302) + self.assertEqual(resp.url, "/accounts/password_reset/done/") + self.assertEqual(len(mail.outbox), 1) + self.assertIn(self.user.email, mail.outbox[0].to) + self.assertEqual(len(mail.outbox[0].to), 1) -- GitLab From 8e4082791a0a8cd927c049d6466e4b903ec53080 Mon Sep 17 00:00:00 2001 From: Nils VAN ZUIJLEN Date: Sun, 4 Sep 2022 21:06:42 +0200 Subject: [PATCH 2/2] Change password reset URL requirements As per specified in https://code.djangoproject.com/ticket/31913 Fixes #75 --- accounts/urls.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/accounts/urls.py b/accounts/urls.py index b74591b8..105167fb 100644 --- a/accounts/urls.py +++ b/accounts/urls.py @@ -51,8 +51,8 @@ urlpatterns = [ ), name="password_reset_done", ), - re_path( - r"^reset/(?P[0-9A-Za-z_\-]+)/(?P[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/a$", + path( + "reset///a", auth_views.PasswordResetConfirmView.as_view( template_name="accounts/password_reset_confirm.html", success_url=reverse_lazy("password_reset_complete"), -- GitLab