0003-iparapheur-resolv-no-basic_authentication-on-w3.org-.patch
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 specific hosts, |
|
296 |
when loading wsdl files and dependencies |
|
297 |
""" |
|
298 |
def _load_remote_data(self, url): |
|
299 |
if urlparse(url).hostname == 'www.w3.org' : |
|
300 |
response = self.session.get(url, timeout=self.load_timeout, auth=None, cert=None) |
|
301 |
else: |
|
302 |
response = self.session.get(url, timeout=self.load_timeout) |
|
303 |
response.raise_for_status() |
|
304 |
return response.content |
|
305 | ||
306 | ||
291 | 307 |
class SOAPClient(Client): |
292 | 308 |
"""Wrapper around zeep.Client |
293 | 309 | |
294 | 310 |
resource muste have a wsdl_url and a requests attribute |
295 | 311 |
""" |
296 | 312 |
def __init__(self, resource, **kwargs): |
297 |
transport = Transport(session=resource.requests, cache=InMemoryCache()) |
|
313 |
transport = SOAPTransport(session=resource.requests, cache=InMemoryCache())
|
|
298 | 314 |
wsdl_url = kwargs.pop('wsdl_url', None) or resource.wsdl_url |
299 | 315 |
super(SOAPClient, self).__init__(wsdl_url, transport=transport, **kwargs) |
300 | 316 |
tests/test_iparapheur.py | ||
---|---|---|
376 | 376 |
'connector': 'iparapheur', 'endpoint': 'get-file-status', 'rest': file_id}) |
377 | 377 |
url += '?apikey=%s' % API_KEY |
378 | 378 | |
379 |
webfault_response = """ |
|
380 |
<?xml version='1.0' encoding='UTF-8'?> |
|
379 |
webfault_response = """<?xml version='1.0' encoding='UTF-8'?> |
|
381 | 380 |
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema"> |
382 | 381 |
<SOAP-ENV:Body> |
383 | 382 |
<SOAP-ENV:Fault> |
... | ... | |
394 | 393 |
resp = app.get(url) |
395 | 394 |
assert resp.json['err'] == 1 |
396 | 395 |
assert 'passerelle.utils.jsonresponse.APIError' in resp.json['err_class'] |
397 |
assert 'Transport Error: Server returned HTTP status 200' in resp.json['err_desc'] |
|
396 |
assert 'ServiceError:' in resp.json['err_desc'] |
|
397 |
assert 'Test server error' in resp.json['err_desc'] |
|
398 | 398 | |
399 | 399 |
def test_get_magic_mime(tmpdir): |
400 | 400 |
from PIL import Image |
401 |
- |