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

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
from pywb.framework.proxy_resolvers import CookieResolver
import threading
import requests
import shutil
import os
TEST_CONFIG = 'tests/test_config_proxy.yaml'
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():
#cookie_val = CookieResolver.SESH_COOKIE_NAME + '=
resp = requests.get('https://iana.org/',
proxies=server.proxy_dict,
# headers={'Cookie': cookie_val},
verify=TEST_CA_ROOT)
assert resp.status_code == 200
def test_replay_static():
resp = requests.get('https://pywb.proxy/static/default/wb.js',
proxies=server.proxy_dict,
verify=TEST_CA_ROOT)
assert resp.status_code == 200
found = u'function init_banner' in resp.text
assert found, resp.text
resp.close()