aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.luacheckrc1
-rw-r--r--test/functional/cases/150_rspamadm.robot26
-rw-r--r--test/functional/cases/151_rspamadm_async.robot36
-rw-r--r--test/functional/lib/rspamd.py9
-rw-r--r--test/functional/lua/rspamadm/test_batch.lua1
-rw-r--r--test/functional/lua/rspamadm/test_message_callback.lua5
-rw-r--r--test/functional/lua/rspamadm/test_tcp_client.lua60
7 files changed, 138 insertions, 0 deletions
diff --git a/.luacheckrc b/.luacheckrc
index 324c45985..a5819a46b 100644
--- a/.luacheckrc
+++ b/.luacheckrc
@@ -5,6 +5,7 @@ exclude_files = {
'/**/contrib/**',
'/**/test/lua/**',
'/**/test/functional/lua/miltertest/**',
+ '/**/test/functional/lua/rspamadm/**',
}
globals = {
diff --git a/test/functional/cases/150_rspamadm.robot b/test/functional/cases/150_rspamadm.robot
index 4e7b3c8aa..82532ddab 100644
--- a/test/functional/cases/150_rspamadm.robot
+++ b/test/functional/cases/150_rspamadm.robot
@@ -1,5 +1,8 @@
*** Settings ***
Library Process
+Library ../lib/rspamd.py
+
+Suite Teardown Terminate All Processes kill=True
*** Test Cases ***
Config Test
@@ -12,3 +15,26 @@ Config Help
${result} = Run Process ${RSPAMADM} confighelp
Should Match Regexp ${result.stderr} ^$
Should Be Equal As Integers ${result.rc} 0
+
+Simple interpreter
+ ${handle} = Start Process ${RSPAMADM} lua
+ ${result} = Write to stdin ${handle} 1+1
+ Should Be Equal As Strings ${result} 2\n
+
+Simple interpreter, two results
+ ${handle} = Start Process ${RSPAMADM} lua
+ ${result} = Write to stdin ${handle} 1+1, 2 * 5
+ Should Be Equal ${result} 2\n10\n
+
+Process message callback
+ ${handle} = Start Process ${RSPAMADM} lua
+ ${result} = Write to stdin ${handle} .load ${TESTDIR}/lua/rspamadm/test_message_callback.lua\n.message message_callback ${TESTDIR}/messages/empty_part.eml
+ Should Contain ${result} n parts = 2
+ Should Contain ${result} 1\n2\n4\n6
+
+Lua batch mode
+ ${result} = Run Process ${RSPAMADM} lua -b ${TESTDIR}/lua/rspamadm/test_batch.lua
+ Should Match Regexp ${result.stderr} ^$
+ Should Be Equal As Integers ${result.rc} 0
+ Should Be Equal ${result.stdout} hello world
+
diff --git a/test/functional/cases/151_rspamadm_async.robot b/test/functional/cases/151_rspamadm_async.robot
new file mode 100644
index 000000000..ec97292dc
--- /dev/null
+++ b/test/functional/cases/151_rspamadm_async.robot
@@ -0,0 +1,36 @@
+*** 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
+Suite Teardown Terminate All Processes kill=True
+
+*** Variables ***
+${REDIS_SCOPE} Test
+
+
+*** Test Cases ***
+Tcp client
+ ${result} = Run Process ${RSPAMADM} lua -b ${TESTDIR}/lua/rspamadm/test_tcp_client.lua
+ Should Match Regexp ${result.stderr} ^$
+ Should Be Equal As Integers ${result.rc} 0
+ Should Be Equal ${result.stdout} hello post
+
+*** Keywords ***
+
+Http Setup
+ Run Dummy Http
+ Run Redis
+
+Http Teardown
+ ${http_pid} = Get File /tmp/dummy_http.pid
+ Shutdown Process With Children ${http_pid}
+ Remove file /tmp/dummy_http.pid
+ Shutdown Process With Children ${REDIS_PID}
+
+Run Dummy Http
+ [Arguments]
+ ${result} = Start Process ${TESTDIR}/util/dummy_http.py
+ Wait Until Created /tmp/dummy_http.pid
diff --git a/test/functional/lib/rspamd.py b/test/functional/lib/rspamd.py
index 97ab516c1..1c4b428a2 100644
--- a/test/functional/lib/rspamd.py
+++ b/test/functional/lib/rspamd.py
@@ -212,3 +212,12 @@ def shutdown_process_with_children(pid):
except:
pass
+
+def write_to_stdin(process_handle, text):
+ lib = BuiltIn().get_library_instance('Process')
+ obj = lib.get_process_object()
+ obj.stdin.write(text + "\n")
+ obj.stdin.flush()
+ obj.stdin.close()
+ out = obj.stdout.read(4096)
+ return out
diff --git a/test/functional/lua/rspamadm/test_batch.lua b/test/functional/lua/rspamadm/test_batch.lua
new file mode 100644
index 000000000..e75154b7c
--- /dev/null
+++ b/test/functional/lua/rspamadm/test_batch.lua
@@ -0,0 +1 @@
+print("hello world") \ No newline at end of file
diff --git a/test/functional/lua/rspamadm/test_message_callback.lua b/test/functional/lua/rspamadm/test_message_callback.lua
new file mode 100644
index 000000000..6be512ac0
--- /dev/null
+++ b/test/functional/lua/rspamadm/test_message_callback.lua
@@ -0,0 +1,5 @@
+function message_callback(task)
+ local parts = task:get_text_parts()
+ print("n parts = " .. tostring(#parts))
+ return 1,2,4,6
+end
diff --git a/test/functional/lua/rspamadm/test_tcp_client.lua b/test/functional/lua/rspamadm/test_tcp_client.lua
new file mode 100644
index 000000000..796fe913b
--- /dev/null
+++ b/test/functional/lua/rspamadm/test_tcp_client.lua
@@ -0,0 +1,60 @@
+local logger = require "rspamd_logger"
+local tcp_sync = require "lua_tcp_sync"
+
+local is_ok, connection = tcp_sync.connect {
+ config = rspamd_config,
+ ev_base = rspamadm_ev_base,
+ session = rspamadm_session,
+ host = '127.0.0.1',
+ timeout = 20,
+ port = 18080,
+}
+local err
+is_ok, err = connection:write(string.format('POST /request HTTP/1.1\r\nConnection: close\r\n\r\n'))
+
+logger.info('write %1, %2', is_ok, err)
+if not is_ok then
+ logger.errx(rspamd_config, 'write error: %1', err)
+ return
+end
+
+local content_length, content
+
+while true do
+ local header_line
+ is_ok, header_line = connection:read_until("\r\n")
+ if not is_ok then
+ logger.errx(rspamd_config, 'failed to get header: %1', header_line)
+ return
+ end
+
+ if header_line == "" then
+ logger.info('headers done')
+ break
+ end
+
+ local value
+ local header = header_line:gsub("([%w-]+): (.*)",
+ function (h, v) value = v; return h:lower() end)
+
+ logger.info('parsed header: %1 -> "%2"', header, value)
+
+ if header == "content-length" then
+ content_length = tonumber(value)
+ end
+
+end
+
+if content_length then
+ is_ok, content = connection:read_bytes(content_length)
+ if is_ok then
+ end
+else
+ is_ok, content = connection:read_until_eof()
+ if is_ok then
+ end
+end
+logger.info('(is_ok: %1) content [%2 bytes] %3', is_ok, content_length, content)
+
+
+print(content)