Skip to content

Commit 226c983

Browse files
committed
[fix] Fixed parsing of wifi with encryption set to none
1 parent a0f78ff commit 226c983

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

netjsonconfig/backends/openwrt/converters/wireless.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def __netjson_wifi_typecast(self, wifi):
255255
'wps_pin',
256256
]
257257

258-
def __netjson_encryption(self, wifi):
258+
def __netjson_encryption(self, wifi): # noqa: max-complexity: 11
259259
if 'encryption' not in wifi:
260260
return
261261
settings = {}
@@ -268,6 +268,10 @@ def __netjson_encryption(self, wifi):
268268
wps = True
269269
# determine NetJSON protocol and cipher
270270
protocol = wifi.pop('encryption')
271+
# if encryption is diabled just set it to none and return
272+
if protocol == 'none':
273+
wifi['encryption'] = {'protocol': 'none'}
274+
return
271275
cipher = 'auto'
272276
if '+' in protocol:
273277
protocol, cipher = protocol.split('+', 1)

tests/openwrt/test_encryption.py

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -950,25 +950,21 @@ def test_encryption_disabled(self):
950950
)
951951
self.assertEqual(o.render(), expected)
952952

953-
def test_no_encryption(self):
954-
o = OpenWrt(
953+
_no_encryption_netjson = {
954+
"interfaces": [
955955
{
956-
"interfaces": [
957-
{
958-
"name": "wlan0",
959-
"type": "wireless",
960-
"wireless": {
961-
"radio": "radio0",
962-
"mode": "access_point",
963-
"ssid": "open",
964-
"encryption": {"protocol": "none"},
965-
},
966-
}
967-
]
956+
"name": "wlan0",
957+
"type": "wireless",
958+
"wireless": {
959+
"radio": "radio0",
960+
"mode": "access_point",
961+
"ssid": "open",
962+
"encryption": {"protocol": "none"},
963+
},
968964
}
969-
)
970-
expected = self._tabs(
971-
"""package network
965+
]
966+
}
967+
_no_encryption_uci = """package network
972968
973969
config device 'device_wlan0'
974970
option name 'wlan0'
@@ -987,9 +983,16 @@ def test_no_encryption(self):
987983
option network 'wlan0'
988984
option ssid 'open'
989985
"""
990-
)
986+
987+
def test_render_no_encryption(self):
988+
o = OpenWrt(self._no_encryption_netjson)
989+
expected = self._tabs(self._no_encryption_uci)
991990
self.assertEqual(o.render(), expected)
992991

992+
def test_parse_no_encryption(self):
993+
o = OpenWrt(native=self._no_encryption_uci)
994+
self.assertEqual(o.config, self._no_encryption_netjson)
995+
993996
_wpa2_80211s_netjson = {
994997
"interfaces": [
995998
{

0 commit comments

Comments
 (0)