diff options
author | Mikhail Galanin <mgalanin@mimecast.com> | 2018-09-05 13:43:21 +0100 |
---|---|---|
committer | Mikhail Galanin <mgalanin@mimecast.com> | 2018-09-05 13:43:21 +0100 |
commit | 49fb6ed4d68e7691b5219c78fd0837ca4e2f7b94 (patch) | |
tree | 753f00b8f55b45596ef09a3eb7214cf518e58a2e /test/functional/lua/rspamadm | |
parent | 3db11dba2f19bef803f44d0e6b0e659d7d57088a (diff) | |
download | rspamd-49fb6ed4d68e7691b5219c78fd0837ca4e2f7b94.tar.gz rspamd-49fb6ed4d68e7691b5219c78fd0837ca4e2f7b94.zip |
[Test] Added more test for rspamadm and test for lua tcp client invoked via rspamadm
Diffstat (limited to 'test/functional/lua/rspamadm')
-rw-r--r-- | test/functional/lua/rspamadm/test_batch.lua | 1 | ||||
-rw-r--r-- | test/functional/lua/rspamadm/test_message_callback.lua | 5 | ||||
-rw-r--r-- | test/functional/lua/rspamadm/test_tcp_client.lua | 60 |
3 files changed, 66 insertions, 0 deletions
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) |