diff options
author | Ivan Kanakarakis <ivan.kanak@gmail.com> | 2021-03-07 20:35:03 +0200 |
---|---|---|
committer | Ivan Kanakarakis <ivan.kanak@gmail.com> | 2021-03-07 20:35:52 +0200 |
commit | 072f8142c8cd06a45f3f8bd6e087df7e895b966b (patch) | |
tree | 49fa6090a3b894b2d432f253f43c3bc246ccd2c9 | |
parent | c1792b071801d175680bc53ce028130a15a9617c (diff) | |
download | pysaml2-072f8142c8cd06a45f3f8bd6e087df7e895b966b.tar.gz |
Raise SAMLError when metadata file cannot be parsed
Signed-off-by: Ivan Kanakarakis <ivan.kanak@gmail.com>
-rw-r--r-- | src/saml2/mdstore.py | 9 | ||||
-rw-r--r-- | tests/invalid_metadata_file.xml | 1 | ||||
-rw-r--r-- | tests/test_30_mdstore.py | 13 |
3 files changed, 17 insertions, 6 deletions
diff --git a/src/saml2/mdstore.py b/src/saml2/mdstore.py index 70bc1b41..44930773 100644 --- a/src/saml2/mdstore.py +++ b/src/saml2/mdstore.py @@ -7,15 +7,14 @@ import os import sys from itertools import chain from warnings import warn as _warn - from hashlib import sha1 from os.path import isfile from os.path import join import requests + import six -from xml.etree.ElementTree import ParseError from saml2 import md from saml2 import saml from saml2 import samlp @@ -25,7 +24,6 @@ from saml2 import SAMLError from saml2 import BINDING_HTTP_REDIRECT from saml2 import BINDING_HTTP_POST from saml2 import BINDING_SOAP - from saml2.httpbase import HTTPBase from saml2.extension.idpdisc import BINDING_DISCO from saml2.extension.idpdisc import DiscoveryResponse @@ -616,9 +614,8 @@ class InMemoryMetaData(MetaData): try: self.entities_descr = md.entities_descriptor_from_string(xmlstr) except Exception as e: - logger.error(f'Metadata Parse Error on: {self.filename}') - return - + raise SAMLError(f'Failed to parse metadata file: {self.filename}') from e + if not self.entities_descr: self.entity_descr = md.entity_descriptor_from_string(xmlstr) if self.entity_descr: diff --git a/tests/invalid_metadata_file.xml b/tests/invalid_metadata_file.xml new file mode 100644 index 00000000..249c87ce --- /dev/null +++ b/tests/invalid_metadata_file.xml @@ -0,0 +1 @@ +this content is invalid diff --git a/tests/test_30_mdstore.py b/tests/test_30_mdstore.py index 4dfa80f3..bfe261dd 100644 --- a/tests/test_30_mdstore.py +++ b/tests/test_30_mdstore.py @@ -7,6 +7,8 @@ from collections import OrderedDict from unittest.mock import Mock from unittest.mock import patch +from pytest import raises + import responses from six.moves.urllib import parse @@ -19,6 +21,7 @@ from saml2.mdstore import locations from saml2.mdstore import name from saml2 import sigver from saml2.httpbase import HTTPBase +from saml2 import SAMLError from saml2 import BINDING_SOAP from saml2 import BINDING_HTTP_REDIRECT from saml2 import BINDING_HTTP_POST @@ -156,6 +159,10 @@ METADATACONF = { "class": "saml2.mdstore.MetaDataFile", "metadata": [(full_path("swamid-2.0.xml"),)], }], + "14": [{ + "class": "saml2.mdstore.MetaDataFile", + "metadata": [(full_path("invalid_metadata_file.xml"),)], + }], } @@ -170,6 +177,12 @@ def _fix_valid_until(xmlstring): xmlstring) +def test_invalid_metadata(): + mds = MetadataStore(ATTRCONV, sec_config, disable_ssl_certificate_validation=True) + with raises(SAMLError): + mds.imp(METADATACONF["14"]) + + def test_swami_1(): UMU_IDP = 'https://idp.umu.se/saml2/idp/metadata.php' mds = MetadataStore(ATTRCONV, sec_config, |