]> source.dussan.org Git - rspamd.git/commitdiff
[Test] Add map reload test 1057/head
authorAndrew Lewis <nerf@judo.za.org>
Wed, 19 Oct 2016 16:04:01 +0000 (18:04 +0200)
committerAndrew Lewis <nerf@judo.za.org>
Wed, 19 Oct 2016 16:04:01 +0000 (18:04 +0200)
test/functional/cases/125_map_reload.robot [new file with mode: 0644]
test/functional/configs/lua_test.conf
test/functional/configs/maps/domains.list.2 [new file with mode: 0644]
test/functional/lib/vars.py
test/functional/lua/mapreload.lua [new file with mode: 0644]

diff --git a/test/functional/cases/125_map_reload.robot b/test/functional/cases/125_map_reload.robot
new file mode 100644 (file)
index 0000000..82fa273
--- /dev/null
@@ -0,0 +1,48 @@
+*** Settings ***
+Suite Setup     Map Reload Setup
+Suite Teardown  Map Reload Teardown
+Library         ${TESTDIR}/lib/rspamd.py
+Resource        ${TESTDIR}/lib/rspamd.robot
+Variables       ${TESTDIR}/lib/vars.py
+
+*** Variables ***
+${CONFIG}       ${TESTDIR}/configs/lua_test.conf
+${MAP_WATCH_INTERVAL}  0.5s
+${MESSAGE}      ${TESTDIR}/messages/spam_message.eml
+${RSPAMD_SCOPE}  Suite
+${URL_TLD}      ${TESTDIR}/../lua/unit/test_tld.dat
+
+*** Test Cases ***
+CHECK HIT AND MISS
+  ${result} =  Scan Message With Rspamc  ${MESSAGE}
+  Check Rspamc  ${result}  MAP_SET_HIT_AND_MISS (1.00)[example.com]
+
+WRITE NEW MAP
+  Sleep  1s  Wait for new time
+  Create File  ${MAP_FILE}  ${MAP2}
+
+CHECK HIT AND MISS AFTER RELOAD
+  Sleep  1s  Wait for map reload
+  ${result} =  Scan Message With Rspamc  ${MESSAGE}
+  Check Rspamc  ${result}  MAP_SET_HIT_AND_MISS (1.00)[rspamd.com]
+
+*** Keywords ***
+Map Reload Setup
+  ${MAP1} =  Get File  ${TESTDIR}/configs/maps/domains.list
+  ${MAP2} =  Get File  ${TESTDIR}/configs/maps/domains.list.2
+  ${MAP_FILE} =  Make Temporary File
+  ${LUA_SCRIPT} =  Make Temporary File
+  Set Suite Variable  ${LUA_SCRIPT}
+  Set Suite Variable  ${MAP_FILE}
+  Set Suite Variable  ${MAP1}
+  Set Suite Variable  ${MAP2}
+  ${lua} =  Get File  ${TESTDIR}/lua/mapreload.lua
+  ${lua} =  Replace Variables  ${lua}
+  Create File  ${LUA_SCRIPT}  ${lua}
+  Create File  ${MAP_FILE}  ${MAP1}
+  Generic Setup
+
+Map Reload Teardown
+  Remove File  ${MAP_FILE}
+  Remove File  ${LUA_SCRIPT}
+  Normal Teardown
index 50ec330ed5e87466acca5a4a0a48f5b5b769ad7d..682609335117841070deaeee8f385d53d6b8ba2d 100644 (file)
@@ -2,6 +2,7 @@ options = {
        filters = ["spf", "dkim", "regexp"]
        url_tld = "${URL_TLD}"
        pidfile = "${TMPDIR}/rspamd.pid"
+       map_watch_interval = ${MAP_WATCH_INTERVAL};
 }
 logging = {
        type = "file",
diff --git a/test/functional/configs/maps/domains.list.2 b/test/functional/configs/maps/domains.list.2
new file mode 100644 (file)
index 0000000..850c640
--- /dev/null
@@ -0,0 +1,2 @@
+rspamd.com
+#other.com
index 3ba68fea38ab4dc804cb0cf123a7f266fd643bf9..a9d5e89f9037753d96924c69ec0d8133e52b3c19 100644 (file)
@@ -3,6 +3,7 @@ import socket
 KEY_PVT1 = 'ekd3x36tfa5gd76t6pa8hqif3ott7n1siuux68exbkk7ukscte9y'
 KEY_PUB1 = 'm8kneubpcjsb8sbsoj7jy7azj9fdd3xmj63txni86a8ye9ncomny'
 LOCAL_ADDR = u'127.0.0.1'
+MAP_WATCH_INTERVAL = '1min'
 PORT_CONTROLLER = 56790
 PORT_CONTROLLER_SLAVE = 56793
 PORT_FUZZY = 56791
diff --git a/test/functional/lua/mapreload.lua b/test/functional/lua/mapreload.lua
new file mode 100644 (file)
index 0000000..73c5d07
--- /dev/null
@@ -0,0 +1,16 @@
+local test_map = rspamd_config:add_map ({
+  url = '${MAP_FILE}',
+  type = 'set',
+})
+
+rspamd_config:register_symbol({
+  name = 'MAP_SET_HIT_AND_MISS',
+  score = 1.0,
+  callback = function(task)
+    if (test_map:get_key('example.com') and not test_map:get_key('rspamd.com')) then
+      return true, 'example.com'
+    elseif (test_map:get_key('rspamd.com') and not test_map:get_key('example.com')) then
+      return true, 'rspamd.com'
+    end
+  end
+})