Skip to content

Commit 8acf8f7

Browse files
committed
mgr/dashboard: disable saml2 tests when the dep is not there
Signed-off-by: Nizamudeen A <[email protected]>
1 parent ffde8d0 commit 8acf8f7

File tree

4 files changed

+22
-16
lines changed

4 files changed

+22
-16
lines changed

debian/control

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ Build-Depends: automake,
105105
python3-prettytable <pkg.ceph.check>,
106106
python3-requests <pkg.ceph.check>,
107107
python3-scipy <pkg.ceph.check>,
108+
python3-onelogin-saml2 <pkg.ceph.check>,
108109
python3-setuptools,
109110
python3-sphinx,
110111
python3-venv,

src/pybind/mgr/dashboard/controllers/saml2.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,10 @@ def _build_req(request, post_data):
3232
'post_data': post_data
3333
}
3434

35-
@staticmethod
36-
def _check_python_saml():
37-
if not python_saml_imported:
38-
raise cherrypy.HTTPError(400, 'Required library not found: `python3-saml`')
39-
try:
40-
OneLogin_Saml2_Settings(mgr.SSO_DB.config.onelogin_settings)
41-
except OneLogin_Saml2_Error:
42-
raise cherrypy.HTTPError(400, 'Single Sign-On is not configured.')
43-
4435
@Endpoint('POST', path="", version=None)
4536
@allow_empty_body
4637
def auth_response(self, **kwargs):
47-
Saml2._check_python_saml()
38+
check_python_saml()
4839
req = Saml2._build_req(self._request, kwargs)
4940
auth = OneLogin_Saml2_Auth(req, mgr.SSO_DB.config.onelogin_settings)
5041
auth.process_response()
@@ -84,30 +75,39 @@ def auth_response(self, **kwargs):
8475

8576
@Endpoint(xml=True, version=None)
8677
def metadata(self):
87-
Saml2._check_python_saml()
78+
check_python_saml()
8879
saml_settings = OneLogin_Saml2_Settings(mgr.SSO_DB.config.onelogin_settings)
8980
return saml_settings.get_sp_metadata()
9081

9182
@Endpoint(json_response=False, version=None)
9283
def login(self):
93-
Saml2._check_python_saml()
84+
check_python_saml()
9485
req = Saml2._build_req(self._request, {})
9586
auth = OneLogin_Saml2_Auth(req, mgr.SSO_DB.config.onelogin_settings)
9687
raise cherrypy.HTTPRedirect(auth.login())
9788

9889
@Endpoint(json_response=False, version=None)
9990
def slo(self):
100-
Saml2._check_python_saml()
91+
check_python_saml()
10192
req = Saml2._build_req(self._request, {})
10293
auth = OneLogin_Saml2_Auth(req, mgr.SSO_DB.config.onelogin_settings)
10394
raise cherrypy.HTTPRedirect(auth.logout())
10495

10596
@Endpoint(json_response=False, version=None)
10697
def logout(self, **kwargs):
10798
# pylint: disable=unused-argument
108-
Saml2._check_python_saml()
99+
check_python_saml()
109100
JwtManager.reset_user()
110101
token = JwtManager.get_token(cherrypy.request)
111102
self._delete_token_cookie(token)
112103
url_prefix = prepare_url_prefix(mgr.get_module_option('url_prefix', default=''))
113104
raise cherrypy.HTTPRedirect("{}/#/login".format(url_prefix))
105+
106+
107+
def check_python_saml():
108+
if not python_saml_imported:
109+
raise cherrypy.HTTPError(400, 'Required library not found: `python3-saml`')
110+
try:
111+
OneLogin_Saml2_Settings(mgr.SSO_DB.config.onelogin_settings)
112+
except OneLogin_Saml2_Error:
113+
raise cherrypy.HTTPError(400, 'Single Sign-On is not configured.')

src/pybind/mgr/dashboard/tests/test_sso.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,17 @@
55
import tempfile
66
import unittest
77

8+
import pytest
9+
10+
from ..controllers.saml2 import check_python_saml
811
from ..services.sso import load_sso_db
912
from ..tests import CLICommandTestMixin, CmdException
1013

1114

15+
@pytest.mark.skipif(
16+
pytest.raises(Exception, check_python_saml),
17+
reason="SAML dependency is missing"
18+
)
1219
class AccessControlTest(unittest.TestCase, CLICommandTestMixin):
1320
IDP_METADATA = '''<?xml version="1.0"?>
1421
<md:EntityDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata"

src/pybind/mgr/dashboard/tox.ini

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ basepython=python3
3535
deps =
3636
{[base]deps}
3737
{[base-test]deps}
38-
-rrequirements-extra.txt
3938
passenv =
4039
PYTHONPATH
4140
sitepackages = true
@@ -187,5 +186,4 @@ description = Generate Python code from Protobuf files for nvmeof gateway
187186
sitepackages = true
188187
commands_pre = cp ../../nvmeof/gateway/control/proto/gateway.proto dashboard/services/proto/
189188
commands =
190-
python -c "import grpc; print(f'using grpc version: {grpc.__version__}')"
191189
python -m grpc_tools.protoc --proto_path=. --python_out=. --grpc_python_out=. dashboard/services/proto/gateway.proto --experimental_allow_proto3_optional

0 commit comments

Comments
 (0)