aboutsummaryrefslogtreecommitdiffstats
path: root/test/lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-01-08 18:24:53 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-01-08 18:59:56 +0000
commitf22e29d1bf2b850ff79e5959a19df534744de75f (patch)
tree9349eebf580e1cb3445087221a4f845609c12baf /test/lua
parent5dcc6259674c783fc76ffde7789d3c76b9d49fee (diff)
downloadrspamd-f22e29d1bf2b850ff79e5959a19df534744de75f.tar.gz
rspamd-f22e29d1bf2b850ff79e5959a19df534744de75f.zip
[Test] Add tests, fix normalization algorithm
Diffstat (limited to 'test/lua')
-rw-r--r--test/lua/unit/url.lua28
1 files changed, 28 insertions, 0 deletions
diff --git a/test/lua/unit/url.lua b/test/lua/unit/url.lua
index de274425d..991c6d0d0 100644
--- a/test/lua/unit/url.lua
+++ b/test/lua/unit/url.lua
@@ -8,6 +8,7 @@ context("URL check functions", function()
ffi.cdef[[
void rspamd_url_init (const char *tld_file);
unsigned ottery_rand_range(unsigned top);
+ void rspamd_http_normalize_path_inplace(char *path, size_t len, size_t *nlen);
]]
local test_dir = string.gsub(debug.getinfo(1).source, "^@(.+/)[^/]+$", "%1")
@@ -119,4 +120,31 @@ context("URL check functions", function()
end
end
)
+ test("Normalize paths", function()
+ local cases = {
+ {"/././foo", "/foo"},
+ {"/a/b/c/./../../g", "/a/g"},
+ {"/./.foo", "/.foo"},
+ {"/foo/.", "/foo"},
+ {"/foo/./", "/foo"},
+ {"/foo/bar/..", "/foo"},
+ {"/foo/bar/../", "/foo/"},
+ {"/foo/..bar", "/foo/..bar"},
+ {"/foo/bar/../ton", "/foo/ton"},
+ {"/foo/bar/../ton/../../a", "/a"},
+ {"/foo/../../..", "/"},
+ {"/foo/../../../ton", "/ton"},
+ {"////../..", "/"},
+ }
+
+ for _,v in ipairs(cases) do
+ print(v[1])
+ local buf = ffi.new("uint8_t[?]", #v[1])
+ local sizbuf = ffi.new("size_t[1]")
+ ffi.copy(buf, v[1], #v[1])
+ ffi.C.rspamd_http_normalize_path_inplace(buf, #v[1], sizbuf)
+ local res = ffi.string(buf, tonumber(sizbuf[0]))
+ assert_equal(v[2], res, 'expected ' .. v[2] .. ' but got ' .. res .. ' in path ' .. v[1])
+ end
+ end)
end)