mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-15 00:03:28 +01:00
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
This commit is contained in:
parent
01e8718640
commit
bfaad224fa
@ -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()
|
||||
|
@ -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
|
||||
|
74
tests/test_proxy_https.py
Normal file
74
tests/test_proxy_https.py
Normal file
@ -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()
|
Loading…
x
Reference in New Issue
Block a user