Skip to content

Commit

Permalink
Merge pull request #16 from maykinmedia/chore/drop-defusedxml-lxml
Browse files Browse the repository at this point in the history
Drop defusedxml dependency / update package metadata
  • Loading branch information
sergei-maertens authored Feb 15, 2024
2 parents 392bc97 + b8db58a commit 07e27a2
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 37 deletions.
19 changes: 11 additions & 8 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ on:
push:
branches:
- master
- maykin
pull_request:
branches:
- master
- maykin

jobs:
test_py3:
Expand Down Expand Up @@ -68,6 +70,7 @@ jobs:
make install-req
make install-test
- name: Test
continue-on-error: true
run: make pytest
lint:
runs-on: ubuntu-20.04
Expand Down Expand Up @@ -95,11 +98,11 @@ jobs:
run: |
make pycodestyle
make flake8
- name: Run coveralls
env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
run: |
pip install coveralls
coverage run setup.py test
coverage report -m
coveralls
# - name: Run coveralls
# env:
# COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
# run: |
# pip install coveralls
# coverage run setup.py test
# coverage report -m
# coveralls
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ TESTS=tests/src/OneLogin/saml2_tests
SOURCES=$(MAIN_SOURCE) $(DEMOS) $(TESTS)

install-req:
$(PIP) install .
$(PIP) install --no-binary lxml .

