@@ -241,8 +241,8 @@ async def test_custom_regex_async(self):
241
241
242
242
def test_error_handler (self ):
243
243
"""
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 .
246
246
247
247
"""
248
248
sync_mock , _ = self .api_error_mocks ()
@@ -251,14 +251,38 @@ def test_error_handler(self):
251
251
self .test_clean , data = {"password" : get_random_string (length = 20 )}
252
252
)
253
253
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
+
254
265
async def test_error_handler_async (self ):
255
266
"""
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.
258
269
259
270
"""
260
- async_mock , _ = self .api_error_mocks ()
271
+ _ , async_mock = self .api_error_mocks ()
261
272
with mock .patch ("pwned_passwords_django.api.check_password_async" , async_mock ):
262
273
await self .async_client .post (
263
274
self .test_clean_async , data = {"password" : get_random_string (length = 20 )}
264
275
)
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