File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -386,6 +386,21 @@ def connect(self, max_attempts=10):
386
386
"'networks' must be a list/tuple of dicts of 'ssid' and 'password'"
387
387
)
388
388
389
+ self ._wifi_credentials = list (
390
+ filter (
391
+ lambda credentials : isinstance (credentials , dict )
392
+ and "ssid" in credentials
393
+ and "password" in credentials
394
+ and isinstance (credentials ["ssid" ], str )
395
+ and isinstance (credentials ["password" ], str )
396
+ and len (credentials ["ssid" ]),
397
+ self ._wifi_credentials ,
398
+ )
399
+ )
400
+ if not len (self ._wifi_credentials ):
401
+ self ._wifi_credentials = None
402
+ raise OSError ("No wifi credentials provided" )
403
+
389
404
for credentials in self ._wifi_credentials :
390
405
self ._wifi .neo_status (STATUS_CONNECTING )
391
406
attempt = 1
Original file line number Diff line number Diff line change @@ -125,3 +125,15 @@ def test_value_stored(settings_toml_current):
125
125
with mock .patch ("os.getenv" , return_value = "test" ) as mock_getenv :
126
126
assert network ._get_setting ("ADAFRUIT_AIO_KEY" ) == "test"
127
127
mock_getenv .assert_not_called ()
128
+
129
+
130
+ def test_invalid_wifi_credentials ():
131
+ for key in ("CIRCUITPY_WIFI_SSID" , "CIRCUITPY_WIFI_PASSWORD" ):
132
+ if os .getenv (key ) is not None and os .getenv (key ) != "" :
133
+ assert False
134
+ network = NetworkBase (None )
135
+ try :
136
+ network .connect ()
137
+ assert False
138
+ except OSError :
139
+ assert True
You can’t perform that action at this time.
0 commit comments