source: branches/samhain-2_2-branch/test/testrun_1b.sh@ 434

Last change on this file since 434 was 60, checked in by rainer, 18 years ago

Add regression test for trac ticket #32.

File size: 8.0 KB
Line 
1#! /bin/sh
2
3#
4# Copyright Rainer Wichmann (2006)
5#
6# License Information:
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program; if not, write to the Free Software
19# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20#
21
22MAXTEST=3; export MAXTEST
23LOGFILE="$PW_DIR/.samhain_log"; export LOGFILE
24RCFILE="$PW_DIR/testrc_1.dyn"; export RCFILE
25
26testrun1b_internal ()
27{
28 BUILDOPTS="$1"
29 #
30 # test standalone compilation
31 #
32 [ -z "$verbose" ] || { echo; echo "${S}Building standalone agent${E}"; echo; }
33 #
34 if test -r "Makefile"; then
35 $MAKE distclean >/dev/null >&1
36 fi
37 #
38 #
39 ${TOP_SRCDIR}/configure ${BUILDOPTS} >/dev/null 2>/dev/null
40 #
41 #
42 if test x$? = x0; then
43 [ -z "$verbose" ] || log_msg_ok "configure...";
44 $MAKE > /dev/null 2>&1
45 if test x$? = x0; then
46 [ -z "$verbose" ] || log_msg_ok "make...";
47 else
48 [ -z "$quiet" ] && log_msg_fail "make...";
49 return 1
50 fi
51
52 else
53 [ -z "$quiet" ] && log_msg_fail "configure...";
54 return 1
55 fi
56
57 SKIP=`awk '/^__ARCHIVE_FOLLOWS__/ { print NR + 1; exit 0; }' ${SCRIPTDIR}/test.sh`
58
59 tail -n "+$SKIP" ${SCRIPTDIR}/test.sh >/dev/null 2>&1
60 if [ $? -eq 0 ]; then
61 tail -n "+$SKIP" ${SCRIPTDIR}/test.sh | gunzip -c - | tar xf - && \
62 mv "./testrc.gpg.asc" "$RCFILE"
63 else
64 tail "+$SKIP" ${SCRIPTDIR}/test.sh | gunzip -c - | tar xf - && \
65 mv "./testrc.gpg.asc" "$RCFILE"
66 fi
67 if test x$? = x0; then
68 [ -z "$verbose" ] || log_msg_ok "extract gpg signed files...";
69 else
70 [ -z "$quiet" ] && log_msg_fail "extract gpg signed files...";
71 return 1
72 fi
73
74 if test "x$2" = "x"; then
75 :
76 else
77 CONVERT="$2"
78 if test -f "${TOP_SRCDIR}/stealth_template.jpg"; then
79 [ -z "$verbose" ] || log_msg_ok "convert..."
80 "${CONVERT}" +compress "${TOP_SRCDIR}/stealth_template.jpg" stealth_template.ps >/dev/null
81 else
82 [ -z "$quiet" ] && log_msg_fail "cannot find file stealth_template.jpg"
83 return 1
84 fi
85 if [ $? -ne 0 ]; then
86 [ -z "$quiet" ] && log_msg_fail "${CONVERT} +compress ${TOP_SRCDIR}/stealth_template.jpg stealth_template.ps";
87 return 1
88 fi
89
90 [ -z "$verbose" ] || log_msg_ok "hide..."
91 ./samhain_stealth -s stealth_template.ps "$RCFILE" >/dev/null
92 if [ $? -ne 0 ]; then
93 [ -z "$quiet" ] && log_msg_fail "${CONVERT} +compress ${TOP_SRCDIR}/stealth_template.jpg stealth_template.ps";
94 return 1
95 fi
96
97 mv -f stealth_template.ps "$RCFILE"
98 if [ $? -ne 0 ]; then
99 [ -z "$quiet" ] && log_msg_fail "mv -f stealth_template.ps $RCFILE";
100 return 1
101 fi
102
103 fi
104
105 rm -f ./.samhain_file
106 rm -f ./.samhain_log
107 rm -f ./.samhain_lock
108
109 ./samhain -t init -p none -l info
110
111 if test x$? = x0; then
112 [ -z "$verbose" ] || log_msg_ok "init...";
113 else
114 [ -z "$quiet" ] && log_msg_fail "init...";
115 return 1
116 fi
117
118 mv $PW_DIR/.samhain_file.asc $PW_DIR/.samhain_file
119}
120
121do_test_1b () {
122
123 ./samhain -t check -p none -l info
124
125 if test x$? = x0; then
126 ./samhain -j -L $LOGFILE >"${LOGFILE}.tmp" && mv "${LOGFILE}.tmp" "${LOGFILE}"
127 if [ $? -ne 0 ]; then
128 [ -z "$quiet" ] && log_msg_fail "mv logfile...";
129 return 1
130 fi
131 [ -z "$verbose" ] || log_msg_ok "check...";
132 else
133 [ -z "$quiet" ] && log_msg_fail "check...";
134 return 1
135 fi
136 #
137 tmp=`egrep "Checking.*/etc(>|\")" $LOGFILE 2>/dev/null | wc -l`
138 if [ $tmp -ne 2 ]; then
139 [ -z "$verbose" ] || log_msg_fail "/etc";
140 return 1
141 fi
142 tmp=`egrep "Checking.*(>|\")" $LOGFILE 2>/dev/null | wc -l`
143 if [ $tmp -ne 8 ]; then
144 [ -z "$verbose" ] || log_msg_fail "checking";
145 return 1
146 fi
147 egrep "ADDED" $LOGFILE >/dev/null 2>&1
148 if [ $? -eq 0 ]; then
149 [ -z "$verbose" ] || log_msg_fail "init was incomplete";
150 return 1
151 fi
152 #
153 return 0
154}
155
156do_test_1b_2 () {
157
158 rm -f $PW_DIR/test_log_prelude
159
160 "$PM" --textmod -l $PW_DIR/test_log_prelude --listen 127.0.0.1:5500 >/dev/null 2>&1 &
161 PID=$!
162
163 five_sec_sleep
164
165 ./samhain -t check -p none -l info --set-prelude-severity=info --prelude --server-addr 127.0.0.1:5500 >/dev/null
166
167 if test x$? = x0; then
168 ./samhain -j -L $LOGFILE >"${LOGFILE}.tmp" && mv "${LOGFILE}.tmp" "${LOGFILE}"
169 if [ $? -ne 0 ]; then
170 [ -z "$quiet" ] && log_msg_fail "mv logfile...";
171 kill $PID
172 return 1
173 fi
174 [ -z "$verbose" ] || log_msg_ok "check...";
175 else
176 [ -z "$quiet" ] && log_msg_fail "check...";
177 kill $PID
178 return 1
179 fi
180 #
181 tmp=`egrep 'File original:.*name=etc.*path=/etc' test_log_prelude 2>/dev/null | wc -l`
182 if [ $tmp -ne 1 ]; then
183 [ -z "$verbose" ] || log_msg_fail "/etc";
184 fi
185 tmp=`egrep 'Classification text: Checking' test_log_prelude 2>/dev/null | wc -l`
186 if [ $tmp -ne 1 ]; then
187 [ -z "$verbose" ] || log_msg_fail "checking";
188 fi
189 tmp=`egrep 'Classification text: Checking' test_log_prelude 2>/dev/null | wc -l`
190 if [ $tmp -ne 1 ]; then
191 [ -z "$verbose" ] || log_msg_fail "checking";
192 fi
193 #
194 kill $PID
195 return 0
196}
197
198testrun1b ()
199{
200 log_start "RUN STANDALONE W/STEALTH W/GPG"
201 GPG=`find_path gpg`
202 if [ -z "$GPG" ]; then
203 log_skip 1 $MAXTEST 'gpg not found in $PATH'
204 log_skip 2 $MAXTEST 'gpg not found in $PATH'
205 else
206 eval "$GPG" --list-keys 0F571F6C >/dev/null 2>/dev/null
207 if [ $? -ne 0 ]; then
208 log_skip 1 $MAXTEST 'public PGP key 0x0F571F6C not present'
209 log_skip 2 $MAXTEST 'public PGP key 0x0F571F6C not present'
210 else
211 #
212 # ------------- first test -------------
213 #
214 BUILDOPTS="--quiet $TRUST --enable-debug --with-gpg=${GPG} --with-checksum=no --enable-micro-stealth=137 --enable-login-watch --prefix=$PW_DIR --localstatedir=$PW_DIR --with-config-file=$RCFILE --with-log-file=$PW_DIR/.samhain_log --with-pid-file=$PW_DIR/.samhain_lock --with-data-file=$PW_DIR/.samhain_file"
215 testrun1b_internal "${BUILDOPTS}"
216 do_test_1b
217 if [ $? -eq 0 ]; then
218 log_ok 1 $MAXTEST 'gpg signed config/database files'
219 else
220 log_fail 1 $MAXTEST 'gpg signed config/database files'
221 fi
222
223
224 #
225 # ------------- second test -------------
226 #
227 PRECONV=`find_path convert`
228 "${PRECONV}" --help | grep ImageMagick >/dev/null 2>&1 && \
229 CONVERT="${PRECONV}"
230
231 if [ -z "$CONVERT" ]; then
232 log_skip 2 $MAXTEST 'ImageMagick convert not found in $PATH'
233 else
234 BUILDOPTS="--quiet $TRUST --enable-debug --with-gpg=${GPG} --with-checksum=no --enable-stealth=137 --enable-login-watch --prefix=$PW_DIR --localstatedir=$PW_DIR --with-config-file=$RCFILE --with-log-file=$PW_DIR/.samhain_log --with-pid-file=$PW_DIR/.samhain_lock --with-data-file=$PW_DIR/.samhain_file"
235 testrun1b_internal "${BUILDOPTS}" "$CONVERT"
236 do_test_1b
237 if [ $? -eq 0 ]; then
238 log_ok 2 $MAXTEST 'gpg signed config/database files'
239 else
240 log_fail 2 $MAXTEST 'gpg signed config/database files'
241 fi
242 fi
243
244
245 #
246 # ------------- third test -------------
247 #
248 PM=`find_path prelude-manager`
249 if [ -z "$PM" ]; then
250 log_skip 3 $MAXTEST 'prelude-manager not found in $PATH'
251 elif [ -z "$doall" ]; then
252 log_skip 3 $MAXTEST 'logging to prelude (or use --really-all)'
253 else
254 BUILDOPTS="--quiet $TRUST --enable-debug --with-prelude --with-gpg=${GPG} --with-checksum=no --enable-micro-stealth=137 --enable-login-watch --prefix=$PW_DIR --localstatedir=$PW_DIR --with-config-file=$RCFILE --with-log-file=$PW_DIR/.samhain_log --with-pid-file=$PW_DIR/.samhain_lock --with-data-file=$PW_DIR/.samhain_file"
255 testrun1b_internal "${BUILDOPTS} CFLAGS=-DSH_NOFAILOVER=1"
256 do_test_1b_2
257 if [ $? -eq 0 ]; then
258 log_ok 3 $MAXTEST 'logging to prelude'
259 else
260 log_fail 3 $MAXTEST 'logging to prelude'
261 fi
262 fi
263 fi
264 fi
265 log_end "RUN STANDALONE W/STEALTH W/GPG"
266 return 0
267}
268
Note: See TracBrowser for help on using the repository browser.