commit df56dd4: [Test] Add test case for settings in the external map

Vsevolod Stakhov vsevolod at rspamd.com
Sun Nov 27 23:14:05 UTC 2022


Author: Vsevolod Stakhov
Date: 2022-11-27 23:09:55 +0000
URL: https://github.com/rspamd/rspamd/commit/df56dd4dc0b286dd8b28ffe05ca5b4722caee89d (HEAD -> master)

[Test] Add test case for settings in the external map

---
 test/functional/cases/108_settings.robot | 11 +++++++++++
 test/functional/configs/settings.conf    | 16 ++++++++++++++++
 test/functional/util/dummy_http.py       |  2 +-
 3 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/test/functional/cases/108_settings.robot b/test/functional/cases/108_settings.robot
index e7f4213a5..240dd6e66 100644
--- a/test/functional/cases/108_settings.robot
+++ b/test/functional/cases/108_settings.robot
@@ -246,6 +246,10 @@ SETTINGS ID - VIRTUAL DEP
   Do Not Expect Symbol  SIMPLE_POST
   Do Not Expect Symbol  SIMPLE_PRE
 
+SETTINGS ID - EXTERNAL MAP
+  Scan File  ${MESSAGE}  Settings-Id=external
+  Expect Symbol  EXTERNAL_SETTINGS
+
 PRIORITY
   Scan File  ${MESSAGE_PRIORITY}  Settings-Id=id_virtual_group  From=user at test.com
   Expect Symbol  PRIORITY_2
@@ -255,8 +259,15 @@ PRIORITY
 Settings Setup
   Copy File  ${RSPAMD_TESTDIR}/data/bayes.spam.sqlite3  /tmp/bayes.spam.sqlite3
   Copy File  ${RSPAMD_TESTDIR}/data/bayes.ham.sqlite3  /tmp/bayes.ham.sqlite3
+  Run Dummy Http
   Rspamd Setup
 
 Settings Teardown
   Rspamd Teardown
+  ${http_pid} =  Get File  /tmp/dummy_http.pid
+  Shutdown Process With Children  ${http_pid}
   Remove Files  /tmp/bayes.spam.sqlite3  /tmp/bayes.ham.sqlite3
+
+Run Dummy Http
+  ${result} =  Start Process  ${RSPAMD_TESTDIR}/util/dummy_http.py
+  Wait Until Created  /tmp/dummy_http.pid
diff --git a/test/functional/configs/settings.conf b/test/functional/configs/settings.conf
index b7166ab3b..7bcc58a1d 100644
--- a/test/functional/configs/settings.conf
+++ b/test/functional/configs/settings.conf
@@ -82,6 +82,22 @@ settings {
       groups_enabled = [];
     }
   }
+
+  external {
+    disabled = true
+    external_map = {
+      map = {
+        backend = "http://127.0.0.1:18080/settings";
+        external = true;
+        method = "body";
+        encode = "json";
+      }
+      selector = "id('from');from('mime')";
+    }
+    register_symbols = {
+      EXTERNAL_SETTINGS = { score = 1.0 }
+    }
+  }
 }
 
 classifier {
diff --git a/test/functional/util/dummy_http.py b/test/functional/util/dummy_http.py
index 92b538845..8de1b027b 100755
--- a/test/functional/util/dummy_http.py
+++ b/test/functional/util/dummy_http.py
@@ -88,7 +88,7 @@ class MyHandler(http.server.BaseHTTPRequestHandler):
         if self.path == "/map-simple":
             response = b"hello map"
         if self.path == "/settings":
-            response = b"{\"actions\": { \"reject\": 1.0}}"
+            response = b"{\"actions\": { \"reject\": 1.0}, \"symbols\": { \"EXTERNAL_SETTINGS\": 1.0 }}"
             content_type = "application/json"
 
         self.send_header("Content-Length", str(len(response)))


More information about the Commits mailing list