Skip to content

Commit

Permalink
test: verify tag based filtering
Browse files Browse the repository at this point in the history
Signed-off-by: Joachim Wiberg <[email protected]>
  • Loading branch information
troglobit committed Dec 30, 2024
1 parent 42c87d7 commit 1f7c110
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
3 changes: 2 additions & 1 deletion test/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
EXTRA_DIST = lib.sh opts.sh
EXTRA_DIST += api.sh local.sh unicode.sh remote.sh fwd.sh mark.sh \
memleak.sh facility.sh notify.sh rotate_all.sh secure.sh \
logger.sh listen.sh sighup.sh
logger.sh listen.sh sighup.sh tag.sh
CLEANFILES = *~ *.trs *.log
TEST_EXTENSIONS = .sh
TESTS_ENVIRONMENT= unshare -mrun
Expand All @@ -27,5 +27,6 @@ TESTS += notify.sh
TESTS += rotate_all.sh
TESTS += secure.sh
TESTS += sighup.sh
TESTS += tag.sh

programs: $(check_PROGRAMS)
59 changes: 59 additions & 0 deletions test/tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/sh
# Verify property based filtering, including ident/tag.
. "${srcdir:-.}/lib.sh"

TG1=pimd
TG2=mrouted
MSG="Multicast, a perfect weapon for an imperfect time."
UNX="In UNIX we trust"

LOGDIR="$DIR/log"
SYSLOG="${LOGDIR}/syslog"
TG1LOG="${LOGDIR}/$TG1.log"
TG2LOG="${LOGDIR}/$TG2.log"

setup_syslogd()
{
mkdir -p "$LOGDIR"
cat <<-EOF >"${CONF}"
#!-$TG1,$TG2
*.* -$SYSLOG
#!$TG1
*.* $TG1LOG
#!$TG2
*.* $TG2LOG
EOF
setup -m0
}

verify_tag()
{
tag="$1"; shift
log="$1"; shift
msg="$*"

logger -t "$tag" "$msg"
grep "$msg" "$log"
}

verify_log()
{
log="$1"; shift
msg="$*"

grep "$msg" "$log"
}

verify_not()
{
verify_log "$@" || return 0
}

run_step "Set up property based filtering syslogd" setup_syslogd
run_step "Verify basic tag based filtering (1)" verify_tag "$TG1" "$TG1LOG" "$MSG"
run_step "Verify basic tag based filtering (2)" verify_tag "$TG2" "$TG2LOG" "$MSG"
run_step "Verify not in syslog" verify_not "$SYSLOG" "$MSG"

run_step "Verify unfiltered tag logging" verify_tag "foo" "$SYSLOG" "$UNX"
run_step "Verify unfiltered message in syslog" verify_log "$SYSLOG" "$UNX"
run_step "Verify unfiltered message not filtered" verify_not "$TG1LOG" "$UNX"

0 comments on commit 1f7c110

Please sign in to comment.