summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Weißschuh <thomas_weissschuh@lavabit.com>2012-08-02 20:52:28 +0000
committerThomas Weißschuh <thomas_weissschuh@lavabit.com>2012-08-02 20:52:28 +0000
commit7856f627e1f0b1b570260c169d4f855bc8b91675 (patch)
treefd8d1945d2567ae75691ece52c8a48fe9342ce3a
parent9056e759fc8fea5885772c3c453ec4e65f84c52e (diff)
downloadurllib3-7856f627e1f0b1b570260c169d4f855bc8b91675.tar.gz
add offline unit test for SNI
-rw-r--r--test/with_dummyserver/test_socketlevel.py30
1 files changed, 29 insertions, 1 deletions
diff --git a/test/with_dummyserver/test_socketlevel.py b/test/with_dummyserver/test_socketlevel.py
index 46510281..65af5afc 100644
--- a/test/with_dummyserver/test_socketlevel.py
+++ b/test/with_dummyserver/test_socketlevel.py
@@ -1,10 +1,16 @@
-from urllib3 import HTTPConnectionPool
+from urllib3 import HTTPConnectionPool, HTTPSConnectionPool
from urllib3.poolmanager import proxy_from_url
+from urllib3.exceptions import SSLError
from dummyserver.testcase import SocketDummyServerTestCase
from threading import Event
+try:
+ from ssl import HAS_SNI
+except ImportError: # openssl without SNI
+ HAS_SNI = False
+
class TestCookies(SocketDummyServerTestCase):
@@ -26,6 +32,28 @@ class TestCookies(SocketDummyServerTestCase):
r = pool.request('GET', '/', retries=0)
self.assertEquals(r.headers, {'set-cookie': 'foo=1, bar=1'})
+if HAS_SNI:
+ class TestSNI(SocketDummyServerTestCase):
+
+ def test_hostname_in_first_request_packet(self):
+ done_receiving = Event()
+ self.buf = b''
+
+ def socket_handler(listener):
+ sock = listener.accept()[0]
+
+ self.buf = sock.recv(65536) # We only accept one packet
+ done_receiving.set() # let the test know it can proceed
+
+ self._start_server(socket_handler)
+ pool = HTTPSConnectionPool(self.host, self.port)
+ try:
+ pool.request('GET', '/', retries=0)
+ except SSLError: # We are violating the protocol
+ pass
+ done_receiving.wait()
+ self.assertTrue(self.buf.find(self.host.encode()) != -1,
+ "missing hostname in SSL handshake")
class TestSocketClosing(SocketDummyServerTestCase):