From: Vsevolod Stakhov Date: Sat, 3 Dec 2022 13:36:17 +0000 (+0000) Subject: [Test] Add external map test for multimap X-Git-Tag: 3.5~168 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=aa2b1b4ef6ca76b816c451401f5b35bf830652f3;p=thirdparty%2Frspamd.git [Test] Add external map test for multimap --- diff --git a/test/functional/cases/001_merged/102_multimap.robot b/test/functional/cases/001_merged/102_multimap.robot index 0312c750b3..f07cc1e253 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@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 diff --git a/test/functional/configs/merged-override.conf b/test/functional/configs/merged-override.conf index d25cce27b4..b589e7da9e 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 8de1b027bb..1fb7214137 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"