summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMikhail Galanin <mgalanin@mimecast.com>2018-09-12 09:01:31 +0100
committerMikhail Galanin <mgalanin@mimecast.com>2018-09-12 09:01:31 +0100
commit22aeb02b7a4ae4c6049b43e21143b1412aa394bd (patch)
tree3402ed85dc00aad0ee785fddbac967c7610ee8b7
parentf0fb847f68543f35257513c6433638f2496ef75b (diff)
downloadrspamd-22aeb02b7a4ae4c6049b43e21143b1412aa394bd.tar.gz
rspamd-22aeb02b7a4ae4c6049b43e21143b1412aa394bd.zip
[Test] Added test for DNS api
-rw-r--r--test/functional/cases/250_dns.robot36
-rw-r--r--test/functional/configs/lua_test.conf4
-rw-r--r--test/functional/lua/dns.lua52
3 files changed, 92 insertions, 0 deletions
diff --git a/test/functional/cases/250_dns.robot b/test/functional/cases/250_dns.robot
new file mode 100644
index 000000000..c19f473e9
--- /dev/null
+++ b/test/functional/cases/250_dns.robot
@@ -0,0 +1,36 @@
+*** Settings ***
+Test Setup Http Setup
+Test Teardown Http Teardown
+Library Process
+Library ${TESTDIR}/lib/rspamd.py
+Resource ${TESTDIR}/lib/rspamd.robot
+Variables ${TESTDIR}/lib/vars.py
+
+*** Variables ***
+${URL_TLD} ${TESTDIR}/../lua/unit/test_tld.dat
+${CONFIG} ${TESTDIR}/configs/lua_test.conf
+${MESSAGE} ${TESTDIR}/messages/spam_message.eml
+${RSPAMD_SCOPE} Test
+
+*** Test Cases ***
+Simple DNS request
+ ${result} = Scan Message With Rspamc --header=to-resolve:example.com ${MESSAGE}
+ Check Rspamc ${result} DNS_SYNC (0.00)[93.184.216.34]
+ Check Rspamc ${result} DNS (0.00)[93.184.216.34]
+
+Faulty DNS request
+ ${result} = Scan Message With Rspamc --header=to-resolve:not-resolvable.com ${MESSAGE}
+ Check Rspamc ${result} DNS_SYNC_ERROR (0.00)[requested record is not found]
+ Check Rspamc ${result} DNS_ERROR (0.00)[requested record is not found]
+
+*** Keywords ***
+Lua Setup
+ [Arguments] ${LUA_SCRIPT}
+ Set Global Variable ${LUA_SCRIPT}
+ Generic Setup
+
+Http Setup
+ Lua Setup ${TESTDIR}/lua/dns.lua
+
+Http Teardown
+ Normal Teardown
diff --git a/test/functional/configs/lua_test.conf b/test/functional/configs/lua_test.conf
index af84a1578..949fd00f2 100644
--- a/test/functional/configs/lua_test.conf
+++ b/test/functional/configs/lua_test.conf
@@ -14,6 +14,10 @@ options = {
name = "site.resolveme",
type = "a";
replies = ["127.0.0.1"];
+ }, {
+ name = "not-resolvable.com",
+ type = "a";
+ rcode = 'norec';
}]
}
}
diff --git a/test/functional/lua/dns.lua b/test/functional/lua/dns.lua
new file mode 100644
index 000000000..dca9d5b1e
--- /dev/null
+++ b/test/functional/lua/dns.lua
@@ -0,0 +1,52 @@
+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
+})
+
+
+-- 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