]> source.dussan.org Git - rspamd.git/commitdiff
[Test] Some basic tests for JSON sanity 800/head
authorAndrew Lewis <nerf@judo.za.org>
Wed, 3 Aug 2016 10:38:45 +0000 (11:38 +0100)
committerAndrew Lewis <nerf@judo.za.org>
Wed, 3 Aug 2016 10:39:10 +0000 (11:39 +0100)
circle.yml
test/functional/cases/121_json.robot [new file with mode: 0644]
test/functional/lib/rspamd.py
test/functional/lua/preresult.lua [new file with mode: 0644]

index e8e695cfb81ee71a0571ac67d0c30de0852845e7..dc813aa99a0d20c9be7b5fdbd2e7ed6ad52d9ef3 100644 (file)
@@ -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 (file)
index 0000000..2bb432f
--- /dev/null
@@ -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]
index c40ac588c3a1b51f79e655f34d1c039b9f68b0d6..4da8712a3b222fd447ee6c7ad329d403e5ef4828 100644 (file)
@@ -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 (file)
index 0000000..72a73b1
--- /dev/null
@@ -0,0 +1,3 @@
+rspamd_config:register_post_filter(function(task)
+  task:set_pre_result('soft reject', 'Pre Result Set')
+end)