Skip to content

Update WIZNet version check for SSL #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 23, 2024
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
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)
Loading