2015-01-14 12:33:52 +00:00
|
|
|
-- WIPF Log Tests
|
|
|
|
|
|
|
|
local sys = require"sys"
|
2015-01-20 10:16:56 +00:00
|
|
|
local sock = require"sys.sock"
|
2015-01-19 06:40:38 +00:00
|
|
|
|
2015-01-14 12:33:52 +00:00
|
|
|
local wipf = require"wipflua"
|
2015-01-26 03:08:04 +00:00
|
|
|
local i18n = require"wipf.util.i18n"
|
|
|
|
local util_conf = require"wipf.util.conf"
|
|
|
|
local util_fs = require"wipf.util.fs"
|
|
|
|
local util_ip = require"wipf.util.ip"
|
2015-01-14 12:33:52 +00:00
|
|
|
|
2015-01-15 06:33:52 +00:00
|
|
|
local mem, win32 = sys.mem, sys.win32
|
|
|
|
|
2015-01-14 12:33:52 +00:00
|
|
|
|
2015-01-16 11:11:59 +00:00
|
|
|
print"-- Log Read/Write"
|
2015-01-14 12:33:52 +00:00
|
|
|
do
|
2015-01-19 06:40:38 +00:00
|
|
|
local path = [[C:\test]]
|
|
|
|
assert(#path == 7)
|
2015-01-16 11:11:59 +00:00
|
|
|
|
2015-01-19 06:40:38 +00:00
|
|
|
local outlen = 12 + #path + 1
|
2015-01-14 12:33:52 +00:00
|
|
|
local bufsize = outlen + 4
|
2015-01-15 06:33:52 +00:00
|
|
|
local buf = assert(mem.pointer(bufsize))
|
2015-01-14 15:06:56 +00:00
|
|
|
|
2015-01-14 12:33:52 +00:00
|
|
|
buf:memset(0, bufsize)
|
|
|
|
buf[outlen] = 127
|
|
|
|
assert(wipf.log_write(buf:getptr(), 1, 2, path) == outlen)
|
|
|
|
assert(buf[outlen] == 127)
|
2015-01-14 15:06:56 +00:00
|
|
|
|
2015-01-15 06:33:52 +00:00
|
|
|
local inlen, ip, pid = wipf.log_read(buf:getptr())
|
|
|
|
assert(inlen == outlen and ip == 1 and pid == 2)
|
2015-01-14 15:06:56 +00:00
|
|
|
|
2015-01-14 12:33:52 +00:00
|
|
|
print("OK")
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2015-01-19 06:40:38 +00:00
|
|
|
print"-- Paths"
|
|
|
|
do
|
|
|
|
local path = [[C:\test]]
|
2015-01-20 14:48:43 +00:00
|
|
|
local dos_path = util_fs.path_to_dospath(path)
|
|
|
|
local win32_path = util_fs.dospath_to_path(dos_path)
|
2015-01-19 06:40:38 +00:00
|
|
|
assert(path == win32_path)
|
|
|
|
print("OK")
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2015-01-20 10:16:56 +00:00
|
|
|
print"-- IPv4 Conversions"
|
|
|
|
do
|
2015-01-25 09:45:23 +00:00
|
|
|
local _, err_line
|
|
|
|
_, err_line = util_ip.ip4range_to_numbers[[172.16.0.0/33]]
|
|
|
|
assert(err_line == 1)
|
|
|
|
_, err_line = util_ip.ip4range_to_numbers[[172.16.0.255/-16]]
|
|
|
|
assert(err_line == 1)
|
|
|
|
_, err_line = util_ip.ip4range_to_numbers[[10.0.0.32 - 10.0.0.24]]
|
|
|
|
assert(err_line == 1)
|
|
|
|
|
|
|
|
local from, to
|
|
|
|
from, to = util_ip.ip4range_to_numbers[[
|
2015-01-20 10:16:56 +00:00
|
|
|
172.16.0.0/20
|
|
|
|
192.168.0.0 - 192.168.255.255
|
|
|
|
]]
|
|
|
|
assert(from.n == 2 and to.n == 2)
|
|
|
|
assert(from[1] == sock.inet_pton("172.16.0.0", true))
|
|
|
|
assert(to[1] == sock.inet_pton("172.31.255.255", true))
|
|
|
|
assert(from[2] == sock.inet_pton("192.168.0.0", true))
|
|
|
|
assert(to[2] == sock.inet_pton("192.168.255.255", true))
|
2015-01-20 13:03:58 +00:00
|
|
|
|
2015-01-25 09:45:23 +00:00
|
|
|
-- merge ranges
|
|
|
|
from, to = util_ip.ip4range_to_numbers[[
|
|
|
|
10.0.0.0 - 10.0.0.255
|
|
|
|
10.0.0.64 - 10.0.0.128
|
|
|
|
10.0.0.128 - 10.0.2.0
|
|
|
|
]]
|
|
|
|
assert(from.n == 1 and to.n == 1)
|
|
|
|
assert(from[1] == sock.inet_pton("10.0.0.0", true))
|
|
|
|
assert(to[1] == sock.inet_pton("10.0.2.0", true))
|
|
|
|
|
2015-01-20 10:16:56 +00:00
|
|
|
print("OK")
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2015-01-19 06:40:38 +00:00
|
|
|
print"-- Conf Read/Write"
|
|
|
|
do
|
2015-01-20 15:39:20 +00:00
|
|
|
local conf = util_conf.new_conf()
|
2015-01-20 13:03:58 +00:00
|
|
|
|
2015-01-20 15:39:20 +00:00
|
|
|
conf:set_ip_include_all(true)
|
|
|
|
conf:set_ip_exclude_all(false)
|
2015-01-20 13:03:58 +00:00
|
|
|
|
2015-01-20 15:39:20 +00:00
|
|
|
conf:set_app_log_blocked(true)
|
2015-02-06 09:56:44 +00:00
|
|
|
conf:set_app_block_all(false)
|
2015-01-20 15:39:20 +00:00
|
|
|
conf:set_app_allow_all(false)
|
|
|
|
|
|
|
|
conf:set_ip_include""
|
|
|
|
conf:set_ip_exclude[[
|
2015-01-19 06:40:38 +00:00
|
|
|
10.0.0.0/24
|
|
|
|
127.0.0.0/24
|
|
|
|
169.254.0.0/16
|
|
|
|
172.16.0.0/20
|
|
|
|
192.168.0.0/16
|
|
|
|
]]
|
2015-01-20 13:03:58 +00:00
|
|
|
|
2015-01-20 15:39:20 +00:00
|
|
|
local app_group1 = util_conf.new_app_group()
|
|
|
|
app_group1:set_name("Base")
|
|
|
|
app_group1:set_enabled(true)
|
|
|
|
app_group1:set_block[[
|
|
|
|
System
|
|
|
|
]]
|
|
|
|
app_group1:set_allow[[
|
2015-02-03 06:41:02 +00:00
|
|
|
C:\Programs\Skype\Phone\Skype.exe
|
2015-02-06 10:33:16 +00:00
|
|
|
C:\Utils\Dev\Git\
|
2015-01-20 15:39:20 +00:00
|
|
|
]]
|
|
|
|
|
|
|
|
local app_group2 = util_conf.new_app_group()
|
|
|
|
app_group2:set_name("Browser")
|
|
|
|
app_group2:set_enabled(false)
|
|
|
|
app_group2:set_allow[[
|
2015-02-03 06:41:02 +00:00
|
|
|
C:\Utils\Firefox\Bin\firefox.exe
|
2015-01-20 15:39:20 +00:00
|
|
|
]]
|
|
|
|
|
|
|
|
conf:add_app_group(app_group1)
|
|
|
|
conf:add_app_group(app_group2)
|
|
|
|
|
2015-01-31 18:30:34 +00:00
|
|
|
local buf = assert(mem.pointer():alloc())
|
2015-01-20 15:39:20 +00:00
|
|
|
assert(conf:write(buf))
|
2015-01-19 06:40:38 +00:00
|
|
|
|
2015-02-01 08:34:35 +00:00
|
|
|
-- Parse buffer
|
|
|
|
local conf2 = util_conf.new_conf()
|
|
|
|
conf2:read(buf)
|
|
|
|
|
|
|
|
assert(conf:get_ip_include_all() == conf2:get_ip_include_all())
|
|
|
|
assert(conf:get_ip_exclude_all() == conf2:get_ip_exclude_all())
|
|
|
|
assert(conf:get_app_log_blocked() == conf2:get_app_log_blocked())
|
|
|
|
assert(conf:get_app_block_all() == conf2:get_app_block_all())
|
|
|
|
assert(conf:get_app_allow_all() == conf2:get_app_allow_all())
|
|
|
|
|
|
|
|
assert(conf2:get_ip_include() == "")
|
|
|
|
|
|
|
|
local ip_exclude = conf2:get_ip_exclude()
|
|
|
|
assert(ip_exclude ~= "")
|
|
|
|
|
|
|
|
local from_exc, to_exc = util_ip.ip4range_to_numbers(ip_exclude)
|
|
|
|
assert(from_exc.n == 5)
|
|
|
|
assert(from_exc[3] == sock.inet_pton("169.254.0.0", true))
|
|
|
|
assert(to_exc[3] == sock.inet_pton("169.254.255.255", true))
|
|
|
|
|
|
|
|
local conf2_app_group1 = conf2:get_app_groups()[1]
|
|
|
|
assert(app_group1:get_name() == conf2_app_group1:get_name())
|
|
|
|
assert(app_group1:get_enabled() == conf2_app_group1:get_enabled())
|
|
|
|
assert(conf2_app_group1:get_block() == "System\n")
|
2015-02-06 10:33:16 +00:00
|
|
|
assert(conf2_app_group1:get_allow():find("C:\\utils\\dev\\git\\\n", 1, true))
|
2015-02-01 08:34:35 +00:00
|
|
|
|
2015-02-13 11:56:28 +00:00
|
|
|
local conf_ptr = buf:getptr()
|
|
|
|
assert(not wipf.conf_ip_inrange(conf_ptr, 0, true))
|
|
|
|
assert(not wipf.conf_ip_inrange(conf_ptr, sock.inet_pton("9.255.255.255", true)))
|
|
|
|
assert(not wipf.conf_ip_inrange(conf_ptr, sock.inet_pton("11.0.0.0", true)))
|
|
|
|
assert(wipf.conf_ip_inrange(conf_ptr, sock.inet_pton("10.0.0.0", true)))
|
|
|
|
assert(wipf.conf_ip_inrange(conf_ptr, sock.inet_pton("169.254.100.100", true)))
|
|
|
|
assert(wipf.conf_ip_inrange(conf_ptr, sock.inet_pton("192.168.255.255", true)))
|
|
|
|
assert(not wipf.conf_ip_inrange(conf_ptr, sock.inet_pton("193.0.0.0", true)))
|
|
|
|
|
|
|
|
assert(wipf.conf_app_blocked(conf_ptr, "System"))
|
|
|
|
assert(not wipf.conf_app_blocked(conf_ptr, util_fs.path_to_dospath[[C:\programs\skype\phone\skype.exe]]))
|
|
|
|
assert(not wipf.conf_app_blocked(conf_ptr, util_fs.path_to_dospath[[C:\utils\dev\git\bin\git.exe]]))
|
2015-02-03 06:41:02 +00:00
|
|
|
|
2015-01-19 06:40:38 +00:00
|
|
|
print("OK")
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2015-01-21 09:59:17 +00:00
|
|
|
print"-- I18n"
|
|
|
|
do
|
|
|
|
local id = 'err_conf_iprange_inc'
|
|
|
|
local text = i18n.tr_fmt(id, 3)
|
|
|
|
assert(text ~= id)
|
|
|
|
print("OK")
|
|
|
|
end
|
|
|
|
|
|
|
|
|