Skip to content

Commit 1ac9e7a

Browse files
afelicianomvantellingen
authored andcommitted
fix(xop): respect RFC2392 when mapping href to cid
- RFC link https://tools.ietf.org/html/rfc2392
1 parent 9dc3eb7 commit 1ac9e7a

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

src/zeep/wsdl/messages/xop.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import base64
2+
from six.moves.urllib.parse import unquote
23

34

45
def process_xop(document, message_pack):
@@ -12,7 +13,8 @@ def process_xop(document, message_pack):
1213
for xop_node in xop_nodes:
1314
href = xop_node.get("href")
1415
if href.startswith("cid:"):
15-
href = "<%s>" % href[4:]
16+
# URL can be encoded. RFC2392
17+
href = "<%s>" % unquote(href[4:])
1618

1719
value = message_pack.get_by_content_id(href)
1820
if not value:

tests/test_soap_xop.py

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def test_rebuild_xml():
7575
assert_nodes_equal(etree.tostring(document), expected)
7676

7777

78-
def test_xop():
78+
def get_client_service():
7979
wsdl_main = StringIO(
8080
"""
8181
<?xml version="1.0"?>
@@ -172,6 +172,11 @@ def test_xop():
172172
"http://tests.python-zeep.org/test",
173173
)
174174

175+
return service
176+
177+
178+
def test_xop():
179+
service = get_client_service()
175180
content_type = 'multipart/related; boundary="boundary"; type="application/xop+xml"; start="<soap:Envelope>"; start-info="application/soap+xml; charset=utf-8"'
176181

177182
response1 = "\r\n".join(
@@ -252,3 +257,48 @@ def test_xop():
252257
)
253258
result = service.TestOperation1("")
254259
assert result == "BINARYDATA".encode()
260+
261+
262+
def test_xop_cid_encoded():
263+
service = get_client_service()
264+
content_type = 'multipart/related; boundary="boundary"; type="application/xop+xml"; start="<soap:Envelope>"; start-info="application/soap+xml; charset=utf-8"'
265+
266+
response_encoded_cid = "\r\n".join(
267+
line.strip()
268+
for line in """
269+
Content-Type: application/xop+xml; charset=utf-8; type="application/soap+xml"
270+
Content-Transfer-Encoding: binary
271+
Content-ID: <soap:Envelope>
272+
273+
<?xml version="1.0" encoding="UTF-8"?>
274+
<soap:Envelope
275+
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
276+
xmlns:xop="http://www.w3.org/2004/08/xop/include"
277+
xmlns:test="http://tests.python-zeep.org/xsd-main">
278+
<soap:Body>
279+
<test:resultComplex>
280+
<test:BinaryData>
281+
<xop:Include href="cid:test_encoding%20cid%25%24%7D%40"/>
282+
</test:BinaryData>
283+
</test:resultComplex>
284+
</soap:Body>
285+
</soap:Envelope>
286+
--boundary
287+
Content-Type: application/binary
288+
Content-Transfer-Encoding: binary
289+
Content-ID: <test_encoding cid%$}@>
290+
291+
BINARYDATA
292+
293+
--boundary--
294+
""".splitlines()
295+
)
296+
297+
with requests_mock.mock() as m:
298+
m.post(
299+
"http://tests.python-zeep.org/test",
300+
content=response_encoded_cid.encode("utf-8"),
301+
headers={"Content-Type": content_type},
302+
)
303+
result = service.TestOperation2("")
304+
assert result["_value_1"] == "BINARYDATA".encode()

0 commit comments

Comments
 (0)