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.

auth: Log the error when OIDC config is missing a required key.

Josh Bartletta63cba58cdff
diff --git a/zerver/tests/test_auth_backends.py b/zerver/tests/test_auth_backends.py
index a8bae6fc81b..0e731d03680 100644
--- a/zerver/tests/test_auth_backends.py
+++ b/zerver/tests/test_auth_backends.py
@@ -5234,8 +5234,13 @@ class GenericOpenIdConnectTest(SocialAuthBaseWithSyncAttrTest):
mock_oidc_setting_dict = copy.deepcopy(settings.SOCIAL_AUTH_OIDC_ENABLED_IDPS)
[idp_config_dict] = mock_oidc_setting_dict.values()
del idp_config_dict["client_id"]
+ missing_keys_log = self.logger_output(
+ "OIDC IdP 'testoidc' is missing required configuration keys: ['client_id']",
+ "error",
+ )
with (
self.settings(SOCIAL_AUTH_OIDC_ENABLED_IDPS=mock_oidc_setting_dict),
+ self.assertLogs(self.logger_string, level="ERROR") as oidc_log,
self.assertLogs("django.request", level="ERROR") as m,
):
result = self.social_auth_test(
@@ -5248,9 +5253,11 @@ class GenericOpenIdConnectTest(SocialAuthBaseWithSyncAttrTest):
m.output,
[f"ERROR:django.request:Internal Server Error: {self.LOGIN_URL}"],
)
+ self.assertEqual(oidc_log.output, [missing_keys_log])
with (
self.settings(SOCIAL_AUTH_OIDC_ENABLED_IDPS=mock_oidc_setting_dict),
+ self.assertLogs(self.logger_string, level="ERROR") as oidc_log,
self.assertLogs("django.request", level="ERROR") as m,
):
result = self.social_auth_test(
@@ -5262,6 +5269,7 @@ class GenericOpenIdConnectTest(SocialAuthBaseWithSyncAttrTest):
self.assertEqual(
m.output, [f"ERROR:django.request:Internal Server Error: {self.SIGNUP_URL}"]
)
+ self.assertEqual(oidc_log.output, [missing_keys_log])
def test_social_auth_oidc_multiple_idps_configured(self) -> None:
idps_dict = copy.deepcopy(settings.SOCIAL_AUTH_OIDC_ENABLED_IDPS)
diff --git a/zproject/backends.py b/zproject/backends.py
index 4a3870992b4..87b45cfff50 100644
--- a/zproject/backends.py
+++ b/zproject/backends.py
@@ -4328,8 +4328,15 @@ class GenericOpenIdConnectBackend(SocialAuthMixin, OpenIdConnectAuth):
@classmethod
def check_config(cls) -> bool:
mandatory_config_keys = ["oidc_url", "client_id", "secret"]
- for idp_config_dict in settings.SOCIAL_AUTH_OIDC_ENABLED_IDPS.values():
- if not all(idp_config_dict.get(key) for key in mandatory_config_keys):
+ logger = logging.getLogger(f"zulip.auth.{cls.name}")
+ for idp_name, idp_config_dict in settings.SOCIAL_AUTH_OIDC_ENABLED_IDPS.items():
+ missing_keys = [key for key in mandatory_config_keys if not idp_config_dict.get(key)]
+ if missing_keys:
+ logger.error(
+ "OIDC IdP %r is missing required configuration keys: %r",
+ idp_name,
+ missing_keys,
+ )
return False
return True