From nobody Mon Dec 23 15:49:52 2024 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4YH2XK2Ppbz5WqtM; Mon, 23 Dec 2024 15:49:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YH2XK0Dwbz4phQ; Mon, 23 Dec 2024 15:49:53 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1734968993; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=XqKd2dOc+snxAVVQvp3qscIviNEVosyT9eTUrG21CJA=; b=Stk2r6Vpm61/Sz28Wj727/C5cXff5D8hPLOnfvtFo3bZnMlQBsE0Q/90sQJ+x+JXkhdfoy xGNzWSG+wcsNmB/BycupcvKMNuJ4YZPccNjCdS1sg0pUN0XEuT0URvAb+MRjsfe701VN/b kPBgFvAqyAP/Ssav6V9Ds+4WRp7BDc/8WSMv16/ajStSnyTNJWpqpLuM8JQZDuRS7b0ywd lN3zdN9swQUT9zbMXgbvUeTHvsbFgtmSXpyaFwm90L42VQ//NuM+XtWlAfPfnHQBPZV5tf U0wmsppBnEYHpqiSHD9pZGpIRTGtSps6qMa38CJdIyHIg8xKQJoV8QPwSkrXwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1734968993; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=XqKd2dOc+snxAVVQvp3qscIviNEVosyT9eTUrG21CJA=; b=laiLfBmZkAjKgcCtegu0xLElmWnnKRXDdQvmfNx/JIP/pVcgwU1Q4Ysw9Uvrnb8igyXW0s 2UXX5lakLBgabzI0B8vlooyLN9HTMgZrgifdn+1hecld0+qGOqsfYhvHcLCUIxpVaKO4CX Za6nURH2kS+Gi/KR8Ilm0lZymuD+HQUqKeNU1YgaCpJsYRYX154hnU5UqoBjg6E2utkH1R 7il6YqfjE1NYwJ7VKGj34Ty2A0gQphRFBm8upJ8UPd9gEZm+f6TkqQSSqOw+klFogC1yZg NEEBRxuVSuZF5uWpESy33iDnq96ksf7DrN851i9v287NWIjwa5qj/dz/sPnT+A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1734968993; a=rsa-sha256; cv=none; b=qQQDtVr/3vUH6fOq1NWyOph7aFSV9aBzOMLVMCY3bYI7ikn+rwENufrxCgotJtrLJft4BD DGTj4o61NtQ4vu/8wqsRztaBQGUmn3m8PjCxD08q/moNmKz3owc+WM/+puku1QuE9ak3OI XLnzD0/NlYsbPb0vfUDtjr1uIFwg+99YrNvQrN3Uu5up7EC4QUVBuUZx9AJ+ebq0i1ocpk qM2OBAqtSeIHDpucYPXXN+OBBH9+xjNfHD/pF7ywZ9dVizEOnNb+qblm7HiUAZ78S3sTKu n8hb4BhtElvwPk7ze8QG2egkQheZRgUyqEQ3nfrf9ymdVgO6u89oXHqbf5Bd5w== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4YH2XJ6fx8z107x; Mon, 23 Dec 2024 15:49:52 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4BNFnqrH011942; Mon, 23 Dec 2024 15:49:52 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4BNFnqRJ011939; Mon, 23 Dec 2024 15:49:52 GMT (envelope-from git) Date: Mon, 23 Dec 2024 15:49:52 GMT Message-Id: <202412231549.4BNFnqRJ011939@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 66a022a30dd9 - main - syslogd: Add syslog basic message format tests List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 66a022a30dd968631c64b73e473dd16589592fad Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=66a022a30dd968631c64b73e473dd16589592fad commit 66a022a30dd968631c64b73e473dd16589592fad Author: Michal Scigocki AuthorDate: 2024-12-23 02:53:51 +0000 Commit: Mark Johnston CommitDate: 2024-12-23 15:45:12 +0000 syslogd: Add syslog basic message format tests RFC 3164 and RFC 5424 syslog message format tests and minor refactor of existing tests to reuse components in new tests. Reviewed by: markj MFC after: 3 weeks Pull Request: https://github.com/freebsd/freebsd-src/pull/1536 --- usr.sbin/syslogd/tests/Makefile | 11 +- .../syslogd/tests/syslogd_basic_format_test.sh | 111 +++++++++++++++++++ .../syslogd/tests/syslogd_format_test_common.sh | 32 ++++++ usr.sbin/syslogd/tests/syslogd_test.sh | 105 +----------------- usr.sbin/syslogd/tests/syslogd_test_common.sh | 117 +++++++++++++++++++++ 5 files changed, 270 insertions(+), 106 deletions(-) diff --git a/usr.sbin/syslogd/tests/Makefile b/usr.sbin/syslogd/tests/Makefile index c60709b0531d..65d08d75fcd1 100644 --- a/usr.sbin/syslogd/tests/Makefile +++ b/usr.sbin/syslogd/tests/Makefile @@ -1,7 +1,14 @@ -ATF_TESTS_SH= syslogd_test +PACKAGE= tests + +ATF_TESTS_SH= syslogd_basic_format_test \ + syslogd_test + # Run in jail with new vnet so we don't need to worry about address conflicts TEST_METADATA= execenv="jail" \ - execenv_jail_params="vnet=new" + execenv_jail_params="vnet=new" \ timeout=20 +${PACKAGE}FILES=syslogd_format_test_common.sh \ + syslogd_test_common.sh + .include diff --git a/usr.sbin/syslogd/tests/syslogd_basic_format_test.sh b/usr.sbin/syslogd/tests/syslogd_basic_format_test.sh new file mode 100644 index 000000000000..7ee7cd0e1e91 --- /dev/null +++ b/usr.sbin/syslogd/tests/syslogd_basic_format_test.sh @@ -0,0 +1,111 @@ +#- +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (c) 2024 Michal Scigocki +# + +. $(atf_get_srcdir)/syslogd_test_common.sh +. $(atf_get_srcdir)/syslogd_format_test_common.sh + +# Basic format tests +# Single server, logging to local socket (inet disabled) +setup_basic_format_test() +{ + local format="$1" + local logfile="$2" + + printf "user.debug\t${logfile}\n" > "${SYSLOGD_CONFIG}" + + syslogd_start \ + -O "${format}" \ + -N \ + -ss + + syslogd_log -p user.debug -t "${TAG}" \ + -h "${SYSLOGD_LOCAL_SOCKET}" \ + -H "${HOSTNAME}" "${MSG}" +} + +atf_test_case "O_flag_bsd_basic" "cleanup" +O_flag_bsd_basic_head() +{ + atf_set descr "bsd format test on local syslog message" +} +O_flag_bsd_basic_body() +{ + local format="bsd" + local logfile="${PWD}/O_flag_${format}_basic.log" + + setup_basic_format_test "${format}" "${logfile}" + + atf_check -s exit:0 -o match:"${REGEX_RFC3164_LOGFILE}" cat "${logfile}" +} +O_flag_bsd_basic_cleanup() +{ + syslogd_stop +} + +atf_test_case "O_flag_rfc3164_basic" "cleanup" +O_flag_rfc3164_basic_head() +{ + atf_set descr "rfc3164 format test on local syslog message" +} +O_flag_rfc3164_basic_body() +{ + local format="rfc3164" + local logfile="${PWD}/O_flag_${format}_basic.log" + + setup_basic_format_test "${format}" "${logfile}" + + atf_check -s exit:0 -o match:"${REGEX_RFC3164_LOGFILE}" cat "${logfile}" +} +O_flag_rfc3164_basic_cleanup() +{ + syslogd_stop +} + +atf_test_case "O_flag_syslog_basic" "cleanup" +O_flag_syslog_basic_head() +{ + atf_set descr "syslog format test on local syslog message" +} +O_flag_syslog_basic_body() +{ + local format="syslog" + local logfile="${PWD}/O_flag_${format}_basic.log" + + setup_basic_format_test "${format}" "${logfile}" + + atf_check -s exit:0 -o match:"${REGEX_RFC5424_LOGFILE}" cat "${logfile}" +} +O_flag_syslog_basic_cleanup() +{ + syslogd_stop +} + +atf_test_case "O_flag_rfc5424_basic" "cleanup" +O_flag_rfc5424_basic_head() +{ + atf_set descr "rfc5424 format test on local syslog message" +} +O_flag_rfc5424_basic_body() +{ + local format="rfc5424" + local logfile="${PWD}/O_flag_${format}_basic.log" + + setup_basic_format_test "${format}" "${logfile}" + + atf_check -s exit:0 -o match:"${REGEX_RFC5424_LOGFILE}" cat "${logfile}" +} +O_flag_rfc5424_basic_cleanup() +{ + syslogd_stop +} + +atf_init_test_cases() +{ + atf_add_test_case "O_flag_bsd_basic" + atf_add_test_case "O_flag_rfc3164_basic" + atf_add_test_case "O_flag_syslog_basic" + atf_add_test_case "O_flag_rfc5424_basic" +} diff --git a/usr.sbin/syslogd/tests/syslogd_format_test_common.sh b/usr.sbin/syslogd/tests/syslogd_format_test_common.sh new file mode 100644 index 000000000000..199fb746839c --- /dev/null +++ b/usr.sbin/syslogd/tests/syslogd_format_test_common.sh @@ -0,0 +1,32 @@ +#- +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (c) 2024 Michal Scigocki +# + +# REGEX Components +readonly PRI="<15>" +readonly VERSION="1" +readonly DATE_RFC3164="[A-Z][a-z]{2} [ 1-3][0-9]" +readonly TIMESPEC_RFC5424="([:TZ0-9\.\+\-]{20,32}|\-)" # Simplified TIMESPEC +readonly TIME_RFC3164="([0-9]{2}:){2}[0-9]{2}" +readonly HOSTNAME="example.test" +readonly HOSTNAME_REGEX="example\.test" +readonly TAG="test_tag" +readonly MSG="test_log_message" + +# Test REGEX +# Dec 2 15:55:00 example.test test_tag: test_log_message +readonly REGEX_RFC3164="${DATE_RFC3164} ${TIME_RFC3164} ${HOSTNAME_REGEX} ${TAG}: ${MSG}" +readonly REGEX_RFC3164_LOGFILE="^${REGEX_RFC3164}$" +readonly REGEX_RFC3164_PAYLOAD="${PRI}${REGEX_RFC3164}$" + +# Dec 2 15:55:00 Forwarded from example.test: test_tag: test_log_message +readonly REGEX_RFC3164_LEGACY="${DATE_RFC3164} ${TIME_RFC3164} Forwarded from ${HOSTNAME_REGEX}: ${TAG}: ${MSG}" +readonly REGEX_RFC3164_LEGACY_LOGFILE="^${REGEX_RFC3164_LEGACY}$" +readonly REGEX_RFC3164_LEGACY_PAYLOAD="${PRI}${REGEX_RFC3164_LEGACY}$" + +# <15>1 2024-12-02T15:55:00.000000+00:00 example.test test_tag - - - test_log_message +readonly REGEX_RFC5424="${PRI}${VERSION} ${TIMESPEC_RFC5424} ${HOSTNAME_REGEX} ${TAG} - - - ${MSG}" +readonly REGEX_RFC5424_LOGFILE="^${REGEX_RFC5424}$" +readonly REGEX_RFC5424_PAYLOAD="${REGEX_RFC5424}$" diff --git a/usr.sbin/syslogd/tests/syslogd_test.sh b/usr.sbin/syslogd/tests/syslogd_test.sh index e75c85d5995a..51c3a5fca1c6 100644 --- a/usr.sbin/syslogd/tests/syslogd_test.sh +++ b/usr.sbin/syslogd/tests/syslogd_test.sh @@ -13,110 +13,7 @@ # Tests to-do: # actions: users -readonly SYSLOGD_UDP_PORT="5140" -readonly SYSLOGD_CONFIG="${PWD}/syslog.conf" -readonly SYSLOGD_LOCAL_SOCKET="${PWD}/log.sock" -readonly SYSLOGD_PIDFILE="${PWD}/syslogd.pid" -readonly SYSLOGD_LOCAL_PRIVSOCKET="${PWD}/logpriv.sock" - -# Start a private syslogd instance. -syslogd_start() -{ - local jail bind_addr conf_file pid_file socket privsocket - local opt next other_args - - # Setup loopback so we can deliver messages to ourself. - atf_check ifconfig lo0 inet 127.0.0.1/16 - - OPTIND=1 - while getopts ":b:f:j:P:p:S:" opt; do - case "${opt}" in - b) - bind_addr="${OPTARG}" - ;; - f) - conf_file="${OPTARG}" - ;; - j) - jail="jexec ${OPTARG}" - ;; - P) - pid_file="${OPTARG}" - ;; - p) - socket="${OPTARG}" - ;; - S) - privsocket="${OPTARG}" - ;; - ?) - opt="${OPTARG}" - next="$(eval echo \${${OPTIND}})" - - case "${next}" in - -* | "") - other_args="${other_args} -${opt}" - shift $((OPTIND - 1)) - ;; - *) - other_args="${other_args} -${opt} ${next}" - shift ${OPTIND} - ;; - esac - - # Tell getopts to continue parsing. - OPTIND=1 - ;; - :) - atf_fail "The -${OPTARG} flag requires an argument" - ;; - esac - done - - $jail syslogd \ - -b "${bind_addr:-":${SYSLOGD_UDP_PORT}"}" \ - -C \ - -d \ - -f "${conf_file:-${SYSLOGD_CONFIG}}" \ - -H \ - -P "${pid_file:-${SYSLOGD_PIDFILE}}" \ - -p "${socket:-${SYSLOGD_LOCAL_SOCKET}}" \ - -S "${privsocket:-${SYSLOGD_LOCAL_PRIVSOCKET}}" \ - ${other_args} \ - & - - # Give syslogd a bit of time to spin up. - while [ "$((i+=1))" -le 20 ]; do - [ -S "${socket:-${SYSLOGD_LOCAL_SOCKET}}" ] && return - sleep 0.1 - done - atf_fail "timed out waiting for syslogd to start" -} - -# Simple logger(1) wrapper. -syslogd_log() -{ - atf_check -s exit:0 -o empty -e empty logger $* -} - -# Make syslogd reload its configuration file. -syslogd_reload() -{ - pkill -HUP -F "${1:-${SYSLOGD_PIDFILE}}" -} - -# Stop a private syslogd instance. -syslogd_stop() -{ - local pid_file="${1:-${SYSLOGD_PIDFILE}}" - - pid=$(cat "${pid_file}") - if pkill -F "${pid_file}"; then - wait "${pid}" - rm -f "${pid_file}" "${2:-${SYSLOGD_LOCAL_SOCKET}}" \ - "${3:-${SYSLOGD_LOCAL_PRIVSOCKET}}" - fi -} +. $(atf_get_srcdir)/syslogd_test_common.sh atf_test_case "unix" "cleanup" unix_head() diff --git a/usr.sbin/syslogd/tests/syslogd_test_common.sh b/usr.sbin/syslogd/tests/syslogd_test_common.sh new file mode 100644 index 000000000000..a764ebfb0e24 --- /dev/null +++ b/usr.sbin/syslogd/tests/syslogd_test_common.sh @@ -0,0 +1,117 @@ +#- +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (c) 2021, 2023 The FreeBSD Foundation +# +# This software was developed by Mark Johnston under sponsorship from +# the FreeBSD Foundation. +# +# This software was developed by Jake Freeland under sponsorship from +# the FreeBSD Foundation. +# + +readonly SYSLOGD_UDP_PORT="5140" +readonly SYSLOGD_CONFIG="${PWD}/syslog.conf" +readonly SYSLOGD_LOCAL_SOCKET="${PWD}/log.sock" +readonly SYSLOGD_PIDFILE="${PWD}/syslogd.pid" +readonly SYSLOGD_LOCAL_PRIVSOCKET="${PWD}/logpriv.sock" + +# Start a private syslogd instance. +syslogd_start() +{ + local jail bind_addr conf_file pid_file socket privsocket + local opt next other_args + + # Setup loopback so we can deliver messages to ourself. + atf_check ifconfig lo0 inet 127.0.0.1/16 + + OPTIND=1 + while getopts ":b:f:j:P:p:S:" opt; do + case "${opt}" in + b) + bind_addr="${OPTARG}" + ;; + f) + conf_file="${OPTARG}" + ;; + j) + jail="jexec ${OPTARG}" + ;; + P) + pid_file="${OPTARG}" + ;; + p) + socket="${OPTARG}" + ;; + S) + privsocket="${OPTARG}" + ;; + ?) + opt="${OPTARG}" + next="$(eval echo \${${OPTIND}})" + + case "${next}" in + -* | "") + other_args="${other_args} -${opt}" + shift $((OPTIND - 1)) + ;; + *) + other_args="${other_args} -${opt} ${next}" + shift ${OPTIND} + ;; + esac + + # Tell getopts to continue parsing. + OPTIND=1 + ;; + :) + atf_fail "The -${OPTARG} flag requires an argument" + ;; + esac + done + + $jail syslogd \ + -b "${bind_addr:-":${SYSLOGD_UDP_PORT}"}" \ + -C \ + -d \ + -f "${conf_file:-${SYSLOGD_CONFIG}}" \ + -H \ + -P "${pid_file:-${SYSLOGD_PIDFILE}}" \ + -p "${socket:-${SYSLOGD_LOCAL_SOCKET}}" \ + -S "${privsocket:-${SYSLOGD_LOCAL_PRIVSOCKET}}" \ + ${other_args} \ + & + + # Give syslogd a bit of time to spin up. + while [ "$((i+=1))" -le 20 ]; do + [ -S "${socket:-${SYSLOGD_LOCAL_SOCKET}}" ] && return + sleep 0.1 + done + atf_fail "timed out waiting for syslogd to start" +} + +# Simple logger(1) wrapper. +syslogd_log() +{ + atf_check -s exit:0 -o empty -e empty logger $* +} + +# Make syslogd reload its configuration file. +syslogd_reload() +{ + pkill -HUP -F "${1:-${SYSLOGD_PIDFILE}}" +} + +# Stop a private syslogd instance. +syslogd_stop() +{ + local pid_file="${1:-${SYSLOGD_PIDFILE}}" + local socket_file="${2:-${SYSLOGD_LOCAL_SOCKET}}" + local privsocket_file="${3:-${SYSLOGD_LOCAL_PRIVSOCKET}}" + + pid=$(cat "${pid_file}") + if pkill -F "${pid_file}"; then + wait "${pid}" + rm -f "${pid_file}" "${socket_file}" "${privsocket_file}" + fi +}