Skip to content

Commit

Permalink
🐛 [#4338] Fix SOAP 1.2 namespace replacement
Browse files Browse the repository at this point in the history
Not the scattering of namespaces is an issue, but our
mapping of namespace replacements. We replace the
namespaces to get easier dict lookups (without ns
URLs prefixed to keys), but we only covered the
SOAP 1.1 Envelope namespace.

The XML message that causes issues uses the XML
namespace for SOAP 1.2 Envelope, and since that
namespace was not being replaced/removed, the
root 'Envelope' key in the dict does not exist
(it only exists with the namespace prefix URL),
causing all nested lookups to fail and no values
to be returend.

This patch adds the SOAP 1.2 namespace, which
ensures this gets replaced and now the root key
can be found, including all nested keys and
data.

Backport-of: #4388
  • Loading branch information
sergei-maertens committed Jun 14, 2024
1 parent 3d47565 commit 1180aba
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/stuf/stuf_bg/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
# Note: This could cause a collision if two of the same elements
# are present in different namespaces
NAMESPACE_REPLACEMENTS = {
"http://schemas.xmlsoap.org/soap/envelope/": None,
"http://www.w3.org/2003/05/soap-envelope": None, # SOAP 1.2
"http://schemas.xmlsoap.org/soap/envelope/": None, # SOAP 1.1
"http://www.egem.nl/StUF/sector/bg/0310": None,
"http://www.egem.nl/StUF/StUF0301": None,
"http://www.w3.org/1999/xlink": None,
Expand Down
58 changes: 58 additions & 0 deletions src/stuf/stuf_bg/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,64 @@ def test_inp_heeftAlsKinderen(self):
value = glom(data_dict, GlomTarget["inp.heeftAlsKinderen"], default=missing)
self.assertNotEqual(value, missing)

@tag("gh-4338")
@requests_mock.Mocker()
def test_scattered_namespaces(self, m):
XML = b"""<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Header />
<soapenv:Body>
<BG:npsLa01 xmlns:BG="http://www.egem.nl/StUF/sector/bg/0310"
xmlns:StUF="http://www.egem.nl/StUF/StUF0301"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<BG:stuurgegevens>
<StUF:berichtcode>La01</StUF:berichtcode>
<StUF:zender>
<StUF:applicatie>CGS</StUF:applicatie>
</StUF:zender>
<StUF:ontvanger>
<StUF:organisatie>Maykin</StUF:organisatie>
<StUF:applicatie>OpenForms</StUF:applicatie>
</StUF:ontvanger>
<StUF:referentienummer>S17170448031</StUF:referentienummer>
<StUF:tijdstipBericht>2024053011095409</StUF:tijdstipBericht>
<StUF:crossRefnummer>6551d7e5-515c-4c30-b249-e8aab590ac06</StUF:crossRefnummer>
<StUF:entiteittype>NPS</StUF:entiteittype>
</BG:stuurgegevens>
<BG:parameters>
<StUF:indicatorVervolgvraag>false</StUF:indicatorVervolgvraag>
</BG:parameters>
<BG:antwoord>
<BG:object StUF:entiteittype="NPS">
<BG:inp.bsn>111222333</BG:inp.bsn>
<BG:geslachtsnaam>Janssen</BG:geslachtsnaam>
<BG:voorvoegselGeslachtsnaam xsi:nil="true" StUF:noValue="geenWaarde" />
<BG:geboortedatum>19820304</BG:geboortedatum>
</BG:object>
</BG:antwoord>
</BG:npsLa01>
</soapenv:Body>
</soapenv:Envelope>
"""
m.post(self.stuf_service.soap_service.url, content=XML)

response_data = self.stufbg_client.get_values("999992314", ["irrelevant"])

expected = {
"inp.bsn": "111222333",
"geslachtsnaam": "Janssen",
"voorvoegselGeslachtsnaam": None,
"geboortedatum": "19820304",
}
for key, value in expected.items():
with self.subTest(key=key, value=value):
self.assertEqual(response_data.get(key), value)


def _contains_nils(d: dict):
"""Check if xmltodict result contains xsi:nil="true" or StUF:noValue="geenWaarde"
Expand Down

0 comments on commit 1180aba

Please sign in to comment.