Skip to content

Commit c99354e

Browse files
committed
Added tests
1 parent 194e174 commit c99354e

File tree

1 file changed

+119
-0
lines changed

1 file changed

+119
-0
lines changed

tests/test_wsdl.py

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,3 +1313,122 @@ def test_import_no_location():
13131313
document = wsdl.Document(
13141314
wsdl_content, transport, "https://tests.python-zeep.org/content.wsdl"
13151315
)
1316+
1317+
1318+
BASE_WSDL = """
1319+
<?xml version="1.0"?>
1320+
<wsdl:definitions
1321+
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
1322+
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
1323+
xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
1324+
xmlns:tns="http://tests.python-zeep.org/xsd-main"
1325+
xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702"
1326+
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
1327+
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
1328+
targetNamespace="http://tests.python-zeep.org/xsd-main">
1329+
1330+
{policy}
1331+
1332+
<wsdl:types>
1333+
<xsd:schema
1334+
targetNamespace="http://tests.python-zeep.org/xsd-main"
1335+
xmlns:tns="http://tests.python-zeep.org/xsd-main">
1336+
<xsd:element name="input" type="xsd:string"/>
1337+
</xsd:schema>
1338+
</wsdl:types>
1339+
1340+
<wsdl:message name="message-1">
1341+
<wsdl:part name="response" element="tns:input"/>
1342+
</wsdl:message>
1343+
1344+
<wsdl:portType name="TestPortType">
1345+
<wsdl:operation name="TestOperation1">
1346+
<wsdl:input message="message-1"/>
1347+
</wsdl:operation>
1348+
</wsdl:portType>
1349+
1350+
<wsdl:binding name="TestBinding" type="tns:TestPortType">
1351+
<wsp:PolicyReference URI="#TestBinding"/>
1352+
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
1353+
<wsdl:operation name="TestOperation1">
1354+
<soap:operation soapAction=""/>
1355+
</wsdl:operation>
1356+
</wsdl:binding>
1357+
1358+
<wsdl:service name="TestService">
1359+
<wsdl:documentation>Test service</wsdl:documentation>
1360+
<wsdl:port name="TestPortType" binding="tns:TestBinding">
1361+
<soap:address location="https://tests.python-zeep.org/tests"/>
1362+
</wsdl:port>
1363+
</wsdl:service>
1364+
</wsdl:definitions>
1365+
"""
1366+
1367+
1368+
def test_parse_bindings_signed_unknown():
1369+
policy = """
1370+
<wsp:Policy wsu:Id="TestBinding_policy">
1371+
<sp:SignedParts>
1372+
<sp:Other/>
1373+
</sp:SignedParts>
1374+
</wsp:Policy>
1375+
"""
1376+
content = StringIO(BASE_WSDL.format(policy=policy).strip())
1377+
document = wsdl.Document(content, None)
1378+
assert document.bindings[
1379+
"{http://tests.python-zeep.org/xsd-main}TestBinding"
1380+
].signatures == {"body": False, "everything": False, "header": []}
1381+
1382+
def test_parse_bindings_signed_body():
1383+
policy = """
1384+
<wsp:Policy wsu:Id="TestBinding_policy">
1385+
<sp:SignedParts>
1386+
<sp:Body/>
1387+
</sp:SignedParts>
1388+
</wsp:Policy>
1389+
"""
1390+
content = StringIO(BASE_WSDL.format(policy=policy).strip())
1391+
document = wsdl.Document(content, None)
1392+
assert document.bindings[
1393+
"{http://tests.python-zeep.org/xsd-main}TestBinding"
1394+
].signatures == {"body": True, "everything": False, "header": []}
1395+
1396+
1397+
def test_parse_bindings_signed_everything():
1398+
policy = """
1399+
<wsp:Policy wsu:Id="TestBinding_policy">
1400+
<sp:SignedParts/>
1401+
</wsp:Policy>
1402+
"""
1403+
content = StringIO(BASE_WSDL.format(policy=policy).strip())
1404+
document = wsdl.Document(content, None)
1405+
assert document.bindings[
1406+
"{http://tests.python-zeep.org/xsd-main}TestBinding"
1407+
].signatures == {"body": True, "everything": True, "header": []}
1408+
1409+
1410+
def test_parse_bindings_signed_headers():
1411+
policy = """
1412+
<wsp:Policy wsu:Id="TestBinding_policy">
1413+
<sp:SignedParts>
1414+
<sp:Header Name="To" Namespace="http://www.w3.org/2005/08/addressing"/>
1415+
</sp:SignedParts>
1416+
</wsp:Policy>
1417+
"""
1418+
content = StringIO(BASE_WSDL.format(policy=policy).strip())
1419+
document = wsdl.Document(content, None)
1420+
assert document.bindings[
1421+
"{http://tests.python-zeep.org/xsd-main}TestBinding"
1422+
].signatures == {
1423+
"body": False,
1424+
"everything": False,
1425+
"header": [{"Name": "To", "Namespace": "http://www.w3.org/2005/08/addressing"}],
1426+
}
1427+
1428+
1429+
def test_parse_bindings_signed_nothing():
1430+
content = StringIO(BASE_WSDL.format(policy="").strip())
1431+
document = wsdl.Document(content, None)
1432+
assert document.bindings[
1433+
"{http://tests.python-zeep.org/xsd-main}TestBinding"
1434+
].signatures == {"body": False, "everything": False, "header": []}

0 commit comments

Comments
 (0)