diff --git a/pywb/framework/proxy.py b/pywb/framework/proxy.py index 61a9a2d3..1264eaef 100644 --- a/pywb/framework/proxy.py +++ b/pywb/framework/proxy.py @@ -103,7 +103,7 @@ class ProxyRouter(object): # attempt to create the root_ca_file if doesn't exist # (generally recommended to create this seperately) certname = proxy_options.get('root_ca_name') - CertificateAuthority.generate_ca_root(certname, ca_file) + CertificateAuthority.generate_ca_root(ca_file, certname) certs_dir = proxy_options.get('certs_dir') self.ca = CertificateAuthority(ca_file=ca_file, @@ -216,7 +216,7 @@ class ProxyRouter(object): sock = None - if env.get('uwsgi.version'): + if env.get('uwsgi.version'): # pragma: no cover try: import uwsgi fd = uwsgi.connection_fd() diff --git a/tests/test_config_proxy.yaml b/tests/test_config_proxy.yaml index 0f3f2c88..c5e39dd1 100644 --- a/tests/test_config_proxy.yaml +++ b/tests/test_config_proxy.yaml @@ -19,3 +19,7 @@ proxy_options: cookie_resolver: true use_default_coll: false + + root_ca_file: ./tests/pywb_test_ca.pem + root_ca_name: pywb Test Cert + certs_dir: ./tests/pywb_test_certs diff --git a/tests/test_proxy_https.py b/tests/test_proxy_https.py new file mode 100644 index 00000000..80e9a833 --- /dev/null +++ b/tests/test_proxy_https.py @@ -0,0 +1,74 @@ +from pywb.webapp.pywb_init import create_wb_router +from pywb.framework.wsgi_wrappers import init_app + +from wsgiref.simple_server import make_server + +import threading +import requests +import shutil +import os + +TEST_CONFIG = 'tests/test_config_proxy.yaml' +CA_BUNDLE = 'pywb-ca.pem' + +TEST_CA_DIR = './tests/pywb_test_certs' +TEST_CA_ROOT = './tests/pywb_test_ca.pem' + +server = None +proxy_str = None + +def setup_module(): + global server + server = ServeThread() + server.daemon = True + server.start() + + +def teardown_module(): + try: + server.httpd.shutdown() + threading.current_thread().join(server) + except Exception: + pass + + # delete test root and certs + shutil.rmtree(TEST_CA_DIR) + os.remove(TEST_CA_ROOT) + + +class ServeThread(threading.Thread): + def __init__(self, *args, **kwargs): + super(ServeThread, self).__init__(*args, **kwargs) + self.app = init_app(create_wb_router, + load_yaml=True, + config_file=TEST_CONFIG) + + # init with port 0 to allow os to pick a port + self.httpd = make_server('', 0, self.app) + port = self.httpd.socket.getsockname()[1] + + proxy_str = 'http://localhost:' + str(port) + self.proxy_dict = {'http': proxy_str, 'https': proxy_str} + + def run(self, *args, **kwargs): + self.httpd.serve_forever() + + +def test_replay(): + resp = requests.get('https://iana.org/', + proxies=server.proxy_dict, + verify=False) +# verify=CA_BUNDLE) + assert resp.status_code == 200 + + +def test_replay_static(): + resp = requests.get('https://pywb.proxy/static/default/wb.js', + proxies=server.proxy_dict, + headers={'Connection': 'close'}, + verify=False) +# verify=CA_BUNDLE) + assert resp.status_code == 200 + found = u'function init_banner' in resp.text + assert found, resp.text + resp.close()