Compare commits

...

5 Commits

Author SHA1 Message Date
Frédéric Péters 87d548b9dc gdc: escape special characters for XML (#44048)
gitea-wip/passerelle/pipeline/head There was a failure building this commit Details
gitea/passerelle/pipeline/head Something is wrong with the build of this commit Details
2020-06-13 21:30:06 +02:00
Serghei Mihai f89faf4af3 api_particulier: fix family situation endoint url (#44005) 2020-06-12 12:30:43 +02:00
Frédéric Péters 0bb026bcbc gdc: force utf-8 encoding of soap requests (#43963) 2020-06-12 10:54:44 +02:00
Frédéric Péters cde0fc1ea4 gdc: handle null values (#43963) 2020-06-12 10:54:44 +02:00
Frédéric Péters 0b3be5b9b2 gdc: fix post demand endpoint to be a POST (#43963) 2020-06-12 10:54:44 +02:00
4 changed files with 22 additions and 7 deletions

View File

@ -214,7 +214,7 @@ class APIParticulier(BaseResource):
def v2_situation_familiale(self, request, code_postal, numero_allocataire, user=None):
if not code_postal.strip() or not numero_allocataire.strip():
raise APIError('missing code_postal or numero_allocataire', status_code=400)
return self.get('v2/situation-familiale', params={
return self.get('v2/composition-familiale', params={
'codePostal': code_postal,
'numeroAllocataire': numero_allocataire,
}, user=user)

View File

@ -62,27 +62,42 @@ class Gdc(BaseResource):
verbose_name = _('GDC Web Service')
def call_soap(self, action, *args, **kwargs):
def escape(s):
return force_text(s).replace('&', '&amp;').replace('>', '&gt;').replace('<', '&lt;')
params = []
for i, arg in enumerate(args):
params.append('<v%(i)s xsi:type="xsd:string">%(value)s</v%(i)s>' % {'i': i + 1, 'value': arg})
params.append('<v%(i)s xsi:type="xsd:string">%(value)s</v%(i)s>' % {
'i': i + 1, 'value': escape(arg)})
for key, value in kwargs.items():
if value is None:
params.append('<%s xsi:null="1"/>' % key)
continue
type_ = 'int' if isinstance(value, int) else 'string'
params.append('<%(key)s xsi:type="xsd:%(type)s">%(value)s</%(key)s>' % {
'key': key, 'type': type_, 'value': value})
'key': key, 'type': type_, 'value': escape(value)})
data = """<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/1999/XMLSchema"
>
<SOAP-ENV:Body>
<%(action)s SOAP-ENC:root="1">
%(params)s
</%(action)s>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>""" % {'action': action, 'params': ''.join(params)}
resp = self.requests.post(self.service_url, data=data)
</SOAP-ENV:Envelope>""" % {'action': action, 'params': '\n'.join(params)}
resp = self.requests.post(
self.service_url,
data=data.encode('utf-8'),
headers={'SOAPAction': '"%s"' % action,
'Content-type': 'text/xml; charset=UTF-8'})
return ET.ElementTree(ET.fromstring(resp.content))
@endpoint()

View File

@ -120,7 +120,7 @@ class PostDemandeView(View, SingleObjectMixin):
model = Gdc
@utils.protected_api('can_post_request')
def get(self, request, *args, **kwargs):
def post(self, request, *args, **kwargs):
# <wsdl:message name='addDemandeExterneParticulierRequest'>
# <wsdl:part name='nom' type='xsd:string'></wsdl:part>
# <wsdl:part name='prenom' type='xsd:string'></wsdl:part>

View File

@ -97,7 +97,7 @@ def api_particulier_v2_avis_imposition(url, request):
return response(200, SVAIR_RESPONSE, request=request)
@urlmatch(netloc=r'^particulier.*\.api\.gouv\.fr$',
path=r'^/api/v2/situation-familiale$')
path=r'^/api/v2/composition-familiale$')
def api_particulier_v2_situation_familiale(url, request):
return response(200, CAF_FAMILLE, request=request)