diff options
Diffstat (limited to 'test/functional/lua/rspamadm')
-rw-r--r-- | test/functional/lua/rspamadm/test_batch.lua | 4 | ||||
-rw-r--r-- | test/functional/lua/rspamadm/test_dns_client.lua | 30 | ||||
-rw-r--r-- | test/functional/lua/rspamadm/test_message_callback.lua | 5 | ||||
-rw-r--r-- | test/functional/lua/rspamadm/test_redis_client.lua | 40 | ||||
-rw-r--r-- | test/functional/lua/rspamadm/test_tcp_client.lua | 64 | ||||
-rw-r--r-- | test/functional/lua/rspamadm/test_verbose.lua | 3 |
6 files changed, 146 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 0000000..dd50c9d --- /dev/null +++ b/test/functional/lua/rspamadm/test_batch.lua @@ -0,0 +1,4 @@ +local rspamd_logger = require "rspamd_logger" + +rspamd_logger.info(rspamd_config, "nope") +rspamd_logger.err(rspamd_config, "hello world") diff --git a/test/functional/lua/rspamadm/test_dns_client.lua b/test/functional/lua/rspamadm/test_dns_client.lua new file mode 100644 index 0000000..c54d594 --- /dev/null +++ b/test/functional/lua/rspamadm/test_dns_client.lua @@ -0,0 +1,30 @@ +local rspamd_dns = require "rspamd_dns" +local logger = require "rspamd_logger" + +local config_path = rspamd_paths['CONFDIR'] .. '/rspamd.conf' +local _r,err = rspamd_config:load_ucl(config_path) + +if not _r then + logger.errx('cannot parse %s: %s (r=%s)', config_path, err, _r) + os.exit(1) +end + +_r,err = rspamd_config:parse_rcl({'logging', 'worker'}) +if not _r then + logger.errx('cannot process %s: %s (r=%s)', config_path, err, _r) + os.exit(1) +end + +rspamd_config:init_subsystem('dns', rspamadm_ev_base) + + +local is_ok, results = rspamd_dns.request({ + config = rspamd_config, + session = rspamadm_session, + + type = 'txt', + name = 'test._domainkey.example.com', + -- name = '_dmarc.google.com', + }) + +print(is_ok, results[1]) 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 0000000..6be512a --- /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_redis_client.lua b/test/functional/lua/rspamadm/test_redis_client.lua new file mode 100644 index 0000000..a7428a8 --- /dev/null +++ b/test/functional/lua/rspamadm/test_redis_client.lua @@ -0,0 +1,40 @@ +local logger = require "rspamd_logger" +local redis = require "lua_redis" +local upstream_list = require "rspamd_upstream_list" + +local upstreams_write = upstream_list.create('127.0.0.1', 56379) +local upstreams_read = upstream_list.create('127.0.0.1', 56379) + +local is_ok, connection = redis.redis_connect_sync({ + write_servers = upstreams_write, + read_servers = upstreams_read, +-- config = rspamd_config, +-- ev_base = rspamadm_ev_base, +-- session = rspamadm_session, + timeout = 2 +}) + + +local lua_script = [[ +local f = function() end +--for k = 1,100000000 do +-- for i=1,100000000 do +-- f() +-- end +--end +return "hello from lua on redis" +]] + +local a,b = connection:add_cmd('EVAL', {lua_script, 0}) +local is_ok,ver = connection:exec() + +print(is_ok, ver) + +--[[ +a,b = connection:add_cmd('EVAL', {lua_script, 0}) +print(a,b) + +is_ok,ver = connection:exec() + +print(is_ok, ver) +]]
\ No newline at end of file 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 0000000..eb103db --- /dev/null +++ b/test/functional/lua/rspamadm/test_tcp_client.lua @@ -0,0 +1,64 @@ +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, +} +if not is_ok then + logger.errx(rspamd_config, 'connect error: %1', connection) + return +end +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) diff --git a/test/functional/lua/rspamadm/test_verbose.lua b/test/functional/lua/rspamadm/test_verbose.lua new file mode 100644 index 0000000..4470c63 --- /dev/null +++ b/test/functional/lua/rspamadm/test_verbose.lua @@ -0,0 +1,3 @@ +local rspamd_logger = require "rspamd_logger" + +rspamd_logger.info(rspamd_config, "hello world") |