diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-12-20 12:59:54 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-12-20 13:00:11 +0000 |
commit | a9beac22cea7a7053dd3b4081e9226441c7c5595 (patch) | |
tree | f6c4e415c4c3a356c587ed118770944f4ad11ef2 /test/lua | |
parent | 85370a6ce83c9bdf861d3377721952f5fbf8b8cd (diff) | |
download | rspamd-a9beac22cea7a7053dd3b4081e9226441c7c5595.tar.gz rspamd-a9beac22cea7a7053dd3b4081e9226441c7c5595.zip |
[Test] Add fuzz testing for rfc2047
Diffstat (limited to 'test/lua')
-rw-r--r-- | test/lua/unit/rfc2047.lua | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/test/lua/unit/rfc2047.lua b/test/lua/unit/rfc2047.lua index 15235f8af..9ddab000c 100644 --- a/test/lua/unit/rfc2047.lua +++ b/test/lua/unit/rfc2047.lua @@ -48,8 +48,36 @@ context("RFC2047 decoding", function() for _,c in ipairs(cases) do local res = ffi.C.rspamd_mime_header_decode(pool, c[1], #c[1]) res = ffi.string(res) - assert_equal(res, c[2], res .. " not equal " .. c[2]) assert_not_nil(res, "cannot decode " .. c[1]) + assert_equal(res, c[2], res .. " not equal " .. c[2]) + + end + + ffi.C.rspamd_mempool_delete(pool) + end) + test("Fuzz test for rfc2047 tokens", function() + local util = require("rspamd_util") + local pool = ffi.C.rspamd_mempool_new(4096, "lua") + local str = "Тест Тест Тест Тест Тест" + + for i = 0,1000 do + local r1 = math.random() + local r2 = math.random() + local sl1 = #str / 2.0 * r1 + local sl2 = #str / 2.0 * r2 + + local s1 = tostring(util.encode_base64(string.sub(str, 1, sl1))) + local s2 = tostring(util.encode_base64(string.sub(str, sl1 + 1, sl2))) + local s3 = tostring(util.encode_base64(string.sub(str, sl2 + 1))) + + if #s1 > 0 and #s2 > 0 and #s3 > 0 then + local s = string.format('=?UTF-8?B?%s?= =?UTF-8?B?%s?= =?UTF-8?B?%s?=', + s1, s2, s3) + local res = ffi.C.rspamd_mime_header_decode(pool, s, #s) + res = ffi.string(res) + assert_not_nil(res, "cannot decode " .. s) + assert_equal(res, str, res .. " not equal " .. str .. " on " .. tostring(i) .. " iteration") + end end ffi.C.rspamd_mempool_delete(pool) |