aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--circle.yml3
-rw-r--r--test/functional/cases/121_json.robot28
-rw-r--r--test/functional/lib/rspamd.py20
-rw-r--r--test/functional/lua/preresult.lua3
4 files changed, 52 insertions, 2 deletions
diff --git a/circle.yml b/circle.yml
index e8e695cfb..dc813aa99 100644
--- a/circle.yml
+++ b/circle.yml
@@ -3,8 +3,7 @@ dependencies:
- sudo apt-get update -qq
- sudo apt-get install -qq cmake gcc lcov libevent-dev libglib2.0-dev libgmime-2.6-dev libluajit-5.1-dev liblua5.1-0-dev libmagic-dev libpcre3-dev libsqlite3-dev libssl-dev make python-dev ragel redis-server
- gem install coveralls-lcov
- - sudo pip install psutil
- - sudo pip install robotframework
+ - sudo pip install demjson psutil robotframework
test:
override:
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)