|
18 | 18 | )
|
19 | 19 | from hyper.common.headers import HTTPHeaderMap
|
20 | 20 | from hyper.common.util import to_bytestring, HTTPVersion
|
21 |
| -from hyper.compat import zlib_compressobj, is_py2 |
| 21 | +from hyper.compat import zlib_compressobj, is_py2, ssl |
22 | 22 | from hyper.contrib import HTTP20Adapter
|
23 | 23 | import hyper.http20.errors as errors
|
24 | 24 | import errno
|
|
31 | 31 | TEST_DIR = os.path.abspath(os.path.dirname(__file__))
|
32 | 32 | TEST_CERTS_DIR = os.path.join(TEST_DIR, 'certs')
|
33 | 33 | CLIENT_PEM_FILE = os.path.join(TEST_CERTS_DIR, 'nopassword.pem')
|
| 34 | +SERVER_CERT_FILE = os.path.join(TEST_CERTS_DIR, 'server.crt') |
34 | 35 |
|
35 | 36 |
|
36 | 37 | def decode_frame(frame_data):
|
@@ -1129,6 +1130,29 @@ def test_adapter_accept_client_certificate(self):
|
1129 | 1130 | 'http',
|
1130 | 1131 | cert=CLIENT_PEM_FILE)
|
1131 | 1132 | assert conn1 is conn2
|
| 1133 | + assert conn1._conn.ssl_context.check_hostname |
| 1134 | + assert conn1._conn.ssl_context.verify_mode == ssl.CERT_REQUIRED |
| 1135 | + |
| 1136 | + def test_adapter_respects_disabled_ca_verification(self): |
| 1137 | + a = HTTP20Adapter() |
| 1138 | + conn = a.get_connection( |
| 1139 | + 'http2bin.org', |
| 1140 | + 80, |
| 1141 | + 'http', |
| 1142 | + verify=False, |
| 1143 | + cert=CLIENT_PEM_FILE) |
| 1144 | + assert not conn._conn.ssl_context.check_hostname |
| 1145 | + assert conn._conn.ssl_context.verify_mode == ssl.CERT_NONE |
| 1146 | + |
| 1147 | + def test_adapter_respects_custom_ca_verification(self): |
| 1148 | + a = HTTP20Adapter() |
| 1149 | + conn = a.get_connection( |
| 1150 | + 'http2bin.org', |
| 1151 | + 80, |
| 1152 | + 'http', |
| 1153 | + verify=SERVER_CERT_FILE) |
| 1154 | + assert conn._conn.ssl_context.check_hostname |
| 1155 | + assert conn._conn.ssl_context.verify_mode == ssl.CERT_REQUIRED |
1132 | 1156 |
|
1133 | 1157 |
|
1134 | 1158 | class TestUtilities(object):
|
|
0 commit comments