mirror of
https://github.com/koreader/koreader
synced 2024-11-13 19:11:25 +00:00
17a4aa962f
* Bump base includes: koreader/koreader-base#1691 koreader/koreader-base#1692 koreader/koreader-base#1689 koreader/koreader-base#1690 koreader/koreader-base#1693 * Integrate decoding of SSIDs within wpa_supplicant The UTF-8 decoding of SSIDs is specific to wpa_supplicant. In this patch, we move all of this decoding logic to the wpa_supplicant module. We expose the raw bytes of the SSID to the NetworkMgr code, and make sure to always fix bad UTF-8 before we display the SSID to the user. Within the wpa_supplicant module, we replace the call to the wpa_passphrase binary to get the PSK with a direct function call to OpenSSL. This allows us to calculate the PSK over any arbitrary bytes, including UTF-8. In the same vein, we use the hex-encoded SSID to communicate with wpa_supplicant when setting up the network to support arbitrary bytes in the SSID. Unfortunately, we also remove the tests, as there is no way to unit test local functions.
82 lines
2.7 KiB
Lua
82 lines
2.7 KiB
Lua
describe("network_manager module", function()
|
|
local Device
|
|
local turn_on_wifi_called
|
|
local turn_off_wifi_called
|
|
local obtain_ip_called
|
|
local release_ip_called
|
|
|
|
local function clearState()
|
|
G_reader_settings:saveSetting("auto_restore_wifi", true)
|
|
turn_on_wifi_called = 0
|
|
turn_off_wifi_called = 0
|
|
obtain_ip_called = 0
|
|
release_ip_called = 0
|
|
end
|
|
|
|
setup(function()
|
|
require("commonrequire")
|
|
Device = require("device")
|
|
function Device:initNetworkManager(NetworkMgr)
|
|
function NetworkMgr:turnOnWifi(callback)
|
|
turn_on_wifi_called = turn_on_wifi_called + 1
|
|
if callback then
|
|
callback()
|
|
end
|
|
end
|
|
function NetworkMgr:turnOffWifi(callback)
|
|
turn_off_wifi_called = turn_off_wifi_called + 1
|
|
if callback then
|
|
callback()
|
|
end
|
|
end
|
|
function NetworkMgr:obtainIP(callback)
|
|
obtain_ip_called = obtain_ip_called + 1
|
|
if callback then
|
|
callback()
|
|
end
|
|
end
|
|
function NetworkMgr:releaseIP(callback)
|
|
release_ip_called = release_ip_called + 1
|
|
if callback then
|
|
callback()
|
|
end
|
|
end
|
|
function NetworkMgr:restoreWifiAsync()
|
|
self:turnOnWifi()
|
|
self:obtainIP()
|
|
end
|
|
end
|
|
function Device:hasWifiRestore()
|
|
return true
|
|
end
|
|
end)
|
|
|
|
it("should restore wifi in init if wifi was on", function()
|
|
package.loaded["ui/network/manager"] = nil
|
|
clearState()
|
|
G_reader_settings:saveSetting("wifi_was_on", true)
|
|
local network_manager = require("ui/network/manager") --luacheck: ignore
|
|
assert.is.same(turn_on_wifi_called, 1)
|
|
assert.is.same(turn_off_wifi_called, 0)
|
|
assert.is.same(obtain_ip_called, 1)
|
|
assert.is.same(release_ip_called, 0)
|
|
end)
|
|
|
|
it("should not restore wifi in init if wifi was off", function()
|
|
package.loaded["ui/network/manager"] = nil
|
|
clearState()
|
|
G_reader_settings:saveSetting("wifi_was_on", false)
|
|
local network_manager = require("ui/network/manager") --luacheck: ignore
|
|
assert.is.same(turn_on_wifi_called, 0)
|
|
assert.is.same(turn_off_wifi_called, 0)
|
|
assert.is.same(obtain_ip_called, 0)
|
|
assert.is.same(release_ip_called, 0)
|
|
end)
|
|
|
|
teardown(function()
|
|
function Device:initNetworkManager() end
|
|
function Device:hasWifiRestore() return false end
|
|
package.loaded["ui/network/manager"] = nil
|
|
end)
|
|
end)
|