Skip to content
This repository has been archived by the owner on May 9, 2022. It is now read-only.

Commit

Permalink
null value error on metadata parser
Browse files Browse the repository at this point in the history
  • Loading branch information
peppelinux committed Feb 10, 2021
1 parent 01ae060 commit a499c1b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions testenv/tests/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,6 @@ def test_broken_metadata_xml_valuerror(self):

def test_stupid_metadata_xml_valuerror(self):
saml_to_dict('test.stupido')

def test_nullmetadata_xml_valuerror(self):
self.assertEqual({}, saml_to_dict(None))
7 changes: 5 additions & 2 deletions testenv/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,17 @@ def saml_to_dict(xmlstr):
_err_msg = 'SP Metadata Parse Error'
_trunc = 254

if not xmlstr:
logger.error(f'{_err_msg} [Null Value Error] on xmlstr')
return {}
# sometimes a bytes objects, sometimes a '_io.TextIOWrapper' object ...
if isinstance(xmlstr, io.TextIOWrapper):
elif isinstance(xmlstr, io.TextIOWrapper):
xmlstr = xmlstr.read()

try:
root = objectify.fromstring(xmlstr)
except ValueError:
logger.error(f'{_err_msg} [ValuerError] on: '
logger.error(f'{_err_msg} [ValueError] on: '
f'{xmlstr[0:_trunc]}')
return {}
# that's for resiliency ...
Expand Down

0 comments on commit a499c1b

Please sign in to comment.