Skip to content

Commit

Permalink
[tests] Add wifi tests
Browse files Browse the repository at this point in the history
  • Loading branch information
devkapilbansal committed Jun 21, 2021
1 parent addc51f commit d8ec7a3
Show file tree
Hide file tree
Showing 5 changed files with 182 additions and 21 deletions.
42 changes: 21 additions & 21 deletions openwrt-openwisp-monitoring/files/lib/openwisp/wifi.lua
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
local wifi = {}

function wifi.parse_hostapd_clients(clients)
local data = {}
for mac, properties in pairs(clients) do
properties.mac = mac
table.insert(data, properties)
end
return data
local data = {}
for mac, properties in pairs(clients) do
properties.mac = mac
table.insert(data, properties)
end
return data
end

function wifi.parse_iwinfo_clients(clients)
local data = {}
for _, p in pairs(clients) do
local client = {}
client.ht = p.rx.ht
client.mac = p.mac
client.authorized = p.authorized
client.vht = p.rx.vht
client.wmm = p.wme
client.mfp = p.mfp
client.auth = p.authenticated
client.signal = p.signal
client.noise = p.noise
table.insert(data, client)
end
return data
local data = {}
for _, p in pairs(clients) do
local client = {}
client.ht = p.rx.ht
client.mac = p.mac
client.authorized = p.authorized
client.vht = p.rx.vht
client.wmm = p.wme
client.mfp = p.mfp
client.auth = p.authenticated
client.signal = p.signal
client.noise = p.noise
table.insert(data, client)
end
return data
end

-- takes ubus wireless.status clients output and converts it to NetJSON
Expand Down
128 changes: 128 additions & 0 deletions openwrt-openwisp-monitoring/tests/test_files/wireless_data.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
local test_data = {}

test_data.wireless_status={
radio0 = {
autostart = true,
config = {
channel = "11",
htmode = "HT20",
hwmode = "11g",
path = "platform/10300000.wmac"
},
disabled = false,
interfaces = { {
config = {
encryption = "none",
mode = "ap",
network = { "lan" },
ssid = "OpenWrt"
},
ifname = "wlan0-1",
section = "default_radio0"
}, {
config = {
encryption = "psk2",
key = "95535210",
mode = "sta",
network = { "wwan" },
ssid = "DIR-615-5A5B"
},
ifname = "wlan0",
section = "wifinet2"
} },
pending = false,
retry_setup_failed = false,
up = true
},
radio1 = {
autostart = true,
config = {
channel = "36",
htmode = "VHT80",
hwmode = "11a",
path = "pci0000:00/0000:00:00.0/0000:01:00.0"
},
disabled = false,
interfaces = { {
config = {
encryption = "none",
mode = "ap",
network = { "lan" },
ssid = "OpenWrt"
},
ifname = "wlan1",
section = "default_radio1"
} },
pending = false,
retry_setup_failed = false,
up = true
}
}

test_data.wlan1_clients = {
["20:a6:0c:b2:da:10"] = {
aid = 2,
assoc = true,
auth = true,
authorized = true,
ht = true,
mfp = false,
preauth = false,
rrm = { 0, 0, 0, 0, 0 },
vht = true,
wds = false,
wmm = true,
wps = false
},
["98:3b:8f:98:b1:fb"] = {
aid = 1,
assoc = true,
auth = true,
authorized = true,
ht = true,
mfp = false,
preauth = false,
rrm = { 0, 0, 0, 0, 0 },
vht = true,
wds = false,
wmm = true,
wps = false
}
}

test_data.wlan0_clients = {}

test_data.parsed_clients = {
{
aid=1,
assoc=true,
auth=true,
authorized=true,
ht=true,
mac="98:3b:8f:98:b1:fb",
mfp=false,
preauth=false,
rrm={0, 0, 0, 0, 0},
vht=true,
wds=false,
wmm=true,
wps=false
},
{
aid=2,
assoc=true,
auth=true,
authorized=true,
ht=true,
mac="20:a6:0c:b2:da:10",
mfp=false,
preauth=false,
rrm={0, 0, 0, 0, 0},
vht=true,
wds=false,
wmm=true,
wps=false
}
}

return test_data
5 changes: 5 additions & 0 deletions openwrt-openwisp-monitoring/tests/test_utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,9 @@ function TestUtils.testDictMerge()
luaunit.assertEquals(utils.dict_merge({['1']='OpenWISP'},{['1']='NetJSON'}), {["1"]="OpenWISP"})
end

function TestUtils.testIsExcluded()
luaunit.assertEquals(utils.is_excluded('lo'), true)
luaunit.assertEquals(utils.is_excluded('wlo1'), false)
end

os.exit(luaunit.LuaUnit.run())
27 changes: 27 additions & 0 deletions openwrt-openwisp-monitoring/tests/test_wifi.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package.path = package.path .. ";../files/lib/openwisp/?.lua"

local wifi_data = require('test_files/wireless_data')

local luaunit = require('luaunit')
local wifi_functions = require('wifi')

TestWifi = {
setUp = function()
end,
tearDown = function()
end
}


function TestWifi.test_parse_hostapd_clients()
luaunit.assertEquals(wifi_functions.parse_hostapd_clients(wifi_data.wlan1_clients), wifi_data.parsed_clients)
luaunit.assertEquals(wifi_functions.parse_hostapd_clients(wifi_data.wlan0_clients), {})
end

function TestWifi.test_netjson_clients()
luaunit.assertEquals(wifi_functions.netjson_clients(wifi_data.wlan1_clients, false), wifi_data.parsed_clients)
luaunit.assertEquals(wifi_functions.netjson_clients(wifi_data.wlan0_clients, false), {})
end


os.exit( luaunit.LuaUnit.run() )
1 change: 1 addition & 0 deletions runtests
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ lua test_interfaces.lua -v
lua test_utils.lua -v
lua test_neighbors.lua -v
lua test_resources.lua -v
lua test_wifi.lua -v

0 comments on commit d8ec7a3

Please sign in to comment.