Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion duo_client/https_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ def connect(self):
self.timeout)
if self._tunnel_host:
self._tunnel()
self.sock = self.default_ssl_context.wrap_socket(self.sock)
self.sock = self.default_ssl_context.wrap_socket(self.sock,
server_hostname=self.host)
if self.default_ssl_context.verify_mode == ssl.CERT_REQUIRED:
cert = self.sock.getpeercert()
cert_validation_host = self._tunnel_host or self.host
Expand Down
14 changes: 14 additions & 0 deletions tests/test_https_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,17 @@ def test_ssl2_ssl3_off(self):
conn = CertValidatingHTTPSConnection('api-fakehost.duosecurity.com')
self.assertEqual(conn.default_ssl_context.options & ssl.OP_NO_SSLv2, ssl.OP_NO_SSLv2)
self.assertEqual(conn.default_ssl_context.options & ssl.OP_NO_SSLv3, ssl.OP_NO_SSLv3)

@mock.patch('socket.socket.connect')
def test_server_hostname(self, mock_connect):
hostname = 'api-fakehost.duosecurity.com'
conn = CertValidatingHTTPSConnection(hostname)
conn.connect()
self.assertEqual(conn.sock.server_hostname, hostname)

@mock.patch('socket.socket.connect')
def test_server_hostname_with_port(self, mock_connect):
hostname = 'api-fakehost.duosecurity.com'
conn = CertValidatingHTTPSConnection(f'{hostname}:443')
conn.connect()
self.assertEqual(conn.sock.server_hostname, hostname)