From b00b1fd84446879e68dc2ff4c3904c8058d25f30 Mon Sep 17 00:00:00 2001 From: Mikhail Galanin Date: Thu, 27 Sep 2018 14:24:32 +0100 Subject: [Test] Added test for dns request from rspamadm --- test/functional/cases/151_rspamadm_async.robot | 22 +++++++++++++++++- test/functional/lua/rspamadm/test_dns_client.lua | 29 ++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 test/functional/lua/rspamadm/test_dns_client.lua (limited to 'test') diff --git a/test/functional/cases/151_rspamadm_async.robot b/test/functional/cases/151_rspamadm_async.robot index 31fa84245..10fa6bbe2 100644 --- a/test/functional/cases/151_rspamadm_async.robot +++ b/test/functional/cases/151_rspamadm_async.robot @@ -9,7 +9,9 @@ Suite Teardown Terminate All Processes kill=True *** Variables *** ${REDIS_SCOPE} Test - +${CONFIG} ${TESTDIR}/configs/plugins.conf +${URL_TLD} ${TESTDIR}/../lua/unit/test_tld.dat +${PLUGIN_CONFIG} *** Test Cases *** Tcp client @@ -24,6 +26,14 @@ Redis client Should Be Equal As Integers ${result.rc} 0 Should Be Equal ${result.stdout} true\thello from lua on redis +DNS client + ${tmpdir} = Prepare temp directory ${CONFIG} + Set test variable ${tmpdir} + ${result} = Run Process ${RSPAMADM} --var\=CONFDIR\=${tmpdir} lua -b ${TESTDIR}/lua/rspamadm/test_dns_client.lua + Should Be Equal As Integers ${result.rc} 0 + Should Be Equal ${result.stdout} true\tk=ed25519; p=yi50DjK5O9pqbFpNHklsv9lqaS0ArSYu02qp1S0DW1Y= + Cleanup Temporary Directory ${tmpdir} + *** Keywords *** Rspamadm test Setup @@ -40,3 +50,13 @@ Run Dummy Http [Arguments] ${result} = Start Process ${TESTDIR}/util/dummy_http.py Wait Until Created /tmp/dummy_http.pid + +Prepare temp directory + [Arguments] ${CONFIG} + ${template} = Get File ${CONFIG} + ${tmpdir} = Make Temporary Directory + ${config} = Replace Variables ${template} + ${config} = Replace Variables ${config} + Log ${config} + Create File ${tmpdir}/rspamd.conf ${config} + [Return] ${tmpdir} \ No newline at end of file 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 000000000..15b1d6044 --- /dev/null +++ b/test/functional/lua/rspamadm/test_dns_client.lua @@ -0,0 +1,29 @@ +local rspamd_dns = require "rspamd_dns" +local logger = require "rspamd_logger" + +local _r,err = rspamd_config:load_ucl('/Users/mgalanin/build/robot-save/rspamd.conf.last') + +if not _r then + rspamd_logger.errx('cannot parse %s: %s', opts['config'], err) + os.exit(1) +end + +_r,err = rspamd_config:parse_rcl({'logging', 'worker'}) +if not _r then + rspamd_logger.errx('cannot process %s: %s', opts['config'], err) + 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]) -- cgit v1.2.3 From 48e23c6397077056ef7ef730ea4e2d76ff6c601a Mon Sep 17 00:00:00 2001 From: Mikhail Galanin Date: Thu, 27 Sep 2018 14:40:00 +0100 Subject: [Test] Add output logging --- test/functional/cases/151_rspamadm_async.robot | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test') diff --git a/test/functional/cases/151_rspamadm_async.robot b/test/functional/cases/151_rspamadm_async.robot index 10fa6bbe2..a496bf12a 100644 --- a/test/functional/cases/151_rspamadm_async.robot +++ b/test/functional/cases/151_rspamadm_async.robot @@ -30,6 +30,8 @@ DNS client ${tmpdir} = Prepare temp directory ${CONFIG} Set test variable ${tmpdir} ${result} = Run Process ${RSPAMADM} --var\=CONFDIR\=${tmpdir} lua -b ${TESTDIR}/lua/rspamadm/test_dns_client.lua + Log ${result.stdout} + Log ${result.stderr} Should Be Equal As Integers ${result.rc} 0 Should Be Equal ${result.stdout} true\tk=ed25519; p=yi50DjK5O9pqbFpNHklsv9lqaS0ArSYu02qp1S0DW1Y= Cleanup Temporary Directory ${tmpdir} -- cgit v1.2.3 From 13a1ea4afb96a189767208f927b4588e9af3faa7 Mon Sep 17 00:00:00 2001 From: Mikhail Galanin Date: Thu, 27 Sep 2018 14:56:02 +0100 Subject: [Test] Fixed undefined variable usage --- test/functional/lua/rspamadm/test_dns_client.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/functional/lua/rspamadm/test_dns_client.lua b/test/functional/lua/rspamadm/test_dns_client.lua index 15b1d6044..9e7edaa46 100644 --- a/test/functional/lua/rspamadm/test_dns_client.lua +++ b/test/functional/lua/rspamadm/test_dns_client.lua @@ -1,16 +1,17 @@ local rspamd_dns = require "rspamd_dns" local logger = require "rspamd_logger" -local _r,err = rspamd_config:load_ucl('/Users/mgalanin/build/robot-save/rspamd.conf.last') +local config_path = '/Users/mgalanin/build/robot-save/rspamd.conf.last' +local _r,err = rspamd_config:load_ucl(config_path) if not _r then - rspamd_logger.errx('cannot parse %s: %s', opts['config'], err) + 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 - rspamd_logger.errx('cannot process %s: %s', opts['config'], err) + logger.errx('cannot process %s: %s (r=%s)', config_path, err, _r) os.exit(1) end -- cgit v1.2.3 From 023a17c1da5fa20491e2926e753f532f2a43d06f Mon Sep 17 00:00:00 2001 From: Mikhail Galanin Date: Thu, 27 Sep 2018 15:07:17 +0100 Subject: [Test] fixed config path --- test/functional/lua/rspamadm/test_dns_client.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/functional/lua/rspamadm/test_dns_client.lua b/test/functional/lua/rspamadm/test_dns_client.lua index 9e7edaa46..c54d59499 100644 --- a/test/functional/lua/rspamadm/test_dns_client.lua +++ b/test/functional/lua/rspamadm/test_dns_client.lua @@ -1,7 +1,7 @@ local rspamd_dns = require "rspamd_dns" local logger = require "rspamd_logger" -local config_path = '/Users/mgalanin/build/robot-save/rspamd.conf.last' +local config_path = rspamd_paths['CONFDIR'] .. '/rspamd.conf' local _r,err = rspamd_config:load_ucl(config_path) if not _r then -- cgit v1.2.3