test_auth_backends: Add request parameter to patched_authenticate.

This is required by social-auth-app-django 4.0.0.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2020-06-24 19:40:06 -07:00
committed by Tim Abbott
parent 30c6797239
commit 6363c49e3f

View File

@@ -464,7 +464,10 @@ class AuthBackendTest(ZulipTestCase):
},
}
def patched_authenticate(**kwargs: Any) -> Any:
def patched_authenticate(
request: Optional[HttpResponse] = None,
**kwargs: Any,
) -> Any:
# This is how we pass the subdomain to the authentication
# backend in production code, so we need to do this setup
# here.
@@ -481,7 +484,7 @@ class AuthBackendTest(ZulipTestCase):
return {'email': user.delivery_email}
backend.strategy.request_data = return_email
result = orig_authenticate(backend, **kwargs)
result = orig_authenticate(backend, request, **kwargs)
return result
def patched_get_verified_emails(*args: Any, **kwargs: Any) -> Any:
@@ -497,12 +500,15 @@ class AuthBackendTest(ZulipTestCase):
status=details['status'],
body=details['body'])
backend_class = backends_to_test[backend_name]['backend']
# We're creating a new class instance here, so the
# monkey-patching of the instance that we're about to
# do will be discarded at the end of this test.
backend = backend_class()
backend.strategy = DjangoStrategy(storage=BaseDjangoStorage())
orig_authenticate = backend_class.authenticate
backend.authenticate = patched_authenticate
orig_get_verified_emails = backend_class.get_verified_emails
if backend_name == "google":
backend.get_verified_emails = patched_get_verified_emails
@@ -520,8 +526,6 @@ class AuthBackendTest(ZulipTestCase):
self.verify_backend(backend,
good_kwargs=good_kwargs,
bad_kwargs=bad_kwargs)
backend.authenticate = orig_authenticate
backend.get_verified_emails = orig_get_verified_emails
class RateLimitAuthenticationTests(ZulipTestCase):
@override_settings(RATE_LIMITING_AUTHENTICATE=True)