[Fuego] [PATCH] Add test cases of command stunnel.

Wang Mingyu wangmy at cn.fujitsu.com
Wed Nov 14 09:30:20 UTC 2018


stunnel is an open-source multi-platform application used to provide a universal TLS/SSL tunneling service.
This test set is used to check the pidfile, log file and process status of stunnel.

Signed-off-by: Wang Mingyu <wangmy at cn.fujitsu.com>
---
 engine/tests/Functional.stunnel/data/stunnel.conf  | 16 +++++
 engine/tests/Functional.stunnel/data/stunnel.pem   | 36 +++++++++++
 engine/tests/Functional.stunnel/fuego_test.sh      | 19 ++++++
 engine/tests/Functional.stunnel/parser.py          | 22 +++++++
 engine/tests/Functional.stunnel/spec.json          |  7 +++
 engine/tests/Functional.stunnel/stunnel_test.sh    |  4 ++
 .../Functional.stunnel/tests/stunnel_netstat.sh    | 58 ++++++++++++++++++
 .../Functional.stunnel/tests/stunnel_pidfile.sh    | 69 ++++++++++++++++++++++
 .../tests/Functional.stunnel/tests/stunnel_ps.sh   | 62 +++++++++++++++++++
 .../Functional.stunnel/tests/stunnel_syslog-ng.sh  | 59 ++++++++++++++++++
 10 files changed, 352 insertions(+)
 create mode 100644 engine/tests/Functional.stunnel/data/stunnel.conf
 create mode 100644 engine/tests/Functional.stunnel/data/stunnel.pem
 create mode 100644 engine/tests/Functional.stunnel/fuego_test.sh
 create mode 100644 engine/tests/Functional.stunnel/parser.py
 create mode 100644 engine/tests/Functional.stunnel/spec.json
 create mode 100755 engine/tests/Functional.stunnel/stunnel_test.sh
 create mode 100644 engine/tests/Functional.stunnel/tests/stunnel_netstat.sh
 create mode 100644 engine/tests/Functional.stunnel/tests/stunnel_pidfile.sh
 create mode 100644 engine/tests/Functional.stunnel/tests/stunnel_ps.sh
 create mode 100644 engine/tests/Functional.stunnel/tests/stunnel_syslog-ng.sh

