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.

redis_stat.lua 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. context("Redis statistics unit tests", function()
  2. local task = require("rspamd_task")
  3. local ffi = require("ffi")
  4. local rspamd_util = require("rspamd_util")
  5. ffi.cdef[[
  6. struct rspamd_statfile_config {
  7. const char *symbol;
  8. const char *label;
  9. void *opts;
  10. int is_spam;
  11. const char *backend;
  12. void *data;
  13. };
  14. unsigned long rspamd_redis_expand_object(const char *pattern,
  15. struct rspamd_statfile_config *stcf,
  16. struct rspamd_task *task,
  17. char **target);
  18. struct rspamd_task * rspamd_task_new(struct rspamd_worker *worker, struct rspamd_config *cfg);
  19. int rspamd_task_add_recipient (struct rspamd_task *task, const char *rcpt);
  20. int rspamd_task_add_sender (struct rspamd_task *task, const char *sender);
  21. ]]
  22. --[[
  23. test("Substitute redis values", function()
  24. local cases = {
  25. {"%s%l", "symbollabel"},
  26. {"%s%%", "symbol%"},
  27. {"%s%u", "symbol"},
  28. {"%s%W", "symbolW"},
  29. {"%r%l", "test@example.comlabel"},
  30. {"%f-from", "test@example.com-from"}
  31. }
  32. local config = {
  33. options = {
  34. filters = { 'spf', 'dkim', 'regexp' },
  35. url_tld = tld_file,
  36. dns = {
  37. nameserver = { '8.8.8.8' }
  38. },
  39. },
  40. logging = {
  41. type = 'console',
  42. level = 'debug'
  43. },
  44. metric = {
  45. name = 'default',
  46. actions = {
  47. reject = 100500,
  48. },
  49. unknown_weight = 1
  50. }
  51. }
  52. local cfg = rspamd_util.config_from_ucl(config)
  53. assert_not_nil(cfg)
  54. local stcf = ffi.new("struct rspamd_statfile_config",
  55. {symbol="symbol",label="label"})
  56. local t = ffi.C.rspamd_task_new(nil, cfg)
  57. assert_equal(ffi.C.rspamd_task_add_recipient(t, "Test <test@example.com>"), 1)
  58. assert_equal(ffi.C.rspamd_task_add_recipient(t, "Test1 <test1@example.com>"), 1)
  59. assert_equal(ffi.C.rspamd_task_add_sender(t, "Test <test@example.com>"), 1)
  60. for _,c in ipairs(cases) do
  61. local pbuf = ffi.new 'char *[1]'
  62. local sz = ffi.C.rspamd_redis_expand_object(c[1], stcf, t, pbuf)
  63. local s = ffi.string(pbuf[0])
  64. assert_equal(s, c[2])
  65. end
  66. end)
  67. --]]
  68. end)