1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
|
Description: Remove some failing tests due to missing build dependencies
The following tests fail due to missing build dependencies
tests/test_wsse_signature.py: xmlsec
Author: Mathias Behrle <mbehrle@debian.org>
--- a/tests/test_wsse_signature.py
+++ /dev/null
@@ -1,268 +0,0 @@
-import os
-import sys
-
-import pytest
-from lxml.etree import QName
-
-from tests.utils import load_xml
-from zeep import ns, wsse
-from zeep.exceptions import SignatureVerificationFailed
-from zeep.wsse import signature
-
-try:
- import xmlsec
-except ImportError:
- xmlsec = None
-
-KEY_FILE = os.path.join(os.path.dirname(os.path.realpath(__file__)), "cert_valid.pem")
-KEY_FILE_PW = os.path.join(
- os.path.dirname(os.path.realpath(__file__)), "cert_valid_pw.pem"
-)
-
-SIGNATURE_METHODS_TESTDATA = (
- ("RSA_SHA1", "http://www.w3.org/2000/09/xmldsig#rsa-sha1"),
- ("RSA_SHA256", "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"),
-)
-
-DIGEST_METHODS_TESTDATA = (
- ("SHA1", "http://www.w3.org/2000/09/xmldsig#sha1"),
- ("SHA256", "http://www.w3.org/2001/04/xmlenc#sha256"),
-)
-
-
-skip_if_no_xmlsec = pytest.mark.skipif(
- sys.platform == "win32", reason="does not run on windows"
-) and pytest.mark.skipif(xmlsec is None, reason="xmlsec library not installed")
-
-
-@skip_if_no_xmlsec
-@pytest.mark.parametrize("digest_method,expected_digest_href", DIGEST_METHODS_TESTDATA)
-@pytest.mark.parametrize(
- "signature_method,expected_signature_href", SIGNATURE_METHODS_TESTDATA
-)
-def test_sign_timestamp_if_present(
- digest_method,
- signature_method,
- expected_digest_href,
- expected_signature_href,
-):
- envelope = load_xml(
- """
- <soap-env:Envelope
- xmlns:ns0="http://example.com/stockquote.xsd"
- xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
- xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"
- xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
- xmlns:wsu="http://schemas.xmlsoap.org/ws/2003/06/utility"
- xmlns:xsd="http://www.w3.org/2001/XMLSchema">
- <soap-env:Header xmlns:ns0="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
- <ns0:Security>
- <wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
- <wsu:Created>2018-11-18T15:44:27Z</wsu:Created>
- <wsu:Expires>2018-11-18T15:54:27Z</wsu:Expires>
- </wsu:Timestamp>
- </ns0:Security>
- </soap-env:Header>
- <soap-env:Body>
- <ns0:TradePriceRequest>
- <tickerSymbol>foobar</tickerSymbol>
- <ns0:country/>
- </ns0:TradePriceRequest>
- </soap-env:Body>
- </soap-env:Envelope>
- """
- )
-
- signature.sign_envelope(
- envelope,
- KEY_FILE,
- KEY_FILE,
- None,
- signature_method=getattr(xmlsec.Transform, signature_method),
- digest_method=getattr(xmlsec.Transform, digest_method),
- )
- signature.verify_envelope(envelope, KEY_FILE)
- digests = envelope.xpath("//ds:DigestMethod", namespaces={"ds": ns.DS})
- assert len(digests)
- for digest in digests:
- assert digest.get("Algorithm") == expected_digest_href
- signatures = envelope.xpath("//ds:SignatureMethod", namespaces={"ds": ns.DS})
- assert len(signatures)
- for sig in signatures:
- assert sig.get("Algorithm") == expected_signature_href
-
-
-@skip_if_no_xmlsec
-@pytest.mark.parametrize("digest_method,expected_digest_href", DIGEST_METHODS_TESTDATA)
-@pytest.mark.parametrize(
- "signature_method,expected_signature_href", SIGNATURE_METHODS_TESTDATA
-)
-def test_sign(
- digest_method, signature_method, expected_digest_href, expected_signature_href
-):
- envelope = load_xml(
- """
- <soapenv:Envelope
- xmlns:tns="http://tests.python-zeep.org/"
- xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
- xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
- xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
- <soapenv:Header></soapenv:Header>
- <soapenv:Body>
- <tns:Function>
- <tns:Argument>OK</tns:Argument>
- </tns:Function>
- </soapenv:Body>
- </soapenv:Envelope>
- """
- )
-
- signature.sign_envelope(
- envelope,
- KEY_FILE,
- KEY_FILE,
- signature_method=getattr(xmlsec.Transform, signature_method),
- digest_method=getattr(xmlsec.Transform, digest_method),
- )
- signature.verify_envelope(envelope, KEY_FILE)
-
- digests = envelope.xpath("//ds:DigestMethod", namespaces={"ds": ns.DS})
- assert len(digests)
- for digest in digests:
- assert digest.get("Algorithm") == expected_digest_href
- signatures = envelope.xpath("//ds:SignatureMethod", namespaces={"ds": ns.DS})
- assert len(signatures)
- for sig in signatures:
- assert sig.get("Algorithm") == expected_signature_href
-
-
-@skip_if_no_xmlsec
-def test_sign_pw():
- envelope = load_xml(
- """
- <soapenv:Envelope
- xmlns:tns="http://tests.python-zeep.org/"
- xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
- xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
- xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
- <soapenv:Header></soapenv:Header>
- <soapenv:Body>
- <tns:Function>
- <tns:Argument>OK</tns:Argument>
- </tns:Function>
- </soapenv:Body>
- </soapenv:Envelope>
- """
- )
-
- signature.sign_envelope(envelope, KEY_FILE_PW, KEY_FILE_PW, "geheim")
- signature.verify_envelope(envelope, KEY_FILE_PW)
-
-
-@skip_if_no_xmlsec
-def test_verify_error():
- envelope = load_xml(
- """
- <soapenv:Envelope
- xmlns:tns="http://tests.python-zeep.org/"
- xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
- xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
- xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
- <soapenv:Header></soapenv:Header>
- <soapenv:Body>
- <tns:Function>
- <tns:Argument>OK</tns:Argument>
- </tns:Function>
- </soapenv:Body>
- </soapenv:Envelope>
- """
- )
-
- signature.sign_envelope(envelope, KEY_FILE, KEY_FILE)
- nsmap = {"tns": "http://tests.python-zeep.org/"}
-
- for elm in envelope.xpath("//tns:Argument", namespaces=nsmap):
- elm.text = "NOT!"
-
- with pytest.raises(SignatureVerificationFailed):
- signature.verify_envelope(envelope, KEY_FILE)
-
-
-@skip_if_no_xmlsec
-def test_signature():
- envelope = load_xml(
- """
- <soapenv:Envelope
- xmlns:tns="http://tests.python-zeep.org/"
- xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
- xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
- xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
- <soapenv:Header></soapenv:Header>
- <soapenv:Body>
- <tns:Function>
- <tns:Argument>OK</tns:Argument>
- </tns:Function>
- </soapenv:Body>
- </soapenv:Envelope>
- """
- )
-
- plugin = wsse.Signature(KEY_FILE_PW, KEY_FILE_PW, "geheim")
- envelope, headers = plugin.apply(envelope, {})
- plugin.verify(envelope)
-
-
-@skip_if_no_xmlsec
-@pytest.mark.parametrize("digest_method,expected_digest_href", DIGEST_METHODS_TESTDATA)
-@pytest.mark.parametrize(
- "signature_method,expected_signature_href", SIGNATURE_METHODS_TESTDATA
-)
-def test_signature_binary(
- digest_method, signature_method, expected_digest_href, expected_signature_href
-):
- envelope = load_xml(
- """
- <soapenv:Envelope
- xmlns:tns="http://tests.python-zeep.org/"
- xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
- xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
- xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
- <soapenv:Header></soapenv:Header>
- <soapenv:Body>
- <tns:Function>
- <tns:Argument>OK</tns:Argument>
- </tns:Function>
- </soapenv:Body>
- </soapenv:Envelope>
- """
- )
-
- plugin = wsse.BinarySignature(
- KEY_FILE_PW,
- KEY_FILE_PW,
- "geheim",
- signature_method=getattr(xmlsec.Transform, signature_method),
- digest_method=getattr(xmlsec.Transform, digest_method),
- )
- envelope, headers = plugin.apply(envelope, {})
- plugin.verify(envelope)
- # Test the reference
- bintok = envelope.xpath(
- "soapenv:Header/wsse:Security/wsse:BinarySecurityToken",
- namespaces={"soapenv": ns.SOAP_ENV_11, "wsse": ns.WSSE},
- )[0]
- ref = envelope.xpath(
- "soapenv:Header/wsse:Security/ds:Signature/ds:KeyInfo/wsse:SecurityTokenReference"
- "/wsse:Reference",
- namespaces={"soapenv": ns.SOAP_ENV_11, "wsse": ns.WSSE, "ds": ns.DS},
- )[0]
- assert "#" + bintok.attrib[QName(ns.WSU, "Id")] == ref.attrib["URI"]
-
- digests = envelope.xpath("//ds:DigestMethod", namespaces={"ds": ns.DS})
- assert len(digests)
- for digest in digests:
- assert digest.get("Algorithm") == expected_digest_href
- signatures = envelope.xpath("//ds:SignatureMethod", namespaces={"ds": ns.DS})
- assert len(signatures)
- for sig in signatures:
- assert sig.get("Algorithm") == expected_signature_href
|