From: Nizamudeen A Date: Wed, 12 Mar 2025 08:32:10 +0000 (+0530) Subject: mgr/dashboard: disable saml2 tests when the dep is not there X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=8acf8f7e4fe6d283212154857abd97b6e641de4d;p=ceph.git mgr/dashboard: disable saml2 tests when the dep is not there Signed-off-by: Nizamudeen A --- diff --git a/debian/control b/debian/control index 0ae66243fa20d..21aeb7247f4f7 100644 --- a/debian/control +++ b/debian/control @@ -105,6 +105,7 @@ Build-Depends: automake, python3-prettytable , python3-requests , python3-scipy , + python3-onelogin-saml2 , python3-setuptools, python3-sphinx, python3-venv, diff --git a/src/pybind/mgr/dashboard/controllers/saml2.py b/src/pybind/mgr/dashboard/controllers/saml2.py index f834be9587ee4..d3f596d7ead39 100644 --- a/src/pybind/mgr/dashboard/controllers/saml2.py +++ b/src/pybind/mgr/dashboard/controllers/saml2.py @@ -32,19 +32,10 @@ class Saml2(BaseController, ControllerAuthMixin): '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() @@ -84,20 +75,20 @@ class Saml2(BaseController, ControllerAuthMixin): @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()) @@ -105,9 +96,18 @@ class Saml2(BaseController, ControllerAuthMixin): @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.') diff --git a/src/pybind/mgr/dashboard/tests/test_sso.py b/src/pybind/mgr/dashboard/tests/test_sso.py index 9492f0a20ed66..9e18a8fb1d4ea 100644 --- a/src/pybind/mgr/dashboard/tests/test_sso.py +++ b/src/pybind/mgr/dashboard/tests/test_sso.py @@ -5,10 +5,17 @@ import errno 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 = '''