diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 21:30:40 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 21:30:40 +0000 |
commit | 133a45c109da5310add55824db21af5239951f93 (patch) | |
tree | ba6ac4c0a950a0dda56451944315d66409923918 /test/functional/lua/dns.lua | |
parent | Initial commit. (diff) | |
download | rspamd-133a45c109da5310add55824db21af5239951f93.tar.xz rspamd-133a45c109da5310add55824db21af5239951f93.zip |
Adding upstream version 3.8.1.upstream/3.8.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/functional/lua/dns.lua')
-rw-r--r-- | test/functional/lua/dns.lua | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/test/functional/lua/dns.lua b/test/functional/lua/dns.lua new file mode 100644 index 0000000..702b985 --- /dev/null +++ b/test/functional/lua/dns.lua @@ -0,0 +1,53 @@ +local rspamd_dns = require "rspamd_dns" +local logger = require "rspamd_logger" + +local function dns_sync_symbol(task) + local to_resolve = tostring(task:get_request_header('to-resolve')) + local is_ok, results = rspamd_dns.request({ + task = task, + type = 'a', + name = to_resolve , + }) + + logger.errx(task, "is_ok=%1, results=%2, results[1]=%3", is_ok, results, results[1]) + + if not is_ok then + task:insert_result('DNS_SYNC_ERROR', 1.0, results) + else + task:insert_result('DNS_SYNC', 1.0, tostring(results[1])) + end +end + +rspamd_config:register_symbol({ + name = 'SIMPLE_DNS_SYNC', + score = 1.0, + callback = dns_sync_symbol, + no_squeeze = true, + flags = 'coro', +}) + + +-- Async request +local function dns_symbol(task) + local function dns_cb(_, to_resolve, results, err) + logger.errx(task, "_=%1, to_resolve=%2, results=%3, err%4", _, to_resolve, results, err) + if err then + task:insert_result('DNS_ERROR', 1.0, err) + else + task:insert_result('DNS', 1.0, tostring(results[1])) + end + end + local to_resolve = tostring(task:get_request_header('to-resolve')) + + task:get_resolver():resolve_a({ + task = task, + name = to_resolve, + callback = dns_cb + }) +end + +rspamd_config:register_symbol({ + name = 'SIMPLE_DNS', + score = 1.0, + callback = dns_symbol, +})
\ No newline at end of file |