Rapid spam filtering system https://rspamd.com/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

161 lines
4.0 KiB

  1. context("Task processing", function()
  2. local fun = require("fun")
  3. local rspamd_task = require("rspamd_task")
  4. test("Process a simple task", function()
  5. --local cfg = rspamd_util.config_from_ucl(config)
  6. --assert_not_nil(cfg)
  7. local msg = [[
  8. From: <>
  9. To: <nobody@example.com>
  10. Subject: test
  11. Content-Type: text/plain
  12. Test.
  13. ]]
  14. local res,task = rspamd_task.load_from_string(msg)
  15. assert_true(res, "failed to load message")
  16. task:process_message()
  17. task:destroy()
  18. end)
  19. local hdrs = [[
  20. From: <>
  21. To: <nobody@example.com>
  22. Subject: test
  23. ]]
  24. local mpart = [[
  25. Content-Type: multipart/mixed; boundary=XXX
  26. ]]
  27. local body = [[
  28. Content-Type: text/html
  29. Content-Transfer-Encoding: quoted-printable
  30. <html>
  31. <body>
  32. =0DAttached is your new documents.
  33. <br>
  34. <a href=3D"http://evil.com/Information/">http:=
  35. //example.com/privacy/XXX/YYY_April_25_2019.doc</a>
  36. <br>
  37. <br>
  38. <br>
  39. Thank you,
  40. <br>
  41. <b>Haloclaims.co</b>
  42. </body></html>
  43. ]]
  44. test("Process mime nesting: simple", function()
  45. local msg = hdrs .. body
  46. local res,task = rspamd_task.load_from_string(msg)
  47. assert_true(res, "failed to load message")
  48. task:process_message()
  49. assert_rspamd_table_eq_sorted({actual = fun.totable(fun.map(function(u)
  50. return u:get_host()
  51. end, task:get_urls())), expect = {
  52. 'evil.com', 'example.com'
  53. }})
  54. task:destroy()
  55. end)
  56. test("Process mime nesting: multipart", function()
  57. local msg = table.concat{
  58. hdrs, mpart, '\n', '--XXX\n', body, '\n--XXX--\n'
  59. }
  60. local res,task = rspamd_task.load_from_string(msg)
  61. assert_true(res, "failed to load message")
  62. task:process_message()
  63. assert_rspamd_table_eq_sorted({
  64. actual = fun.totable(fun.map(function(u)
  65. return u:get_host()
  66. end, task:get_urls())),
  67. expect = {
  68. 'evil.com', 'example.com'
  69. }})
  70. task:destroy()
  71. end)
  72. test("Process mime nesting: multipart, broken", function()
  73. local msg = table.concat{
  74. hdrs, mpart, '\n', '--XXX\n', 'garbadge\n', '\n--XXX--\n', '--XXX\n', body
  75. }
  76. local res,task = rspamd_task.load_from_string(msg)
  77. assert_true(res, "failed to load message")
  78. task:process_message()
  79. assert_rspamd_table_eq_sorted({
  80. actual = fun.totable(fun.map(function(u)
  81. return u:get_host()
  82. end, task:get_urls())),
  83. expect = {
  84. 'evil.com', 'example.com'
  85. }})
  86. task:destroy()
  87. end)
  88. test("Process mime nesting: message", function()
  89. local msg = table.concat{
  90. hdrs, 'Content-Type: message/rfc822\n', '\n', hdrs, body
  91. }
  92. local res,task = rspamd_task.load_from_string(msg)
  93. assert_true(res, "failed to load message")
  94. task:process_message()
  95. assert_rspamd_table_eq_sorted({
  96. actual = fun.totable(fun.map(function(u)
  97. return u:get_host()
  98. end, task:get_urls())),
  99. expect = {
  100. 'evil.com', 'example.com'
  101. }})
  102. task:destroy()
  103. end)
  104. test("Process mime nesting: message in multipart", function()
  105. local msg = table.concat{
  106. hdrs, mpart, '\n',
  107. '--XXX\n',
  108. 'Content-Type: message/rfc822\n', '\n', hdrs, body ,
  109. '\n--XXX--\n',
  110. }
  111. local res,task = rspamd_task.load_from_string(msg)
  112. assert_true(res, "failed to load message")
  113. task:process_message()
  114. assert_rspamd_table_eq_sorted({
  115. actual = fun.totable(fun.map(function(u)
  116. return u:get_host()
  117. end, task:get_urls())),
  118. expect = {
  119. 'evil.com', 'example.com'
  120. }})
  121. task:destroy()
  122. end)
  123. test("Process mime nesting: multipart message in multipart", function()
  124. local msg = table.concat{
  125. hdrs, mpart, '\n',
  126. '--XXX\n',
  127. 'Content-Type: message/rfc822\n', '\n', hdrs, mpart, '\n',
  128. '--XXX\n',
  129. body ,
  130. '\n--XXX--\n',
  131. '\n--XXX--\n',
  132. }
  133. local res,task = rspamd_task.load_from_string(msg)
  134. assert_true(res, "failed to load message")
  135. task:process_message()
  136. assert_rspamd_table_eq_sorted({
  137. actual = fun.totable(fun.map(function(u)
  138. return u:get_host()
  139. end, task:get_urls())),
  140. expect = {
  141. 'evil.com', 'example.com'
  142. }})
  143. task:destroy()
  144. end)
  145. end)