aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2020-04-10 12:45:26 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2020-04-10 12:45:26 +0100
commit5c54ca768bef91fbf0978077d0255698034b9480 (patch)
tree67eac95d0e9447e4fd7866858df58f939bb601fd
parentf943c725865cd70859efb765ce643434d87e3ff9 (diff)
downloadrspamd-5c54ca768bef91fbf0978077d0255698034b9480.tar.gz
rspamd-5c54ca768bef91fbf0978077d0255698034b9480.zip
[Test] Fix tests
-rw-r--r--test/lua/unit/base32.lua23
1 files changed, 12 insertions, 11 deletions
diff --git a/test/lua/unit/base32.lua b/test/lua/unit/base32.lua
index 07fe14129..a460b6575 100644
--- a/test/lua/unit/base32.lua
+++ b/test/lua/unit/base32.lua
@@ -5,42 +5,43 @@ context("Base32 encodning", function()
ffi.cdef[[
void ottery_rand_bytes(void *buf, size_t n);
unsigned ottery_rand_unsigned(void);
- unsigned char* rspamd_decode_base32 (const char *in, size_t inlen, size_t *outlen);
- char * rspamd_encode_base32 (const unsigned char *in, size_t inlen);
+ unsigned char* rspamd_decode_base32 (const char *in, size_t inlen, size_t *outlen, int how);
+ char * rspamd_encode_base32 (const unsigned char *in, size_t inlen, int how);
void g_free(void *ptr);
int memcmp(const void *a1, const void *a2, size_t len);
]]
-
+
local function random_buf(max_size)
local l = ffi.C.ottery_rand_unsigned() % max_size + 1
local buf = ffi.new("unsigned char[?]", l)
ffi.C.ottery_rand_bytes(buf, l)
-
+
return buf, l
end
-
+
test("Base32 encode test", function()
local cases = {
{'test123', 'wm3g84fg13cy'},
{'hello', 'em3ags7p'}
}
-
+
for _,c in ipairs(cases) do
- local b = ffi.C.rspamd_encode_base32(c[1], #c[1])
+ local b = ffi.C.rspamd_encode_base32(c[1], #c[1], 0)
local s = ffi.string(b)
ffi.C.g_free(b)
assert_equal(s, c[2], s .. " not equal " .. c[2])
end
end)
-
+
test("Base32 fuzz test", function()
for i = 1,1000 do
local b, l = random_buf(4096)
- local ben = ffi.C.rspamd_encode_base32(b, l)
+ local how = math.floor(math.random(3) - 1)
+ local ben = ffi.C.rspamd_encode_base32(b, l, how)
local bs = ffi.string(ben)
local nl = ffi.new("size_t [1]")
- local nb = ffi.C.rspamd_decode_base32(bs, #bs, nl)
-
+ local nb = ffi.C.rspamd_decode_base32(bs, #bs, nl, how)
+
local cmp = ffi.C.memcmp(b, nb, l)
ffi.C.g_free(ben)
ffi.C.g_free(nb)