@@ -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 |
@@ -0,0 +1,3 @@ | |||
t.co | |||
bit.ly | |||
127.0.0.1 |
@@ -0,0 +1,6 @@ | |||
redis { | |||
servers = "${REDIS_ADDR}:${REDIS_PORT}"; | |||
} | |||
url_redirector { | |||
redirector_hosts_map = "${TESTDIR}/configs/maps/redir.map"; | |||
} |
@@ -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} |
@@ -0,0 +1,6 @@ | |||
Content-type: text/plain | |||
bla http://127.0.0.1:18080/redirect2 | |||
lol http://127.0.0.1:18080/redirect3 | |||
@@ -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" |