Skip to content

Commit f17f4b9

Browse files
ch3pjwhoefling
authored andcommitted
Use xpath to traverse signature structure in tests
It seems to be way more robust across library versions.
1 parent ce90c06 commit f17f4b9

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

tests/test_main.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,15 @@ def _register_match_callbacks(self):
8080
)
8181

8282
def _find(self, elem, *tags):
83-
for tag in tags:
84-
elem = elem.find(
85-
'{{http://www.w3.org/2000/09/xmldsig#}}{}'.format(tag))
86-
return elem
83+
try:
84+
return elem.xpath(
85+
'./' + '/'.join('xmldsig:{}'.format(tag) for tag in tags),
86+
namespaces={
87+
'xmldsig': 'http://www.w3.org/2000/09/xmldsig#',
88+
}
89+
)[0]
90+
except IndexError as e:
91+
raise KeyError(tags) from e
8792

8893
def _verify_external_data_signature(self):
8994
signature = self._sign_doc()

0 commit comments

Comments
 (0)