Skip to content
This repository was archived by the owner on Jan 13, 2021. It is now read-only.

Commit b033641

Browse files
committed
Add tests for requests adapter verify option
1 parent 8c375ea commit b033641

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

test/test_hyper.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
)
1919
from hyper.common.headers import HTTPHeaderMap
2020
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
2222
from hyper.contrib import HTTP20Adapter
2323
import hyper.http20.errors as errors
2424
import errno
@@ -31,6 +31,7 @@
3131
TEST_DIR = os.path.abspath(os.path.dirname(__file__))
3232
TEST_CERTS_DIR = os.path.join(TEST_DIR, 'certs')
3333
CLIENT_PEM_FILE = os.path.join(TEST_CERTS_DIR, 'nopassword.pem')
34+
SERVER_CERT_FILE = os.path.join(TEST_CERTS_DIR, 'server.crt')
3435

3536

3637
def decode_frame(frame_data):
@@ -1129,6 +1130,29 @@ def test_adapter_accept_client_certificate(self):
11291130
'http',
11301131
cert=CLIENT_PEM_FILE)
11311132
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
11321156

11331157

11341158
class TestUtilities(object):

0 commit comments

Comments
 (0)