Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Tests for urllib3.contrib.pyopenssl.

This makes the SNI-test raise SkipTest if SNI is not supported, so
it can be reused by test.contrib.test_pyopenssl even when the stdlib
does not support SNI.

It also tests the urllib3.contrib.pyopenssl module when its
dependencies are installed, by re-exporting HTTPS test-cases and
using module-level setup/teardown code to monkey patch urllib3.
  • Loading branch information...
commit a10511947458c7ba3ea651edf24d0faa785b2a51 1 parent 35485d8
@kirkeby authored
View
0  test/contrib/__init__.py
No changes.
View
17 test/contrib/test_pyopenssl.py
@@ -0,0 +1,17 @@
+try:
+ from urllib3.contrib.pyopenssl import (inject_into_urllib3,
+ extract_from_urllib3)
+except ImportError as e:
+ from nose.plugins.skip import SkipTest
+ raise SkipTest('Could not import pyopenssl: %r' % e)
+
+from ..with_dummyserver.test_https import TestHTTPS, TestHTTPS_TLSv1
+from ..with_dummyserver.test_socketlevel import TestSNI, TestSocketClosing
+
+
+def setup_module():
+ inject_into_urllib3()
+
+
+def teardown_module():
+ extract_from_urllib3()
View
43 test/with_dummyserver/test_socketlevel.py
@@ -1,10 +1,11 @@
from urllib3 import HTTPConnectionPool, HTTPSConnectionPool
from urllib3.poolmanager import proxy_from_url
from urllib3.exceptions import MaxRetryError, TimeoutError, SSLError
-from urllib3.util import HAS_SNI
+from urllib3 import util
from dummyserver.testcase import SocketDummyServerTestCase
+from nose.plugins.skip import SkipTest
from threading import Event
@@ -30,28 +31,30 @@ def multicookie_response_handler(listener):
self.assertEquals(r.headers, {'set-cookie': 'foo=1, bar=1'})
-if HAS_SNI:
- class TestSNI(SocketDummyServerTestCase):
+class TestSNI(SocketDummyServerTestCase):
- def test_hostname_in_first_request_packet(self):
- done_receiving = Event()
- self.buf = b''
+ def test_hostname_in_first_request_packet(self):
+ if not util.HAS_SNI:
+ raise SkipTest('SNI-support not available')
- def socket_handler(listener):
- sock = listener.accept()[0]
+ 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.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.host.encode() in self.buf,
- "missing hostname in SSL handshake")
+ 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.host.encode() in self.buf,
+ "missing hostname in SSL handshake")
class TestSocketClosing(SocketDummyServerTestCase):
Please sign in to comment.
Something went wrong with that request. Please try again.