commit aa2b1b4: [Test] Add external map test for multimap

Vsevolod Stakhov vsevolod at rspamd.com
Sat Dec 3 13:42:06 UTC 2022


Author: Vsevolod Stakhov
Date: 2022-12-03 13:36:17 +0000
URL: https://github.com/rspamd/rspamd/commit/aa2b1b4ef6ca76b816c451401f5b35bf830652f3 (HEAD -> master)

[Test] Add external map test for multimap

---
 .../functional/cases/001_merged/102_multimap.robot | 10 ++++++++
 test/functional/configs/merged-override.conf       | 10 ++++++++
 test/functional/util/dummy_http.py                 | 28 ++++++++++++++++++----
 3 files changed, 43 insertions(+), 5 deletions(-)

diff --git a/test/functional/cases/001_merged/102_multimap.robot b/test/functional/cases/001_merged/102_multimap.robot
index 0312c750b..f07cc1e25 100644
--- a/test/functional/cases/001_merged/102_multimap.robot
+++ b/test/functional/cases/001_merged/102_multimap.robot
@@ -401,3 +401,13 @@ MAP - MULTISYMBOL DISABLED
   Scan File  ${MESSAGE}  Rcpt=user3 at example.com
   ...   Settings={symbols_enabled = [RCPT_MAP_NOMULTISYM, SYM1]}
   Expect Symbol With Exact Options  RCPT_MAP_NOMULTISYM  user3 at example.com  SYM1
+
+MAP - EXTERNAL
+  Scan File  ${MESSAGE}  IP=127.0.0.1  Hostname=example.com.au
+  ...   Settings={symbols_enabled = [EXTERNAL_MULTIMAP]}
+  Expect Symbol  EXTERNAL_MULTIMAP
+
+MAP - EXTERNAL MISS
+  Scan File  ${MESSAGE}  IP=127.0.0.1  Hostname=example.com.bg
+  ...   Settings={symbols_enabled = [EXTERNAL_MULTIMAP]}
+  Do Not Expect Symbol  EXTERNAL_MULTIMAP
diff --git a/test/functional/configs/merged-override.conf b/test/functional/configs/merged-override.conf
index d25cce27b..b589e7da9 100644
--- a/test/functional/configs/merged-override.conf
+++ b/test/functional/configs/merged-override.conf
@@ -237,6 +237,16 @@ multimap {
     }
     expression = "from || ip"
   }
+
+  EXTERNAL_MULTIMAP {
+      type = "hostname";
+      filter = "top";
+      map = {
+        external = true;
+        backend = "http://127.0.0.1:18080/map-query",
+        method = "query",
+      }
+  }
 }
 
 rbl {
diff --git a/test/functional/util/dummy_http.py b/test/functional/util/dummy_http.py
index 8de1b027b..1fb721413 100755
--- a/test/functional/util/dummy_http.py
+++ b/test/functional/util/dummy_http.py
@@ -6,6 +6,7 @@ import socket
 import socketserver
 import sys
 import time
+from urllib.parse import urlparse, parse_qs
 
 import dummy_killer
 
@@ -40,21 +41,30 @@ class MyHandler(http.server.BaseHTTPRequestHandler):
     def do_GET(self):
         """Respond to a GET request."""
         response = b"hello world"
+        url = urlparse(self.path)
+        self.path = url.path
+
         if self.path == "/empty":
             self.finish()
             return
 
         if self.path == "/timeout":
             time.sleep(2)
-
-        if self.path == "/error_403":
+        elif self.path == "/error_403":
             self.send_response(403)
+        elif self.path == "/map-query":
+            query = parse_qs(url.query)
+            self.log_message('query=%s', query)
+            if query['key'][0] == 'au':
+                response = b"1.0"
+                self.send_response(200)
+            else:
+                response = b""
+                self.send_response(404)
         else:
             self.send_response(200)
 
-        if self.path == "/content-length":
-            self.send_header("Content-Length", str(len(response)))
-
+        self.send_header("Content-Length", str(len(response)))
         self.send_header("Content-type", "text/plain")
         self.end_headers()
         self.wfile.write(response)
@@ -72,6 +82,8 @@ class MyHandler(http.server.BaseHTTPRequestHandler):
         response = b"hello post"
         content_length = int(self.headers.get('Content-Length', "0")) or 0
         content_type = "text/plain"
+        url = urlparse(self.path)
+        self.path = url.path
         if content_length > 0:
             _ = self.rfile.read(content_length)
         if self.path == "/empty":
@@ -87,6 +99,12 @@ class MyHandler(http.server.BaseHTTPRequestHandler):
             self.send_response(200)
         if self.path == "/map-simple":
             response = b"hello map"
+        if self.path == "/map-query":
+            query = parse_qs(url.query)
+            if query['key'] == 'au':
+                response = b"hit"
+            else:
+                self.send_response(404)
         if self.path == "/settings":
             response = b"{\"actions\": { \"reject\": 1.0}, \"symbols\": { \"EXTERNAL_SETTINGS\": 1.0 }}"
             content_type = "application/json"


More information about the Commits mailing list