Projet

Général

Profil

0003-iparapheur-resolv-no-basic_authentication-on-w3.org-.patch

Nicolas Roche, 11 mars 2019 17:04

Télécharger (2,11 ko)

Voir les différences:

Subject: [PATCH 3/3] iparapheur: resolv no basic_authentication on w3.org
 (#31274)

 passerelle/utils/__init__.py | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
passerelle/utils/__init__.py
24 24
from requests import Session as RequestSession, Response as RequestResponse
25 25
from requests.structures import CaseInsensitiveDict
26 26
from urllib3.exceptions import InsecureRequestWarning
27
from urlparse import urlparse
27 28

  
28 29
from django.conf import settings
29 30
from django.core.cache import cache
......
288 289
        log_http_request(self.logger, request=request, response=response, exception=exception, error_log=error_log)
289 290

  
290 291

  
292
class SOAPTransport(Transport):
293
    """Wrapper around zeep.Transport
294

  
295
    disable basic_authentication on other hosts
296
    """
297
    def __init__(self, wsdl_url, **kwargs):
298
        self.wsdl_host = urlparse(wsdl_url).hostname
299
        super(SOAPTransport, self).__init__(**kwargs)
300

  
301
    def _load_remote_data(self, url):
302
        if urlparse(url).hostname != self.wsdl_host:
303
            response = self.session.get(url, timeout=self.load_timeout, auth=None, cert=None)
304
            response.raise_for_status()
305
            return response.content
306
        return super(SOAPTransport, self)._load_remote_data(url)
307

  
308

  
291 309
class SOAPClient(Client):
292 310
    """Wrapper around zeep.Client
293 311

  
294 312
    resource muste have a wsdl_url and a requests attribute
295 313
    """
296 314
    def __init__(self, resource, **kwargs):
297
        transport = Transport(session=resource.requests, cache=InMemoryCache())
298 315
        wsdl_url = kwargs.pop('wsdl_url', None) or resource.wsdl_url
316
        transport = SOAPTransport(wsdl_url, session=resource.requests, cache=InMemoryCache())
299 317
        super(SOAPClient, self).__init__(wsdl_url, transport=transport, **kwargs)
300 318

  
301 319

  
302
-