You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

217 lines
9.2 KiB

Pouze v M2Crypto-0.21.1: randpool.dat
diff -ur M2Crypto/tests/test_bio_ssl.py M2Crypto-0.21.1/tests/test_bio_ssl.py
--- M2Crypto/tests/test_bio_ssl.py 2011-01-15 20:10:05.000000000 +0100
+++ M2Crypto-0.21.1/tests/test_bio_ssl.py 2014-01-06 23:31:47.709383892 +0100
@@ -11,7 +11,7 @@
from M2Crypto import Rand
from M2Crypto import threading as m2threading
-from test_ssl import srv_host, srv_port
+from test_ssl import srv_host, allocate_srv_port
class HandshakeClient(threading.Thread):
@@ -113,6 +113,7 @@
conn.set_bio(readbio, writebio)
conn.set_accept_state()
handshake_complete = False
+ srv_port = allocate_srv_port()
sock = socket.socket()
sock.bind((srv_host, srv_port))
sock.listen(5)
diff -ur M2Crypto/tests/test_ssl.py M2Crypto-0.21.1/tests/test_ssl.py
--- M2Crypto/tests/test_ssl.py 2014-01-06 22:49:57.961307007 +0100
+++ M2Crypto-0.21.1/tests/test_ssl.py 2014-01-06 23:30:13.856457390 +0100
@@ -26,7 +26,16 @@
from fips import fips_mode
srv_host = 'localhost'
-srv_port = 64000
+
+def allocate_srv_port():
+ s = socket.socket()
+ try:
+ s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+ s.bind((srv_host, 0))
+ (host, port) = s.getsockname()
+ finally:
+ s.close()
+ return port
def verify_cb_new_function(ok, store):
try:
@@ -113,17 +122,13 @@
def setUp(self):
self.srv_host = srv_host
- self.srv_port = srv_port
- self.srv_addr = (srv_host, srv_port)
- self.srv_url = 'https://%s:%s/' % (srv_host, srv_port)
+ self.srv_port = allocate_srv_port()
+ self.srv_addr = (srv_host, self.srv_port)
+ self.srv_url = 'https://%s:%s/' % (srv_host, self.srv_port)
self.args = ['s_server', '-quiet', '-www',
#'-cert', 'server.pem', Implicitly using this
'-accept', str(self.srv_port)]
- def tearDown(self):
- global srv_port
- srv_port = srv_port - 1
-
class PassSSLClientTestCase(BaseSSLClientTestCase):
@@ -136,7 +141,7 @@
pid = self.start_server(self.args)
try:
from M2Crypto import httpslib
- c = httpslib.HTTPSConnection(srv_host, srv_port)
+ c = httpslib.HTTPSConnection(srv_host, self.srv_port)
c.request('GET', '/')
data = c.getresponse().read()
c.close()
@@ -153,7 +158,7 @@
ctx.load_cert('tests/x509.pem')
ctx.set_verify(SSL.verify_peer | SSL.verify_fail_if_no_peer_cert, 1)
ctx.set_session_cache_mode(m2.SSL_SESS_CACHE_CLIENT)
- c = httpslib.HTTPSConnection(srv_host, srv_port, ssl_context=ctx)
+ c = httpslib.HTTPSConnection(srv_host, self.srv_port, ssl_context=ctx)
c.request('GET', '/')
ses = c.get_session()
t = ses.as_text()
@@ -166,7 +171,7 @@
ctx2.load_cert('tests/x509.pem')
ctx2.set_verify(SSL.verify_peer | SSL.verify_fail_if_no_peer_cert, 1)
ctx2.set_session_cache_mode(m2.SSL_SESS_CACHE_CLIENT)
- c2 = httpslib.HTTPSConnection(srv_host, srv_port, ssl_context=ctx2)
+ c2 = httpslib.HTTPSConnection(srv_host, self.srv_port, ssl_context=ctx2)
c2.set_session(ses)
c2.request('GET', '/')
ses2 = c2.get_session()
@@ -186,7 +191,7 @@
ctx = SSL.Context()
ctx.set_verify(SSL.verify_peer | SSL.verify_fail_if_no_peer_cert, 9)
ctx.load_verify_locations('tests/ca.pem')
- c = httpslib.HTTPSConnection(srv_host, srv_port, ssl_context=ctx)
+ c = httpslib.HTTPSConnection(srv_host, self.srv_port, ssl_context=ctx)
c.request('GET', '/')
data = c.getresponse().read()
c.close()
@@ -201,7 +206,7 @@
ctx = SSL.Context()
ctx.set_verify(SSL.verify_peer | SSL.verify_fail_if_no_peer_cert, 9)
ctx.load_verify_locations('tests/server.pem')
- c = httpslib.HTTPSConnection(srv_host, srv_port, ssl_context=ctx)
+ c = httpslib.HTTPSConnection(srv_host, self.srv_port, ssl_context=ctx)
self.assertRaises(SSL.SSLError, c.request, 'GET', '/')
c.close()
finally:
@@ -211,7 +216,7 @@
pid = self.start_server(self.args)
try:
from M2Crypto import httpslib
- c = httpslib.HTTPS(srv_host, srv_port)
+ c = httpslib.HTTPS(srv_host, self.srv_port)
c.putrequest('GET', '/')
c.putheader('Accept', 'text/html')
c.putheader('Accept', 'text/plain')
@@ -232,7 +237,7 @@
ctx = SSL.Context()
ctx.set_verify(SSL.verify_peer | SSL.verify_fail_if_no_peer_cert, 9)
ctx.load_verify_locations('tests/ca.pem')
- c = httpslib.HTTPS(srv_host, srv_port, ssl_context=ctx)
+ c = httpslib.HTTPS(srv_host, self.srv_port, ssl_context=ctx)
c.putrequest('GET', '/')
c.putheader('Accept', 'text/html')
c.putheader('Accept', 'text/plain')
@@ -253,7 +258,7 @@
ctx = SSL.Context()
ctx.set_verify(SSL.verify_peer | SSL.verify_fail_if_no_peer_cert, 9)
ctx.load_verify_locations('tests/server.pem')
- c = httpslib.HTTPS(srv_host, srv_port, ssl_context=ctx)
+ c = httpslib.HTTPS(srv_host, self.srv_port, ssl_context=ctx)
c.putrequest('GET', '/')
c.putheader('Accept', 'text/html')
c.putheader('Accept', 'text/plain')
@@ -871,7 +876,7 @@
from M2Crypto import m2urllib
url = m2urllib.FancyURLopener()
url.addheader('Connection', 'close')
- u = url.open('https://%s:%s/' % (srv_host, srv_port))
+ u = url.open('https://%s:%s/' % (srv_host, self.srv_port))
data = u.read()
u.close()
finally:
@@ -896,7 +901,7 @@
from M2Crypto import m2urllib2
opener = m2urllib2.build_opener()
opener.addheaders = [('Connection', 'close')]
- u = opener.open('https://%s:%s/' % (srv_host, srv_port))
+ u = opener.open('https://%s:%s/' % (srv_host, self.srv_port))
data = u.read()
u.close()
finally:
@@ -913,7 +918,7 @@
from M2Crypto import m2urllib2
opener = m2urllib2.build_opener(ctx)
opener.addheaders = [('Connection', 'close')]
- u = opener.open('https://%s:%s/' % (srv_host, srv_port))
+ u = opener.open('https://%s:%s/' % (srv_host, self.srv_port))
data = u.read()
u.close()
finally:
@@ -930,7 +935,7 @@
from M2Crypto import m2urllib2
opener = m2urllib2.build_opener(ctx)
opener.addheaders = [('Connection', 'close')]
- self.assertRaises(SSL.SSLError, opener.open, 'https://%s:%s/' % (srv_host, srv_port))
+ self.assertRaises(SSL.SSLError, opener.open, 'https://%s:%s/' % (srv_host, self.srv_port))
finally:
self.stop_server(pid)
@@ -942,7 +947,7 @@
from M2Crypto import m2urllib2
opener = m2urllib2.build_opener(ctx, m2urllib2.HTTPBasicAuthHandler())
m2urllib2.install_opener(opener)
- req = m2urllib2.Request('https://%s:%s/' % (srv_host, srv_port))
+ req = m2urllib2.Request('https://%s:%s/' % (srv_host, self.srv_port))
u = m2urllib2.urlopen(req)
data = u.read()
u.close()
@@ -963,7 +968,7 @@
import gc
from M2Crypto import m2urllib2
o = m2urllib2.build_opener()
- r = o.open('https://%s:%s/' % (srv_host, srv_port))
+ r = o.open('https://%s:%s/' % (srv_host, self.srv_port))
s = [r.fp._sock.fp]
r.close()
self.assertEqual(len(gc.get_referrers(s[0])), 1)
@@ -990,7 +995,7 @@
pid = self.start_server(self.args)
try:
from M2Crypto import httpslib
- c = httpslib.HTTPS(srv_host, srv_port)
+ c = httpslib.HTTPS(srv_host, self.srv_port)
c.putrequest('GET', '/')
c.putheader('Accept', 'text/html')
c.putheader('Accept', 'text/plain')
@@ -1029,7 +1034,7 @@
pid = self.start_server(self.args)
try:
from M2Crypto import httpslib
- c = httpslib.HTTPS(srv_host, srv_port)
+ c = httpslib.HTTPS(srv_host, self.srv_port)
c.putrequest('GET', '/' + FIFO_NAME)
c.putheader('Accept', 'text/html')
c.putheader('Accept', 'text/plain')
@@ -1086,7 +1091,7 @@
contextFactory = ContextFactory()
factory = EchoClientFactory()
- wrapper.connectSSL(srv_host, srv_port, factory, contextFactory)
+ wrapper.connectSSL(srv_host, self.srv_port, factory, contextFactory)
reactor.run() # This will block until reactor.stop() is called
finally:
self.stop_server(pid)