[Fuego] [PATCH v3] samhain: Add test cases of command samhain.

Wang Mingyu wangmy at cn.fujitsu.com
Tue Apr 9 13:02:08 UTC 2019


Command samhain is used to check file integrity.
This test set is to check the initialization of the database of file signatures.
And check the filesystem against the database of file signatures.

Signed-off-by: Wang Mingyu <wangmy at cn.fujitsu.com>
---
 tests/Functional.samhain/fuego_test.sh          | 20 ++++++++
 tests/Functional.samhain/parser.py              | 20 ++++++++
 tests/Functional.samhain/samhain_test.sh        |  4 ++
 tests/Functional.samhain/spec.json              |  6 +++
 tests/Functional.samhain/tests/samhain_check.sh | 64 +++++++++++++++++++++++++
 tests/Functional.samhain/tests/samhain_help.sh  | 13 +++++
 tests/Functional.samhain/tests/samhain_init.sh  | 49 +++++++++++++++++++
 7 files changed, 176 insertions(+)
 create mode 100644 tests/Functional.samhain/fuego_test.sh
 create mode 100644 tests/Functional.samhain/parser.py
 create mode 100644 tests/Functional.samhain/samhain_test.sh
 create mode 100644 tests/Functional.samhain/spec.json
 create mode 100644 tests/Functional.samhain/tests/samhain_check.sh
 create mode 100644 tests/Functional.samhain/tests/samhain_help.sh
 create mode 100644 tests/Functional.samhain/tests/samhain_init.sh

