Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ class RESTClientObject:
self.ssl_context.check_hostname = False
self.ssl_context.verify_mode = ssl.CERT_NONE

# Honor assert_hostname like the urllib3 client. Only when verify_ssl is
# on: enabling check_hostname would otherwise turn verification back on.
if configuration.verify_ssl and configuration.assert_hostname is not None:
self.ssl_context.check_hostname = bool(configuration.assert_hostname)

self.proxy = configuration.proxy
self.proxy_headers = configuration.proxy_headers

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ class RESTClientObject:
self.ssl_context.check_hostname = False
self.ssl_context.verify_mode = ssl.CERT_NONE

# Honor assert_hostname like the urllib3 client. Only when verify_ssl is
# on: enabling check_hostname would otherwise turn verification back on.
if configuration.verify_ssl and configuration.assert_hostname is not None:
self.ssl_context.check_hostname = bool(configuration.assert_hostname)

self.proxy = configuration.proxy
self.proxy_headers = configuration.proxy_headers

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ def __init__(self, configuration) -> None:
self.ssl_context.check_hostname = False
self.ssl_context.verify_mode = ssl.CERT_NONE

# Honor assert_hostname like the urllib3 client. Only when verify_ssl is
# on: enabling check_hostname would otherwise turn verification back on.
if configuration.verify_ssl and configuration.assert_hostname is not None:
self.ssl_context.check_hostname = bool(configuration.assert_hostname)

self.proxy = configuration.proxy
self.proxy_headers = configuration.proxy_headers

Expand Down
22 changes: 22 additions & 0 deletions samples/openapi3/client/petstore/python-aiohttp/tests/test_rest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import ssl
import unittest
from unittest.mock import AsyncMock, Mock, patch

Expand Down Expand Up @@ -72,3 +73,24 @@ async def test_multipart_requests_with_file_and_additional_properties(self):

assert type(data_count) is str
assert type(data_object) is str


class TestAssertHostname(unittest.TestCase):
def test_assert_hostname_false_disables_hostname_check(self):
config = petstore_api.Configuration()
config.assert_hostname = False

client = petstore_api.rest.RESTClientObject(config)

self.assertFalse(client.ssl_context.check_hostname)
self.assertEqual(ssl.CERT_REQUIRED, client.ssl_context.verify_mode)

def test_assert_hostname_does_not_reenable_verification(self):
config = petstore_api.Configuration()
config.verify_ssl = False
config.assert_hostname = True

client = petstore_api.rest.RESTClientObject(config)

self.assertFalse(client.ssl_context.check_hostname)
self.assertEqual(ssl.CERT_NONE, client.ssl_context.verify_mode)
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ def __init__(self, configuration) -> None:
self.ssl_context.check_hostname = False
self.ssl_context.verify_mode = ssl.CERT_NONE

# Honor assert_hostname like the urllib3 client. Only when verify_ssl is
# on: enabling check_hostname would otherwise turn verification back on.
if configuration.verify_ssl and configuration.assert_hostname is not None:
self.ssl_context.check_hostname = bool(configuration.assert_hostname)

self.proxy = configuration.proxy
self.proxy_headers = configuration.proxy_headers

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ def __init__(self, configuration) -> None:
self.ssl_context.check_hostname = False
self.ssl_context.verify_mode = ssl.CERT_NONE

# Honor assert_hostname like the urllib3 client. Only when verify_ssl is
# on: enabling check_hostname would otherwise turn verification back on.
if configuration.verify_ssl and configuration.assert_hostname is not None:
self.ssl_context.check_hostname = bool(configuration.assert_hostname)

self.proxy = configuration.proxy
self.proxy_headers = configuration.proxy_headers

Expand Down
22 changes: 22 additions & 0 deletions samples/openapi3/client/petstore/python-httpx/tests/test_rest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import ssl
import unittest
from unittest.mock import AsyncMock, Mock, patch

Expand Down Expand Up @@ -73,3 +74,24 @@ async def test_multipart_requests_with_file_and_additional_properties(self):

assert type(data_count) is str
assert type(data_object) is str


class TestAssertHostname(unittest.TestCase):
def test_assert_hostname_false_disables_hostname_check(self):
config = petstore_api.Configuration()
config.assert_hostname = False

client = petstore_api.rest.RESTClientObject(config)

self.assertFalse(client.ssl_context.check_hostname)
self.assertEqual(ssl.CERT_REQUIRED, client.ssl_context.verify_mode)

def test_assert_hostname_does_not_reenable_verification(self):
config = petstore_api.Configuration()
config.verify_ssl = False
config.assert_hostname = True

client = petstore_api.rest.RESTClientObject(config)

self.assertFalse(client.ssl_context.check_hostname)
self.assertEqual(ssl.CERT_NONE, client.ssl_context.verify_mode)
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ def __init__(self, configuration) -> None:
self.ssl_context.check_hostname = False
self.ssl_context.verify_mode = ssl.CERT_NONE

# Honor assert_hostname like the urllib3 client. Only when verify_ssl is
# on: enabling check_hostname would otherwise turn verification back on.
if configuration.verify_ssl and configuration.assert_hostname is not None:
self.ssl_context.check_hostname = bool(configuration.assert_hostname)

self.proxy = configuration.proxy
self.proxy_headers = configuration.proxy_headers

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ def __init__(self, configuration) -> None:
self.ssl_context.check_hostname = False
self.ssl_context.verify_mode = ssl.CERT_NONE

# Honor assert_hostname like the urllib3 client. Only when verify_ssl is
# on: enabling check_hostname would otherwise turn verification back on.
if configuration.verify_ssl and configuration.assert_hostname is not None:
self.ssl_context.check_hostname = bool(configuration.assert_hostname)

self.proxy = configuration.proxy
self.proxy_headers = configuration.proxy_headers

Expand Down
Loading