Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

test_auth_backends: Add request parameter to patched_authenticate.

Anders Kaseorg6363c49e3fc7
diff --git a/zerver/tests/test_auth_backends.py b/zerver/tests/test_auth_backends.py
index 65f4282e3ff..8494cbe49d9 100644
--- a/zerver/tests/test_auth_backends.py
+++ b/zerver/tests/test_auth_backends.py
@@ -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)