1
0
mirror of https://github.com/webrecorder/pywb.git synced 2025-03-23 22:52:25 +01:00
pywb/tests/test_proxy_https.py
Ilya Kreymer bfaad224fa proxy tests: add test for https proxy, using requests and wsgiref server!
testing one https replay and static https handling
fix bug in certauth params
2014-08-18 19:58:53 -07:00

75 lines
2.0 KiB
Python

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()