diff --git a/tests/Functional.samhain/fuego_test.sh b/tests/Functional.samhain/fuego_test.sh
new file mode 100644
index 0000000..186a74e
--- /dev/null
+++ b/tests/Functional.samhain/fuego_test.sh
@@ -0,0 +1,20 @@
+function test_pre_check {
+    assert_has_program samhain
+}
+
+function test_deploy {
+    put $TEST_HOME/samhain_test.sh $BOARD_TESTDIR/fuego.$TESTDIR/
+    put $FUEGO_CORE/scripts/fuego_board_function_lib.sh $BOARD_TESTDIR/fuego.$TESTDIR
+    put -r $TEST_HOME/tests $BOARD_TESTDIR/fuego.$TESTDIR/
+}
+
+function test_run {
+    report "cd $BOARD_TESTDIR/fuego.$TESTDIR;\
+    export board=$BOARD_TESTDIR;\
+    export testdir=$TESTDIR;\
+    ./samhain_test.sh"
+}
+
+function test_processing {
+    log_compare "$TESTDIR" "0" "TEST-FAIL" "n"
+}
diff --git a/tests/Functional.samhain/parser.py b/tests/Functional.samhain/parser.py
new file mode 100644
index 0000000..f25a608
--- /dev/null
+++ b/tests/Functional.samhain/parser.py
@@ -0,0 +1,20 @@
+#!/usr/bin/python
+# See common.py for description of command-line arguments
+
+import os, sys, collections
+import common as plib
+
+measurements = {}
+measurements = collections.OrderedDict()
+
+regex_string = '^ -> (.*): TEST-(.*)$'
+matches = plib.parse_log(regex_string)
+
+if matches:
+    for m in matches:
+        measurements['default.' + m[0]] = 'PASS' if m[1] == 'PASS' else 'FAIL'
+
+# split the output for each testcase
+plib.split_output_per_testcase(regex_string, measurements)
+
+sys.exit(plib.process(measurements))
diff --git a/tests/Functional.samhain/samhain_test.sh b/tests/Functional.samhain/samhain_test.sh
new file mode 100644
index 0000000..dd5ce37
--- /dev/null
+++ b/tests/Functional.samhain/samhain_test.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+for i in tests/*.sh; do
+    sh $i
+done
diff --git a/tests/Functional.samhain/spec.json b/tests/Functional.samhain/spec.json
new file mode 100644
index 0000000..da029b3
--- /dev/null
+++ b/tests/Functional.samhain/spec.json
@@ -0,0 +1,6 @@
+{
+    "testName": "Functional.samhain",
+    "specs": {
+        "default": {}
+    }
+}
diff --git a/tests/Functional.samhain/tests/samhain_check.sh b/tests/Functional.samhain/tests/samhain_check.sh
new file mode 100644
index 0000000..b94263c
--- /dev/null
+++ b/tests/Functional.samhain/tests/samhain_check.sh
@@ -0,0 +1,64 @@
+#!/bin/sh
+
+#  In target, run command samhain.
+#  Check the filesystem against the database of file signatures.
+#  option: -t
+
+test="check"
+
+. ./fuego_board_function_lib.sh
+
+set_init_manager
+logger_service=$(detect_logger_service)
+
+cp /etc/samhainrc /etc/samhainrc_bak
+sed -i "s%dir = 99/usr%dir = 99$board/fuego.$testdir/test_dir/samhain_test%" /etc/samhainrc
+
+rm -fr /var/samhain/* /var/lib/samhain/*
+
+exec_service_on_target $logger_service stop
+if [ -f /var/log/syslog ]
+then
+    mv /var/log/syslog /var/log/syslog_bak
+fi
+
+exec_service_on_target $logger_service restart
+
+sleep 1
+
+mkdir -p test_dir/samhain_test/
+touch test_dir/samhain_test/test.txt
+
+samhain -t init -p info > /dev/null 2&> 1
+
+sleep 1
+
+echo test > test_dir/samhain_test/test.txt
+
+sleep 1
+
+if samhain -t check
+then
+    echo " -> samhain -t check succeeded."
+else
+    echo " -> $test: TEST-FAIL"
+    rm -fr test_dir
+    mv /etc/samhainrc_bak /etc/samhainrc
+    exit
+fi
+
+sleep 10
+
+if cat /var/log/syslog | grep "test_dir/samhain_test"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+
+rm -fr test_dir
+mv /etc/samhainrc_bak /etc/samhainrc
+if [ -f /var/log/syslog_bak ]
+then
+    mv /var/log/syslog_bak /var/log/syslog
+fi
diff --git a/tests/Functional.samhain/tests/samhain_help.sh b/tests/Functional.samhain/tests/samhain_help.sh
new file mode 100644
index 0000000..f16b680
--- /dev/null
+++ b/tests/Functional.samhain/tests/samhain_help.sh
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+#  In target, run command samhain.
+#  option: --help
+
+test="help"
+
+if samhain --help | grep "Usage"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
diff --git a/tests/Functional.samhain/tests/samhain_init.sh b/tests/Functional.samhain/tests/samhain_init.sh
new file mode 100644
index 0000000..b15297d
--- /dev/null
+++ b/tests/Functional.samhain/tests/samhain_init.sh
@@ -0,0 +1,49 @@
+#!/bin/sh
+
+#  In target, run command samhain.
+#  Initialize the database of file signatures.
+#  option: -t
+
+test="init"
+
+. ./fuego_board_function_lib.sh
+
+set_init_manager
+logger_service=$(detect_logger_service)
+
+cp /etc/samhainrc /etc/samhainrc_bak
+sed -i "s%dir = 99/usr%dir = 99$board/fuego.$testdir/test_dir/samhain_test%" /etc/samhainrc
+
+rm -fr /var/samhain/* /var/lib/samhain/*
+
+exec_service_on_target $logger_service stop
+
+if [ -f /var/log/syslog ]
+then
+    mv /var/log/syslog /var/log/syslog_bak
+fi
+
+exec_service_on_target $logger_service restart
+
+sleep 1
+
+mkdir -p test_dir/samhain_test/
+touch test_dir/samhain_test/test.txt
+
+samhain -t init -p info > /dev/null 2&> 1
+
+sleep 1
+
+if cat /var/log/syslog | grep "ALRT.*-.*-.*T.*:.*:.*msg=\"EXIT\""
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+
+rm -fr test_dir
+mv /etc/samhainrc_bak /etc/samhainrc
+if [ -f /var/log/syslog_bak ]
+then
+    mv /var/log/syslog_bak /var/log/syslog
+fi
-- 
1.8.3.1





More information about the Fuego mailing list