]> source.dussan.org Git - rspamd.git/commitdiff
[Test] Start write tests for external maps
authorVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 12 Nov 2022 15:53:56 +0000 (15:53 +0000)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 19 Nov 2022 12:44:14 +0000 (12:44 +0000)
test/functional/cases/001_merged/101_lua.robot
test/functional/cases/001_merged/__init__.robot
test/functional/lua/maps_kv.lua
test/functional/util/dummy_http.py

index ac4f8677a9ba2633e91e0c9877426a95a16cc412..5d70feea2eb0877132eb532b43fe042b2ed56f37 100644 (file)
@@ -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
index 7f2c7bb430158e892f8e8644a6f2bb8ecdcb4b7f..350e272430507a555fd4fd2038ffe6277c0bc265 100644 (file)
@@ -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
index a62d25ddd67efc3ff40c984380ca56626256111f..0b1b535bfa4c4eb71da983bf47f0d4b035d6ca86 100644 (file)
@@ -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,
+})
index 4bec24119fd83785b7c5b3e8a2ff115153c8ef24..c683d66a2f71ad7594ee0268823f98129894def5 100755 (executable)
@@ -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)