|
1 |
| -import xmlsec |
2 |
| -from xmlsec import constants as consts |
3 |
| - |
| 1 | +import sys |
4 | 2 | from io import BytesIO
|
| 3 | +from unittest import skipIf |
5 | 4 |
|
| 5 | +import xmlsec |
6 | 6 | from tests import base
|
| 7 | +from xmlsec import constants as consts |
7 | 8 |
|
8 | 9 |
|
9 | 10 | class TestBase64LineSize(base.TestMemoryLeaks):
|
@@ -43,18 +44,11 @@ def setUp(self):
|
43 | 44 |
|
44 | 45 | def _sign_doc(self):
|
45 | 46 | root = self.load_xml("doc.xml")
|
46 |
| - sign = xmlsec.template.create( |
47 |
| - root, |
48 |
| - c14n_method=consts.TransformExclC14N, |
49 |
| - sign_method=consts.TransformRsaSha1 |
50 |
| - ) |
51 |
| - xmlsec.template.add_reference( |
52 |
| - sign, consts.TransformSha1, uri="cid:123456") |
| 47 | + sign = xmlsec.template.create(root, c14n_method=consts.TransformExclC14N, sign_method=consts.TransformRsaSha1) |
| 48 | + xmlsec.template.add_reference(sign, consts.TransformSha1, uri="cid:123456") |
53 | 49 |
|
54 | 50 | ctx = xmlsec.SignatureContext()
|
55 |
| - ctx.key = xmlsec.Key.from_file( |
56 |
| - self.path("rsakey.pem"), format=consts.KeyDataFormatPem |
57 |
| - ) |
| 51 | + ctx.key = xmlsec.Key.from_file(self.path("rsakey.pem"), format=consts.KeyDataFormatPem) |
58 | 52 | ctx.sign(sign)
|
59 | 53 | return sign
|
60 | 54 |
|
@@ -87,16 +81,14 @@ def _find(self, elem, *tags):
|
87 | 81 | './' + '/'.join('xmldsig:{}'.format(tag) for tag in tags),
|
88 | 82 | namespaces={
|
89 | 83 | 'xmldsig': 'http://www.w3.org/2000/09/xmldsig#',
|
90 |
| - } |
| 84 | + }, |
91 | 85 | )[0]
|
92 | 86 | except IndexError as e:
|
93 | 87 | raise KeyError(tags) from e
|
94 | 88 |
|
95 | 89 | def _verify_external_data_signature(self):
|
96 | 90 | signature = self._sign_doc()
|
97 |
| - digest = self._find( |
98 |
| - signature, 'SignedInfo', 'Reference', 'DigestValue' |
99 |
| - ).text |
| 91 | + digest = self._find(signature, 'SignedInfo', 'Reference', 'DigestValue').text |
100 | 92 | self.assertEqual(digest, 'VihZwVMGJ48NsNl7ertVHiURXk8=')
|
101 | 93 |
|
102 | 94 | def test_sign_external_data_no_callbacks_fails(self):
|
@@ -133,6 +125,7 @@ def match_cb(filename):
|
133 | 125 | self._verify_external_data_signature()
|
134 | 126 | self.assertEqual(bad_match_calls, 0)
|
135 | 127 |
|
| 128 | + @skipIf(sys.platform == "win32", "unclear behaviour on windows") |
136 | 129 | def test_failed_sign_because_default_callbacks(self):
|
137 | 130 | mismatch_calls = 0
|
138 | 131 |
|
|
0 commit comments