add fc requests proxies support (#24713)
This commit is contained in:
parent
0a8628ae54
commit
deebd83a60
|
@ -108,6 +108,10 @@ class AppSettings(object):
|
|||
def scopes(self):
|
||||
return self._setting('SCOPES', [])
|
||||
|
||||
@property
|
||||
def requests_proxies(self):
|
||||
return self._setting('REQUESTS_PROXIES', {})
|
||||
|
||||
|
||||
import sys
|
||||
|
||||
|
|
|
@ -182,4 +182,6 @@ def requests_retry_session(
|
|||
adapter = HTTPAdapter(max_retries=retry)
|
||||
session.mount('http://', adapter)
|
||||
session.mount('https://', adapter)
|
||||
# set proxies
|
||||
session.proxies.update(app_settings.requests_proxies)
|
||||
return session
|
||||
|
|
|
@ -2,11 +2,14 @@
|
|||
import pytest
|
||||
import urlparse
|
||||
import httmock
|
||||
import mock
|
||||
import json
|
||||
import base64
|
||||
from jwcrypto import jwk, jwt
|
||||
import datetime
|
||||
|
||||
import requests
|
||||
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.utils.timezone import now
|
||||
|
@ -14,6 +17,7 @@ from django.utils.timezone import now
|
|||
from authentic2.utils import timestamp_from_datetime
|
||||
|
||||
from authentic2_auth_fc import models
|
||||
from authentic2_auth_fc.utils import requests_retry_session
|
||||
|
||||
|
||||
User = get_user_model()
|
||||
|
@ -214,3 +218,21 @@ def test_login_email_is_unique_and_already_linked(app, fc_settings, caplog):
|
|||
assert 'is already used' in str(response)
|
||||
assert User.objects.count() == 1
|
||||
assert '_auth_user_id' not in app.session
|
||||
|
||||
|
||||
def test_requests_proxies_support(app, fc_settings, caplog):
|
||||
session = requests_retry_session()
|
||||
assert session.proxies == {}
|
||||
other_session = requests.Session()
|
||||
other_session.proxies = {'http': 'http://example.net'}
|
||||
session = requests_retry_session(session=other_session)
|
||||
assert session is other_session
|
||||
assert session.proxies == {'http': 'http://example.net'}
|
||||
fc_settings.A2_FC_REQUESTS_PROXIES = {'https': 'http://pubproxy.com/api/proxy'}
|
||||
session = requests_retry_session()
|
||||
assert session.proxies == {'https': 'http://pubproxy.com/api/proxy'}
|
||||
|
||||
with mock.patch('authentic2_auth_fc.utils.requests.Session.send') as mocked_send:
|
||||
mocked_send.return_value = mock.Mock(status_code=200, content='whatever')
|
||||
session.get('https://example.net/')
|
||||
assert mocked_send.call_args[1]['proxies'] == {'https': 'http://pubproxy.com/api/proxy'}
|
||||
|
|
Reference in New Issue