mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-15 00:03:28 +01:00
* https over socks fix: fix issue with https url handling by using 'adapter.proxy_manager_for()' instead of 'adapter.get_connection' to get proxy manager, which create connection indirectly (parallel to no-proxy path). - simplify socks config, avoiding global monkey-patch, as requests/urllib3 now support socks proxy directly and do not require patching global socket. - add SOCKS_DISABLE env dynamically disabling socks proxy
36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
from .base_config_test import BaseConfigTest, fmod_sl
|
|
|
|
import os
|
|
import pytest
|
|
|
|
|
|
# ============================================================================
|
|
class TestSOCKSProxy(BaseConfigTest):
|
|
@classmethod
|
|
def setup_class(cls):
|
|
pytest.importorskip('socks')
|
|
os.environ['SOCKS_HOST'] = 'localhost'
|
|
os.environ['SOCKS_PORT'] = '0'
|
|
|
|
super(TestSOCKSProxy, cls).setup_class('config_test.yaml')
|
|
|
|
@classmethod
|
|
def teardown_class(cls):
|
|
super(TestSOCKSProxy, cls).teardown_class()
|
|
|
|
def test_socks_attempt_connect(self, fmod_sl):
|
|
# no proxy is set, expect to fail if socks is being used
|
|
resp = self.get('/live/{0}http://httpbin.org/get', fmod_sl, status=400)
|
|
assert resp.status_int == 400
|
|
|
|
def test_socks_disable_enable(self, fmod_sl):
|
|
os.environ['SOCKS_DISABLE'] = '1'
|
|
|
|
resp = self.get('/live/{0}http://httpbin.org/get', fmod_sl, status=200)
|
|
assert resp.status_int == 200
|
|
|
|
os.environ['SOCKS_DISABLE'] = ''
|
|
|
|
resp = self.get('/live/{0}http://httpbin.org/get', fmod_sl, status=400)
|
|
assert resp.status_int == 400
|