Selaa lähdekoodia

fix(api): auth action link after activation w/o domain was using wrong state

Peter Thomassen 2 vuotta sitten
vanhempi
commit
303ce2b2ff

+ 7 - 3
api/desecapi/tests/test_user_management.py

@@ -564,8 +564,11 @@ class UserManagementTestCase(DesecTestCase, PublicSuffixMockMixin):
 
 
     def _test_reset_password(self, email, new_password=None, **kwargs):
     def _test_reset_password(self, email, new_password=None, **kwargs):
         new_password = new_password or self.random_password()
         new_password = new_password or self.random_password()
-        self.assertResetPasswordSuccessResponse(self.reset_password(email))
-        confirmation_link = self.assertResetPasswordEmail(email)
+        try:
+            confirmation_link = kwargs.pop("confirmation_link")
+        except KeyError:
+            self.assertResetPasswordSuccessResponse(self.reset_password(email))
+            confirmation_link = self.assertResetPasswordEmail(email)
         self.assertConfirmationLinkRedirect(confirmation_link)
         self.assertConfirmationLinkRedirect(confirmation_link)
         self.assertResetPasswordVerificationSuccessResponse(
         self.assertResetPasswordVerificationSuccessResponse(
             self.client.verify(
             self.client.verify(
@@ -663,7 +666,8 @@ class NoUserAccountTestCase(UserLifeCycleTestCase):
 
 
     def test_registration_without_domain_and_password(self):
     def test_registration_without_domain_and_password(self):
         email, password = self._test_registration(self.random_username(), None)
         email, password = self._test_registration(self.random_username(), None)
-        self.assertResetPasswordEmail(email)
+        confirmation_link = self.assertResetPasswordEmail(email)
+        self._test_reset_password(email, confirmation_link=confirmation_link)
 
 
     def test_registration_with_tampered_domain(self):
     def test_registration_with_tampered_domain(self):
         PublicSuffixMockMixin.setUpMockPatch(self)
         PublicSuffixMockMixin.setUpMockPatch(self)

+ 1 - 0
api/desecapi/views/authenticated_actions.py

@@ -119,6 +119,7 @@ class AuthenticatedActivateUserActionView(AuthenticatedActionView):
 
 
     def post(self, request, *args, **kwargs):
     def post(self, request, *args, **kwargs):
         super().post(request, *args, **kwargs)
         super().post(request, *args, **kwargs)
+        self.request.user.refresh_from_db()  # subsequent action link generation needs current state
         if not self.authenticated_action.domain:
         if not self.authenticated_action.domain:
             return self._finalize_without_domain()
             return self._finalize_without_domain()
         else:
         else: