diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-07-22 15:45:37 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-07-22 15:45:37 +0100 |
commit | ccf98c926f2ac03f8c117182f1db613de151c437 (patch) | |
tree | d6bf20a7540f3b173aef6614ca78b18f3bbb40b1 /test/lua | |
parent | b916a6f9bf99157cc7eb0224e17ce2e9dc3d1632 (diff) | |
download | rspamd-ccf98c926f2ac03f8c117182f1db613de151c437.tar.gz rspamd-ccf98c926f2ac03f8c117182f1db613de151c437.zip |
[Test] Add QP fuzz testing
Diffstat (limited to 'test/lua')
-rw-r--r-- | test/lua/unit/quoted_printable.lua | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/test/lua/unit/quoted_printable.lua b/test/lua/unit/quoted_printable.lua index 97c49877c..4756c632a 100644 --- a/test/lua/unit/quoted_printable.lua +++ b/test/lua/unit/quoted_printable.lua @@ -75,6 +75,13 @@ context("Quoted-Printable encoding", function() }, } for _,c in ipairs(cases) do + test("QP sanity test case: " .. c[3], function() + local res = { + expect = c[1], + actual = tostring(rspamd_util.decode_qp((rspamd_util.encode_qp(c[1], 76)))) + } + assert_rspamd_eq(res) + end) test("QP encoding test case: " .. c[3], function() local res = { expect = c[2], @@ -83,4 +90,31 @@ context("Quoted-Printable encoding", function() assert_rspamd_eq(res) end) end + + -- Fuzz testing + local charset = {} + for i = 0, 255 do table.insert(charset, string.char(i)) end + + local function random_string(length) + + if length > 0 then + return random_string(length - 1) .. charset[math.random(1, #charset)] + else + return "" + end + end + + + for _,l in ipairs({10, 100, 1000, 10000}) do + test("QP fuzz test max length " .. tostring(l), function() + for _=1,100 do + local inp = random_string(math.random() * l + 1) + local res = { + expect = inp, + actual = tostring(rspamd_util.decode_qp((rspamd_util.encode_qp(inp, 0)))) + } + assert_rspamd_eq(res) + end + end) + end end) |