Skip to content

Commit

Permalink
Handle empty SOAP body as client error
Browse files Browse the repository at this point in the history
  • Loading branch information
sashawood authored and plq committed Jan 11, 2023
1 parent daf2f66 commit 3b413b6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
7 changes: 6 additions & 1 deletion spyne/protocol/soap/soap11.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,12 @@ def _from_soap(in_envelope_xml, xmlids=None, **kwargs):

def _parse_xml_string(xml_string, parser, charset=None):
xml_string = iter(xml_string)
chunk = next(xml_string)
try:
chunk = next(xml_string)
except StopIteration:
logger_invalid.error("missing body")
raise Fault('Client.XMLSyntaxError', 'Missing body')

if isinstance(chunk, six.binary_type):
string = b''.join(chain( (chunk,), xml_string ))
else:
Expand Down
12 changes: 12 additions & 0 deletions spyne/test/protocol/test_soap11.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,18 @@ def test_href(self):
# quick and dirty test href reconstruction
self.assertEqual(len(payload[0]), 2)

def test_empty_body(self):
# If the soap request has no body, then you get an empty iterable
# as the envelope string.
# This should be treated as a client error.
envelope_string = iter([])

with self.assertRaises(Fault) as cm:
_parse_xml_string(envelope_string,
etree.XMLParser(), 'utf8')
self.assertEqual(cm.exception.faultcode, 'Client.XMLSyntaxError')
self.assertEqual(cm.exception.faultstring, 'Missing body')

def test_namespaces(self):
m = ComplexModel.produce(
namespace="some_namespace",
Expand Down

0 comments on commit 3b413b6

Please sign in to comment.