source: trunk/test/testrun_1h.sh@ 559

Last change on this file since 559 was 550, checked in by katerina, 5 years ago

Fix for ticket #442 (support for OpenBSD signify).

File size: 6.9 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
22RCFILE="$PW_DIR/testrc_1.dyn"; export RCFILE
23LOGFILE="$PW_DIR/.samhain_log"; export LOGFILE
24
25# --enable-login-watch --enable-xml-log
26# --enable-debug --enable-suidcheck --with-prelude
27
28BUILDOPTS="--quiet $TRUST --prefix=$PW_DIR --localstatedir=$PW_DIR --with-config-file=$RCFILE --with-log-file=$LOGFILE --with-pid-file=$PW_DIR/.samhain_lock --with-data-file=$PW_DIR/.samhain_file --enable-debug"
29export BUILDOPTS
30
31BASE="${PW_DIR}/testrun_testdata"; export BASE
32TDIRS="a b c a/a a/b a/c a/a/a a/a/b a/a/c a/a/a/a a/a/a/b a/a/a/c"; export TDIRS
33TFILES="x y z"; export TFILES
34TFILES_PART="c/miss c/add c/change c/leave"; export TFILES_PART
35
36###########################################################
37#
38# ---- [Define tests here] ----
39#
40
41# 1 for testing new tests
42testrun1_setup=0
43
44MAXTEST=5; export MAXTEST
45
46PARTIAL_OUTFILE=".samhain_file_partial"; export PARTIAL_OUTFILE
47PARTIAL_FILTER="c/create c/miss c/change c/leave"; export PARTIAL_FILTER
48
49TEST_PART_POLICY_1="
50[ReadOnly]
51dir=${BASE}
52"
53mod_testdata_partial_1 () {
54 one_sec_sleep
55 rm "${BASE}/a/a/c/x" # delete
56}
57EXPECT_1="nullok"
58
59TEST_PART_POLICY_2="
60[ReadOnly]
61dir=${BASE}
62"
63mod_testdata_partial_2 () {
64 one_sec_sleep
65 echo "foobar" > "${BASE}/foo" # new
66}
67EXPECT_2="nullok"
68
69TEST_PART_POLICY_3="
70[ReadOnly]
71dir=${BASE}
72"
73mod_testdata_partial_3 () {
74 one_sec_sleep
75 rm -f "${BASE}/c/miss"
76}
77EXPECT_3=""
78
79TEST_PART_POLICY_4="
80[ReadOnly]
81dir=${BASE}
82"
83mod_testdata_partial_4 () {
84 one_sec_sleep
85 echo foo >"${BASE}/c/create"
86}
87EXPECT_4=""
88
89TEST_PART_POLICY_5="
90[ReadOnly]
91dir=${BASE}
92"
93mod_testdata_partial_5 () {
94 one_sec_sleep
95 echo toodledoo >"${BASE}/c/change"
96}
97EXPECT_5=""
98
99#
100# $2 == "nullok" means no mods should be detected,
101# else it is an error to detect no mods
102#
103run_check_partial_verify ()
104{
105 if [ "x$1" = "x" ]; then
106 logsev=debug
107 else
108 logsev=$1
109 fi
110 if ! test -f ${PARTIAL_OUTFILE}; then
111 [ -z "$quiet" ] && log_msg_fail "missing ${PARTIAL_OUTFILE} ...";
112 return 1
113 fi
114
115 rm -f test_log_valgrind
116
117 ${VALGRIND} ./samhain -p =err --verify-database ${PARTIAL_OUTFILE} 2>>test_log_valgrind
118
119 if test x$? = x0; then
120 if [ "x$2" != "xnullok" ]; then
121 [ -z "$quiet" ] && log_msg_fail "check (1a)...";
122 return 1
123 fi
124 else
125 if [ "x$2" = "xnullok" ]; then
126 [ -z "$quiet" ] && log_msg_fail "check (1b)...";
127 return 1
128 fi
129 fi
130
131 LL=`wc -l test_log_valgrind | awk '{ print $1; }'`
132 if ! test x$LL = x0; then
133 [ -z "$quiet" ] && log_msg_fail "check (2)...";
134 [ -z "$quiet" ] && cat test_log_valgrind
135 return 1
136 fi
137
138 [ -z "$verbose" ] || log_msg_ok "check...";
139}
140
141run_update_partial_verify ()
142{
143 ${VALGRIND} ./samhain -t update -p none -l debug 2>>test_log_valgrind
144
145 if test x$? = x0; then
146 [ -z "$verbose" ] || log_msg_ok "update...";
147 else
148 [ -z "$quiet" ] && log_msg_fail "update...";
149 return 1
150 fi
151}
152
153run_check_after_update_partial ()
154{
155 rm -rf $LOGFILE
156
157 run_check_partial_verify debug nullok
158}
159
160create_partial ()
161{
162 echo "${BASE}/c" > test_filter.txt
163 for ff in ${TFILES_PART}; do
164 echo "${BASE}/${ff}" >> test_filter.txt
165 done
166
167 ./samhain -o "${PARTIAL_OUTFILE}" --binary --list-filter=test_filter.txt --list-database=./.samhain_file
168
169 if test x$? = x0; then
170 [ -z "$verbose" ] || log_msg_ok "create partial DB...";
171 else
172 [ -z "$quiet" ] && log_msg_fail "create partial DB...";
173 return 1
174 fi
175
176 if test -f "${PARTIAL_OUTFILE}"; then
177 [ -z "$verbose" ] || log_msg_ok "partial DB exists...";
178 else
179 [ -z "$quiet" ] && log_msg_fail "partial DB exists...";
180 return 1
181 fi
182 rm -f test_filter.txt
183}
184
185prep_partial_testpolicy ()
186{
187 test -f "${RCFILE}" || touch "${RCFILE}"
188 eval echo '"$'"TEST_PART_POLICY_$1"'"' >>"${RCFILE}"
189}
190
191prep_testdata_partial ()
192{
193 prep_testdata
194 if test x$? = x0; then
195 touch "${BASE}/c/miss"
196 touch "${BASE}/c/change"
197 touch "${BASE}/c/leave"
198 else
199 return 1
200 fi
201}
202
203testrun_internal_partial_verify ()
204{
205 [ -z "$verbose" ] || echo Working directory: $PW_DIR
206 [ -z "$verbose" ] || { echo MAKE is $MAKE; echo; }
207
208 #
209 # test standalone compilation
210 #
211 [ -z "$verbose" ] || { echo; echo "${S}Building standalone agent${E}"; echo; }
212
213 if test -r "Makefile"; then
214 $MAKE distclean >/dev/null
215 fi
216
217 ${TOP_SRCDIR}/configure ${BUILDOPTS}
218
219 #
220 if test x$? = x0; then
221 [ -z "$verbose" ] || log_msg_ok "configure...";
222 $MAKE >/dev/null 2>>test_log
223 if test x$? = x0; then
224 [ -z "$verbose" ] || log_msg_ok "make...";
225 else
226 [ -z "$quiet" ] && log_msg_fail "make...";
227 return 1
228 fi
229
230 else
231 [ -z "$quiet" ] && log_msg_fail "configure...";
232 return 1
233 fi
234
235 [ -z "$verbose" ] || { echo; echo "${S}Running test suite${E}"; echo; }
236
237 tcount=1
238 POLICY=`eval echo '"$'"TEST_PART_POLICY_$tcount"'"'`
239
240 until [ -z "$POLICY" ]
241 do
242 prep_init
243 check_err $? ${tcount}; errval=$?
244 if [ $errval -eq 0 ]; then
245 prep_testdata_partial
246 check_err $? ${tcount}; errval=$?
247 fi
248 if [ $errval -eq 0 ]; then
249 prep_partial_testpolicy ${tcount}
250 check_err $? ${tcount}; errval=$?
251 fi
252 if [ $errval -eq 0 ]; then
253 run_init
254 check_err $? ${tcount}; errval=$?
255 fi
256 if [ $errval -eq 0 ]; then
257 create_partial
258 check_err $? ${tcount}; errval=$?
259 fi
260 if [ $errval -eq 0 ]; then
261 eval mod_testdata_partial_${tcount}
262 check_err $? ${tcount}; errval=$?
263 fi
264 if [ $errval -eq 0 ]; then
265 arg2=`eval echo '"$'"EXPECT_$tcount"'"'`
266 run_check_partial_verify debug $arg2
267 check_err $? ${tcount}; errval=$?
268 fi
269 if [ $testrun1_setup -eq 0 ]; then
270 if [ $errval -eq 0 ]; then
271 run_update_partial_verify
272 check_err $? ${tcount}; errval=$?
273 fi
274 if [ $errval -eq 0 ]; then
275 create_partial
276 check_err $? ${tcount}; errval=$?
277 fi
278 if [ $errval -eq 0 ]; then
279 run_check_after_update_partial
280 check_err $? ${tcount}; errval=$?
281 fi
282 fi
283 #
284 if [ $errval -eq 0 ]; then
285 [ -z "$quiet" ] && log_ok ${tcount} ${MAXTEST};
286 fi
287 #
288 let "tcount = tcount + 1" >/dev/null
289 #
290 POLICY=`eval echo '"$'"TEST_PART_POLICY_$tcount"'"'`
291 done
292
293 return 0
294}
295
296testrun1h ()
297{
298 log_start "RUN CL Partial DB Verify"
299 testrun_internal_partial_verify
300 log_end "RUN CL Partial DB Verify"
301 return 0
302}
303
304
305
Note: See TracBrowser for help on using the repository browser.