From 1f7c110083ca2dabd4a7bfbe16b903da178403ef Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Mon, 30 Dec 2024 12:43:50 +0100 Subject: [PATCH] test: verify tag based filtering Signed-off-by: Joachim Wiberg --- test/Makefile.am | 3 ++- test/tag.sh | 59 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100755 test/tag.sh diff --git a/test/Makefile.am b/test/Makefile.am index e56da64..1454304 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -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 @@ -27,5 +27,6 @@ TESTS += notify.sh TESTS += rotate_all.sh TESTS += secure.sh TESTS += sighup.sh +TESTS += tag.sh programs: $(check_PROGRAMS) diff --git a/test/tag.sh b/test/tag.sh new file mode 100755 index 0000000..d337231 --- /dev/null +++ b/test/tag.sh @@ -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"