mirror of
https://github.com/internetarchive/warcprox.git
synced 2025-01-18 13:22:09 +01:00
really fix tests for python2
This commit is contained in:
parent
859c93f390
commit
1c7564ee6a
2
setup.py
2
setup.py
@ -51,7 +51,7 @@ except:
|
|||||||
|
|
||||||
setuptools.setup(
|
setuptools.setup(
|
||||||
name='warcprox',
|
name='warcprox',
|
||||||
version='2.1b1.dev48',
|
version='2.1b1.dev49',
|
||||||
description='WARC writing MITM HTTP/S proxy',
|
description='WARC writing MITM HTTP/S proxy',
|
||||||
url='https://github.com/internetarchive/warcprox',
|
url='https://github.com/internetarchive/warcprox',
|
||||||
author='Noah Levitt',
|
author='Noah Levitt',
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
'''
|
'''
|
||||||
tests/test_warcprox.py - automated tests for warcprox
|
tests/test_warcprox.py - automated tests for warcprox
|
||||||
|
|
||||||
Copyright (C) 2013-2016 Internet Archive
|
Copyright (C) 2013-2017 Internet Archive
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License
|
modify it under the terms of the GNU General Public License
|
||||||
@ -44,7 +44,6 @@ import traceback
|
|||||||
import signal
|
import signal
|
||||||
from collections import Counter
|
from collections import Counter
|
||||||
import socket
|
import socket
|
||||||
import urllib
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import http.server as http_server
|
import http.server as http_server
|
||||||
@ -60,22 +59,26 @@ import certauth.certauth
|
|||||||
|
|
||||||
import warcprox
|
import warcprox
|
||||||
|
|
||||||
|
try:
|
||||||
|
import http.client as http_client
|
||||||
|
except ImportError:
|
||||||
|
import httplib as http_client
|
||||||
|
orig_send = http_client.HTTPConnection.send
|
||||||
|
def _send(self, data):
|
||||||
|
if isinstance(data, bytes) and hasattr(
|
||||||
|
logging.root.handlers[0].stream, 'buffer'):
|
||||||
|
logging.info('sending data (bytes): ')
|
||||||
|
logging.root.handlers[0].stream.buffer.write(data)
|
||||||
|
logging.root.handlers[0].stream.buffer.write(b'\n')
|
||||||
|
elif isinstance(data, str):
|
||||||
|
logging.info('sending data (str): ')
|
||||||
|
logging.root.handlers[0].stream.write(data)
|
||||||
|
logging.root.handlers[0].stream.write('\n')
|
||||||
|
else:
|
||||||
|
logging.info('sending data from %s', repr(data))
|
||||||
|
orig_send(self, data)
|
||||||
### uncomment this to block see raw requests going over the wire
|
### uncomment this to block see raw requests going over the wire
|
||||||
# import http.client
|
# http_client.HTTPConnection.send = _send
|
||||||
# orig_send = http.client.HTTPConnection.send
|
|
||||||
# def _send(self, data):
|
|
||||||
# if isinstance(data, bytes):
|
|
||||||
# logging.info('sending data (bytes): ')
|
|
||||||
# logging.root.handlers[0].stream.buffer.write(data)
|
|
||||||
# logging.root.handlers[0].stream.buffer.write(b'\n')
|
|
||||||
# elif isinstance(data, str):
|
|
||||||
# logging.info('sending data (str): ')
|
|
||||||
# logging.root.handlers[0].stream.write(data)
|
|
||||||
# logging.root.handlers[0].stream.write('\n')
|
|
||||||
# else:
|
|
||||||
# logging.info('sending data from %s', repr(data))
|
|
||||||
# orig_send(self, data)
|
|
||||||
# http.client.HTTPConnection.send = _send
|
|
||||||
|
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
stream=sys.stdout, level=logging.INFO, # level=warcprox.TRACE,
|
stream=sys.stdout, level=logging.INFO, # level=warcprox.TRACE,
|
||||||
@ -1171,8 +1174,7 @@ def test_missing_content_length(archiving_proxies, http_daemon, https_daemon):
|
|||||||
assert not 'content-length' in response.headers
|
assert not 'content-length' in response.headers
|
||||||
|
|
||||||
def test_method_filter(
|
def test_method_filter(
|
||||||
https_daemon, http_daemon, archiving_proxies, playback_proxies,
|
https_daemon, http_daemon, archiving_proxies, playback_proxies):
|
||||||
warcprox_):
|
|
||||||
# we've configured warcprox with method_filters=['GET','POST'] so HEAD
|
# we've configured warcprox with method_filters=['GET','POST'] so HEAD
|
||||||
# requests should not be archived
|
# requests should not be archived
|
||||||
|
|
||||||
@ -1188,23 +1190,17 @@ def test_method_filter(
|
|||||||
assert response.content == b'404 Not in Archive\n'
|
assert response.content == b'404 Not in Archive\n'
|
||||||
|
|
||||||
# WARCPROX_WRITE_RECORD is exempt from method filter
|
# WARCPROX_WRITE_RECORD is exempt from method filter
|
||||||
|
url = 'http://fakeurl/'
|
||||||
|
payload = b'I am the WARCPROX_WRITE_RECORD payload'
|
||||||
headers = {
|
headers = {
|
||||||
'Content-Type': 'text/plain',
|
'Content-Type': 'text/plain',
|
||||||
'WARC-Type': 'metadata',
|
'WARC-Type': 'metadata',
|
||||||
'Host': 'N/A'
|
'Host': 'N/A'
|
||||||
}
|
}
|
||||||
url = 'http://fakeurl/'
|
response = requests.request(
|
||||||
payload = b'I am the WARCPROX_WRITE_RECORD payload'
|
method='WARCPROX_WRITE_RECORD', url=url, data=payload,
|
||||||
request = urllib.request.Request(
|
headers=headers, proxies=archiving_proxies)
|
||||||
url, method="WARCPROX_WRITE_RECORD", headers=headers, data=payload)
|
assert response.status_code == 204
|
||||||
|
|
||||||
# XXX setting request.type="http" is a hack to stop urllib from trying
|
|
||||||
# to tunnel if url is https
|
|
||||||
request.type = 'http'
|
|
||||||
request.set_proxy('localhost:%s' % warcprox_.proxy.server_port, 'http')
|
|
||||||
|
|
||||||
with urllib.request.urlopen(request) as response:
|
|
||||||
assert response.getcode() == 204
|
|
||||||
|
|
||||||
response = _poll_playback_until(
|
response = _poll_playback_until(
|
||||||
playback_proxies, url, status=200, timeout_sec=10)
|
playback_proxies, url, status=200, timeout_sec=10)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user