]> source.dussan.org Git - rspamd.git/commitdiff
[Test] Add QP fuzz testing
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 22 Jul 2019 14:45:37 +0000 (15:45 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 22 Jul 2019 14:45:37 +0000 (15:45 +0100)
test/lua/unit/quoted_printable.lua

index 97c49877c1fdb455b1a8bf8afbb678f91330277b..4756c632a07ca0740d588300775e11de42ba7b5d 100644 (file)
@@ -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)