diff --git a/authserv/test/test_integration.py b/authserv/test/test_integration.py index 5b4290ebb7291905e363e8e6da5dbff13999bf43..9104858c3d605f80947b87b488e79a4d7a20fe90 100644 --- a/authserv/test/test_integration.py +++ b/authserv/test/test_integration.py @@ -3,6 +3,7 @@ from gevent import subprocess import httplib import os import socket +import ssl import sys import time import urllib @@ -22,8 +23,10 @@ def _relpath(x): class HTTPSClientAuthHandler(urllib2.HTTPSHandler): - def __init__(self, cert, key): - urllib2.HTTPSHandler.__init__(self) + def __init__(self, cert, key, cafile): + urllib2.HTTPSHandler.__init__(self, context=ssl.create_default_context( + purpose=ssl.Purpose.SERVER_AUTH, + cafile=cafile)) self.key = key self.cert = cert @@ -34,7 +37,8 @@ class HTTPSClientAuthHandler(urllib2.HTTPSHandler): return self.do_open(self.getConnection, req) def getConnection(self, host, timeout=300): - return httplib.HTTPSConnection(host, key_file=self.key, cert_file=self.cert) + return httplib.HTTPSConnection(host, key_file=self.key, cert_file=self.cert, + context=self._context) class SSLServerTest(unittest.TestCase): @@ -67,14 +71,14 @@ class SSLServerTest(unittest.TestCase): print >>sys.stderr, 'starting HTTP server on port', cls.port server.run( - app, '127.0.0.1', cls.port, cls.ssl_ca, + app, 'localhost', cls.port, cls.ssl_ca, cls.ssl_cert, cls.ssl_key, cls.dhparams) gevent.spawn(_runserver) gevent.sleep(1) cls.opener = urllib2.build_opener( - HTTPSClientAuthHandler(cls.client_cert, cls.client_key)) + HTTPSClientAuthHandler(cls.client_cert, cls.client_key, cls.ssl_ca)) @classmethod def teardown_class(cls): @@ -82,7 +86,7 @@ class SSLServerTest(unittest.TestCase): os.kill(cls.pid, 15) def test_python_request_failure_without_cert(self): - req = urllib2.Request('https://127.0.0.1:%d%s' % (self.port, URL), + req = urllib2.Request('https://localhost:%d%s' % (self.port, URL), data=urllib.urlencode( {'username': 'user2', 'password': 'pass2', @@ -91,7 +95,7 @@ class SSLServerTest(unittest.TestCase): self.assertRaises(urllib2.URLError, urllib2.urlopen, req) def test_python_auth_simple_ok(self): - req = urllib2.Request('https://127.0.0.1:%d%s' % (self.port, URL), + req = urllib2.Request('https://localhost:%d%s' % (self.port, URL), data=urllib.urlencode( {'username': 'user2', 'password': 'pass2',