--- /dev/null
+*** Settings ***
+# Test Setup Http Setup
+Test Teardown Http Teardown
+Library Process
+Library ${TESTDIR}/lib/rspamd.py
+Resource ${TESTDIR}/lib/rspamd.robot
+Variables ${TESTDIR}/lib/vars.py
+
+*** Variables ***
+# ${CONFIG} ${TESTDIR}/configs/http.conf
+${URL_TLD} ${TESTDIR}/../lua/unit/test_tld.dat
+${CONFIG} ${TESTDIR}/configs/lua_test.conf
+${MESSAGE} ${TESTDIR}/messages/spam_message.eml
+${MESSAGE2} ${TESTDIR}/messages/freemail.eml
+${REDIS_SCOPE} Suite
+${RSPAMD_SCOPE} Suite
+
+*** Test Cases ***
+HTTP
+ Run Dummy Http
+ [Setup] Lua Setup ${TESTDIR}/lua/http.lua
+ ${result} = Scan Message With Rspamc ${MESSAGE}
+ Check Rspamc ${result} HTTP_DNS_200
+ Check Rspamc ${result} HTTP_200
+
+
+*** Keywords ***
+Lua Setup
+ [Arguments] ${LUA_SCRIPT}
+ Set Test Variable ${LUA_SCRIPT}
+ Generic Setup
+
+Http Teardown
+ ${http_pid} = Get File /tmp/dummy_http.pid
+ # Shutdown Process With Children ${http_pid}
+ Normal Teardown
+
+Run Dummy Http
+ [Arguments]
+ ${result} = Start Process ${TESTDIR}/util/dummy_http.py
+ Wait Until Created /tmp/dummy_http.pid
name = "example.com",
type = "a";
replies = ["93.184.216.34"];
+ }, {
+ name = "site.resolveme",
+ type = "a";
+ replies = ["127.0.0.1"];
}]
}
}
--- /dev/null
+local rspamd_http = require "rspamd_http"
+
+local function http_symbol(task)
+ local function http_callback(err, code, body)
+ task:insert_result('HTTP_' .. code, 1.0)
+ end
+
+ local function http_dns_callback(err, code, body)
+ task:insert_result('HTTP_DNS_' .. code, 1.0)
+ end
+
+ rspamd_http.request({
+ url = 'http://127.0.0.1:18080/request',
+ task = task,
+ method = 'post',
+ callback = http_callback,
+ })
+
+ --[[ request to this address involved DNS resolver subsystem ]]
+ rspamd_http.request({
+ url = 'http://site.resolveme:18080/request',
+ task = task,
+ method = 'post',
+ callback = http_dns_callback,
+ })
+end
+
+rspamd_config:register_symbol({
+ name = 'SIMPLE_TEST',
+ score = 1.0,
+ callback = http_symbol
+})
#!/usr/bin/env python
-
-PID = "/tmp/dummy_fprot.pid"
-
import os
import sys
+import signal
+
+
try:
import SocketServer as socketserver
except:
import socketserver
-import signal
+
+PID = "/tmp/dummy_fprot.pid"
class MyTCPHandler(socketserver.BaseRequestHandler):
--- /dev/null
+#!/usr/bin/env python
+
+import BaseHTTPServer
+import time
+import os
+import sys
+import signal
+
+PORT = 18080
+HOST_NAME = '127.0.0.1'
+
+PID = "/tmp/dummy_http.pid"
+
+
+class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler):
+
+ def do_HEAD(self):
+ self.send_response(200)
+ self.send_header("Content-type", "text/html")
+ self.end_headers()
+
+ def do_GET(self):
+ """Respond to a GET request."""
+ self.send_response(200)
+ self.send_header("Content-type", "text/plain")
+ self.end_headers()
+ self.wfile.write("hello world")
+
+ def do_POST(self):
+ """Respond to a GET request."""
+ self.send_response(200)
+ self.send_header("Content-type", "text/plain")
+ self.end_headers()
+ self.wfile.write("hello post")
+
+
+class MyHttp(BaseHTTPServer.HTTPServer):
+ def __init__(self, server_address, RequestHandlerClass, bind_and_activate=False):
+ BaseHTTPServer.HTTPServer.__init__(self, server_address, RequestHandlerClass, bind_and_activate)
+ self.keep_running = True
+
+ def run(self):
+ self.server_bind()
+ self.server_activate()
+
+ with open(PID, 'w+') as f:
+ f.write(str(os.getpid()))
+ f.close()
+
+ while self.keep_running:
+ try:
+ self.handle_request()
+ except Exception:
+ pass
+
+ def stop(self):
+ self.keep_running = False
+ self.server_close()
+
+
+if __name__ == '__main__':
+ server_class = BaseHTTPServer.HTTPServer
+ httpd = MyHttp((HOST_NAME, PORT), MyHandler)
+ httpd.allow_reuse_address = True
+ httpd.timeout = 1
+
+ def alarm_handler(signum, frame):
+ httpd.stop()
+
+ signal.signal(signal.SIGALRM, alarm_handler)
+ signal.signal(signal.SIGTERM, alarm_handler)
+ signal.alarm(5)
+
+ try:
+ httpd.run()
+ except KeyboardInterrupt:
+ pass
+ httpd.server_close()