Skip to content

Commit 67d649b

Browse files
authored
Merge pull request #21 from justmobilize/update-wiznet-version-check
Update WIZNet version check for SSL
2 parents b514b44 + 1247dd4 commit 67d649b

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

adafruit_connection_manager.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,13 @@ def get_radio_socketpool(radio):
149149
# versions of the Wiznet5k library or on boards withouut the ssl module
150150
# see https://docs.circuitpython.org/en/latest/shared-bindings/support_matrix.html
151151
ssl_context = None
152-
cp_version = sys.implementation[1]
153-
if pool.SOCK_STREAM == 1 and cp_version >= WIZNET5K_SSL_SUPPORT_VERSION:
152+
implementation_name = sys.implementation.name
153+
implementation_version = sys.implementation.version
154+
if (
155+
pool.SOCK_STREAM == 1
156+
and implementation_name == "circuitpython"
157+
and implementation_version >= WIZNET5K_SSL_SUPPORT_VERSION
158+
):
154159
try:
155160
import ssl # pylint: disable=import-outside-toplevel
156161

tests/ssl_context_test.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
""" SLL Context Tests """
66

77
import ssl
8+
from collections import namedtuple
89
from unittest import mock
910

1011
import mocket
@@ -13,6 +14,8 @@
1314
import adafruit_connection_manager
1415
from adafruit_connection_manager import WIZNET5K_SSL_SUPPORT_VERSION
1516

17+
SimpleNamespace = namedtuple("SimpleNamespace", "name version")
18+
1619

1720
def test_connect_esp32spi_https( # pylint: disable=unused-argument
1821
adafruit_esp32spi_socketpool_module,
@@ -53,7 +56,9 @@ def test_connect_wiznet5k_https_not_supported( # pylint: disable=unused-argumen
5356
mock_pool = mocket.MocketPool()
5457
radio = mocket.MockRadio.WIZNET5K()
5558
old_version = (WIZNET5K_SSL_SUPPORT_VERSION[0] - 1, 0, 0)
56-
with mock.patch("sys.implementation", (None, old_version)):
59+
with mock.patch(
60+
"sys.implementation", SimpleNamespace("circuitpython", old_version)
61+
):
5762
ssl_context = adafruit_connection_manager.get_radio_ssl_context(radio)
5863
connection_manager = adafruit_connection_manager.ConnectionManager(mock_pool)
5964

@@ -69,6 +74,9 @@ def test_connect_wiznet5k_https_supported( # pylint: disable=unused-argument
6974
adafruit_wiznet5k_with_ssl_socketpool_module,
7075
):
7176
radio = mocket.MockRadio.WIZNET5K()
72-
with mock.patch("sys.implementation", (None, WIZNET5K_SSL_SUPPORT_VERSION)):
77+
with mock.patch(
78+
"sys.implementation",
79+
SimpleNamespace("circuitpython", WIZNET5K_SSL_SUPPORT_VERSION),
80+
):
7381
ssl_context = adafruit_connection_manager.get_radio_ssl_context(radio)
7482
assert isinstance(ssl_context, ssl.SSLContext)

0 commit comments

Comments
 (0)