Skip to content

Commit

Permalink
Fix parsing of faults with empty namespace
Browse files Browse the repository at this point in the history
Parsing soap faults falls back to extracting attributes without a
namespace, if it can't find a namespaced attribute.

Fixes mvantellingen#1254
  • Loading branch information
David Poisl committed Jul 28, 2023
1 parent 377d931 commit b69d992
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/zeep/wsdl/bindings/soap.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,16 +321,23 @@ def process_error(self, doc, operation):
detail=etree_to_string(doc),
)

def get_text(name):
def get_node(name):
child = fault_node.find(name, namespaces=fault_node.nsmap)
if child is not None:
return child
child = fault_node.find(name)
return child

def get_text(name):
child = get_node(name)
if child is not None:
return child.text

raise Fault(
message=get_text("faultstring"),
code=get_text("faultcode"),
actor=get_text("faultactor"),
detail=fault_node.find("detail", namespaces=fault_node.nsmap),
detail=get_node("detail"),
)

def _set_http_headers(self, serialized, operation):
Expand Down
33 changes: 33 additions & 0 deletions tests/test_wsdl_soap.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,39 @@ def test_soap11_process_error():
"utf-8"
)

responseWithEmptyNamespaceInFault = load_xml(
"""
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns="http://example.com/my/schema">
<soapenv:Body>
<soapenv:Fault>
<faultcode xmlns="">fault-code-withEmptyNamespace</faultcode>
<faultstring xmlns="">fault-string-withEmptyNamespace</faultstring>
<detail xmlns="">
<myFaultDetails xmlns="http://example.com/my/schema">
<message>detail-message-withNamespace</message>
<errorcode>detail-code-withNamespace</errorcode>
</myFaultDetails>
</detail>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
"""
)

try:
binding.process_error(responseWithEmptyNamespaceInFault, None)
except Fault as exc:
assert exc.message == "fault-string-withEmptyNamespace"
assert exc.code == "fault-code-withEmptyNamespace"
assert exc.actor is None
assert exc.subcodes is None
assert "detail-message-withNamespace" in etree.tostring(exc.detail).decode(
"utf-8"
)



def test_soap12_process_error():
response = """
Expand Down

0 comments on commit b69d992

Please sign in to comment.