aboutsummaryrefslogtreecommitdiff
path: root/dummyserver
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2015-12-22 14:09:50 +0000
committerChristopher Baines <mail@cbaines.net>2015-12-22 14:09:50 +0000
commitdff63335f212d32d7c1a4bb5276f2d31f5995ea1 (patch)
tree4b32f426e18fec38cbfa9468d0dfc0cbf2279363 /dummyserver
parent2b3d330a120a16e97cecd5163b5d454dcfe38a2b (diff)
downloadpython-urllib3-dff63335f212d32d7c1a4bb5276f2d31f5995ea1.tar
python-urllib3-dff63335f212d32d7c1a4bb5276f2d31f5995ea1.tar.gz
Import python-urllib3_1.13.1.orig.tar.gzupstream/1.13.1upstream
Diffstat (limited to 'dummyserver')
-rw-r--r--dummyserver/certs/server.ipv6addr.crt16
-rw-r--r--dummyserver/certs/server.ipv6addr.key27
-rw-r--r--dummyserver/handlers.py11
-rwxr-xr-xdummyserver/proxy.py9
-rwxr-xr-xdummyserver/server.py6
-rw-r--r--dummyserver/testcase.py19
6 files changed, 75 insertions, 13 deletions
diff --git a/dummyserver/certs/server.ipv6addr.crt b/dummyserver/certs/server.ipv6addr.crt
new file mode 100644
index 0000000..c32a0ce
--- /dev/null
+++ b/dummyserver/certs/server.ipv6addr.crt
@@ -0,0 +1,16 @@
+-----BEGIN CERTIFICATE-----
+MIIClTCCAX2gAwIBAgIBATANBgkqhkiG9w0BAQsFADAOMQwwCgYDVQQDDAM6OjEw
+HhcNMTUxMjE1MTY0NjQxWhcNMjEwODAyMDAwMDAwWjAOMQwwCgYDVQQDDAM6OjEw
+ggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCvFke8g6Pco24cdWuOD8Wb
+blIUH6iieNpJqcdNTzKUgtWvlpDeiIOweTuawUWX7bz35fn2KBMty68tmz+64iWJ
+AKe6tJtbXQHty+Y09CPDkkC8f0cmXjqwnNbMT7kVPTaPQZkW7hnGS4XgpnzswpqP
+dMLpUzYwoucaScC/flawLafP3jq6hfae2F5wafwPIVvlURL7ZR7FZPuLW2L4T1Wu
+BHc6gOPQfohjQtiiTNtcEIhsmA3zY4DWuMUJePrEtXhPqcXtogoEiwzLKBeKOYJu
+LIQ3++nWLel+HPvhg52wT4Dhb45PQy55ziyelXiHSro5PQmXTiQebuPMLy/8CiSn
+AgMBAAEwDQYJKoZIhvcNAQELBQADggEBAILPtFVSOrXiXQ3b8Gslh4TOxxTPSdnO
+AkOooYyg5oLJy+CAnDL+u+mFCDFC2maDPm3qyeAn31h5aDyazCzyDvVFVw2uWSuG
+a67YNbCLrVBLVIgqyJfMayY3rcjz6rV4n7hpHn42zuwaI8H1z2T1bjvNU6nsizNK
+qo80nvJ6Kge2kbAa0aMOIHsGX4KGiUwUb4+LpRAP5ZDC8EnDNNfURt1w94nnAH70
+V1RgztaAlVNcPqrSMBLXryNXz+X+Hyd79Nd5runemYUG4fQ50jabC5WHeXqH0uOC
+sDtBgqWHxcxnAQhhJ8jF7wodcUjv5AE204ECmZgyQ475kuZpSh6+IvQ=
+-----END CERTIFICATE-----
diff --git a/dummyserver/certs/server.ipv6addr.key b/dummyserver/certs/server.ipv6addr.key
new file mode 100644
index 0000000..0891327
--- /dev/null
+++ b/dummyserver/certs/server.ipv6addr.key
@@ -0,0 +1,27 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIIEpAIBAAKCAQEArxZHvIOj3KNuHHVrjg/Fm25SFB+oonjaSanHTU8ylILVr5aQ
+3oiDsHk7msFFl+289+X59igTLcuvLZs/uuIliQCnurSbW10B7cvmNPQjw5JAvH9H
+Jl46sJzWzE+5FT02j0GZFu4ZxkuF4KZ87MKaj3TC6VM2MKLnGknAv35WsC2nz946
+uoX2nthecGn8DyFb5VES+2UexWT7i1ti+E9VrgR3OoDj0H6IY0LYokzbXBCIbJgN
+82OA1rjFCXj6xLV4T6nF7aIKBIsMyygXijmCbiyEN/vp1i3pfhz74YOdsE+A4W+O
+T0Muec4snpV4h0q6OT0Jl04kHm7jzC8v/AokpwIDAQABAoIBAB5Av0x3goz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BgQCurY35+4jdMOtMuAHquAEtzpf5zbO8p9Bj5qet8N+QXuGTXwaGXlkT
+S6i2iXjboNIWfPhqna+BMAmw+NP4TYiNgWoiRd27SDY8LcPXJee8c0+iWKsJkdl8
+90guxzVXSZg478by9ob83Zod2xBhzUSXYGuQrOrItiuiSnMMhHgtrw==
+-----END RSA PRIVATE KEY-----
diff --git a/dummyserver/handlers.py b/dummyserver/handlers.py
index 43398cd..fb6f44f 100644
--- a/dummyserver/handlers.py
+++ b/dummyserver/handlers.py
@@ -28,8 +28,8 @@ class Response(object):
def __call__(self, request_handler):
status, reason = self.status.split(' ', 1)
request_handler.set_status(int(status), reason)
- for header,value in self.headers:
- request_handler.add_header(header,value)
+ for header, value in self.headers:
+ request_handler.add_header(header, value)
# chunked
if isinstance(self.body, list):
@@ -48,6 +48,7 @@ class Response(object):
RETRY_TEST_NAMES = collections.defaultdict(int)
+
class TestingApp(RequestHandler):
"""
Simple app that performs various operations, useful for testing an HTTP
@@ -136,8 +137,8 @@ class TestingApp(RequestHandler):
files_ = request.files.get(param)
if len(files_) != 1:
- return Response("Expected 1 file for '%s', not %d" %(param, len(files_)),
- status='400 Bad Request')
+ return Response("Expected 1 file for '%s', not %d" % (param, len(files_)),
+ status='400 Bad Request')
file_ = files_[0]
data = file_['body']
@@ -277,7 +278,7 @@ def _parse_header(line):
value = p[i + 1:].strip()
params.append((name, value))
params = email.utils.decode_params(params)
- params.pop(0) # get rid of the dummy again
+ params.pop(0) # get rid of the dummy again
pdict = {}
for name, value in params:
value = email.utils.collapse_rfc2231_value(value)
diff --git a/dummyserver/proxy.py b/dummyserver/proxy.py
index aca92a7..5b9984d 100755
--- a/dummyserver/proxy.py
+++ b/dummyserver/proxy.py
@@ -45,14 +45,14 @@ class ProxyHandler(tornado.web.RequestHandler):
def handle_response(response):
if response.error and not isinstance(response.error,
- tornado.httpclient.HTTPError):
+ tornado.httpclient.HTTPError):
self.set_status(500)
self.write('Internal server error:\n' + str(response.error))
self.finish()
else:
self.set_status(response.code)
for header in ('Date', 'Cache-Control', 'Server',
- 'Content-Type', 'Location'):
+ 'Content-Type', 'Location'):
v = response.headers.get(header)
if v:
self.set_header(header, v)
@@ -60,7 +60,8 @@ class ProxyHandler(tornado.web.RequestHandler):
self.write(response.body)
self.finish()
- req = tornado.httpclient.HTTPRequest(url=self.request.uri,
+ req = tornado.httpclient.HTTPRequest(
+ url=self.request.uri,
method=self.request.method, body=self.request.body,
headers=self.request.headers, follow_redirects=False,
allow_nonstandard_methods=True)
@@ -133,5 +134,5 @@ if __name__ == '__main__':
if len(sys.argv) > 1:
port = int(sys.argv[1])
- print ("Starting HTTP proxy on port %d" % port)
+ print("Starting HTTP proxy on port %d" % port)
run_proxy(port)
diff --git a/dummyserver/server.py b/dummyserver/server.py
index e0b6345..ef053a7 100755
--- a/dummyserver/server.py
+++ b/dummyserver/server.py
@@ -34,10 +34,16 @@ NO_SAN_CERTS = {
'certfile': os.path.join(CERTS_PATH, 'server.no_san.crt'),
'keyfile': DEFAULT_CERTS['keyfile']
}
+IPV6_ADDR_CERTS = {
+ 'certfile': os.path.join(CERTS_PATH, 'server.ipv6addr.crt'),
+ 'keyfile': os.path.join(CERTS_PATH, 'server.ipv6addr.key'),
+}
DEFAULT_CA = os.path.join(CERTS_PATH, 'cacert.pem')
DEFAULT_CA_BAD = os.path.join(CERTS_PATH, 'client_bad.pem')
NO_SAN_CA = os.path.join(CERTS_PATH, 'cacert.no_san.pem')
DEFAULT_CA_DIR = os.path.join(CERTS_PATH, 'ca_path_test')
+IPV6_ADDR_CA = os.path.join(CERTS_PATH, 'server.ipv6addr.crt')
+
def _has_ipv6(host):
""" Returns True if the system can bind an IPv6 address. """
diff --git a/dummyserver/testcase.py b/dummyserver/testcase.py
index e5ae51b..f5588a0 100644
--- a/dummyserver/testcase.py
+++ b/dummyserver/testcase.py
@@ -42,10 +42,10 @@ class SocketDummyServerTestCase(unittest.TestCase):
@classmethod
def start_response_handler(cls, response, num=1, block_send=None):
ready_event = threading.Event()
+
def socket_handler(listener):
for _ in range(num):
ready_event.set()
- ready_event.clear()
sock = listener.accept()[0]
consume_socket(sock)
@@ -61,9 +61,9 @@ class SocketDummyServerTestCase(unittest.TestCase):
@classmethod
def start_basic_handler(cls, **kw):
return cls.start_response_handler(
- b'HTTP/1.1 200 OK\r\n'
- b'Content-Length: 0\r\n'
- b'\r\n', **kw)
+ b'HTTP/1.1 200 OK\r\n'
+ b'Content-Length: 0\r\n'
+ b'\r\n', **kw)
@classmethod
def tearDownClass(cls):
@@ -113,6 +113,17 @@ class HTTPSDummyServerTestCase(HTTPDummyServerTestCase):
certs = DEFAULT_CERTS
+class IPV6HTTPSDummyServerTestCase(HTTPSDummyServerTestCase):
+ host = '::1'
+
+ @classmethod
+ def setUpClass(cls):
+ if not socket.has_ipv6:
+ raise SkipTest('IPv6 not available')
+ else:
+ super(IPV6HTTPSDummyServerTestCase, cls).setUpClass()
+
+
class HTTPDummyProxyTestCase(unittest.TestCase):
http_host = 'localhost'