From: Vsevolod Stakhov Date: Mon, 22 Jul 2019 14:45:37 +0000 (+0100) Subject: [Test] Add QP fuzz testing X-Git-Tag: 2.0~515 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ccf98c926f2ac03f8c117182f1db613de151c437;p=thirdparty%2Frspamd.git [Test] Add QP fuzz testing --- diff --git a/test/lua/unit/quoted_printable.lua b/test/lua/unit/quoted_printable.lua index 97c49877c1..4756c632a0 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)