]> source.dussan.org Git - rspamd.git/commitdiff
[Test] url-redirector 3718/head
authorAndrew Lewis <nerf@judo.za.org>
Tue, 13 Apr 2021 13:06:36 +0000 (14:06 +0100)
committerAndrew Lewis <nerf@judo.za.org>
Tue, 13 Apr 2021 13:06:36 +0000 (14:06 +0100)
test/functional/cases/162_url_redirector.robot [new file with mode: 0644]
test/functional/configs/maps/redir.map [new file with mode: 0644]
test/functional/configs/url_redirector.conf [new file with mode: 0644]
test/functional/lib/rspamd.robot
test/functional/messages/redir.eml [new file with mode: 0644]
test/functional/util/dummy_http.py

diff --git a/test/functional/cases/162_url_redirector.robot b/test/functional/cases/162_url_redirector.robot
new file mode 100644 (file)
index 0000000..dd812b2
--- /dev/null
@@ -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 (file)
index 0000000..5b7eb38
--- /dev/null
@@ -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 (file)
index 0000000..f61fa30
--- /dev/null
@@ -0,0 +1,6 @@
+redis {
+  servers = "${REDIS_ADDR}:${REDIS_PORT}";
+}
+url_redirector {
+  redirector_hosts_map = "${TESTDIR}/configs/maps/redir.map";
+}
index 0b6cc6f3853db525ce5ad23656bbbf11124deb49..c52bcc51aec50fc41baa2d072641dce06804f3c7 100644 (file)
@@ -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 (file)
index 0000000..c521802
--- /dev/null
@@ -0,0 +1,6 @@
+Content-type: text/plain
+
+bla http://127.0.0.1:18080/redirect2
+
+lol http://127.0.0.1:18080/redirect3
+
index c05ee2d0210f3cea81c055ce41e3da7963fa6acf..4bec24119fd83785b7c5b3e8a2ff115153c8ef24 100755 (executable)
@@ -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"