@@ -241,8 +241,8 @@ async def test_custom_regex_async(self):
241241
242242 def test_error_handler (self ):
243243 """
244- The middleware will catch a PwnedPasswordsError and set
245- `` request.pwned_passwords`` based on CommonPasswordValidator .
244+ If the sync middleware fails and the submitted password is not in
245+ Django's common passwords list, request.pwned_passwords will be empty .
246246
247247 """
248248 sync_mock , _ = self .api_error_mocks ()
@@ -251,14 +251,38 @@ def test_error_handler(self):
251251 self .test_clean , data = {"password" : get_random_string (length = 20 )}
252252 )
253253
254+ def test_error_handler_bad_password (self ):
255+ """
256+ If the sync mdidleware fails and the submitted password is in Django's
257+ common passwords list, the request.pwned_passwords list is still
258+ correctly populated.
259+
260+ """
261+ sync_mock , _ = self .api_error_mocks ()
262+ with mock .patch ("pwned_passwords_django.api.check_password" , sync_mock ):
263+ self .client .post (self .test_breach , data = {"password" : "password" })
264+
254265 async def test_error_handler_async (self ):
255266 """
256- The async middleware will catch a PwnedPasswordsError and set
257- `` request.pwned_passwords`` to an empty dictionary .
267+ If the async middleware fails and the submitted password is not in
268+ Django's common passwords list, request.pwned_passwords will be empty.
258269
259270 """
260- async_mock , _ = self .api_error_mocks ()
271+ _ , async_mock = self .api_error_mocks ()
261272 with mock .patch ("pwned_passwords_django.api.check_password_async" , async_mock ):
262273 await self .async_client .post (
263274 self .test_clean_async , data = {"password" : get_random_string (length = 20 )}
264275 )
276+
277+ async def test_error_handler_async_bad_password (self ):
278+ """
279+ If the async mdidleware fails and the submitted password is in Django's
280+ common passwords list, the request.pwned_passwords list is still
281+ correctly populated.
282+
283+ """
284+ _ , async_mock = self .api_error_mocks ()
285+ with mock .patch ("pwned_passwords_django.api.check_password_async" , async_mock ):
286+ await self .async_client .post (
287+ self .test_breach_async , data = {"password" : "password" }
288+ )
0 commit comments