Skip to content

Commit

Permalink
Merge pull request #21 from justmobilize/update-wiznet-version-check
Browse files Browse the repository at this point in the history
Update WIZNet version check for SSL
  • Loading branch information
dhalbert authored Jun 23, 2024
2 parents b514b44 + 1247dd4 commit 67d649b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
9 changes: 7 additions & 2 deletions adafruit_connection_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,13 @@ def get_radio_socketpool(radio):
# versions of the Wiznet5k library or on boards withouut the ssl module
# see https://docs.circuitpython.org/en/latest/shared-bindings/support_matrix.html
ssl_context = None
cp_version = sys.implementation[1]
if pool.SOCK_STREAM == 1 and cp_version >= WIZNET5K_SSL_SUPPORT_VERSION:
implementation_name = sys.implementation.name
implementation_version = sys.implementation.version
if (
pool.SOCK_STREAM == 1
and implementation_name == "circuitpython"
and implementation_version >= WIZNET5K_SSL_SUPPORT_VERSION
):
try:
import ssl # pylint: disable=import-outside-toplevel

Expand Down
12 changes: 10 additions & 2 deletions tests/ssl_context_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
""" SLL Context Tests """

import ssl
from collections import namedtuple
from unittest import mock

import mocket
Expand All @@ -13,6 +14,8 @@
import adafruit_connection_manager
from adafruit_connection_manager import WIZNET5K_SSL_SUPPORT_VERSION

SimpleNamespace = namedtuple("SimpleNamespace", "name version")


def test_connect_esp32spi_https( # pylint: disable=unused-argument
adafruit_esp32spi_socketpool_module,
Expand Down Expand Up @@ -53,7 +56,9 @@ def test_connect_wiznet5k_https_not_supported( # pylint: disable=unused-argumen
mock_pool = mocket.MocketPool()
radio = mocket.MockRadio.WIZNET5K()
old_version = (WIZNET5K_SSL_SUPPORT_VERSION[0] - 1, 0, 0)
with mock.patch("sys.implementation", (None, old_version)):
with mock.patch(
"sys.implementation", SimpleNamespace("circuitpython", old_version)
):
ssl_context = adafruit_connection_manager.get_radio_ssl_context(radio)
connection_manager = adafruit_connection_manager.ConnectionManager(mock_pool)

Expand All @@ -69,6 +74,9 @@ def test_connect_wiznet5k_https_supported( # pylint: disable=unused-argument
adafruit_wiznet5k_with_ssl_socketpool_module,
):
radio = mocket.MockRadio.WIZNET5K()
with mock.patch("sys.implementation", (None, WIZNET5K_SSL_SUPPORT_VERSION)):
with mock.patch(
"sys.implementation",
SimpleNamespace("circuitpython", WIZNET5K_SSL_SUPPORT_VERSION),
):
ssl_context = adafruit_connection_manager.get_radio_ssl_context(radio)
assert isinstance(ssl_context, ssl.SSLContext)

0 comments on commit 67d649b

Please sign in to comment.