]> source.dussan.org Git - rspamd.git/commitdiff
[Test] Some tests for antivirus module 1487/head
authorAndrew Lewis <nerf@judo.za.org>
Mon, 6 Mar 2017 14:45:21 +0000 (16:45 +0200)
committerAndrew Lewis <nerf@judo.za.org>
Mon, 6 Mar 2017 14:45:21 +0000 (16:45 +0200)
test/functional/cases/160_antivirus.robot [new file with mode: 0644]
test/functional/configs/antivirus.conf [new file with mode: 0644]
test/functional/lib/rspamd.py
test/functional/lib/vars.py
test/functional/util/dummy_clam.py [new file with mode: 0755]
test/functional/util/dummy_fprot.py [new file with mode: 0755]

diff --git a/test/functional/cases/160_antivirus.robot b/test/functional/cases/160_antivirus.robot
new file mode 100644 (file)
index 0000000..f3604b2
--- /dev/null
@@ -0,0 +1,80 @@
+*** Settings ***
+Suite Setup     Antivirus Setup
+Suite Teardown  Antivirus Teardown
+Library         Process
+Library         ${TESTDIR}/lib/rspamd.py
+Resource        ${TESTDIR}/lib/rspamd.robot
+Variables       ${TESTDIR}/lib/vars.py
+
+*** Variables ***
+${CONFIG}       ${TESTDIR}/configs/plugins.conf
+${MESSAGE}      ${TESTDIR}/messages/spam_message.eml
+${MESSAGE2}     ${TESTDIR}/messages/freemail.eml
+${REDIS_SCOPE}  Suite
+${RSPAMD_SCOPE}  Suite
+${URL_TLD}      ${TESTDIR}/../lua/unit/test_tld.dat
+
+*** Test Cases ***
+CLAMAV MISS
+  Run Dummy Clam  ${PORT_CLAM}
+  ${result} =  Scan Message With Rspamc  ${MESSAGE}
+  Check Rspamc  ${result}  CLAM_VIRUS  inverse=1
+
+CLAMAV HIT
+  Run Dummy Clam  ${PORT_CLAM}  1
+  ${result} =  Scan Message With Rspamc  ${MESSAGE2}
+  Check Rspamc  ${result}  CLAM_VIRUS (1.00)[Eicar-Test-Signature]
+  Should Not Contain  ${result.stdout}  FPROT_
+
+CLAMAV CACHE HIT
+  ${result} =  Scan Message With Rspamc  ${MESSAGE2}
+  Check Rspamc  ${result}  CLAM_VIRUS (1.00)[Eicar-Test-Signature]
+  Should Not Contain  ${result.stdout}  FPROT_
+
+CLAMAV CACHE MISS
+  ${result} =  Scan Message With Rspamc  ${MESSAGE}
+  Check Rspamc  ${result}  CLAM_VIRUS  inverse=1
+  Should Not Contain  ${result.stdout}  FPROT_
+
+FPROT MISS
+  Run Dummy Fprot  ${PORT_FPROT}
+  ${result} =  Scan Message With Rspamc  ${MESSAGE2}
+  Check Rspamc  ${result}  FPROT_VIRUS  inverse=1
+  Should Not Contain  ${result.stdout}  FPROT_EICAR
+
+FPROT HIT - PATTERN
+  Run Dummy Fprot  ${PORT_FPROT}  1
+  ${result} =  Scan Message With Rspamc  ${MESSAGE}
+  Check Rspamc  ${result}  FPROT_EICAR (1.00)[EICAR_Test_File]
+  Should Not Contain  ${result.stdout}  CLAMAV_VIRUS
+
+FPROT CACHE HIT
+  ${result} =  Scan Message With Rspamc  ${MESSAGE}
+  Check Rspamc  ${result}  FPROT_EICAR (1.00)[EICAR_Test_File]
+  Should Not Contain  ${result.stdout}  CLAMAV_VIRUS
+
+FPROT CACHE MISS
+  ${result} =  Scan Message With Rspamc  ${MESSAGE2}
+  Check Rspamc  ${result}  FPROT_  inverse=1
+
+*** Keywords ***
+Antivirus Setup
+  ${PLUGIN_CONFIG} =  Get File  ${TESTDIR}/configs/antivirus.conf
+  Set Suite Variable  ${PLUGIN_CONFIG}
+  Generic Setup  PLUGIN_CONFIG
+  Run Redis
+
+Antivirus Teardown
+  Normal Teardown
+  Shutdown Process With Children  ${REDIS_PID}
+  Wait For Port  ${SOCK_STREAM}  ${LOCAL_ADDR}  ${REDIS_PORT}
+
+Run Dummy Clam
+  [Arguments]  ${port}  ${found}=
+  Wait For Port  ${SOCK_STREAM}  ${LOCAL_ADDR}  ${port}
+  ${result} =  Start Process  ${TESTDIR}/util/dummy_clam.py  ${port}  ${found}
+
+Run Dummy Fprot
+  [Arguments]  ${port}  ${found}=
+  Wait For Port  ${SOCK_STREAM}  ${LOCAL_ADDR}  ${port}
+  ${result} =  Start Process  ${TESTDIR}/util/dummy_fprot.py  ${port}  ${found}
diff --git a/test/functional/configs/antivirus.conf b/test/functional/configs/antivirus.conf
new file mode 100644 (file)
index 0000000..a4b0739
--- /dev/null
@@ -0,0 +1,20 @@
+redis {
+  servers = "${REDIS_ADDR}:${REDIS_PORT}";
+}
+antivirus {
+ clam {
+    attachments_only = false;
+    symbol = "CLAM_VIRUS";
+    type = "clamav";
+    servers = "127.0.0.1:${PORT_CLAM}";
+  }
+  fprot {
+    attachments_only = false;
+    symbol = "FPROT_VIRUS";
+    type = "fprot";
+    servers = "127.0.0.1:${PORT_FPROT}";
+    patterns {
+      FPROT_EICAR = "^EICAR_Test_File$";
+    }
+  }
+}
index bfad7d61dc834be4f0e8f3ed337095cd317549dd..a2be23e87a92975e1006c76cd5e43966d4fef018 100644 (file)
@@ -177,5 +177,5 @@ def wait_for_port(proto, addr, num):
             break
         except:
             pass
