Skip to content

Commit

Permalink
[fix] Fixed parsing of wifi with encryption set to none
Browse files Browse the repository at this point in the history
  • Loading branch information
nemesifier committed May 15, 2022
1 parent a0f78ff commit 226c983
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
6 changes: 5 additions & 1 deletion netjsonconfig/backends/openwrt/converters/wireless.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def __netjson_wifi_typecast(self, wifi):
'wps_pin',
]

def __netjson_encryption(self, wifi):
def __netjson_encryption(self, wifi): # noqa: max-complexity: 11
if 'encryption' not in wifi:
return
settings = {}
Expand All @@ -268,6 +268,10 @@ def __netjson_encryption(self, wifi):
wps = True
# determine NetJSON protocol and cipher
protocol = wifi.pop('encryption')
# if encryption is diabled just set it to none and return
if protocol == 'none':
wifi['encryption'] = {'protocol': 'none'}
return
cipher = 'auto'
if '+' in protocol:
protocol, cipher = protocol.split('+', 1)
Expand Down
39 changes: 21 additions & 18 deletions tests/openwrt/test_encryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -950,25 +950,21 @@ def test_encryption_disabled(self):
)
self.assertEqual(o.render(), expected)

def test_no_encryption(self):
o = OpenWrt(
_no_encryption_netjson = {
"interfaces": [
{
"interfaces": [
{
"name": "wlan0",
"type": "wireless",
"wireless": {
"radio": "radio0",
"mode": "access_point",
"ssid": "open",
"encryption": {"protocol": "none"},
},
}
]
"name": "wlan0",
"type": "wireless",
"wireless": {
"radio": "radio0",
"mode": "access_point",
"ssid": "open",
"encryption": {"protocol": "none"},
},
}
)
expected = self._tabs(
"""package network
]
}
_no_encryption_uci = """package network
config device 'device_wlan0'
option name 'wlan0'
Expand All @@ -987,9 +983,16 @@ def test_no_encryption(self):
option network 'wlan0'
option ssid 'open'
"""
)

def test_render_no_encryption(self):
o = OpenWrt(self._no_encryption_netjson)
expected = self._tabs(self._no_encryption_uci)
self.assertEqual(o.render(), expected)

def test_parse_no_encryption(self):
o = OpenWrt(native=self._no_encryption_uci)
self.assertEqual(o.config, self._no_encryption_netjson)

_wpa2_80211s_netjson = {
"interfaces": [
{
Expand Down

0 comments on commit 226c983

Please sign in to comment.