]> source.dussan.org Git - rspamd.git/commitdiff
[Test] Add external map test for multimap
authorVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 3 Dec 2022 13:36:17 +0000 (13:36 +0000)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 3 Dec 2022 13:36:17 +0000 (13:36 +0000)
test/functional/cases/001_merged/102_multimap.robot
test/functional/configs/merged-override.conf
test/functional/util/dummy_http.py

index 0312c750b3af1f0a8f33331f02077f871eb55ed1..f07cc1e25346dae0be86d63316789c1864f2a2f8 100644 (file)
@@ -401,3 +401,13 @@ MAP - MULTISYMBOL DISABLED
   Scan File  ${MESSAGE}  Rcpt=user3@example.com
   ...   Settings={symbols_enabled = [RCPT_MAP_NOMULTISYM, SYM1]}
   Expect Symbol With Exact Options  RCPT_MAP_NOMULTISYM  user3@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
index d25cce27b4d02ddc8d6c08cb17e7624358f913b3..b589e7da9e6487544c7b257f2318d0f90854d5ae 100644 (file)
@@ -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 {
index 8de1b027bb61f85507c5d6a658d2fe9255d1e778..1fb721413728ca0c961d6d34ce637934199921f0 100755 (executable)
@@ -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"