mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-15 00:03:28 +01:00
openssl: make openssl install optional, remove from dependency
https proxy support contingest on openssl installation if not installed and https use is enabled, a warning is printed tests: updated tests to skip if openssl not installed (make https post to only run in 2.7, as there are issues with in 2.6)
This commit is contained in:
parent
c7228bf887
commit
f82afbc977
@ -6,6 +6,7 @@ python:
|
||||
|
||||
install:
|
||||
- "pip install 'argparse>=1.2.1' --allow-all-external"
|
||||
- pip install pyopenssl
|
||||
- python setup.py -q install
|
||||
- pip install coverage pytest-cov coveralls --use-mirrors
|
||||
|
||||
|
@ -1,7 +1,13 @@
|
||||
import logging
|
||||
import os
|
||||
openssl_avail = False
|
||||
try:
|
||||
from OpenSSL import crypto
|
||||
from OpenSSL.SSL import FILETYPE_PEM
|
||||
openssl_avail = True
|
||||
except ImportError: # pragma: no cover
|
||||
pass
|
||||
|
||||
import random
|
||||
from argparse import ArgumentParser
|
||||
|
||||
|
@ -12,7 +12,7 @@ from pywb.utils.wbexception import BadRequestException
|
||||
|
||||
from pywb.utils.bufferedreaders import BufferedReader
|
||||
|
||||
from certauth import CertificateAuthority
|
||||
from certauth import CertificateAuthority, openssl_avail
|
||||
|
||||
from proxy_resolvers import ProxyAuthResolver, CookieResolver
|
||||
|
||||
@ -91,6 +91,13 @@ class ProxyRouter(object):
|
||||
self.proxy_cert_dl_view = None
|
||||
return
|
||||
|
||||
if not openssl_avail: # pragma: no coverage
|
||||
print('HTTPS proxy not available as pyopenssl is not installed')
|
||||
print('Please install via "pip install pyopenssl" to enable HTTPS support')
|
||||
self.ca = None
|
||||
self.proxy_cert_dl_view = None
|
||||
return
|
||||
|
||||
# HTTPS Only Options
|
||||
ca_file = proxy_options.get('root_ca_file')
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
import pytest
|
||||
|
||||
import os
|
||||
import shutil
|
||||
|
||||
@ -6,6 +8,10 @@ from pywb.framework.certauth import main, CertificateAuthority
|
||||
TEST_CA_DIR = './pywb/framework/test/pywb_test_ca_certs'
|
||||
TEST_CA_ROOT = './pywb/framework/test/pywb_test_ca.pem'
|
||||
|
||||
def setup_module():
|
||||
openssl_support = pytest.importorskip("OpenSSL")
|
||||
pass
|
||||
|
||||
def test_create_root():
|
||||
ret = main([TEST_CA_ROOT, '-n', 'Test Root Cert'])
|
||||
assert ret == 0
|
||||
|
1
setup.py
1
setup.py
@ -70,7 +70,6 @@ setup(
|
||||
'jinja2',
|
||||
'surt',
|
||||
'pyyaml',
|
||||
'pyopenssl',
|
||||
],
|
||||
tests_require=[
|
||||
'pytest',
|
||||
|
@ -1,3 +1,5 @@
|
||||
import pytest
|
||||
|
||||
from pywb.webapp.pywb_init import create_wb_router
|
||||
from pywb.framework.wsgi_wrappers import init_app
|
||||
|
||||
@ -8,8 +10,10 @@ from pywb.framework.proxy_resolvers import CookieResolver
|
||||
import threading
|
||||
import requests
|
||||
import shutil
|
||||
import sys
|
||||
import os
|
||||
|
||||
|
||||
TEST_CONFIG = 'tests/test_config_proxy.yaml'
|
||||
|
||||
TEST_CA_DIR = './tests/pywb_test_certs'
|
||||
@ -19,6 +23,8 @@ server = None
|
||||
sesh_key = None
|
||||
|
||||
def setup_module():
|
||||
openssl_support = pytest.importorskip("OpenSSL")
|
||||
|
||||
global server
|
||||
server = ServeThread()
|
||||
server.daemon = True
|
||||
@ -67,7 +73,6 @@ class TestHttpsProxy:
|
||||
if sesh_key:
|
||||
self.session.headers.update({'Cookie': '__pywb_proxy_sesh=' + sesh_key})
|
||||
self.session.cookies.set('__pywb_proxy_sesh', sesh_key, domain='.pywb.proxy')
|
||||
#self.session.cookies.set('__pywb_proxy_sesh', sesh_key, domain='.iana.org')
|
||||
|
||||
return self.session.get(url,
|
||||
proxies=server.proxy_dict,
|
||||
@ -78,7 +83,6 @@ class TestHttpsProxy:
|
||||
if sesh_key:
|
||||
self.session.headers.update({'Cookie': '__pywb_proxy_sesh=' + sesh_key})
|
||||
self.session.cookies.set('__pywb_proxy_sesh', sesh_key, domain='.pywb.proxy')
|
||||
#self.session.cookies.set('__pywb_proxy_sesh', sesh_key, domain='.iana.org')
|
||||
|
||||
return self.session.post(url,
|
||||
data=data,
|
||||
@ -160,15 +164,14 @@ class TestHttpsProxy:
|
||||
assert resp.url == 'https://example.com/'
|
||||
assert '20140127171251' in resp.text
|
||||
|
||||
@pytest.mark.skipif(sys.version_info < (2,7),
|
||||
reason="doesn't work in 2.6")
|
||||
def test_post_replay_all_coll(self):
|
||||
resp = self.post_url('https://httpbin.org/post', data={'foo': 'bar', 'test': 'abc'})
|
||||
assert resp.url == 'https://httpbin.org/post'
|
||||
assert 'application/json' in resp.headers['content-type']
|
||||
assert resp.status_code == 200
|
||||
|
||||
#assert 'wbinfo.proxy_magic = "pywb.proxy";' in resp.text
|
||||
#assert '20140126200624' in resp.text
|
||||
|
||||
# Bounce back to select.pywb.proxy due to missing session
|
||||
def test_clear_key(self):
|
||||
# clear session key
|
||||
|
Loading…
x
Reference in New Issue
Block a user