Skip to content

MessagePack strips newlines in binary attachment content #1481

@lazka

Description

@lazka

Using zeep 4.3.2:

I'm not that deep into soap etc so I hope I'm not missing something, or my SOAP server is not doing something stupid. I get a binary response from a SOAP service which with zeep is missing a trailing newline (I know this because I also get a signature of the content in the response, and adding a newline makes the signature verification pass).

Here is an example based on the zeep test suite:

from requests_toolbelt.multipart.decoder import MultipartDecoder
from pretend import stub

from zeep.wsdl.attachments import MessagePack

data = "\r\n".join(
    line.strip()
    for line in """
    --MIME_boundary
    Content-Type: application/soap+xml; charset=UTF-8
    Content-Transfer-Encoding: 8bit
    Content-ID: <root@test>

    <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"/>

    --MIME_boundary
    Content-Type: application/octet-stream
    Content-Transfer-Encoding: binary
    Content-ID: <attachment@test>

    hello world

    --MIME_boundary--
""".splitlines()
).encode("utf-8")

response = stub(
    status_code=200,
    content=data,
    encoding=None,
    headers={
        "Content-Type": 'multipart/related; boundary=MIME_boundary; type="application/soap+xml"; start="<root@test>"'
    },
)

decoder = MultipartDecoder(response.content, response.headers["Content-Type"], "utf-8")
part = decoder.parts[1]
actual = MessagePack(decoder.parts[1:]).attachments[0].content

expected = b"hello world\r\n"
assert actual == expected, f"Expected {expected!r}, got {actual!r}"

I see that these are removed in

return content.strip(b"\r\n")
but maybe that is not considering that the binary content itself could contain those characters at the end?

thanks for zeep!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions