From e9e0ee39de0c5ee1143edf495908820eb31e116a Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sat, 12 Nov 2022 15:53:56 +0000 Subject: [PATCH] [Test] Start write tests for external maps --- .../functional/cases/001_merged/101_lua.robot | 4 +++ .../cases/001_merged/__init__.robot | 25 ++++++++++++++++++- test/functional/lua/maps_kv.lua | 24 ++++++++++++++++++ test/functional/util/dummy_http.py | 3 +++ 4 files changed, 55 insertions(+), 1 deletion(-) diff --git a/test/functional/cases/001_merged/101_lua.robot b/test/functional/cases/001_merged/101_lua.robot index ac4f8677a..5d70feea2 100644 --- a/test/functional/cases/001_merged/101_lua.robot +++ b/test/functional/cases/001_merged/101_lua.robot @@ -44,3 +44,7 @@ Rule conditions Expect Symbol With Option ANY_A hello3 Expect Symbol With Option ANY_A hello1 Expect Symbol With Option ANY_A hello2 + +External Maps Simple + Scan File ${MESSAGE} Settings={symbols_enabled = [EXTERNAL_MAP]} + Expect Symbol With Exact Options EXTERNAL_MAP +hello \ No newline at end of file diff --git a/test/functional/cases/001_merged/__init__.robot b/test/functional/cases/001_merged/__init__.robot index 7f2c7bb43..350e27243 100644 --- a/test/functional/cases/001_merged/__init__.robot +++ b/test/functional/cases/001_merged/__init__.robot @@ -1,5 +1,5 @@ *** Settings *** -Suite Setup Rspamd Redis Setup +Suite Setup Multi Setup Suite Teardown Rspamd Redis Teardown Library ${RSPAMD_TESTDIR}/lib/rspamd.py Resource ${RSPAMD_TESTDIR}/lib/rspamd.robot @@ -13,3 +13,26 @@ ${RSPAMD_MAP_MAP} ${RSPAMD_TESTDIR}/configs/maps/map.list ${RSPAMD_RADIX_MAP} ${RSPAMD_TESTDIR}/configs/maps/ip2.list ${RSPAMD_REGEXP_MAP} ${RSPAMD_TESTDIR}/configs/maps/regexp.list ${RSPAMD_SCOPE} Suite + +*** Keywords *** +Multi Setup + Run Redis + Run Dummy Http + Run Dummy Https + Rspamd Setup + +Multi Teardown + Rspamd Teardown + ${http_pid} = Get File /tmp/dummy_http.pid + Shutdown Process With Children ${http_pid} + ${https_pid} = Get File /tmp/dummy_https.pid + Shutdown Process With Children ${https_pid} + Redis Teardown + +Run Dummy Http + ${result} = Start Process ${RSPAMD_TESTDIR}/util/dummy_http.py + Wait Until Created /tmp/dummy_http.pid + +Run Dummy Https + ${result} = Start Process ${RSPAMD_TESTDIR}/util/dummy_https.py ${RSPAMD_TESTDIR}/util/server.pem + Wait Until Created /tmp/dummy_https.pid \ No newline at end of file diff --git a/test/functional/lua/maps_kv.lua b/test/functional/lua/maps_kv.lua index a62d25ddd..0b1b535bf 100644 --- a/test/functional/lua/maps_kv.lua +++ b/test/functional/lua/maps_kv.lua @@ -1,5 +1,6 @@ local rspamd_ip = require 'rspamd_ip' local rspamd_logger = require 'rspamd_logger' +local lua_maps = require "lua_maps" local radix_map = rspamd_config:add_map ({ url = rspamd_env.RADIX_MAP, @@ -68,3 +69,26 @@ rspamd_config:register_symbol({ return true, 'no worry' end, }) + +local simple_ext_map = lua_maps.map_add_from_ucl({ + external = true, + backend = "http://localhost:18080/map-simple", + method = "body", + encode = "json", +}, '', 'external map') +rspamd_config:register_symbol({ + name = 'EXTERNAL_MAP', + score = 1.0, + callback = function(task) + local function cb(res, data, code) + if res then + task:insert_result('EXTERNAL_MAP', string.format('+%s', data)) + else + task:insert_result('EXTERNAL_MAP', string.format('-%s:%s', code, data)) + end + end + simple_ext_map:get_key({ + key = "value", + }, cb, task) + end, +}) diff --git a/test/functional/util/dummy_http.py b/test/functional/util/dummy_http.py index 4bec24119..c683d66a2 100755 --- a/test/functional/util/dummy_http.py +++ b/test/functional/util/dummy_http.py @@ -89,6 +89,9 @@ class MyHandler(http.server.BaseHTTPRequestHandler): if self.path == "/content-length": self.send_header("Content-Length", str(len(response))) + if self.path == "/map-simple": + response = "hello" + self.send_header("Content-type", "text/plain") self.end_headers() self.wfile.write(response) -- 2.39.5