Skip to content

Commit 072f814

Browse files
committed
Raise SAMLError when metadata file cannot be parsed
Signed-off-by: Ivan Kanakarakis <[email protected]>
1 parent c1792b0 commit 072f814

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

src/saml2/mdstore.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@
77
import sys
88
from itertools import chain
99
from warnings import warn as _warn
10-
1110
from hashlib import sha1
1211
from os.path import isfile
1312
from os.path import join
1413

1514
import requests
15+
1616
import six
1717

18-
from xml.etree.ElementTree import ParseError
1918
from saml2 import md
2019
from saml2 import saml
2120
from saml2 import samlp
@@ -25,7 +24,6 @@
2524
from saml2 import BINDING_HTTP_REDIRECT
2625
from saml2 import BINDING_HTTP_POST
2726
from saml2 import BINDING_SOAP
28-
2927
from saml2.httpbase import HTTPBase
3028
from saml2.extension.idpdisc import BINDING_DISCO
3129
from saml2.extension.idpdisc import DiscoveryResponse
@@ -616,9 +614,8 @@ def parse(self, xmlstr):
616614
try:
617615
self.entities_descr = md.entities_descriptor_from_string(xmlstr)
618616
except Exception as e:
619-
logger.error(f'Metadata Parse Error on: {self.filename}')
620-
return
621-
617+
raise SAMLError(f'Failed to parse metadata file: {self.filename}') from e
618+
622619
if not self.entities_descr:
623620
self.entity_descr = md.entity_descriptor_from_string(xmlstr)
624621
if self.entity_descr:

tests/invalid_metadata_file.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
this content is invalid

tests/test_30_mdstore.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
from unittest.mock import Mock
88
from unittest.mock import patch
99

10+
from pytest import raises
11+
1012
import responses
1113

1214
from six.moves.urllib import parse
@@ -19,6 +21,7 @@
1921
from saml2.mdstore import name
2022
from saml2 import sigver
2123
from saml2.httpbase import HTTPBase
24+
from saml2 import SAMLError
2225
from saml2 import BINDING_SOAP
2326
from saml2 import BINDING_HTTP_REDIRECT
2427
from saml2 import BINDING_HTTP_POST
@@ -156,6 +159,10 @@
156159
"class": "saml2.mdstore.MetaDataFile",
157160
"metadata": [(full_path("swamid-2.0.xml"),)],
158161
}],
162+
"14": [{
163+
"class": "saml2.mdstore.MetaDataFile",
164+
"metadata": [(full_path("invalid_metadata_file.xml"),)],
165+
}],
159166
}
160167

161168

@@ -170,6 +177,12 @@ def _fix_valid_until(xmlstring):
170177
xmlstring)
171178

172179

180+
def test_invalid_metadata():
181+
mds = MetadataStore(ATTRCONV, sec_config, disable_ssl_certificate_validation=True)
182+
with raises(SAMLError):
183+
mds.imp(METADATACONF["14"])
184+
185+
173186
def test_swami_1():
174187
UMU_IDP = 'https://idp.umu.se/saml2/idp/metadata.php'
175188
mds = MetadataStore(ATTRCONV, sec_config,

0 commit comments

Comments
 (0)