commit 548f117: [Test] url-redirector
Andrew Lewis
nerf at judo.za.org
Tue Apr 13 19:35:04 UTC 2021
Author: Andrew Lewis
Date: 2021-04-13 14:06:36 +0100
URL: https://github.com/rspamd/rspamd/commit/548f11798641f7933f6e7b20a621f91f58ccc23e (refs/pull/3718/head)
[Test] url-redirector
---
test/functional/cases/162_url_redirector.robot | 51 ++++++++++++++++++++++++++
test/functional/configs/maps/redir.map | 3 ++
test/functional/configs/url_redirector.conf | 6 +++
test/functional/lib/rspamd.robot | 11 ++++++
test/functional/messages/redir.eml | 6 +++
test/functional/util/dummy_http.py | 19 ++++++++--
6 files changed, 93 insertions(+), 3 deletions(-)
diff --git a/test/functional/cases/162_url_redirector.robot b/test/functional/cases/162_url_redirector.robot
new file mode 100644
index 000000000..dd812b21e
--- /dev/null
+++ b/test/functional/cases/162_url_redirector.robot
@@ -0,0 +1,51 @@
+*** Settings ***
+Suite Setup Urlredirector Setup
+Suite Teardown Urlredirector Teardown
+Library Process
+Library ${TESTDIR}/lib/rspamd.py
+Resource ${TESTDIR}/lib/rspamd.robot
+Variables ${TESTDIR}/lib/vars.py
+
+*** Variables ***
+${CONFIG} ${TESTDIR}/configs/plugins.conf
+${MESSAGE} ${TESTDIR}/messages/redir.eml
+${REDIS_SCOPE} Suite
+${RSPAMD_SCOPE} Suite
+${SETTINGS} {symbols_enabled=[URL_REDIRECTOR_CHECK]}
+${URL_TLD} ${TESTDIR}/../../contrib/publicsuffix/effective_tld_names.dat
+
+*** Test Cases ***
+RESOLVE URLS
+ Scan File ${MESSAGE} Flags=ext_urls Settings=${SETTINGS}
+ Expect Extended URL http://127.0.0.1:18080/hello
+
+RESOLVE URLS CACHED
+ Stop Dummy Http
+ Scan File ${MESSAGE} Flags=ext_urls Settings=${SETTINGS}
+ Expect Extended URL http://127.0.0.1:18080/hello
+
+*** Keywords ***
+Urlredirector Setup
+ ${TMPDIR} = Make Temporary Directory
+ Set Suite Variable ${TMPDIR}
+ Set Suite Variable ${REDIS_TMPDIR} ${TMPDIR}
+ Run Redis
+ Run Dummy Http
+ ${PLUGIN_CONFIG} = Get File ${TESTDIR}/configs/url_redirector.conf
+ Set Suite Variable ${PLUGIN_CONFIG}
+ Generic Setup PLUGIN_CONFIG
+
+Urlredirector Teardown
+ Normal Teardown
+ Shutdown Process With Children ${REDIS_PID}
+ #Stop Dummy Http
+ Terminate All Processes kill=True
+ Cleanup Temporary Directory ${REDIS_TMPDIR}
+
+Stop Dummy Http
+ ${http_pid} = Get File /tmp/dummy_http.pid
+ Shutdown Process With Children ${http_pid}
+
+Run Dummy Http
+ ${result} = Start Process ${TESTDIR}/util/dummy_http.py
+ Wait Until Created /tmp/dummy_http.pid
diff --git a/test/functional/configs/maps/redir.map b/test/functional/configs/maps/redir.map
new file mode 100644
index 000000000..5b7eb38ba
--- /dev/null
+++ b/test/functional/configs/maps/redir.map
@@ -0,0 +1,3 @@
+t.co
+bit.ly
+127.0.0.1
diff --git a/test/functional/configs/url_redirector.conf b/test/functional/configs/url_redirector.conf
new file mode 100644
index 000000000..f61fa3086
--- /dev/null
+++ b/test/functional/configs/url_redirector.conf
@@ -0,0 +1,6 @@
+redis {
+ servers = "${REDIS_ADDR}:${REDIS_PORT}";
+}
+url_redirector {
+ redirector_hosts_map = "${TESTDIR}/configs/maps/redir.map";
+}
diff --git a/test/functional/lib/rspamd.robot b/test/functional/lib/rspamd.robot
index 0b6cc6f38..c52bcc51a 100644
--- a/test/functional/lib/rspamd.robot
+++ b/test/functional/lib/rspamd.robot
@@ -94,6 +94,17 @@ Expect URL
[Arguments] ${url}
List Should Contain Value ${SCAN_RESULT}[urls] ${url}
+Expect Extended URL
+ [Arguments] ${url}
+ ${found_url} = Set Variable ${FALSE}
+ ${url_list} = Convert To List ${SCAN_RESULT}[urls]
+ FOR ${item} IN @{url_list}
+ ${d} = Convert To Dictionary ${item}
+ ${found_url} = Evaluate "${d}[url]" == "${url}"
+ Exit For Loop If ${found_url} == ${TRUE}
+ END
+ Should Be True ${found_url} msg="Expected URL was not found: ${url}"
+
Expect Symbol With Exact Options
[Arguments] ${symbol} @{options}
Expect Symbol ${symbol}
diff --git a/test/functional/messages/redir.eml b/test/functional/messages/redir.eml
new file mode 100644
index 000000000..c5218022f
--- /dev/null
+++ b/test/functional/messages/redir.eml
@@ -0,0 +1,6 @@
+Content-type: text/plain
+
+bla http://127.0.0.1:18080/redirect2
+
+lol http://127.0.0.1:18080/redirect3
+
diff --git a/test/functional/util/dummy_http.py b/test/functional/util/dummy_http.py
index c05ee2d02..4bec24119 100755
--- a/test/functional/util/dummy_http.py
+++ b/test/functional/util/dummy_http.py
@@ -10,7 +10,7 @@ import time
import dummy_killer
PORT = 18080
-HOST_NAME = '127.0.0.1'
+HOST_NAME = '0.0.0.0'
PID = "/tmp/dummy_http.pid"
@@ -22,10 +22,23 @@ class MyHandler(http.server.BaseHTTPRequestHandler):
self.protocol_version = "HTTP/1.1" # allow connection: keep-alive
def do_HEAD(self):
- self.send_response(200)
+ if self.path == "/redirect1":
+ self.send_response(301)
+ self.send_header("Location", "http://127.0.0.1:"+str(PORT)+"/hello")
+ elif self.path == "/redirect2":
+ self.send_response(301)
+ self.send_header("Location", "http://127.0.0.1:"+str(PORT)+"/redirect1")
+ elif self.path == "/redirect3":
+ self.send_response(301)
+ self.send_header("Location", "http://127.0.0.1:"+str(PORT)+"/redirect4")
+ elif self.path == "/redirect4":
+ self.send_response(301)
+ self.send_header("Location", "http://127.0.0.1:"+str(PORT)+"/redirect3")
+ else:
+ self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()
- self.log_message("to be closed: " + self.close_connection)
+ self.log_message("to be closed: " + repr(self.close_connection))
def do_GET(self):
response = b"hello world"
More information about the Commits
mailing list