Skip to content

Commit

Permalink
test: verify hostname 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 679a70f commit 02011d8
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 2 deletions.
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 tag.sh
logger.sh listen.sh sighup.sh tag.sh hostname.sh
CLEANFILES = *~ *.trs *.log
TEST_EXTENSIONS = .sh
TESTS_ENVIRONMENT= unshare -mrun
Expand All @@ -28,5 +28,6 @@ TESTS += rotate_all.sh
TESTS += secure.sh
TESTS += sighup.sh
TESTS += tag.sh
TESTS += hostname.sh

programs: $(check_PROGRAMS)
69 changes: 69 additions & 0 deletions test/hostname.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/sh
# Verify hstname based filtering.
#set -x
. "${srcdir:-.}/lib.sh"

HST1="finlandia"
HST2="sibelius"
MSG1="Be Still, My Soul"
MSG2="Oi Suomi, katso"
TEXT="Ack Värmeland, du sköna"

LOGDIR="$DIR/log"
SYSLOG="${LOGDIR}/syslog"
HST1LG="${LOGDIR}/$HST1.log"
HST2LG="${LOGDIR}/$HST2.log"

setup_syslogd()
{
mkdir -p "$LOGDIR"
cat <<-EOF >"${CONF}"
#-$HST1,$HST2
*.* -$SYSLOG
#+$HST1
*.* $HST1LG
#+$HST2
*.* $HST2LG
EOF
setup -m0 -8
}

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

if [ "$hst" = "@" ]; then
pri=user.panic
usr="$LOGNAME"
else
pri=daemon.notice
usr="jean"
fi

logger -H "$hst" -t "$usr" -p $pri "$msg"
grep -H "$msg" "$log"
}

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

grep -H "$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_hst "$HST1" "$HST1LG" "$MSG1"
run_step "Verify basic tag based filtering (2)" verify_hst "$HST2" "$HST2LG" "$MSG2"
run_step "Verify not in syslog" verify_not "$SYSLOG" "$MSG1"

run_step "Verify unfiltered host logging" verify_hst "@" "$SYSLOG" "$TEXT"
run_step "Verify unfiltered message in syslog" verify_log "$SYSLOG" "$TEXT"
run_step "Verify unfiltered message not filtered" verify_not "$HST1LG" "$TEXT"
2 changes: 1 addition & 1 deletion test/tag.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
# Verify property based filtering, including ident/tag.
# Verify log filtering based on ident/tag.
. "${srcdir:-.}/lib.sh"

TG1=pimd
Expand Down

0 comments on commit 02011d8

Please sign in to comment.