commit 4f1f869: [Test] Add large https body test
Vsevolod Stakhov
vsevolod at highsecure.ru
Wed Aug 14 09:00:07 UTC 2019
Author: Vsevolod Stakhov
Date: 2019-08-14 09:56:06 +0100
URL: https://github.com/rspamd/rspamd/commit/4f1f869748207d12c2deda80e12aeb206ce37fcb (HEAD -> master)
[Test] Add large https body test
---
test/functional/cases/220_http.robot | 9 ++++
test/functional/lua/http.lua | 48 +++++++++++++++++++---
.../util/{dummy_http.py => dummy_https.py} | 26 ++++++++----
3 files changed, 71 insertions(+), 12 deletions(-)
diff --git a/test/functional/cases/220_http.robot b/test/functional/cases/220_http.robot
index b4292897e..acdb75431 100644
--- a/test/functional/cases/220_http.robot
+++ b/test/functional/cases/220_http.robot
@@ -35,6 +35,9 @@ HTTP empty response
Check url /empty get HTTP_ERROR HTTP_ERROR HTTP_CORO_DNS_ERROR HTTP_CORO_ERROR method_get IO read error: unexpected EOF
Check url /empty post HTTP_DNS_ERROR HTTP_ERROR HTTP_CORO_DNS_ERROR HTTP_CORO_ERROR method_post IO read error: unexpected EOF
+SSL Large HTTP request
+ ${result} = Scan Message With Rspamc ${MESSAGE}
+ Check Rspamc ${result} HTTP_SSL_LARGE
*** Keywords ***
Lua Setup
@@ -44,17 +47,23 @@ Lua Setup
Http Setup
Run Dummy Http
+ Run Dummy Https
Lua Setup ${TESTDIR}/lua/http.lua
Http Teardown
${http_pid} = Get File /tmp/dummy_http.pid
Shutdown Process With Children ${http_pid}
+ ${https_pid} = Get File /tmp/dummy_https.pid
+ Shutdown Process With Children ${https_pid}
Normal Teardown
Run Dummy Http
${result} = Start Process ${TESTDIR}/util/dummy_http.py
Wait Until Created /tmp/dummy_http.pid
+Run Dummy Https
+ ${result} = Start Process ${TESTDIR}/util/dummy_https.py ${TESTDIR}/util/server.pem
+ Wait Until Created /tmp/dummy_https.pid
Check url
[Arguments] ${url} ${method} @{expect_results}
diff --git a/test/functional/lua/http.lua b/test/functional/lua/http.lua
index 1981c8734..d0ed4e7b7 100644
--- a/test/functional/lua/http.lua
+++ b/test/functional/lua/http.lua
@@ -106,13 +106,51 @@ local function periodic(cfg, ev_base)
end
rspamd_config:register_symbol({
-name = 'SIMPLE_TEST',
-score = 1.0,
-callback = http_symbol,
-no_squeeze = true,
-flags = 'coro'
+ name = 'SIMPLE_TEST',
+ score = 1.0,
+ callback = http_symbol,
+ no_squeeze = true,
+ flags = 'coro'
})
+local function http_large_symbol(task)
+ if task:get_queue_id() == 'SSL Large HTTP request' then
+ local data = {}
+ for i = 1,2 do
+ local st = {}
+ for j=1,300000 do
+ st[j] = 't'
+ end
+ data[i] = table.concat(st)
+ end
+ data[#data + 1] = '\n'
+
+ local function http_callback(err, code, body)
+ if err then
+ rspamd_logger.errx('http_callback error: ' .. err)
+ task:insert_result('HTTP_ERROR', 1.0, err)
+ else
+ task:insert_result('HTTP_SSL_LARGE', 1.0)
+ end
+ end
+ rspamd_http.request({
+ url = 'https://127.0.0.1:18081/',
+ task = task,
+ method = 'post',
+ callback = http_callback,
+ timeout = 10,
+ body = data,
+ no_ssl_verify = true,
+ })
+ end
+end
+rspamd_config:register_symbol({
+ name = 'LARGE_TEST',
+ score = 1.0,
+ callback = http_large_symbol,
+ no_squeeze = true,
+ flags = 'coro'
+})
rspamd_config:register_finish_script(finish)
diff --git a/test/functional/util/dummy_http.py b/test/functional/util/dummy_https.py
similarity index 81%
copy from test/functional/util/dummy_http.py
copy to test/functional/util/dummy_https.py
index 614fced29..43c5d9122 100755
--- a/test/functional/util/dummy_http.py
+++ b/test/functional/util/dummy_https.py
@@ -4,16 +4,17 @@ import BaseHTTPServer
import SocketServer
import SimpleHTTPServer
import dummy_killer
+import ssl
import time
import os
import sys
import socket
-PORT = 18080
+PORT = 18081
HOST_NAME = '127.0.0.1'
-PID = "/tmp/dummy_http.pid"
+PID = "/tmp/dummy_https.pid"
class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler):
@@ -60,8 +61,15 @@ class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_POST(self):
- response = "hello post"
- """Respond to a GET request."""
+ """Respond to a POST request."""
+
+ content_length = int(self.headers['Content-Length'])
+ response = 'hello post'
+
+ if content_length > 0:
+ body = self.rfile.read(content_length)
+ response = "hello post: " + str(len(body))
+
if self.path == "/empty":
self.finish()
return
@@ -84,10 +92,14 @@ class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler):
class ThreadingSimpleServer(SocketServer.ThreadingMixIn,
BaseHTTPServer.HTTPServer):
- def __init__(self):
+ def __init__(self, certfile,
+ keyfile,):
self.allow_reuse_address = True
- self.timeout = 1
+ self.timeout = 10
BaseHTTPServer.HTTPServer.__init__(self, (HOST_NAME, PORT), MyHandler)
+ self.socket = ssl.wrap_socket (self.socket,
+ keyfile=keyfile,
+ certfile=certfile, server_side=True)
def run(self):
dummy_killer.write_pid(PID)
@@ -106,7 +118,7 @@ class ThreadingSimpleServer(SocketServer.ThreadingMixIn,
if __name__ == '__main__':
- server = ThreadingSimpleServer()
+ server = ThreadingSimpleServer(sys.argv[1], sys.argv[1])
dummy_killer.setup_killer(server, server.stop)
More information about the Commits
mailing list