]> source.dussan.org Git - rspamd.git/commitdiff
[Test] Add large https body test
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 14 Aug 2019 08:56:06 +0000 (09:56 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 14 Aug 2019 08:56:06 +0000 (09:56 +0100)
test/functional/cases/220_http.robot
test/functional/lua/http.lua
test/functional/util/dummy_https.py [new file with mode: 0755]

index b4292897e765a9e02c396884707c5d5ea4c1d0b8..acdb754314672b6e9137ef11da5f5c839b9948a4 100644 (file)
@@ -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}
index 1981c873426c22103564e63ac7204edb9b05a04f..d0ed4e7b7f661a1edd8a01d9e55e9043cf61a44b 100644 (file)
@@ -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_https.py b/test/functional/util/dummy_https.py
new file mode 100755 (executable)
index 0000000..43c5d91
--- /dev/null
@@ -0,0 +1,125 @@
+#!/usr/bin/env python
+
+import BaseHTTPServer
+import SocketServer
+import SimpleHTTPServer
+import dummy_killer
+import ssl
+
+import time
+import os
+import sys
+import socket
+
+PORT = 18081
+HOST_NAME = '127.0.0.1'
+
+PID = "/tmp/dummy_https.pid"
+
+
+class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler):
+
+    def setup(self):
+        BaseHTTPServer.BaseHTTPRequestHandler.setup(self)
+        self.protocol_version = "HTTP/1.1" # allow connection: keep-alive
+
+    def do_HEAD(self):
+        self.send_response(200)
+        self.send_header("Content-type", "text/html")
+        self.end_headers()
+        self.log_message("to be closed: " + self.close_connection)
+
+    def do_GET(self):
+        response = "hello world"
+
+        """Respond to a GET request."""
+        if self.path == "/empty":
+            self.finish()
+            return
+
+        if self.path == "/timeout":
+            time.sleep(2)
+
+        if self.path == "/error_403":
+            self.send_response(403)
+        else:
+            self.send_response(200)
+
+        if self.path == "/content-length":
+            self.send_header("Content-Length", str(len(response)))
+
+        self.send_header("Content-type", "text/plain")
+        self.end_headers()
+        self.wfile.write(response)
+        self.log_message("to be closed: %d, headers: %s, conn:'%s'" % (self.close_connection, str(self.headers), self.headers.get('Connection', "").lower()))
+
+        conntype = self.headers.get('Connection', "").lower()
+        if conntype != 'keep-alive':
+            self.close_connection = True
+
+        self.log_message("ka:'%s', pv:%s[%s]" % (str(conntype == 'keep-alive'), str(self.protocol_version >= "HTTP/1.1"), self.protocol_version))
+
+
+    def do_POST(self):
+        """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
+
+        if self.path == "/timeout":
+            time.sleep(2)
+
+        if self.path == "/error_403":
+            self.send_response(403)
+        else:
+            self.send_response(200)
+
+        if self.path == "/content-length":
+            self.send_header("Content-Length", str(len(response)))
+
+        self.send_header("Content-type", "text/plain")
+        self.end_headers()
+        self.wfile.write(response)
+
+
+class ThreadingSimpleServer(SocketServer.ThreadingMixIn,
+                   BaseHTTPServer.HTTPServer):
+    def __init__(self, certfile,
+                 keyfile,):
+        self.allow_reuse_address = True
+        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)
+        try:
+            while 1:
+                sys.stdout.flush()
+                server.handle_request()
+        except KeyboardInterrupt:
+            print "Interrupt"
+        except socket.error:
+            print "Socket closed"
+
+    def stop(self):
+        self.keep_running = False
+        self.server_close()
+
+
+if __name__ == '__main__':
+    server = ThreadingSimpleServer(sys.argv[1], sys.argv[1])
+
+    dummy_killer.setup_killer(server, server.stop)
+
+    server.run()