From f22e29d1bf2b850ff79e5959a19df534744de75f Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sun, 8 Jan 2017 18:24:53 +0000 Subject: [Test] Add tests, fix normalization algorithm --- test/lua/unit/url.lua | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'test/lua') 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) -- cgit v1.2.3