'post_data': post_data
}
- @staticmethod
- def _check_python_saml():
- if not python_saml_imported:
- raise cherrypy.HTTPError(400, 'Required library not found: `python3-saml`')
- try:
- OneLogin_Saml2_Settings(mgr.SSO_DB.config.onelogin_settings)
- except OneLogin_Saml2_Error:
- raise cherrypy.HTTPError(400, 'Single Sign-On is not configured.')
-
@Endpoint('POST', path="", version=None)
@allow_empty_body
def auth_response(self, **kwargs):
- Saml2._check_python_saml()
+ check_python_saml()
req = Saml2._build_req(self._request, kwargs)
auth = OneLogin_Saml2_Auth(req, mgr.SSO_DB.config.onelogin_settings)
auth.process_response()
@Endpoint(xml=True, version=None)
def metadata(self):
- Saml2._check_python_saml()
+ check_python_saml()
saml_settings = OneLogin_Saml2_Settings(mgr.SSO_DB.config.onelogin_settings)
return saml_settings.get_sp_metadata()
@Endpoint(json_response=False, version=None)
def login(self):
- Saml2._check_python_saml()
+ check_python_saml()
req = Saml2._build_req(self._request, {})
auth = OneLogin_Saml2_Auth(req, mgr.SSO_DB.config.onelogin_settings)
raise cherrypy.HTTPRedirect(auth.login())
@Endpoint(json_response=False, version=None)
def slo(self):
- Saml2._check_python_saml()
+ check_python_saml()
req = Saml2._build_req(self._request, {})
auth = OneLogin_Saml2_Auth(req, mgr.SSO_DB.config.onelogin_settings)
raise cherrypy.HTTPRedirect(auth.logout())
@Endpoint(json_response=False, version=None)
def logout(self, **kwargs):
# pylint: disable=unused-argument
- Saml2._check_python_saml()
+ check_python_saml()
JwtManager.reset_user()
token = JwtManager.get_token(cherrypy.request)
self._delete_token_cookie(token)
url_prefix = prepare_url_prefix(mgr.get_module_option('url_prefix', default=''))
raise cherrypy.HTTPRedirect("{}/#/login".format(url_prefix))
+
+
+def check_python_saml():
+ if not python_saml_imported:
+ raise cherrypy.HTTPError(400, 'Required library not found: `python3-saml`')
+ try:
+ OneLogin_Saml2_Settings(mgr.SSO_DB.config.onelogin_settings)
+ except OneLogin_Saml2_Error:
+ raise cherrypy.HTTPError(400, 'Single Sign-On is not configured.')
import tempfile
import unittest
+import pytest
+
+from ..controllers.saml2 import check_python_saml
from ..services.sso import load_sso_db
from ..tests import CLICommandTestMixin, CmdException
+@pytest.mark.skipif(
+ pytest.raises(Exception, check_python_saml),
+ reason="SAML dependency is missing"
+)
class AccessControlTest(unittest.TestCase, CLICommandTestMixin):
IDP_METADATA = '''<?xml version="1.0"?>
<md:EntityDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata"