sne: fail silently on common sne errors (#81452)
gitea/passerelle/pipeline/head This commit looks good Details

This commit is contained in:
Emmanuel Cazenave 2023-09-22 18:16:20 +02:00
parent bf2610b4c5
commit ef0b518aba
4 changed files with 49 additions and 6 deletions

View File

@ -23,6 +23,12 @@ from django.utils.translation import gettext_lazy as _
from passerelle.base.models import BaseResource, HTTPResource
from passerelle.utils.api import endpoint
from passerelle.utils.soap import SOAPFault
PASS_THROUGH_MESSAGES = [
"La demande de logement n'existe pas dans le système.",
'Votre guichet enregistreur ne couvre pas au moins une des communes souhaitées de la demande de logement.',
]
class SNE(BaseResource, HTTPResource):
@ -66,9 +72,15 @@ class SNE(BaseResource, HTTPResource):
client = self.soap_client(wsdl_url=self.wsdl_url, api_error=True)
cert_type = client.get_type('{http://ws.metier.nuu.application.i2/}base64Binary')
cert = cert_type(_value_1=self.cert_public_bytes)
res = client.service.getDemandeLogement(
numUnique=demand_id, nomCertificat=self.certificate_name, certificat=cert
)
try:
res = client.service.getDemandeLogement(
numUnique=demand_id, nomCertificat=self.certificate_name, certificat=cert
)
except SOAPFault as e:
message = e.data.get('soap_fault', {}).get('message', '')
if message in PASS_THROUGH_MESSAGES:
return {'err_desc': message}
raise
namespaces = {
'http://nuu.application.i2/': None,
}

View File

@ -0,0 +1,7 @@
--uuid:7902e9bd-21a8-4632-8760-d79a67eb89a1
Content-Id: <rootpart*7902e9bd-21a8-4632-8760-d79a67eb89a1@example.jaxws.sun.com>
Content-Type: application/xop+xml;charset=utf-8;type="application/soap+xml"
Content-Transfer-Encoding: binary
<?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://www.w3.org/2003/05/soap-envelope"><S:Header><Action xmlns="http://www.w3.org/2005/08/addressing">http://www.w3.org/2005/08/addressing/fault</Action><MessageID xmlns="http://www.w3.org/2005/08/addressing">uuid:1e213982-4a8d-4722-bb24-a2c5f48dd5c7</MessageID><RelatesTo xmlns="http://www.w3.org/2005/08/addressing">urn:uuid:93d3b273-c123-4277-b288-24a77b1e90dc</RelatesTo><To xmlns="http://www.w3.org/2005/08/addressing">http://www.w3.org/2005/08/addressing/anonymous</To></S:Header><S:Body><S:Fault xmlns:ns4="http://schemas.xmlsoap.org/soap/envelope/"><S:Code><S:Value>S:Receiver</S:Value></S:Code><S:Reason><S:Text xml:lang="fr">Votre guichet enregistreur ne couvre pas au moins une des communes souhaitées de la demande de logement.</S:Text></S:Reason></S:Fault></S:Body></S:Envelope>
--uuid:7902e9bd-21a8-4632-8760-d79a67eb89a1--

View File

@ -0,0 +1,7 @@
--uuid:7902e9bd-21a8-4632-8760-d79a67eb89a1
Content-Id: <rootpart*7902e9bd-21a8-4632-8760-d79a67eb89a1@example.jaxws.sun.com>
Content-Type: application/xop+xml;charset=utf-8;type="application/soap+xml"
Content-Transfer-Encoding: binary
<?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://www.w3.org/2003/05/soap-envelope"><S:Header><Action xmlns="http://www.w3.org/2005/08/addressing">http://www.w3.org/2005/08/addressing/fault</Action><MessageID xmlns="http://www.w3.org/2005/08/addressing">uuid:1e213982-4a8d-4722-bb24-a2c5f48dd5c7</MessageID><RelatesTo xmlns="http://www.w3.org/2005/08/addressing">urn:uuid:93d3b273-c123-4277-b288-24a77b1e90dc</RelatesTo><To xmlns="http://www.w3.org/2005/08/addressing">http://www.w3.org/2005/08/addressing/anonymous</To></S:Header><S:Body><S:Fault xmlns:ns4="http://schemas.xmlsoap.org/soap/envelope/"><S:Code><S:Value>S:Receiver</S:Value></S:Code><S:Reason><S:Text xml:lang="fr">Unkown error</S:Text></S:Reason></S:Fault></S:Body></S:Envelope>
--uuid:7902e9bd-21a8-4632-8760-d79a67eb89a1--

View File

@ -90,10 +90,27 @@ def test_get_demande_logement_does_not_exist(app, connector, settings):
)
resp = app.get('/sne/test/get-demande-logement?demand_id=0690221008931G3164')
json_resp = resp.json
assert json_resp['err'] == 1
assert json_resp['err'] == 0
assert json_resp['err_desc'] == "La demande de logement n'existe pas dans le système."
def test_get_demande_logement_bad_guichet(app, connector, settings):
with responses.RequestsMock() as rsps:
setup_(rsps, settings)
with open('%s/tests/data/sne/response_mauvais_guichet' % os.getcwd(), 'rb') as f:
rsps.post(
'https://sne-ws-2.site-ecole.din.developpement-durable.gouv.invalid/services/DemandeLogementImplService',
status=200,
body=f.read(),
content_type='multipart/related; start="<rootpart*7902e9bd-21a8-4632-8760-d79a67eb89a1@example.jaxws.sun.com>"; type="application/xop+xml";'
' boundary="uuid:7902e9bd-21a8-4632-8760-d79a67eb89a1"; start-info="application/soap+xml"',
)
resp = app.get('/sne/test/get-demande-logement?demand_id=0690221008931G3164')
json_resp = resp.json
assert json_resp['err'] == 0
assert (
json_resp['data']['soap_fault']['message']
== "La demande de logement n'existe pas dans le système."
json_resp['err_desc']
== 'Votre guichet enregistreur ne couvre pas au moins une des communes souhaitées de la demande de logement.'
)