Skip to content

Commit 742baf6

Browse files
committed
test: add stop-processing regression test
Verify that the :: (propfilter), !! (program), and ++ (hostname) stop-block prefixes prevent a matched message from reaching subsequent rules, while non-matching messages continue to fall through normally. Eight steps cover both positive (message lands in the right log) and negative (message absent from the wrong log) assertions for the propfilter and program-filter variants. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
1 parent 33d9fc9 commit 742baf6

2 files changed

Lines changed: 112 additions & 1 deletion

File tree

test/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ EXTRA_DIST += api.sh local.sh unicode.sh remote.sh fwd.sh mark.sh \
44
logger.sh listen.sh sighup.sh tag.sh hostname.sh \
55
property.sh raw.sh regression.sh multicast.sh \
66
mcast-fwd.sh mcast-iface.sh parens.sh tcp-fwd.sh sign.sh \
7-
tls-fwd.sh
7+
tls-fwd.sh stop.sh
88
CLEANFILES = *~ *.trs *.log
99
TEST_EXTENSIONS = .sh
1010
TESTS_ENVIRONMENT= unshare -mrun --map-auto
@@ -40,6 +40,7 @@ TESTS += multicast.sh
4040
TESTS += mcast-fwd.sh
4141
TESTS += mcast-iface.sh
4242
TESTS += tcp-fwd.sh
43+
TESTS += stop.sh
4344
if ENABLE_SSL
4445
TESTS += sign.sh
4546
TESTS += tls-fwd.sh

test/stop.sh

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#!/bin/sh
2+
# Verify stop-processing block prefixes (!! ++ ::)
3+
#
4+
# A block prefixed with :: (propfilter), !! (program), or ++ (hostname)
5+
# stops further rule processing for a matching message. This test
6+
# exercises all three forms and confirms that non-matching messages
7+
# fall through to subsequent rules as expected.
8+
#
9+
. "${srcdir:-.}/lib.sh"
10+
11+
MSG_STOP="STOPME-needle-7a3f"
12+
MSG_PASS="PASSTHRU-needle-8b2e"
13+
MSG_PROG="PROGSTOP-needle-9c1d"
14+
MSG_OTHER="OTHERPROG-needle-0d4c"
15+
16+
LOGDIR="$DIR/log"
17+
STOPLOG="${LOGDIR}/stop.log"
18+
PROGLOG="${LOGDIR}/prog.log"
19+
CATCHALL="${LOGDIR}/all.log"
20+
21+
# Config layout:
22+
# 1. ::propfilter stop-block → STOPLOG (stops; MSG_STOP never reaches CATCHALL)
23+
# 2. !!stopper stop-block → PROGLOG (stops; MSG_PROG from "stopper" never reaches CATCHALL)
24+
# 3. !* resets program filter so the catch-all below applies to all programs
25+
# 4. catch-all → CATCHALL (receives everything not stopped above)
26+
setup_syslogd()
27+
{
28+
mkdir -p "$LOGDIR"
29+
cat <<-EOF >"${CONF}"
30+
::msg, contains, "${MSG_STOP}"
31+
*.* ${STOPLOG}
32+
!!stopper
33+
*.* ${PROGLOG}
34+
!*
35+
*.* -${CATCHALL}
36+
EOF
37+
setup -m0
38+
}
39+
40+
# Send MSG_STOP, expect it in STOPLOG
41+
check_stop_in_stoplog()
42+
{
43+
logger -t test -p user.notice "${MSG_STOP}"
44+
sleep 1
45+
grep "${MSG_STOP}" "${STOPLOG}"
46+
}
47+
48+
# MSG_STOP must NOT appear in CATCHALL (stop-processing worked)
49+
check_stop_not_in_catchall()
50+
{
51+
grep "${MSG_STOP}" "${CATCHALL}" && return 1
52+
return 0
53+
}
54+
55+
# Send MSG_PASS (no match for stop filter), expect it in CATCHALL
56+
check_pass_in_catchall()
57+
{
58+
logger -t test -p user.notice "${MSG_PASS}"
59+
sleep 1
60+
grep "${MSG_PASS}" "${CATCHALL}"
61+
}
62+
63+
# MSG_PASS must NOT appear in STOPLOG
64+
check_pass_not_in_stoplog()
65+
{
66+
grep "${MSG_PASS}" "${STOPLOG}" && return 1
67+
return 0
68+
}
69+
70+
# Send MSG_PROG from tag "stopper", expect it in PROGLOG (!! stop-block)
71+
check_prog_in_proglog()
72+
{
73+
logger -t stopper -p user.notice "${MSG_PROG}"
74+
sleep 1
75+
grep "${MSG_PROG}" "${PROGLOG}"
76+
}
77+
78+
# MSG_PROG from "stopper" must NOT appear in CATCHALL
79+
check_prog_not_in_catchall()
80+
{
81+
grep "${MSG_PROG}" "${CATCHALL}" && return 1
82+
return 0
83+
}
84+
85+
# Send MSG_OTHER from a different tag, expect it in CATCHALL only
86+
check_other_in_catchall()
87+
{
88+
logger -t otherprog -p user.notice "${MSG_OTHER}"
89+
sleep 1
90+
grep "${MSG_OTHER}" "${CATCHALL}"
91+
}
92+
93+
# MSG_OTHER must NOT appear in PROGLOG
94+
check_other_not_in_proglog()
95+
{
96+
grep "${MSG_OTHER}" "${PROGLOG}" && return 1
97+
return 0
98+
}
99+
100+
run_step "Set up syslogd with stop-processing rules" setup_syslogd
101+
102+
run_step "Matched msg (propfilter ::) lands in stop log" check_stop_in_stoplog
103+
run_step "Matched msg (propfilter ::) absent from catch-all" check_stop_not_in_catchall
104+
run_step "Non-matched msg reaches catch-all" check_pass_in_catchall
105+
run_step "Non-matched msg absent from stop log" check_pass_not_in_stoplog
106+
107+
run_step "Matched msg (program !!) lands in prog log" check_prog_in_proglog
108+
run_step "Matched msg (program !!) absent from catch-all" check_prog_not_in_catchall
109+
run_step "Other-program msg reaches catch-all" check_other_in_catchall
110+
run_step "Other-program msg absent from prog log" check_other_not_in_proglog

0 commit comments

Comments
 (0)