diff options
author | Andrew Lewis <nerf@judo.za.org> | 2016-08-03 11:38:45 +0100 |
---|---|---|
committer | Andrew Lewis <nerf@judo.za.org> | 2016-08-03 11:39:10 +0100 |
commit | c1c49ce51d25138a94a41a23452e078a660f1248 (patch) | |
tree | 3a48261dd03ecefd2c717d4623caa8332cf0ab75 /test | |
parent | aa1a1c9c09f33cc1e12a874e3577126579397756 (diff) | |
download | rspamd-c1c49ce51d25138a94a41a23452e078a660f1248.tar.gz rspamd-c1c49ce51d25138a94a41a23452e078a660f1248.zip |
[Test] Some basic tests for JSON sanity
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/cases/121_json.robot | 28 | ||||
-rw-r--r-- | test/functional/lib/rspamd.py | 20 | ||||
-rw-r--r-- | test/functional/lua/preresult.lua | 3 |
3 files changed, 51 insertions, 0 deletions
diff --git a/test/functional/cases/121_json.robot b/test/functional/cases/121_json.robot new file mode 100644 index 000000000..2bb432f5a --- /dev/null +++ b/test/functional/cases/121_json.robot @@ -0,0 +1,28 @@ +*** Settings *** +Suite Setup Generic Setup +Suite Teardown Generic Teardown +Library ${TESTDIR}/lib/rspamd.py +Resource ${TESTDIR}/lib/rspamd.robot +Variables ${TESTDIR}/lib/vars.py + +*** Variables *** +${CONFIG} ${TESTDIR}/configs/lua_test.conf +${LUA_SCRIPT} ${TESTDIR}/lua/preresult.lua +${MESSAGE} ${TESTDIR}/messages/spam_message.eml +${RSPAMD_SCOPE} Suite + +*** Test Cases *** +Stat + @{result} = HTTP GET ${LOCAL_ADDR} ${PORT_CONTROLLER} /stat + Check JSON @{result}[1] + +History + ${result} = Scan Message With Rspamc ${MESSAGE} + Check Rspamc ${result} soft reject + @{result} = HTTP GET ${LOCAL_ADDR} ${PORT_CONTROLLER} /history + Check JSON @{result}[1] + +Scan + ${content} = Get File ${MESSAGE} + @{result} = HTTP POST ${LOCAL_ADDR} ${PORT_NORMAL} /check ${content} + Check JSON @{result}[1] diff --git a/test/functional/lib/rspamd.py b/test/functional/lib/rspamd.py index c40ac588c..4da8712a3 100644 --- a/test/functional/lib/rspamd.py +++ b/test/functional/lib/rspamd.py @@ -1,3 +1,4 @@ +import demjson import grp import os import os.path @@ -17,6 +18,16 @@ try: from urllib.request import urlopen except: from urllib2 import urlopen +try: + import http.client as httplib +except: + import httplib + +def Check_JSON(j): + d = demjson.decode(j, strict=True) + assert len(d) > 0 + assert 'error' not in d + return d def cleanup_temporary_directory(directory): shutil.rmtree(directory) @@ -49,6 +60,15 @@ def get_rspamadm(): dname = get_top_dir() return dname + "/src/rspamadm/rspamadm" +def HTTP(method, host, port, path, data=None, headers={}): + c = httplib.HTTPConnection("%s:%s" % (host, port)) + c.request(method, path, data, headers) + r = c.getresponse() + t = r.read() + s = r.status + c.close() + return [s, t] + def make_temporary_directory(): return tempfile.mkdtemp() diff --git a/test/functional/lua/preresult.lua b/test/functional/lua/preresult.lua new file mode 100644 index 000000000..72a73b1d7 --- /dev/null +++ b/test/functional/lua/preresult.lua @@ -0,0 +1,3 @@ +rspamd_config:register_post_filter(function(task) + task:set_pre_result('soft reject', 'Pre Result Set') +end) |