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="https://schemas.xmlsoap.org/wsdl/" xmlns:soapenv="https://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="https://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_installed.Transform, signature_method), digest_method=getattr(xmlsec_installed.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
def test_signature_binary(): 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') envelope, headers = plugin.apply(envelope, {}) plugin.verify(envelope)
def test_signature_binary(): 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") 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"]