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
15 changes: 15 additions & 0 deletions adafruit_portalbase/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,21 @@ def connect(self, max_attempts=10):
"'networks' must be a list/tuple of dicts of 'ssid' and 'password'"
)

self._wifi_credentials = list(
filter(
lambda credentials: isinstance(credentials, dict)
and "ssid" in credentials
and "password" in credentials
and isinstance(credentials["ssid"], str)
and isinstance(credentials["password"], str)
and len(credentials["ssid"]),
self._wifi_credentials,
)
)
if not len(self._wifi_credentials):
self._wifi_credentials = None
raise OSError("No wifi credentials provided")

for credentials in self._wifi_credentials:
self._wifi.neo_status(STATUS_CONNECTING)
attempt = 1
Expand Down
12 changes: 12 additions & 0 deletions tests/test_get_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,15 @@ def test_value_stored(settings_toml_current):
with mock.patch("os.getenv", return_value="test") as mock_getenv:
assert network._get_setting("ADAFRUIT_AIO_KEY") == "test"
mock_getenv.assert_not_called()


def test_invalid_wifi_credentials():
for key in ("CIRCUITPY_WIFI_SSID", "CIRCUITPY_WIFI_PASSWORD"):
if os.getenv(key) is not None and os.getenv(key) != "":
assert False
network = NetworkBase(None)
try:
network.connect()
assert False
except OSError:
assert True