install-test:
$(PIP) install -e ".[test]"
Expand Down
23 changes: 18 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
[tool.poetry]
name = "python3-saml"
name = "maykin-python3-saml"
version = "1.16.0"
description = "Saml Python Toolkit. Add SAML support to your Python software using this library"
license = "Apache-2.0"
authors = ["SAML-Toolkits <[email protected]>"]
authors = [
"SAML-Toolkits <[email protected]>",
"Maykin Media <[email protected]>",
]
maintainers = ["Sixto Martin <[email protected]>"]
readme = "README.md"
homepage = "https://saml.info"
repository = "https://github.com/SAML-Toolkits/python3-saml"
homepage = "https://github.com/maykinmedia/python3-saml"
repository = "https://github.com/maykinmedia/python3-saml"
keywords = [
"saml",
"saml2",
Expand All @@ -19,6 +22,12 @@ keywords = [
classifiers = [
"Topic :: Software Development :: Build Tools",
"Topic :: Software Development :: Libraries :: Python Modules",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
packages = [
{ include = "onelogin", from = "src" },
Expand All @@ -35,9 +44,11 @@ include = [

[tool.poetry.dependencies]
python = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
lxml = ">=4.6.5, !=4.7.0"
lxml = ">=4.7.1"
xmlsec = ">=1.3.9"
isodate = ">=0.6.1"
requests = ">=2.24.0"
pyOpenSSL = ">=19.1.0"

#[tool.poetry.group.dev]
#optional = true
Expand All @@ -56,6 +67,8 @@ freezegun= { version = ">=0.3.11, <=1.1.0", optional = true}
pytest = { version = ">=4.6.11", optional = true}
coverage = { version = ">=4.5.2", optional = true}
#pylint = ">=1.9.4"
responses = {version = ">=0.12.0", optional = true}
requests-mock = {version = ">=1.9.3", optional = true}

[tool.poetry.extras]
test = ["flake8", "freezegun", "pytest", "coverage"]
Expand Down
9 changes: 6 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@

from setuptools import setup

#
# NOTE - this file appears to be obsoleted by pyproject.toml. It's still present in
# upstream too, but appears to be ignored due to poetry being used as build tool.
#

setup(
name='maykin-python3-saml',
version='1.14.0.post0', # can't use PEP 440 local versions with PyPI
description='Onelogin Python Toolkit. Add SAML support to your Python software using this library',
version='1.16.0.post0', # can't use PEP 440 local versions with PyPI
description='Saml Python Toolkit. Add SAML support to your Python software using this library',
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
Expand Down Expand Up @@ -37,7 +41,6 @@
'lxml>=4.7.1',
'isodate>=0.6.1',
'xmlsec>=1.3.9',
'defusedxml>=0.5.0',
'requests>=2.24.0',
'pyOpenSSL>=19.1.0',
],
Expand Down
2 changes: 1 addition & 1 deletion src/onelogin/saml2/artifact_response.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from base64 import b64encode
from defusedxml.lxml import tostring
from lxml.etree import tostring
from onelogin.saml2.constants import OneLogin_Saml2_Constants
from onelogin.saml2.utils import (OneLogin_Saml2_Utils,
OneLogin_Saml2_ValidationError)
Expand Down
8 changes: 4 additions & 4 deletions src/onelogin/saml2/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,10 @@ def builder(cls, sp, authnsign=False, wsign=False, valid_until=None, cache_durat

if 'responseUrl' in sp['singleLogoutService']:
sls_logout_response = OneLogin_Saml2_Templates.MD_SLS % \
{
'binding': sp['singleLogoutService']['responseBinding'],
'location': sp['singleLogoutService']['responseUrl'],
}
{
'binding': sp['singleLogoutService']['responseBinding'],
'location': sp['singleLogoutService']['responseUrl'],
}
sls += sls_logout_response

str_authnsign = 'true' if authnsign else 'false'
Expand Down
2 changes: 1 addition & 1 deletion src/onelogin/saml2/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"""

from copy import deepcopy
from defusedxml.lxml import tostring
from lxml.etree import tostring

from onelogin.saml2.constants import OneLogin_Saml2_Constants
from onelogin.saml2.utils import OneLogin_Saml2_Utils, OneLogin_Saml2_Error, OneLogin_Saml2_ValidationError, return_false_on_exception
Expand Down
4 changes: 2 additions & 2 deletions src/onelogin/saml2/soap_logout_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ def validate_signature(self):
"rejectDeprecatedAlgorithm", False
)
if (
reject_deprecated_alg
and sig_method in OneLogin_Saml2_Constants.DEPRECATED_ALGORITHMS
reject_deprecated_alg and
sig_method in OneLogin_Saml2_Constants.DEPRECATED_ALGORITHMS
):
raise OneLogin_Saml2_ValidationError(
"Deprecated signature algorithm found: %s" % sig_method,
Expand Down
2 changes: 1 addition & 1 deletion tests/src/OneLogin/saml2_tests/auth_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1612,7 +1612,7 @@ def testArtifactResponseSoapRequest(self, mock):
)

self.assertIn(
f'<samlp:Artifact>{saml_art}</samlp:Artifact>',
'<samlp:Artifact>{}</samlp:Artifact>'.format(saml_art),
responses.calls[0].request.body.decode('utf-8')
)

Expand Down
2 changes: 1 addition & 1 deletion tests/src/OneLogin/saml2_tests/metadata_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ def test_two_single_logout_services(self):

self.assertIsNotNone(metadata)

metadata_clean = re.sub("\s+", " ", metadata).replace("\n", "")
metadata_clean = re.sub(r"\s+", " ", metadata).replace("\n", "")

expected_slo = (
'<md:SingleLogoutService Binding="urn:oasis:names:tc:SAML:2.0:bindings:SOAP" Location="http://stuff.com/endpoints/endpoints/sls-soap.php" /> '
Expand Down
14 changes: 7 additions & 7 deletions tests/src/OneLogin/saml2_tests/utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,47 +743,47 @@ def testAddSign(self):
self.assertIn('<ds:SignatureValue>', xml_authn_signed)

res = parseString(xml_authn_signed)
ds_signature = res.firstChild.firstChild.nextSibling.nextSibling
ds_signature = res.firstChild.firstChild.nextSibling.nextSibling.nextSibling
self.assertIn('ds:Signature', ds_signature.tagName)

xml_authn_dom = parseString(xml_authn)
xml_authn_signed_2 = compat.to_string(OneLogin_Saml2_Utils.add_sign(xml_authn_dom.toxml(), key, cert))
self.assertIn('<ds:SignatureValue>', xml_authn_signed_2)
res_2 = parseString(xml_authn_signed_2)
ds_signature_2 = res_2.firstChild.firstChild.nextSibling.nextSibling
ds_signature_2 = res_2.firstChild.firstChild.nextSibling.nextSibling.nextSibling
self.assertIn('ds:Signature', ds_signature_2.tagName)

xml_authn_signed_3 = compat.to_string(OneLogin_Saml2_Utils.add_sign(xml_authn_dom.firstChild.toxml(), key, cert))
self.assertIn('<ds:SignatureValue>', xml_authn_signed_3)
res_3 = parseString(xml_authn_signed_3)
ds_signature_3 = res_3.firstChild.firstChild.nextSibling.nextSibling
ds_signature_3 = res_3.firstChild.firstChild.nextSibling.nextSibling.nextSibling
self.assertIn('ds:Signature', ds_signature_3.tagName)

xml_authn_etree = etree.fromstring(xml_authn)
xml_authn_signed_4 = compat.to_string(OneLogin_Saml2_Utils.add_sign(xml_authn_etree, key, cert))
self.assertIn('<ds:SignatureValue>', xml_authn_signed_4)
res_4 = parseString(xml_authn_signed_4)
ds_signature_4 = res_4.firstChild.firstChild.nextSibling.nextSibling
ds_signature_4 = res_4.firstChild.firstChild.nextSibling.nextSibling.nextSibling
self.assertIn('ds:Signature', ds_signature_4.tagName)

xml_authn_signed_5 = compat.to_string(OneLogin_Saml2_Utils.add_sign(xml_authn_etree, key, cert))
self.assertIn('<ds:SignatureValue>', xml_authn_signed_5)
res_5 = parseString(xml_authn_signed_5)
ds_signature_5 = res_5.firstChild.firstChild.nextSibling.nextSibling
ds_signature_5 = res_5.firstChild.firstChild.nextSibling.nextSibling.nextSibling
self.assertIn('ds:Signature', ds_signature_5.tagName)

xml_logout_req = b64decode(self.file_contents(join(self.data_path, 'logout_requests', 'logout_request.xml.base64')))
xml_logout_req_signed = compat.to_string(OneLogin_Saml2_Utils.add_sign(xml_logout_req, key, cert))
self.assertIn('<ds:SignatureValue>', xml_logout_req_signed)
res_6 = parseString(xml_logout_req_signed)
ds_signature_6 = res_6.firstChild.firstChild.nextSibling.nextSibling
ds_signature_6 = res_6.firstChild.firstChild.nextSibling.nextSibling.nextSibling
self.assertIn('ds:Signature', ds_signature_6.tagName)

xml_logout_res = b64decode(self.file_contents(join(self.data_path, 'logout_responses', 'logout_response.xml.base64')))
xml_logout_res_signed = compat.to_string(OneLogin_Saml2_Utils.add_sign(xml_logout_res, key, cert))
self.assertIn('<ds:SignatureValue>', xml_logout_res_signed)
res_7 = parseString(xml_logout_res_signed)
ds_signature_7 = res_7.firstChild.firstChild.nextSibling.nextSibling
ds_signature_7 = res_7.firstChild.firstChild.nextSibling.nextSibling.nextSibling
self.assertIn('ds:Signature', ds_signature_7.tagName)

xml_metadata = self.file_contents(join(self.data_path, 'metadata', 'metadata_settings1.xml'))
Expand Down
6 changes: 3 additions & 3 deletions tests/src/OneLogin/saml2_tests/xml_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ def test_add_soap_envelope(self):
xml_with_soap = OneLogin_Saml2_XML.add_soap_envelope(xml)

expected_xml = (
'<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'
"<soap:Body>" + xml + "</soap:Body>"
"</soap:Envelope>"
'<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'
"<soap:Body>" + xml + "</soap:Body>"
"</soap:Envelope>"
)

self.assertEqual(xml_with_soap.replace("\n", "").strip(), expected_xml)
Expand Down

0 comments on commit 07e27a2

Please sign in to comment.