diff --git a/engine/tests/Functional.stunnel/data/stunnel.conf b/engine/tests/Functional.stunnel/data/stunnel.conf
new file mode 100644
index 0000000..85b1a55
--- /dev/null
+++ b/engine/tests/Functional.stunnel/data/stunnel.conf
@@ -0,0 +1,16 @@
+cert = /etc/stunnel/stunnel.pem
+
+pid = /var/run/stunnel.pid
+output = /var/log/stunnel.log
+debug      = 7
+foreground = no
+setuid = root
+setgid = root
+
+client = no
+
+[https]
+accept  = 443
+connect = 80
+TIMEOUTclose = 30
+
diff --git a/engine/tests/Functional.stunnel/data/stunnel.pem b/engine/tests/Functional.stunnel/data/stunnel.pem
new file mode 100644
index 0000000..2abdf2e
--- /dev/null
+++ b/engine/tests/Functional.stunnel/data/stunnel.pem
@@ -0,0 +1,36 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIICWwIBAAKBgQC5qdFVZB4TK0wf1Ni3LMbzcXG7tgcq8P5ThNVn4NIQjb5lghN2
+XVZp5lYoUByzxQmB3wSUe/Foag6b56Ju70jkjnzCdCpBJQLrtr+AOGB1e7Og41Ob
+OIeNPRT0lzykAVY08FlN5FV4UqfGmkSeClkncmsDZ6NszZn1a/7SSBQIsQIDAQAB
+AoGAMQy+MxMKJwJPUDGJN4tq3DHiXDcQ2bVlW2dCgfkRRjJMVMDyp1itVbj2lhvk
+GVI62sayjQ/ZjT5HscSWUzyAQv492VrYLBFy4j10f+i63L/ag1z86NSd+zC7/Ft1
+uIjUzygxy18Z4lL+hPYh4ezNZLM9D0o8jntgdXvJBWhjYuECQQDoJ9hP2L0R+S2S
+v9BCXyKPOlh8TlUDf+MEp+EuE1JbnjwSxhQ5xLUr7odXK+TK2Dx5Cq3yOrKtyw5W
+trU9e+q1AkEAzLuIk06au1Co362EiCpY4vZw1X7YWzHWLr0jn8dZTFV4Rie9ThtI
+kIwfKt12K35pYflbtWdqT9kQAaOH3LeXjQJAMKA/56GPIJefmxBAL9a7Z2KiLA9A
+MUZ1J4F+Yec8JeKD1K7Wh68S/4urn2+bMX2PVQ8OliEDUfGpJDKKzcEJzQJAZMJO
+/yCKanHSCvOc7F7bDCh5c7lPxeILJUmUxMgZnMXbwbtBIbWvyuQLWs9PnyxBtSRC
+DE9vNQkBJa1T6j646QJAWuk21jm3pQ8Fv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c2fHChpksKSraZUQ==
+-----END CERTIFICATE-----
+-----BEGIN DH PARAMETERS-----
+MEYCQQDVQM6ONF+Tsxd7O/6op5zJpU+7hyEn/+TPrX3QJKRoAVcRFrKaCo+Pq2c8
+6ckvVH6FoFuGniVaAbCG9K8Nl7nLAgEC
+-----END DH PARAMETERS-----
diff --git a/engine/tests/Functional.stunnel/fuego_test.sh b/engine/tests/Functional.stunnel/fuego_test.sh
new file mode 100644
index 0000000..e425d9c
--- /dev/null
+++ b/engine/tests/Functional.stunnel/fuego_test.sh
@@ -0,0 +1,19 @@
+function test_pre_check {
+    assert_has_program stunnel
+}
+
+function test_deploy {
+    put $TEST_HOME/stunnel_test.sh $BOARD_TESTDIR/fuego.$TESTDIR/
+    put $FUEGO_CORE/engine/scripts/fuego_board_function_lib.sh $BOARD_TESTDIR/fuego.$TESTDIR
+    put -r $TEST_HOME/tests $BOARD_TESTDIR/fuego.$TESTDIR/
+    put -r $TEST_HOME/data $BOARD_TESTDIR/fuego.$TESTDIR/
+}
+
+function test_run {
+    report "cd $BOARD_TESTDIR/fuego.$TESTDIR;\
+    ./stunnel_test.sh"
+}
+
+function test_processing {
+    log_compare "$TESTDIR" "0" "TEST-FAIL" "n"
+}
diff --git a/engine/tests/Functional.stunnel/parser.py b/engine/tests/Functional.stunnel/parser.py
new file mode 100644
index 0000000..d85abd7
--- /dev/null
+++ b/engine/tests/Functional.stunnel/parser.py
@@ -0,0 +1,22 @@
+#!/usr/bin/python
+# See common.py for description of command-line arguments
+
+import os, sys, collections
+
+sys.path.insert(0, os.environ['FUEGO_CORE'] + '/engine/scripts/parser')
+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/engine/tests/Functional.stunnel/spec.json b/engine/tests/Functional.stunnel/spec.json
new file mode 100644
index 0000000..21c837c
--- /dev/null
+++ b/engine/tests/Functional.stunnel/spec.json
@@ -0,0 +1,7 @@
+{
+    "testName": "Functional.stunnel",
+    "specs": {
+        "default": {}
+    }
+}
+
diff --git a/engine/tests/Functional.stunnel/stunnel_test.sh b/engine/tests/Functional.stunnel/stunnel_test.sh
new file mode 100755
index 0000000..dd5ce37
--- /dev/null
+++ b/engine/tests/Functional.stunnel/stunnel_test.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+for i in tests/*.sh; do
+    sh $i
+done
diff --git a/engine/tests/Functional.stunnel/tests/stunnel_netstat.sh b/engine/tests/Functional.stunnel/tests/stunnel_netstat.sh
new file mode 100644
index 0000000..b594e89
--- /dev/null
+++ b/engine/tests/Functional.stunnel/tests/stunnel_netstat.sh
@@ -0,0 +1,58 @@
+#!/bin/sh
+
+# Edit stunnel.conf and set the port on the client side.
+
+test="netstat"
+
+. ./fuego_board_function_lib.sh
+
+set_init_manager
+
+exec_service_on_target lighttpd stop
+
+if [ ! -f /etc/stunnel/stunnel.pem ]
+then
+    touch /etc/stunnel/stunnel.pem
+fi
+
+mv /etc/stunnel/stunnel.pem /etc/stunnel/stunnel.pem_bak
+cp data/stunnel.pem /etc/stunnel/stunnel.pem
+
+if [ -e /etc/stunnel/stunnel.conf ]
+then
+    mv /etc/stunnel/stunnel.conf /etc/stunnel/stunnel.conf_bak
+fi
+
+cp data/stunnel.conf /etc/stunnel/stunnel.conf
+
+if [ -e /var/log/stunnel.log ]
+then
+    rm -fr /var/log/stunnel.log
+fi
+
+stunnel
+sleep 5
+
+if netstat -tlnp | grep 443 | grep stunnel
+then
+    echo " -> set the port on the client side succeeded."
+else
+    echo " -> set the port on the client side failed."
+    echo " -> $test: TEST-FAIL"
+    killall stunnel
+    exit
+fi
+
+if killall stunnel
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> killall stunnel failed."
+    echo " -> $test: TEST-FAIL"
+fi
+
+if [ -e /etc/stunnel/stunnel.conf_ares.backup ]
+then
+    mv /etc/stunnel/stunnel.conf_bak /etc/stunnel/stunnel.conf
+fi
+mv /etc/stunnel/stunnel.pem_bak /etc/stunnel/stunnel.pem
diff --git a/engine/tests/Functional.stunnel/tests/stunnel_pidfile.sh b/engine/tests/Functional.stunnel/tests/stunnel_pidfile.sh
new file mode 100644
index 0000000..a7ff7eb
--- /dev/null
+++ b/engine/tests/Functional.stunnel/tests/stunnel_pidfile.sh
@@ -0,0 +1,69 @@
+#!/bin/sh
+
+#  In the target start stunnel, and check if the /var/run/stunnel.pid is exist.
+
+test="pidfile"
+
+. ./fuego_board_function_lib.sh
+
+set_init_manager
+
+exec_service_on_target lighttpd stop
+
+if [ ! -f /etc/stunnel/stunnel.pem ]
+then
+    touch /etc/stunnel/stunnel.pem
+fi
+
+mv /etc/stunnel/stunnel.pem /etc/stunnel/stunnel.pem_bak
+cp data/stunnel.pem /etc/stunnel/stunnel.pem
+
+if [ -e /etc/stunnel/stunnel.conf ]
+then
+    mv /etc/stunnel/stunnel.conf /etc/stunnel/stunnel.conf_bak
+fi
+
+cp data/stunnel.conf /etc/stunnel/stunnel.conf
+
+if [ -e /var/log/stunnel.log ]
+then
+    rm -fr /var/log/stunnel.log
+fi
+
+stunnel
+
+sleep 5
+
+if test -f /var/run/stunnel.pid
+then
+    echo " -> /var/run/stunnel.pid is exist."
+else
+    echo " -> /var/run/stunnel.pid is not exist."
+    echo " -> $test: TEST-FAIL"
+    killall stunnel
+    exit
+fi
+
+if killall stunnel
+then
+    echo " -> killall stunnel succeeded."
+else
+    echo " -> killall stunnel failed."
+    echo " -> $test: TEST-FAIL"
+    exit
+fi
+
+sleep 5
+
+if test -f /var/run/stunnel.pid
+then
+    echo " -> $test: TEST-FAIL"
+else
+    echo " -> $test: TEST-PASS"
+fi
+
+if [ -e /etc/stunnel/stunnel.conf_ares.backup ]
+then
+    mv /etc/stunnel/stunnel.conf_bak /etc/stunnel/stunnel.conf
+fi
+mv /etc/stunnel/stunnel.pem_bak /etc/stunnel/stunnel.pem
diff --git a/engine/tests/Functional.stunnel/tests/stunnel_ps.sh b/engine/tests/Functional.stunnel/tests/stunnel_ps.sh
new file mode 100644
index 0000000..1934fc6
--- /dev/null
+++ b/engine/tests/Functional.stunnel/tests/stunnel_ps.sh
@@ -0,0 +1,62 @@
+#!/bin/sh
+
+#  In the target start stunnel, and confirm the process condition by command ps.
+#  check the keyword "stunnel".
+
+test="ps"
+
+. ./fuego_board_function_lib.sh
+
+set_init_manager
+
+exec_service_on_target lighttpd stop
+
+if [ ! -f /etc/stunnel/stunnel.pem ]
+then
+    touch /etc/stunnel/stunnel.pem
+fi
+
+mv /etc/stunnel/stunnel.pem /etc/stunnel/stunnel.pem_bak
+cp data/stunnel.pem /etc/stunnel/stunnel.pem
+
+if [ -e /etc/stunnel/stunnel.conf ]
+then
+    mv /etc/stunnel/stunnel.conf /etc/stunnel/stunnel.conf_bak
+fi
+
+cp data/stunnel.conf /etc/stunnel/stunnel.conf
+
+stunnel
+sleep 5
+
+if ps -ax -ocommand | grep "^stunnel"
+then
+    echo " -> get the pid of stunnel."
+else
+    echo " -> can't get the pid of stunnel."
+    echo " -> $test: TEST-FAIL"
+    killall stunnel
+    exit
+fi
+
+if killall stunnel
+then
+    echo " -> killall stunnel succeeded."
+else
+    echo " -> killall stunnel failed."
+    echo " -> $test: TEST-FAIL"
+    exit
+fi
+
+if ps -ax -ocommand | grep "^stunnel"
+then
+    echo " -> $test: TEST-FAIL"
+else
+    echo " -> $test: TEST-PASS"
+fi
+
+if [ -e /etc/stunnel/stunnel.conf_ares.backup ]
+then
+    mv /etc/stunnel/stunnel.conf_bak /etc/stunnel/stunnel.conf
+fi
+mv /etc/stunnel/stunnel.pem_bak /etc/stunnel/stunnel.pem
diff --git a/engine/tests/Functional.stunnel/tests/stunnel_syslog-ng.sh b/engine/tests/Functional.stunnel/tests/stunnel_syslog-ng.sh
new file mode 100644
index 0000000..33b7e3b
--- /dev/null
+++ b/engine/tests/Functional.stunnel/tests/stunnel_syslog-ng.sh
@@ -0,0 +1,59 @@
+#!/bin/sh
+
+#  In the target start stunnel, and check the message of /var/log/stunnel.log.
+
+test="syslog-ng"
+
+. ./fuego_board_function_lib.sh
+
+set_init_manager
+
+exec_service_on_target lighttpd stop
+
+if [ ! -f /etc/stunnel/stunnel.pem ]
+then
+    touch /etc/stunnel/stunnel.pem
+fi
+
+mv /etc/stunnel/stunnel.pem /etc/stunnel/stunnel.pem_bak
+cp data/stunnel.pem /etc/stunnel/stunnel.pem
+
+if [ -e /etc/stunnel/stunnel.conf ]
+then
+    mv /etc/stunnel/stunnel.conf /etc/stunnel/stunnel.conf_bak
+fi
+cp data/stunnel.conf /etc/stunnel/stunnel.conf
+
+if [ -e /var/log/stunnel.log ]
+then
+    rm -fr /var/log/stunnel.log
+fi
+
+stunnel
+
+sleep 5
+
+if cat /var/log/stunnel.log | grep "Configuration successful"
+then
+    echo " -> creation of /var/log/stunnel.log succeeded."
+else
+    echo " -> creation of /var/log/stunnel.log failed."
+    echo " -> $test: TEST-FAIL"
+    killall stunnel
+exit
+fi
+
+if killall stunnel
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> killall stunnel failed."
+    echo " -> $test: TEST-FAIL"
+    exit
+fi
+
+if [ -e /etc/stunnel/stunnel.conf_ares.backup ]
+then
+    mv /etc/stunnel/stunnel.conf_bak /etc/stunnel/stunnel.conf
+fi
+mv /etc/stunnel/stunnel.pem_bak /etc/stunnel/stunnel.pem
-- 
1.8.3.1





More information about the Fuego mailing list