Skip to content

Commit 2dd02b5

Browse files
authored
Merge pull request ceph#62239 from rhcs-dashboard/xmlsec-fail-main
mgr/dashboard: use system packages when running tox
2 parents e51b70b + acb0f19 commit 2dd02b5

File tree

6 files changed

+37
-20
lines changed

6 files changed

+37
-20
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/requirements.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ pyyaml
1111
natsort
1212
setuptools
1313
jsonpatch
14-
grpcio==1.46.5
15-
grpcio-tools==1.46.5
14+
grpcio
15+
grpcio-tools
1616
jmespath
17-
lxml==4.8.0 # to fix https://github.com/xmlsec/python-xmlsec/issues/320
1817
xmltodict

src/pybind/mgr/dashboard/services/nvmeof_client.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# pylint: disable=unexpected-keyword-arg
2+
13
import functools
24
import logging
35
from typing import Annotated, Any, Callable, Dict, Generator, List, \
@@ -9,6 +11,14 @@
911
logger = logging.getLogger("nvmeof_client")
1012

1113
try:
14+
# if the protobuf version is newer than what we generated with
15+
# proto file import will fail (because of differences between what's
16+
# available in centos and ubuntu).
17+
# this "hack" should be removed once we update both the
18+
# distros; centos and ubuntu.
19+
import os
20+
os.environ["PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION"] = "python"
21+
1222
import grpc # type: ignore
1323
import grpc._channel # type: ignore
1424
from google.protobuf.json_format import MessageToDict # type: ignore
@@ -223,7 +233,7 @@ def decorator(func: Callable[..., Message]) -> Callable[..., Model]:
223233
def wrapper(*args, **kwargs) -> Model:
224234
message = func(*args, **kwargs)
225235
msg_dict = MessageToDict(message, including_default_value_fields=True,
226-
preserving_proto_field_name=True)
236+
preserving_proto_field_name=True) # type: ignore
227237

228238
result = namedtuple_to_dict(obj_to_namedtuple(msg_dict, model))
229239
if finalize:

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ skipsdist = true
1010
minversion = 2.9.1
1111

1212
[pytest]
13+
sitepackages = true
1314
addopts =
1415
--cov --cov-append --cov-report=term
1516
--doctest-modules
@@ -29,13 +30,13 @@ deps =
2930
[base-lint]
3031
deps =
3132
-rrequirements-lint.txt
33+
sitepackages = false
3234

3335
[testenv]
3436
basepython=python3
3537
deps =
3638
{[base]deps}
3739
{[base-test]deps}
38-
-rrequirements-extra.txt
3940
passenv =
4041
PYTHONPATH
4142
setenv =
@@ -186,5 +187,4 @@ description = Generate Python code from Protobuf files for nvmeof gateway
186187
sitepackages = true
187188
commands_pre = cp ../../nvmeof/gateway/control/proto/gateway.proto dashboard/services/proto/
188189
commands =
189-
python -c "import grpc; print(f'using grpc version: {grpc.__version__}')"
190190
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)