-            time.sleep(0.1)
+            time.sleep(0.01)
     s.close()
index a9d5e89f9037753d96924c69ec0d8133e52b3c19..d76c3c0c57dbff501b1ebd0c42da4379c638831c 100644 (file)
@@ -11,6 +11,8 @@ PORT_FUZZY_SLAVE = 56792
 PORT_NORMAL = 56789
 PORT_NORMAL_SLAVE = 56794
 PORT_PROXY = 56795
+PORT_CLAM = 56796
+PORT_FPROT = 56797
 REDIS_ADDR = u'127.0.0.1'
 REDIS_PORT = 56379
 RSPAMD_GROUP = 'nogroup'
diff --git a/test/functional/util/dummy_clam.py b/test/functional/util/dummy_clam.py
new file mode 100755 (executable)
index 0000000..8c68889
--- /dev/null
@@ -0,0 +1,45 @@
+#!/usr/bin/env python
+
+import os
+import sys
+try:
+    import SocketServer as socketserver
+except:
+    import socketserver
+
+class MyTCPHandler(socketserver.BaseRequestHandler):
+
+    def handle(self):
+        self.data = self.request.recv(1024).strip()
+        if self.server.foundvirus:
+            self.request.sendall(b"stream: Eicar-Test-Signature FOUND\0")
+        else:
+            self.request.sendall(b"stream: OK\0")
+        self.request.close()
+
+if __name__ == "__main__":
+    pid = os.fork()
+    if pid > 0:
+        sys.exit(0)
+
+    HOST = "localhost"
+
+    alen = len(sys.argv)
+    if alen > 1:
+        port = int(sys.argv[1])
+        if alen >= 3:
+            foundvirus = bool(sys.argv[2])
+        else:
+            foundvirus = False
+    else:
+        port = 3310
+        foundvirus = False
+
+    server = socketserver.TCPServer((HOST, port), MyTCPHandler, bind_and_activate=False)
+    server.allow_reuse_address = True
+    server.foundvirus = foundvirus
+    server.server_bind()
+    server.server_activate()
+    server.handle_request()
+    server.server_close()
+    os.exit(0)
diff --git a/test/functional/util/dummy_fprot.py b/test/functional/util/dummy_fprot.py
new file mode 100755 (executable)
index 0000000..01e7e57
--- /dev/null
@@ -0,0 +1,45 @@
+#!/usr/bin/env python
+
+import os
+import sys
+try:
+    import SocketServer as socketserver
+except:
+    import socketserver
+
+class MyTCPHandler(socketserver.BaseRequestHandler):
+
+    def handle(self):
+        self.data = self.request.recv(1024).strip()
+        if self.server.foundvirus:
+            self.request.sendall(b"1 <infected: EICAR_Test_File> FOO\n")
+        else:
+            self.request.sendall(b"0 <clean> FOO\n")
+        self.request.close()
+
+if __name__ == "__main__":
+    pid = os.fork()
+    if pid > 0:
+        sys.exit(0)
+
+    HOST = "localhost"
+
+    alen = len(sys.argv)
+    if alen > 1:
+        port = int(sys.argv[1])
+        if alen >= 3:
+            foundvirus = bool(sys.argv[2])
+        else:
+            foundvirus = False
+    else:
+        port = 10200
+        foundvirus = False
+
+    server = socketserver.TCPServer((HOST, port), MyTCPHandler, bind_and_activate=False)
+    server.allow_reuse_address = True
+    server.foundvirus = foundvirus
+    server.server_bind()
+    server.server_activate()
+    server.handle_request()
+    server.server_close()
+    os.exit(0)