Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
saml: Log the provided IdP issuers.
Alex Vandiver16bd7a030a99
diff --git a/zerver/tests/test_auth_backends.py b/zerver/tests/test_auth_backends.pyindex a1dfa5afbf8..a8bae6fc81b 100644--- a/zerver/tests/test_auth_backends.py+++ b/zerver/tests/test_auth_backends.py@@ -3912,6 +3912,12 @@ class SAMLAuthBackendTest(SocialAuthBaseWithSyncAttrTest):email=self.example_email("hamlet"), name="King Hamlet")+ # These are from the fixture+ got_idps = [+ "http://www.okta.com/exk1da4osrIL3Y7ip357",+ "https://idp.testshib.org/idp/shibboleth",+ ]+# We change the entity_id of the configured test IdP, which means it won't match# the Entity ID in the SAMLResponse generated above.idps_dict = copy.deepcopy(settings.SOCIAL_AUTH_SAML_ENABLED_IDPS)@@ -3926,7 +3932,8 @@ class SAMLAuthBackendTest(SocialAuthBaseWithSyncAttrTest):m.output,[self.logger_output(- "/complete/saml/: No valid IdP as issuer of the SAMLResponse.", "info"+ f"/complete/saml/: No valid IdP found as issuer of the SAMLResponse; got {got_idps}",+ "info",)],)@@ -3960,7 +3967,7 @@ class SAMLAuthBackendTest(SocialAuthBaseWithSyncAttrTest):m.output,["ERROR:zulip.auth.saml:Error parsing SAMLResponse: Issuer of the Assertion not found or multiple.",- "INFO:zulip.auth.saml:/complete/saml/: No valid IdP as issuer of the SAMLResponse.",+ "INFO:zulip.auth.saml:/complete/saml/: No IdP issuers in SAMLResponse (parse failure?)",],)@@ -3988,7 +3995,7 @@ class SAMLAuthBackendTest(SocialAuthBaseWithSyncAttrTest):self.assertEqual(result.status_code, 302)self.assertIn("login", result["Location"])- self.assert_length(m.output, 3)+ self.assert_length(m.output, 2)def test_social_auth_saml_bad_idp_param_on_login_page(self) -> None:with self.assertLogs(self.logger_string, level="INFO") as m:diff --git a/zproject/backends.py b/zproject/backends.pyindex d2e4344dae4..4a3870992b4 100644--- a/zproject/backends.py+++ b/zproject/backends.py@@ -3554,7 +3554,7 @@ class SAMLResponse(SAMLDocument):settings=saml_settings, response=self.encoded_saml_message)return resp.get_session_index()- except self.SAML_PARSING_EXCEPTIONS as e:+ except self.SAML_PARSING_EXCEPTIONS as e: # nocoverageself.logger.error("Error parsing SAMLResponse: %s", str(e))return None@@ -3907,10 +3907,19 @@ class SAMLAuthBackend(SocialAuthMixin, SAMLAuth):self.logger.info(error_msg, saml_document.document_type(), relayed_params)return None+ if not saml_document.get_issuers():+ self.logger.info(+ "/complete/saml/: No IdP issuers in %s (parse failure?)",+ saml_document.document_type(),+ )+ return None+idp_name = saml_document.get_issuing_idp()if idp_name is None:self.logger.info(- "/complete/saml/: No valid IdP as issuer of the %s.", saml_document.document_type()+ "/complete/saml/: No valid IdP found as issuer of the %s; got %s",+ saml_document.document_type(),+ sorted(saml_document.get_issuers()),)return None@@ -3978,7 +3987,7 @@ class SAMLAuthBackend(SocialAuthMixin, SAMLAuth):# Call the auth_complete method of SocialAuthMixInresult = super().auth_complete(*args, **kwargs)- except SAMLResponse.SAML_PARSING_EXCEPTIONS:+ except SAMLResponse.SAML_PARSING_EXCEPTIONS: # nocoverage# These can be raised if SAMLResponse is missing or badly formatted.self.logger.info("/complete/saml/: error while parsing SAMLResponse:", exc_info=True)# Fall through to returning None.