commit ccf98c9: [Test] Add QP fuzz testing

Vsevolod Stakhov vsevolod at highsecure.ru
Mon Jul 22 14:49:09 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-07-22 15:45:37 +0100
URL: https://github.com/rspamd/rspamd/commit/ccf98c926f2ac03f8c117182f1db613de151c437 (HEAD -> master)

[Test] Add QP fuzz testing

---
 test/lua/unit/quoted_printable.lua | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

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)


More information about the Commits mailing list