From 37beecab8080112418463640c97ae9a102d558ed Mon Sep 17 00:00:00 2001 From: Victor Moene Date: Tue, 27 Oct 2026 15:57:41 +0100 Subject: [PATCH 01/39] Run reactor tests in jenkins Added the reactor tests to jenkins, to be able to run them in jenkins. This means we can test cf-reactor on all the different platforms. Signed-off-by: Victor Moene --- .gitignore | 1 + configure.ac | 1 + tests/Makefile.am | 2 +- tests/reactor/Makefile.am | 44 +++++++++ tests/reactor/lib.sh | 82 ++++++++++++++--- tests/reactor/run.sh | 65 +++---------- tests/reactor/run_test.sh | 92 +++++++++++++++++++ tests/reactor/tests/00_basics/009_interval.sh | 4 +- .../tests/00_basics/020_policy_reload.sh | 2 +- .../tests/02_then_bundles/010_processes.sh | 7 +- 10 files changed, 229 insertions(+), 71 deletions(-) create mode 100644 tests/reactor/Makefile.am create mode 100644 tests/reactor/run_test.sh diff --git a/.gitignore b/.gitignore index ff74fda4594..cb1a01a8fe5 100644 --- a/.gitignore +++ b/.gitignore @@ -58,6 +58,7 @@ stamp-h1 /tests/acceptance/25_cf-execd/Makefile /tests/acceptance/Makefile /tests/load/Makefile +/tests/reactor/Makefile /tests/unit/Makefile /tests/static-check/Makefile /tests/valgrind-check/Makefile diff --git a/configure.ac b/configure.ac index 5ed3b61a351..414aa1d4c66 100644 --- a/configure.ac +++ b/configure.ac @@ -2032,6 +2032,7 @@ AC_CONFIG_FILES([Makefile tests/acceptance/25_cf-execd/Makefile tests/unit/Makefile tests/load/Makefile + tests/reactor/Makefile tests/static-check/Makefile tests/valgrind-check/Makefile tests/asan-check/Makefile]) diff --git a/tests/Makefile.am b/tests/Makefile.am index 0f80e566120..8603fc839e3 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -21,4 +21,4 @@ # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. # -SUBDIRS = unit load acceptance static-check valgrind-check asan-check +SUBDIRS = unit load acceptance reactor static-check valgrind-check asan-check diff --git a/tests/reactor/Makefile.am b/tests/reactor/Makefile.am new file mode 100644 index 00000000000..eb5325d0fbf --- /dev/null +++ b/tests/reactor/Makefile.am @@ -0,0 +1,44 @@ +# +# Copyright 2026 Northern.tech AS +# +# This file is part of CFEngine 3 - written and maintained by Northern.tech AS. +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA +# +# To the extent this program is licensed as part of the Enterprise +# versions of CFEngine, the applicable Commercial Open Source License +# (COSL) may apply to this file if you as a licensee so wish it. See +# included file COSL.txt. +# + +# The test scripts, with their policy next to them +REACTOR_TEST_SH = $(sort $(wildcard \ + $(srcdir)/tests/*/*.sh \ + $(srcdir)/tests/*/unsafe/*.sh)) +REACTOR_TEST_CF = $(REACTOR_TEST_SH:.sh=.cf) + +# cf-reactor is not built with builtin extensions (e.g. on Windows) +if !BUILTIN_EXTENSIONS +TESTS = $(patsubst $(srcdir)/%,%,$(REACTOR_TEST_SH)) +endif + +# Each test is run by run_test.sh, with the binaries of this build. The ones +# in an unsafe/ directory are skipped unless UNSAFE_TESTS=1. +TESTS_ENVIRONMENT = env \ + CF_REACTOR=$(abs_top_builddir)/cf-reactor/cf-reactor \ + CF_PROMISES=$(abs_top_builddir)/cf-promises/cf-promises \ + $(SHELL) $(srcdir)/run_test.sh + +EXTRA_DIST = lib.cf lib.sh run.sh run_test.sh \ + $(patsubst $(srcdir)/%,%,$(REACTOR_TEST_SH) $(REACTOR_TEST_CF)) diff --git a/tests/reactor/lib.sh b/tests/reactor/lib.sh index f49a25905a2..d9754155079 100644 --- a/tests/reactor/lib.sh +++ b/tests/reactor/lib.sh @@ -1,21 +1,81 @@ # Helpers sourced by the tests. Expects CF_REACTOR and LOG to be exported by -# run.sh. +# run_test.sh. +# +# Only POSIX tools are used, as the tests are run on all the platforms (e.g. +# no timeout(1), grep -m or date +%s). + +# Seconds to wait for something before giving up +WAIT_TIMEOUT=60 # number of log lines already consumed by wait_for_log log_offset=0 +# Run command $@ until it succeeds, for at most WAIT_TIMEOUT seconds, polling +# every 0.1 second, or every second where sleep only takes whole seconds. +# Fails if it never succeeded. Runs in a subshell without tracing, so that +# set -x doesn't log every poll. +wait_until() { + ( + set +x + if sleep 0.1 2>/dev/null; then + interval=0.1 polls=$((WAIT_TIMEOUT * 10)) + else + interval=1 polls=$WAIT_TIMEOUT + fi + until "$@"; do + [ "$polls" -gt 0 ] || exit 1 + polls=$((polls - 1)) + sleep "$interval" + done + ) +} + +# Print the current time in seconds since the Epoch. date +%s is not POSIX; +# without it, srand() seeds with the time of day and returns the last seed. +now() { + t=$(date +%s 2>/dev/null) + case "$t" in + ''|*[!0-9]*) awk 'BEGIN { srand(); print srand() }' ;; + *) echo "$t" ;; + esac +} + +# Print the first line of the reactor log after line $1 that contains $2, +# prefixed with its number counted from line $1. Fails if there is none. +log_match() { + tail -n "+$(($1 + 1))" "$LOG" 2>/dev/null | grep -n -F -- "$2" | head -n 1 | grep . +} + +# Fail unless the reactor log contains $1. +log_contains() { + grep -q -F -- "$1" "$LOG" 2>/dev/null +} + +# Print the number of lines of file $1, 0 if it doesn't exist. +count_lines() { + if [ -f "$1" ]; then + # without the padding of some wc implementations + echo $(( $(wc -l < "$1") )) + else + echo 0 + fi +} + +# Fail unless file $1 has at least $2 lines. +has_lines() { + [ "$(count_lines "$1")" -ge "$2" ] +} + # Wait until the reactor log contains $1 in a line after the last match, then # skip past that line, so that the next wait only sees newer output. wait_for_log() { - if ! match=$(timeout 60 sh -c ' - until tail -n "+$(($2 + 1))" "$1" | grep -n -F -m 1 -- "$3"; do - sleep 0.1 - done' _ "$LOG" "$log_offset" "$1") + if ! wait_until log_match "$log_offset" "$1" >/dev/null then echo "Timed out waiting for '$1' in reactor log:" >&2 cat "$LOG" >&2 return 1 fi + match=$(log_match "$log_offset" "$1") log_offset=$((log_offset + ${match%%:*})) } @@ -23,10 +83,7 @@ wait_for_log() { # The watcher thread may log before this line, so search the whole log and # leave the offset of wait_for_log as is. wait_for_watchers() { - if ! timeout 60 sh -c ' - until grep -q -F -- "$2" "$1"; do - sleep 0.1 - done' _ "$LOG" "verbose: cf-reactor event watcher has $1 watcher(s)" + if ! wait_until log_contains "verbose: cf-reactor event watcher has $1 watcher(s)" then echo "Timed out waiting for $1 watcher(s) in reactor log:" >&2 cat "$LOG" >&2 @@ -36,17 +93,14 @@ wait_for_watchers() { # Wait until file $1 has at least $2 lines, then fail if it has more than $2. wait_for_lines() { - if ! timeout 60 sh -c ' - until [ "$(cat "$1" 2>/dev/null | wc -l)" -ge "$2" ]; do - sleep 0.1 - done' _ "$1" "$2" + if ! wait_until has_lines "$1" "$2" then echo "Timed out waiting for $2 line(s) in '$1', reactor log:" >&2 cat "$LOG" >&2 return 1 fi - lines=$(wc -l < "$1") + lines=$(count_lines "$1") if [ "$lines" -ne "$2" ] then echo "Expected $2 line(s) in '$1', got $lines" >&2 diff --git a/tests/reactor/run.sh b/tests/reactor/run.sh index 17e21f198c5..dcf07967ae5 100644 --- a/tests/reactor/run.sh +++ b/tests/reactor/run.sh @@ -2,10 +2,11 @@ # Usage: run.sh [--unsafe] # -# Must be run from the tests/reactor directory. +# Runs all the reactor tests, see run_test.sh. They are also run by +# "make check". # # Tests in an unsafe/ directory modify the system they are running on, so they -# are only run with --unsafe. +# are only run with --unsafe (or UNSAFE_TESTS=1). # # The binaries are taken from $CF_BINDIR if it is set, otherwise from the # CFEngine build tree this directory is part of if they are built, otherwise @@ -13,10 +14,10 @@ fail=0 -unsafe=0 if [ "$1" = "--unsafe" ]; then - unsafe=1 + UNSAFE_TESTS=1 fi +export UNSAFE_TESTS banner() { name=" $(basename "$(dirname "$1")")/$(basename "$1") " @@ -36,62 +37,22 @@ error() { fail=1 } -# Print the path of binary $1, see the usage above. -find_binary() { - if [ -n "$CF_BINDIR" ]; then - echo "$CF_BINDIR/$1" - elif [ -x "$PWD/../../$1/$1" ]; then - # in-tree build, may be a libtool wrapper script - echo "$PWD/../../$1/$1" - else - echo "/var/cfengine/bin/$1" - fi -} - -CF_REACTOR=$(find_binary cf-reactor) -CF_PROMISES=$(find_binary cf-promises) -export CF_REACTOR +dir=$(cd "$(dirname "$0")" && pwd) -for b in "$CF_REACTOR" "$CF_PROMISES"; do - if [ ! -x "$b" ]; then - echo "'$b' not found, build CFEngine or set CF_BINDIR" >&2 - exit 2 - fi -done -echo "Using $CF_REACTOR and $CF_PROMISES" - -for t in "$PWD"/tests/*/*.sh "$PWD"/tests/*/unsafe/*.sh; do +for t in "$dir"/tests/*/*.sh "$dir"/tests/*/unsafe/*.sh; do # skip the pattern itself if there are no unsafe tests [ -f "$t" ] || continue case "$t" in - */unsafe/*) [ "$unsafe" = 1 ] || continue ;; + */unsafe/*) [ "$UNSAFE_TESTS" = 1 ] || continue ;; esac banner "$t" - # create throwaway work dir - WORKDIR=$(mktemp -d) - mkdir -p "$WORKDIR/bin" "$WORKDIR/tmp" - ln -s "$CF_PROMISES" "$WORKDIR/bin/cf-promises" - - # Run a copy of the policy, keeping its path relative to lib.cf, as - # CFEngine refuses to read policy files writable by group or others, which - # those of a checkout made with a umask of 002 are - rel=${t#"$PWD"/} - policy="$WORKDIR/policy/${rel%.sh}.cf" - mkdir -p "$(dirname "$policy")" - cp lib.cf "$WORKDIR/policy/" - cp "${t%.sh}.cf" "$policy" - chmod 600 "$WORKDIR/policy/lib.cf" "$policy" - - CFENGINE_TEST_OVERRIDE_WORKDIR="$WORKDIR" - LOG="$WORKDIR/reactor.log" - PROMISE_NAME=$(basename "$t" .sh) - export WORKDIR CFENGINE_TEST_OVERRIDE_WORKDIR LOG PROMISE_NAME - - sh "$t" "$policy" || error "$t" - - rm -rf "$WORKDIR" + sh "$dir/run_test.sh" "$t" + case $? in + 0|77) ;; + *) error "$t" ;; + esac done exit $fail diff --git a/tests/reactor/run_test.sh b/tests/reactor/run_test.sh new file mode 100644 index 00000000000..22e2f299a14 --- /dev/null +++ b/tests/reactor/run_test.sh @@ -0,0 +1,92 @@ +#!/bin/sh + +# Usage: run_test.sh TEST +# +# Runs the reactor test TEST (a tests/*/*.sh or tests/*/unsafe/*.sh file) in a +# throwaway work dir, and exits with its result: 0 if it passed, 77 if it was +# skipped, anything else if it failed. Used as the test driver by "make check" +# and by run.sh. +# +# Tests in an unsafe/ directory modify the system they are running on, so they +# are skipped unless UNSAFE_TESTS=1. +# +# The binaries are taken from $CF_REACTOR and $CF_PROMISES if they are set, +# otherwise from $CF_BINDIR if it is set, otherwise from the CFEngine build +# tree this directory is part of if they are built, otherwise from +# /var/cfengine/bin. + +if [ $# -ne 1 ]; then + echo "Usage: $0 TEST" >&2 + exit 2 +fi + +t=$1 + +# Explicitly use POSIX tools if needed (Solaris) +if [ -f /usr/xpg4/bin/grep ]; then + PATH=/usr/xpg4/bin:$PATH + export PATH +fi + +case "$t" in + */unsafe/*) + if [ "$UNSAFE_TESTS" != 1 ]; then + echo "Skipping unsafe test '$t', set UNSAFE_TESTS=1 to run it" + exit 77 + fi + ;; +esac + +# directory of lib.cf and lib.sh +REACTOR_TESTS_DIR=$(cd "$(dirname "$0")" && pwd) + +# Print the path of binary $1, see the usage above. +find_binary() { + if [ -n "$CF_BINDIR" ]; then + echo "$CF_BINDIR/$1" + elif [ -x "$REACTOR_TESTS_DIR/../../$1/$1" ]; then + # in-tree build, may be a libtool wrapper script + echo "$REACTOR_TESTS_DIR/../../$1/$1" + else + echo "/var/cfengine/bin/$1" + fi +} + +CF_REACTOR=${CF_REACTOR:-$(find_binary cf-reactor)} +CF_PROMISES=${CF_PROMISES:-$(find_binary cf-promises)} +export CF_REACTOR + +for b in "$CF_REACTOR" "$CF_PROMISES"; do + if [ ! -x "$b" ]; then + echo "'$b' not found, build CFEngine or set CF_BINDIR" >&2 + exit 2 + fi +done + +# Create the throwaway work dir, with mktemp -d where available +WORKDIR=$(mktemp -d "${TMPDIR:-/tmp}/cf-reactor-test.XXXXXX" 2>/dev/null) || { + WORKDIR="${TMPDIR:-/tmp}/cf-reactor-test.$$" + (umask 077 && mkdir "$WORKDIR") || exit 2 +} +WORKDIR=$(cd "$WORKDIR" && pwd) +trap 'rm -rf "$WORKDIR"' EXIT +mkdir -p "$WORKDIR/bin" "$WORKDIR/tmp" +ln -s "$CF_PROMISES" "$WORKDIR/bin/cf-promises" + +# Run a copy of the policy, keeping its path relative to lib.cf, as CFEngine +# refuses to read policy files writable by group or others, which those of a +# checkout made with a umask of 002 are +p="/$t" +rel="tests/${p##*/tests/}" +policy="$WORKDIR/policy/${rel%.sh}.cf" +mkdir -p "$(dirname "$policy")" +cp "$REACTOR_TESTS_DIR/lib.cf" "$WORKDIR/policy/" +cp "${t%.sh}.cf" "$policy" +chmod 600 "$WORKDIR/policy/lib.cf" "$policy" + +CFENGINE_TEST_OVERRIDE_WORKDIR="$WORKDIR" +LOG="$WORKDIR/reactor.log" +PROMISE_NAME=$(basename "$t" .sh) +export WORKDIR CFENGINE_TEST_OVERRIDE_WORKDIR LOG PROMISE_NAME + +sh "$t" "$policy" diff --git a/tests/reactor/tests/00_basics/009_interval.sh b/tests/reactor/tests/00_basics/009_interval.sh index 4a749849370..df73a4cf09d 100644 --- a/tests/reactor/tests/00_basics/009_interval.sh +++ b/tests/reactor/tests/00_basics/009_interval.sh @@ -19,7 +19,7 @@ wait_for_log "File '$TESTFILE' is present, watching for its deletion" rm "$TESTFILE" wait_for_lines "$EVENTS_FILE" 1 check_event "$EVENTS_FILE" 1 "$TESTFILE was deleted" -t1=$(date +%s) +t1=$(now) # recreate the file and wait for the watcher to see it before deleting it again touch "$TESTFILE" @@ -27,7 +27,7 @@ wait_for_log "File '$TESTFILE' is present, watching for its deletion" rm "$TESTFILE" wait_for_lines "$EVENTS_FILE" 2 check_event "$EVENTS_FILE" 2 "$TESTFILE was deleted" -t2=$(date +%s) +t2=$(now) # checking that the interval is at minimum 10 seconds delta=$((t2 - t1)) diff --git a/tests/reactor/tests/00_basics/020_policy_reload.sh b/tests/reactor/tests/00_basics/020_policy_reload.sh index 48348e72338..d6476072c9d 100644 --- a/tests/reactor/tests/00_basics/020_policy_reload.sh +++ b/tests/reactor/tests/00_basics/020_policy_reload.sh @@ -30,7 +30,7 @@ reload_and_wait_for_paused_watchers() { kill -HUP "$reactor_pid" wait_for_log "Rereading policy file" - if ! timeout 60 sh -c 'until [ -f "$1" ]; do sleep 0.1; done' _ "$RELOAD_MARKER" + if ! wait_until [ -f "$RELOAD_MARKER" ] then echo "Timed out waiting for the policy to be reloaded, reactor log:" >&2 cat "$LOG" >&2 diff --git a/tests/reactor/tests/02_then_bundles/010_processes.sh b/tests/reactor/tests/02_then_bundles/010_processes.sh index b653eb059e9..ea0aa104fef 100644 --- a/tests/reactor/tests/02_then_bundles/010_processes.sh +++ b/tests/reactor/tests/02_then_bundles/010_processes.sh @@ -21,8 +21,13 @@ start_process() { ( sleep 978654 & echo $! > "$PID_FILE" ) } +# Fail if process $1 still exists +process_gone() { + ! kill -0 "$1" 2>/dev/null +} + wait_for_process_killed() { - if ! timeout 60 sh -c 'while kill -0 "$1" 2>/dev/null; do sleep 0.1; done' _ "$(cat "$PID_FILE")" + if ! wait_until process_gone "$(cat "$PID_FILE")" then echo "Process $(cat "$PID_FILE") not killed, reactor log:" >&2 cat "$LOG" >&2 From 5f352d3ad9ddc2575d28d6a307b7b504d97f7e2d Mon Sep 17 00:00:00 2001 From: Victor Moene Date: Tue, 27 Oct 2026 16:50:48 +0100 Subject: [PATCH 02/39] Added better logging of the cf-reactor tests Made the logs prettier and added a log file where the xtrace is printed Signed-off-by: Victor Moene --- tests/reactor/run.sh | 90 ++++++++++++++++++++++++--------------- tests/reactor/run_test.sh | 10 ++++- 2 files changed, 65 insertions(+), 35 deletions(-) diff --git a/tests/reactor/run.sh b/tests/reactor/run.sh index dcf07967ae5..8394314c5d6 100644 --- a/tests/reactor/run.sh +++ b/tests/reactor/run.sh @@ -2,57 +2,79 @@ # Usage: run.sh [--unsafe] # -# Runs all the reactor tests, see run_test.sh. They are also run by -# "make check". +# Runs all the reactor tests, see run_test.sh, and prints a summary of their +# results. The output of a test is only printed if it failed. They are also +# run by "make check". # # Tests in an unsafe/ directory modify the system they are running on, so they -# are only run with --unsafe (or UNSAFE_TESTS=1). +# are skipped unless run with --unsafe (or UNSAFE_TESTS=1). # # The binaries are taken from $CF_BINDIR if it is set, otherwise from the # CFEngine build tree this directory is part of if they are built, otherwise # from /var/cfengine/bin. -fail=0 - if [ "$1" = "--unsafe" ]; then UNSAFE_TESTS=1 fi export UNSAFE_TESTS -banner() { - name=" $(basename "$(dirname "$1")")/$(basename "$1") " - width=72 - left=$(( (width - ${#name}) / 2 )) - right=$(( width - ${#name} - left )) - [ "$left" -lt 0 ] && left=0 - [ "$right" -lt 0 ] && right=0 - printf '%s%s%s\n' \ - "$(printf "%${left}s" '' | tr ' ' '=')" \ - "$name" \ - "$(printf "%${right}s" '' | tr ' ' '=')" -} +dir=$(cd "$(dirname "$0")" && pwd) -error() { - echo "test '$1' FAILED" >&2 - fail=1 -} +# for now() +. "$dir/lib.sh" -dir=$(cd "$(dirname "$0")" && pwd) +passed=0 +failed=0 +skipped=0 +total=0 +failures="" +suite_start=$(now) -for t in "$dir"/tests/*/*.sh "$dir"/tests/*/unsafe/*.sh; do - # skip the pattern itself if there are no unsafe tests - [ -f "$t" ] || continue - case "$t" in - */unsafe/*) [ "$UNSAFE_TESTS" = 1 ] || continue ;; - esac +# Run test $1 and print its result, with its output if it failed +run_test() { + name=${1#"$dir/tests/"} + name=${name%.sh} + total=$((total + 1)) - banner "$t" + start=$(now) + output=$(sh "$dir/run_test.sh" "$1" 2>&1) + result=$? + elapsed=$(($(now) - start)) - sh "$dir/run_test.sh" "$t" - case $? in - 0|77) ;; - *) error "$t" ;; + case $result in + 0) + passed=$((passed + 1)) + echo "--- PASS: $name (${elapsed}s)" + ;; + 77) + skipped=$((skipped + 1)) + echo "--- SKIP: $name (${elapsed}s)" + ;; + *) + failed=$((failed + 1)) + failures="$failures $name +" + echo "--- FAIL: $name (${elapsed}s)" + echo "$output" + echo "---" + ;; esac +} + +for t in "$dir"/tests/*/*.sh "$dir"/tests/*/unsafe/*.sh; do + # skip the pattern itself if there are no unsafe tests + [ -f "$t" ] || continue + run_test "$t" done -exit $fail +echo "" +echo "==============================" +echo "Test Results: $passed passed, $failed failed, $skipped skipped (total: $total, $(($(now) - suite_start))s)" +if [ "$failed" -gt 0 ]; then + echo "" + echo "Failed tests:" + printf '%s' "$failures" + exit 1 +fi +echo "==============================" +echo "All reactor tests passed" diff --git a/tests/reactor/run_test.sh b/tests/reactor/run_test.sh index 22e2f299a14..dc4b66fb79b 100644 --- a/tests/reactor/run_test.sh +++ b/tests/reactor/run_test.sh @@ -7,6 +7,9 @@ # skipped, anything else if it failed. Used as the test driver by "make check" # and by run.sh. # +# The output of the test, with its set -x trace, is only printed if it didn't +# pass, so that the output of the tests that pass doesn't bury it. +# # Tests in an unsafe/ directory modify the system they are running on, so they # are skipped unless UNSAFE_TESTS=1. # @@ -89,4 +92,9 @@ LOG="$WORKDIR/reactor.log" PROMISE_NAME=$(basename "$t" .sh) export WORKDIR CFENGINE_TEST_OVERRIDE_WORKDIR LOG PROMISE_NAME -sh "$t" "$policy" +sh "$t" "$policy" > "$WORKDIR/test.log" 2>&1 +result=$? +if [ "$result" -ne 0 ]; then + cat "$WORKDIR/test.log" +fi +exit "$result" From 51a201433a28bc458d831795b4159217729f0b71 Mon Sep 17 00:00:00 2001 From: Victor Moene Date: Wed, 28 Oct 2026 15:26:13 +0100 Subject: [PATCH 03/39] Fixed out of range scalar value for guest environments The guest environment cannot contain "-". On hosts containing "-", the promise fails. The host name is now canonofied. Signed-off-by: Victor Moene --- tests/reactor/tests/02_then_bundles/008_guest_environments.cf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/reactor/tests/02_then_bundles/008_guest_environments.cf b/tests/reactor/tests/02_then_bundles/008_guest_environments.cf index 9cbb424c202..eb03bec6746 100644 --- a/tests/reactor/tests/02_then_bundles/008_guest_environments.cf +++ b/tests/reactor/tests/02_then_bundles/008_guest_environments.cf @@ -24,7 +24,7 @@ bundle reactor run_guest_environments # no classes body here: the test looks at the log instead. "test" environment_type => "test", - environment_host => "$(sys.host)", + environment_host => canonify("$(sys.host)"), environment_state => "running"; } From f0f66f4b1ecc885e23933111b6a8ef2219a79e08 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Wed, 28 Oct 2026 10:08:43 +0100 Subject: [PATCH 04/39] Fixed build against OpenSSL 4 X509_get_subject_name() now returns a const name. Build a new X509_NAME and set it as both subject and issuer instead. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Lars Erik Wik --- libcfnet/tls_generic.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libcfnet/tls_generic.c b/libcfnet/tls_generic.c index d3882abb5ba..e34fb6dbc8a 100644 --- a/libcfnet/tls_generic.c +++ b/libcfnet/tls_generic.c @@ -480,10 +480,12 @@ X509 *TLSGenerateCertFromPrivKey(RSA *privkey) goto err3; } - X509_NAME *name = X509_get_subject_name(x509); + /* OpenSSL 4 returns a const name from X509_get_subject_name(), so build + * a new one and set it. */ + X509_NAME *name = X509_NAME_new(); if (name == NULL) { - Log(LOG_LEVEL_ERR, "X509_get_subject_name: %s", + Log(LOG_LEVEL_ERR, "X509_NAME_new: %s", TLSErrorString(ERR_get_error())); goto err3; } @@ -492,9 +494,11 @@ X509 *TLSGenerateCertFromPrivKey(RSA *privkey) ret += X509_NAME_add_entry_by_txt(name, "CN", MBSTRING_ASC, (const unsigned char *) "a", -1, -1, 0); + ret += X509_set_subject_name(x509, name); ret += X509_set_issuer_name(x509, name); + X509_NAME_free(name); ret += X509_set_pubkey(x509, pkey); - if (ret < 3) + if (ret < 4) { Log(LOG_LEVEL_ERR, "Failed to set certificate details: %s", TLSErrorString(ERR_get_error())); From 23ba79719ee50f4f01fa6605f645f1c4ad68d38b Mon Sep 17 00:00:00 2001 From: Ihor Aleksandrychiev Date: Wed, 14 Oct 2026 15:18:53 +0300 Subject: [PATCH 05/39] Made testall fail regular acceptance tests which log errors Tests that print Pass message but have logs errors will fail with `FAIL (Error printed)` message. Tests which are expected to log errors should use `.error.cf` or `.error.pass.cf` suffix. see: `tests/acceptance/README` Ticket: CFE-3041 Signed-off-by: Ihor Aleksandrychiev --- tests/acceptance/README | 7 +++++++ tests/acceptance/testall | 14 ++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/tests/acceptance/README b/tests/acceptance/README index 2435b57b224..b192cb5995c 100644 --- a/tests/acceptance/README +++ b/tests/acceptance/README @@ -113,6 +113,13 @@ case letters and underscores only. If the test is expected to generate an error additional '.x' suffix before '.cf' (e.g. 'string_vars.x.cf'). A crash will still cause a failure. +Regular tests (without any special suffix) fail if they log any errors, even +if they print the Pass message. If the test is expected to log errors (e.g. it +contains promises which are intentionally not kept), it should have an +additional '.error' suffix before '.cf' (e.g. 'bad_perms.error.cf'), in which +case it passes as long as it logs at least one error and exits with 0. If it +should also print the Pass message, use the '.error.pass.cf' suffix instead. + Tests which are not expected to pass yet (e.g. there is a bug in code which prevents tests from passing) should be placed in 'staging' subdirectory in the test directory where they belong. Such test cases will be only run if --staging diff --git a/tests/acceptance/testall b/tests/acceptance/testall index b35bb1a962e..4d40ebb301d 100755 --- a/tests/acceptance/testall +++ b/tests/acceptance/testall @@ -217,6 +217,8 @@ usage() { echo "If no test is given, all standard tests are run:" echo " Tests with names of form .cf are expected to run successfully" echo " Tests with names of form .x.cf are expected to exit with error" + echo " Tests with names of form .error.cf are expected to log error(s) and exit with 0" + echo " Tests with names of form .error.pass.cf are expected to log error(s), pass and exit with 0" echo "Set ${COLOR_SUCCESS}CFENGINE_COLOR=1${COLOR_NORMAL} to get ANSI color markers where appropriate." echo echo "If arguments are given, those are executed as tests" @@ -646,8 +648,16 @@ export CFENGINE_TEST_OVERRIDE_WORKDIR TEMP CFENGINE_TEST_OVERRIDE_EXTENSION_LIBR fi elif grep -E "R: .*$ESCAPED_TEST Pass" $OUTFILE > /dev/null then - RESULT=Pass - RESULT_MSG="${COLOR_SUCCESS}Pass${COLOR_NORMAL}" + # Regular tests must not log errors, tests which are expected + # to log errors should be named *.error.cf or *.error.pass.cf + if grep -E '^ *error: ' $OUTFILE > /dev/null + then + RESULT=FAIL + RESULT_MSG="${COLOR_FAILURE}FAIL (Error printed)${COLOR_NORMAL}" + else + RESULT=Pass + RESULT_MSG="${COLOR_SUCCESS}Pass${COLOR_NORMAL}" + fi elif grep -E "R: .*$ESCAPED_TEST Skip/unsupported" $OUTFILE > /dev/null then RESULT=Skip From 97d424941676d040abdcc1c1b561e6a5a51d73fe Mon Sep 17 00:00:00 2001 From: Ihor Aleksandrychiev Date: Thu, 15 Oct 2026 14:21:10 +0300 Subject: [PATCH 06/39] Added fileexists() guards to file reads in acceptance tests These tests read files created by their own init bundle, but pre-evaluation calls the read functions before the files exist, logging "Could not examine file" errors which now fail regular tests. Ticket: CFE-3041 Signed-off-by: Ihor Aleksandrychiev --- .../01_vars/01_basic/this_promiser_with_readjson.cf | 3 ++- tests/acceptance/01_vars/02_functions/011.cf | 3 ++- tests/acceptance/01_vars/02_functions/012.cf | 3 ++- tests/acceptance/01_vars/02_functions/013.cf | 3 ++- tests/acceptance/01_vars/02_functions/014.cf | 3 ++- tests/acceptance/01_vars/02_functions/015.cf | 3 ++- tests/acceptance/01_vars/02_functions/016.cf | 3 ++- tests/acceptance/01_vars/02_functions/017.cf | 3 ++- tests/acceptance/01_vars/02_functions/018.cf | 3 ++- tests/acceptance/01_vars/02_functions/019.cf | 3 ++- tests/acceptance/01_vars/02_functions/020.cf | 3 ++- tests/acceptance/01_vars/02_functions/021.cf | 3 ++- tests/acceptance/01_vars/02_functions/024.cf | 3 ++- tests/acceptance/01_vars/02_functions/025.cf | 3 ++- tests/acceptance/01_vars/02_functions/026.cf | 3 ++- tests/acceptance/01_vars/02_functions/027.cf | 3 ++- tests/acceptance/01_vars/02_functions/028.cf | 3 ++- tests/acceptance/01_vars/02_functions/029.cf | 3 ++- tests/acceptance/01_vars/02_functions/030.cf | 3 ++- tests/acceptance/01_vars/02_functions/031.cf | 3 ++- tests/acceptance/01_vars/02_functions/032.cf | 3 ++- tests/acceptance/01_vars/02_functions/033.cf | 3 ++- tests/acceptance/01_vars/02_functions/034.cf | 3 ++- tests/acceptance/01_vars/02_functions/037.cf | 3 ++- tests/acceptance/01_vars/02_functions/038.cf | 3 ++- tests/acceptance/01_vars/02_functions/039.cf | 3 ++- tests/acceptance/01_vars/02_functions/040.cf | 3 ++- tests/acceptance/01_vars/02_functions/041.cf | 3 ++- tests/acceptance/01_vars/02_functions/042.cf | 3 ++- tests/acceptance/01_vars/02_functions/043.cf | 3 ++- tests/acceptance/01_vars/02_functions/044.cf | 3 ++- tests/acceptance/01_vars/02_functions/045.cf | 3 ++- tests/acceptance/01_vars/02_functions/046.cf | 3 ++- tests/acceptance/01_vars/02_functions/047.cf | 3 ++- tests/acceptance/01_vars/02_functions/050.cf | 3 ++- tests/acceptance/01_vars/02_functions/400.cf | 3 ++- tests/acceptance/01_vars/02_functions/401.cf | 3 ++- tests/acceptance/01_vars/02_functions/410.cf | 3 ++- tests/acceptance/01_vars/02_functions/420.cf | 3 ++- tests/acceptance/01_vars/02_functions/421.cf | 3 ++- tests/acceptance/01_vars/02_functions/440.cf | 3 ++- tests/acceptance/01_vars/02_functions/441.cf | 3 ++- tests/acceptance/01_vars/02_functions/442.cf | 3 ++- tests/acceptance/01_vars/02_functions/443.cf | 3 ++- tests/acceptance/01_vars/02_functions/444.cf | 3 ++- tests/acceptance/01_vars/02_functions/445.cf | 3 ++- tests/acceptance/01_vars/02_functions/447.cf | 3 ++- tests/acceptance/01_vars/02_functions/450.cf | 3 ++- tests/acceptance/01_vars/02_functions/500.cf | 3 ++- tests/acceptance/01_vars/02_functions/501.cf | 3 ++- tests/acceptance/01_vars/02_functions/520.cf | 3 ++- tests/acceptance/01_vars/02_functions/521.cf | 3 ++- tests/acceptance/01_vars/02_functions/600.cf | 3 ++- tests/acceptance/01_vars/02_functions/601.cf | 3 ++- tests/acceptance/01_vars/02_functions/620.cf | 3 ++- tests/acceptance/01_vars/02_functions/621.cf | 3 ++- .../01_vars/02_functions/classfilterdata_collecting.cf | 3 ++- .../01_vars/02_functions/long_string_from_text_file.cf | 3 ++- ...sestringarray_dontread_comment_duplicate_lastline2.cf | 3 ++- ...ngarray_weird_indices_real_comments_noemptyfields2.cf | 3 ++- tests/acceptance/01_vars/02_functions/peers.cf | 9 ++++++--- tests/acceptance/01_vars/02_functions/read_empty_file.cf | 6 ++++-- ...stringarray_dontread_comment_duplicatekey_lastline.cf | 3 ++- .../01_vars/02_functions/readstringarrayidx_order.cf | 3 ++- tests/acceptance/01_vars/04_containers/readjson.cf | 3 ++- .../acceptance/01_vars/04_containers/readjson_arrays.cf | 3 ++- tests/acceptance/01_vars/04_containers/readjson_new.cf | 3 ++- tests/acceptance/01_vars/04_containers/readjson_null.cf | 3 ++- .../acceptance/01_vars/04_containers/readjson_objects.cf | 3 ++- .../acceptance/01_vars/04_containers/readjson_scalar.cf | 3 ++- .../01_vars/04_containers/readjson_subindex.cf | 3 ++- .../01_vars/04_containers/readjson_subindex_quoted.cf | 3 ++- tests/acceptance/08_commands/arglist.cf | 3 ++- .../09_insert_lines/preserve_block_blank_lines.cf | 3 ++- .../10_files/templating/empty_template_empty_file.cf | 3 ++- tests/acceptance/10_files/templating/mustache_abuse.cf | 3 ++- .../10_files/templating/mustache_datastate_demo.cf | 3 ++- tests/acceptance/10_files/templating/mustache_demo.cf | 3 ++- .../templating/mustache_expect_list_find_string.cf | 6 ++++-- .../10_files/templating/mustache_html_escape.cf | 3 ++- .../10_files/templating/mustache_inline_demo.cf | 3 ++- .../10_files/templating/mustache_render_quote.cf | 3 ++- .../10_files/templating/mustache_repair_existing.cf | 3 ++- tests/acceptance/31_tickets/CFE-3866/test.cf | 3 ++- 84 files changed, 176 insertions(+), 88 deletions(-) diff --git a/tests/acceptance/01_vars/01_basic/this_promiser_with_readjson.cf b/tests/acceptance/01_vars/01_basic/this_promiser_with_readjson.cf index 60cfff7563f..4d7d32a549b 100644 --- a/tests/acceptance/01_vars/01_basic/this_promiser_with_readjson.cf +++ b/tests/acceptance/01_vars/01_basic/this_promiser_with_readjson.cf @@ -26,7 +26,8 @@ bundle agent test { vars: "cf_promises_validated" - data => readjson("$(G.testfile).$(this.promiser)", 1K); + data => readjson("$(G.testfile).$(this.promiser)", 1K), + if => fileexists("$(G.testfile).$(this.promiser)"); "printable" string => format("%S", "cf_promises_validated"); diff --git a/tests/acceptance/01_vars/02_functions/011.cf b/tests/acceptance/01_vars/02_functions/011.cf index 0405b37d51a..93a5a1c3384 100644 --- a/tests/acceptance/01_vars/02_functions/011.cf +++ b/tests/acceptance/01_vars/02_functions/011.cf @@ -37,7 +37,8 @@ body delete init_delete bundle agent test { vars: - "nums" slist => readstringlist("$(G.testfile)", "NoComment", "\s+", 5, 100); + "nums" slist => readstringlist("$(G.testfile)", "NoComment", "\s+", 5, 100), + if => fileexists("$(G.testfile)"); "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/012.cf b/tests/acceptance/01_vars/02_functions/012.cf index 6ace98654cb..55de4ce5573 100644 --- a/tests/acceptance/01_vars/02_functions/012.cf +++ b/tests/acceptance/01_vars/02_functions/012.cf @@ -38,7 +38,8 @@ body delete init_delete bundle agent test { vars: - "nums" slist => readstringlist("$(G.testfile)", "NoComment", "\s+", 5, 100); + "nums" slist => readstringlist("$(G.testfile)", "NoComment", "\s+", 5, 100), + if => fileexists("$(G.testfile)"); "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/013.cf b/tests/acceptance/01_vars/02_functions/013.cf index 1708bbaddc0..4e493478c13 100644 --- a/tests/acceptance/01_vars/02_functions/013.cf +++ b/tests/acceptance/01_vars/02_functions/013.cf @@ -37,7 +37,8 @@ body delete init_delete bundle agent test { vars: - "nums" slist => readstringlist("$(G.testfile)", "NoComment", "\s+", 5, 100); + "nums" slist => readstringlist("$(G.testfile)", "NoComment", "\s+", 5, 100), + if => fileexists("$(G.testfile)"); "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/014.cf b/tests/acceptance/01_vars/02_functions/014.cf index 716e8873390..c981a70bac4 100644 --- a/tests/acceptance/01_vars/02_functions/014.cf +++ b/tests/acceptance/01_vars/02_functions/014.cf @@ -37,7 +37,8 @@ body delete init_delete bundle agent test { vars: - "nums" slist => readstringlist("$(G.testfile)", "NoComment", "\.", 5, 100); + "nums" slist => readstringlist("$(G.testfile)", "NoComment", "\.", 5, 100), + if => fileexists("$(G.testfile)"); "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/015.cf b/tests/acceptance/01_vars/02_functions/015.cf index c515ba037d5..f96df7ab224 100644 --- a/tests/acceptance/01_vars/02_functions/015.cf +++ b/tests/acceptance/01_vars/02_functions/015.cf @@ -37,7 +37,8 @@ body delete init_delete bundle agent test { vars: - "nums" slist => readstringlist("$(G.testfile)", "NoComment", "\s+", 5, 100); + "nums" slist => readstringlist("$(G.testfile)", "NoComment", "\s+", 5, 100), + if => fileexists("$(G.testfile)"); "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/016.cf b/tests/acceptance/01_vars/02_functions/016.cf index 0688544a875..2b7482ddb8f 100644 --- a/tests/acceptance/01_vars/02_functions/016.cf +++ b/tests/acceptance/01_vars/02_functions/016.cf @@ -38,7 +38,8 @@ body delete init_delete bundle agent test { vars: - "nums" slist => readstringlist("$(G.testfile)", "NoComment", "\s+", 5, 100); + "nums" slist => readstringlist("$(G.testfile)", "NoComment", "\s+", 5, 100), + if => fileexists("$(G.testfile)"); "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/017.cf b/tests/acceptance/01_vars/02_functions/017.cf index b9cfa15a1bc..0b15619d31e 100644 --- a/tests/acceptance/01_vars/02_functions/017.cf +++ b/tests/acceptance/01_vars/02_functions/017.cf @@ -38,7 +38,8 @@ body delete init_delete bundle agent test { vars: - "nums" slist => readstringlist("$(G.testfile)", "NoComment", "\s+", 5, 100); + "nums" slist => readstringlist("$(G.testfile)", "NoComment", "\s+", 5, 100), + if => fileexists("$(G.testfile)"); "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/018.cf b/tests/acceptance/01_vars/02_functions/018.cf index d72de43df26..4173999135b 100644 --- a/tests/acceptance/01_vars/02_functions/018.cf +++ b/tests/acceptance/01_vars/02_functions/018.cf @@ -37,7 +37,8 @@ body delete init_delete bundle agent test { vars: - "nums" slist => readstringlist("$(G.testfile)", "NoComment", "\s+", 5, 100); + "nums" slist => readstringlist("$(G.testfile)", "NoComment", "\s+", 5, 100), + if => fileexists("$(G.testfile)"); "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/019.cf b/tests/acceptance/01_vars/02_functions/019.cf index 6b1af5b6871..d269fda0c69 100644 --- a/tests/acceptance/01_vars/02_functions/019.cf +++ b/tests/acceptance/01_vars/02_functions/019.cf @@ -37,7 +37,8 @@ body delete init_delete bundle agent test { vars: - "nums" slist => readstringlist("$(G.testfile)", "NoComment", "X", 5, 100); + "nums" slist => readstringlist("$(G.testfile)", "NoComment", "X", 5, 100), + if => fileexists("$(G.testfile)"); "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/020.cf b/tests/acceptance/01_vars/02_functions/020.cf index cc59c326708..3a1a1fe0723 100644 --- a/tests/acceptance/01_vars/02_functions/020.cf +++ b/tests/acceptance/01_vars/02_functions/020.cf @@ -37,7 +37,8 @@ body delete init_delete bundle agent test { vars: - "nums" slist => readstringlist("$(G.testfile)", "NoComment", "\s", 5, 100); + "nums" slist => readstringlist("$(G.testfile)", "NoComment", "\s", 5, 100), + if => fileexists("$(G.testfile)"); "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/021.cf b/tests/acceptance/01_vars/02_functions/021.cf index 8032a987cc5..f62d85462bb 100644 --- a/tests/acceptance/01_vars/02_functions/021.cf +++ b/tests/acceptance/01_vars/02_functions/021.cf @@ -37,7 +37,8 @@ body delete init_delete bundle agent test { vars: - "nums" slist => readstringlist("$(G.testfile)", "NoComment", ",", 5, 100); + "nums" slist => readstringlist("$(G.testfile)", "NoComment", ",", 5, 100), + if => fileexists("$(G.testfile)"); "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/024.cf b/tests/acceptance/01_vars/02_functions/024.cf index 74df030785c..6f7382d12d2 100644 --- a/tests/acceptance/01_vars/02_functions/024.cf +++ b/tests/acceptance/01_vars/02_functions/024.cf @@ -36,7 +36,8 @@ body delete init_delete bundle agent test { vars: - "nums" ilist => readintlist("$(G.testfile)", "NoComment", "\s+", 5, 100); + "nums" ilist => readintlist("$(G.testfile)", "NoComment", "\s+", 5, 100), + if => fileexists("$(G.testfile)"); "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/025.cf b/tests/acceptance/01_vars/02_functions/025.cf index 3d6351e52c1..4c7c07f1079 100644 --- a/tests/acceptance/01_vars/02_functions/025.cf +++ b/tests/acceptance/01_vars/02_functions/025.cf @@ -37,7 +37,8 @@ body delete init_delete bundle agent test { vars: - "nums" ilist => readintlist("$(G.testfile)", "NoComment", "\s+", 5, 100); + "nums" ilist => readintlist("$(G.testfile)", "NoComment", "\s+", 5, 100), + if => fileexists("$(G.testfile)"); "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/026.cf b/tests/acceptance/01_vars/02_functions/026.cf index 50b0cf1ec32..5e0ea912cc8 100644 --- a/tests/acceptance/01_vars/02_functions/026.cf +++ b/tests/acceptance/01_vars/02_functions/026.cf @@ -36,7 +36,8 @@ body delete init_delete bundle agent test { vars: - "nums" ilist => readintlist("$(G.testfile)", "NoComment", "\s+", 5, 100); + "nums" ilist => readintlist("$(G.testfile)", "NoComment", "\s+", 5, 100), + if => fileexists("$(G.testfile)"); "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/027.cf b/tests/acceptance/01_vars/02_functions/027.cf index 55a80306d4f..75e7c539cd5 100644 --- a/tests/acceptance/01_vars/02_functions/027.cf +++ b/tests/acceptance/01_vars/02_functions/027.cf @@ -36,7 +36,8 @@ body delete init_delete bundle agent test { vars: - "nums" ilist => readintlist("$(G.testfile)", "NoComment", "\.", 5, 100); + "nums" ilist => readintlist("$(G.testfile)", "NoComment", "\.", 5, 100), + if => fileexists("$(G.testfile)"); "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/028.cf b/tests/acceptance/01_vars/02_functions/028.cf index 322b4fa70a3..850cbb5fc44 100644 --- a/tests/acceptance/01_vars/02_functions/028.cf +++ b/tests/acceptance/01_vars/02_functions/028.cf @@ -36,7 +36,8 @@ body delete init_delete bundle agent test { vars: - "nums" ilist => readintlist("$(G.testfile)", "NoComment", "\s+", 5, 100); + "nums" ilist => readintlist("$(G.testfile)", "NoComment", "\s+", 5, 100), + if => fileexists("$(G.testfile)"); "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/029.cf b/tests/acceptance/01_vars/02_functions/029.cf index 3a746744265..b15d19dcffa 100644 --- a/tests/acceptance/01_vars/02_functions/029.cf +++ b/tests/acceptance/01_vars/02_functions/029.cf @@ -37,7 +37,8 @@ body delete init_delete bundle agent test { vars: - "nums" ilist => readintlist("$(G.testfile)", "NoComment", "\s+", 5, 100); + "nums" ilist => readintlist("$(G.testfile)", "NoComment", "\s+", 5, 100), + if => fileexists("$(G.testfile)"); "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/030.cf b/tests/acceptance/01_vars/02_functions/030.cf index c5e438f364f..3938eda2acb 100644 --- a/tests/acceptance/01_vars/02_functions/030.cf +++ b/tests/acceptance/01_vars/02_functions/030.cf @@ -37,7 +37,8 @@ body delete init_delete bundle agent test { vars: - "nums" ilist => readintlist("$(G.testfile)", "NoComment", "\s+", 5, 100); + "nums" ilist => readintlist("$(G.testfile)", "NoComment", "\s+", 5, 100), + if => fileexists("$(G.testfile)"); "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/031.cf b/tests/acceptance/01_vars/02_functions/031.cf index d40f59a1035..dd199a7d122 100644 --- a/tests/acceptance/01_vars/02_functions/031.cf +++ b/tests/acceptance/01_vars/02_functions/031.cf @@ -36,7 +36,8 @@ body delete init_delete bundle agent test { vars: - "nums" ilist => readintlist("$(G.testfile)", "NoComment", "\s+", 5, 100); + "nums" ilist => readintlist("$(G.testfile)", "NoComment", "\s+", 5, 100), + if => fileexists("$(G.testfile)"); "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/032.cf b/tests/acceptance/01_vars/02_functions/032.cf index 742c4e4f0b2..2c0d4cf6c0f 100644 --- a/tests/acceptance/01_vars/02_functions/032.cf +++ b/tests/acceptance/01_vars/02_functions/032.cf @@ -36,7 +36,8 @@ body delete init_delete bundle agent test { vars: - "nums" ilist => readintlist("$(G.testfile)", "NoComment", "X", 5, 100); + "nums" ilist => readintlist("$(G.testfile)", "NoComment", "X", 5, 100), + if => fileexists("$(G.testfile)"); "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/033.cf b/tests/acceptance/01_vars/02_functions/033.cf index e90f323f897..7e3a5d367d3 100644 --- a/tests/acceptance/01_vars/02_functions/033.cf +++ b/tests/acceptance/01_vars/02_functions/033.cf @@ -36,7 +36,8 @@ body delete init_delete bundle agent test { vars: - "nums" ilist => readintlist("$(G.testfile)", "NoComment", "\s", 5, 100); + "nums" ilist => readintlist("$(G.testfile)", "NoComment", "\s", 5, 100), + if => fileexists("$(G.testfile)"); "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/034.cf b/tests/acceptance/01_vars/02_functions/034.cf index e9d1dbfafcf..38abced469c 100644 --- a/tests/acceptance/01_vars/02_functions/034.cf +++ b/tests/acceptance/01_vars/02_functions/034.cf @@ -36,7 +36,8 @@ body delete init_delete bundle agent test { vars: - "nums" ilist => readintlist("$(G.testfile)", "NoComment", ",", 5, 100); + "nums" ilist => readintlist("$(G.testfile)", "NoComment", ",", 5, 100), + if => fileexists("$(G.testfile)"); "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/037.cf b/tests/acceptance/01_vars/02_functions/037.cf index 770c373c58c..6e65a785ceb 100644 --- a/tests/acceptance/01_vars/02_functions/037.cf +++ b/tests/acceptance/01_vars/02_functions/037.cf @@ -36,7 +36,8 @@ body delete init_delete bundle agent test { vars: - "nums" rlist => readreallist("$(G.testfile)", "NoComment", "\s+", 5, 100); + "nums" rlist => readreallist("$(G.testfile)", "NoComment", "\s+", 5, 100), + if => fileexists("$(G.testfile)"); "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/038.cf b/tests/acceptance/01_vars/02_functions/038.cf index 26eabcf4638..4fc8fb18a79 100644 --- a/tests/acceptance/01_vars/02_functions/038.cf +++ b/tests/acceptance/01_vars/02_functions/038.cf @@ -37,7 +37,8 @@ body delete init_delete bundle agent test { vars: - "nums" rlist => readreallist("$(G.testfile)", "NoComment", "\s+", 5, 100); + "nums" rlist => readreallist("$(G.testfile)", "NoComment", "\s+", 5, 100), + if => fileexists("$(G.testfile)"); "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/039.cf b/tests/acceptance/01_vars/02_functions/039.cf index 53dd4046be4..6f72f753c8c 100644 --- a/tests/acceptance/01_vars/02_functions/039.cf +++ b/tests/acceptance/01_vars/02_functions/039.cf @@ -36,7 +36,8 @@ body delete init_delete bundle agent test { vars: - "nums" rlist => readreallist("$(G.testfile)", "NoComment", "\s+", 5, 100); + "nums" rlist => readreallist("$(G.testfile)", "NoComment", "\s+", 5, 100), + if => fileexists("$(G.testfile)"); "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/040.cf b/tests/acceptance/01_vars/02_functions/040.cf index 3ba0f3c2dba..4c10aaa8d9d 100644 --- a/tests/acceptance/01_vars/02_functions/040.cf +++ b/tests/acceptance/01_vars/02_functions/040.cf @@ -36,7 +36,8 @@ body delete init_delete bundle agent test { vars: - "nums" rlist => readreallist("$(G.testfile)", "NoComment", "\.", 5, 100); + "nums" rlist => readreallist("$(G.testfile)", "NoComment", "\.", 5, 100), + if => fileexists("$(G.testfile)"); "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/041.cf b/tests/acceptance/01_vars/02_functions/041.cf index 61608635fd5..7fefc1cb209 100644 --- a/tests/acceptance/01_vars/02_functions/041.cf +++ b/tests/acceptance/01_vars/02_functions/041.cf @@ -36,7 +36,8 @@ body delete init_delete bundle agent test { vars: - "nums" rlist => readreallist("$(G.testfile)", "NoComment", "\s+", 5, 100); + "nums" rlist => readreallist("$(G.testfile)", "NoComment", "\s+", 5, 100), + if => fileexists("$(G.testfile)"); "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/042.cf b/tests/acceptance/01_vars/02_functions/042.cf index ee96964fae0..a1e160b2a42 100644 --- a/tests/acceptance/01_vars/02_functions/042.cf +++ b/tests/acceptance/01_vars/02_functions/042.cf @@ -37,7 +37,8 @@ body delete init_delete bundle agent test { vars: - "nums" rlist => readreallist("$(G.testfile)", "NoComment", "\s+", 5, 100); + "nums" rlist => readreallist("$(G.testfile)", "NoComment", "\s+", 5, 100), + if => fileexists("$(G.testfile)"); "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/043.cf b/tests/acceptance/01_vars/02_functions/043.cf index 7a9427aed85..54b5bff2c65 100644 --- a/tests/acceptance/01_vars/02_functions/043.cf +++ b/tests/acceptance/01_vars/02_functions/043.cf @@ -37,7 +37,8 @@ body delete init_delete bundle agent test { vars: - "nums" rlist => readreallist("$(G.testfile)", "NoComment", "\s+", 5, 100); + "nums" rlist => readreallist("$(G.testfile)", "NoComment", "\s+", 5, 100), + if => fileexists("$(G.testfile)"); "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/044.cf b/tests/acceptance/01_vars/02_functions/044.cf index 6b0e85e0c7f..a28458dcc12 100644 --- a/tests/acceptance/01_vars/02_functions/044.cf +++ b/tests/acceptance/01_vars/02_functions/044.cf @@ -36,7 +36,8 @@ body delete init_delete bundle agent test { vars: - "nums" rlist => readreallist("$(G.testfile)", "NoComment", "\s+", 5, 100); + "nums" rlist => readreallist("$(G.testfile)", "NoComment", "\s+", 5, 100), + if => fileexists("$(G.testfile)"); "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/045.cf b/tests/acceptance/01_vars/02_functions/045.cf index 0cddcd75623..4aaa3c1fd7f 100644 --- a/tests/acceptance/01_vars/02_functions/045.cf +++ b/tests/acceptance/01_vars/02_functions/045.cf @@ -36,7 +36,8 @@ body delete init_delete bundle agent test { vars: - "nums" rlist => readreallist("$(G.testfile)", "NoComment", "X", 5, 100); + "nums" rlist => readreallist("$(G.testfile)", "NoComment", "X", 5, 100), + if => fileexists("$(G.testfile)"); "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/046.cf b/tests/acceptance/01_vars/02_functions/046.cf index 41a076f5609..251535cd8bb 100644 --- a/tests/acceptance/01_vars/02_functions/046.cf +++ b/tests/acceptance/01_vars/02_functions/046.cf @@ -36,7 +36,8 @@ body delete init_delete bundle agent test { vars: - "nums" rlist => readreallist("$(G.testfile)", "NoComment", "\s", 5, 100); + "nums" rlist => readreallist("$(G.testfile)", "NoComment", "\s", 5, 100), + if => fileexists("$(G.testfile)"); "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/047.cf b/tests/acceptance/01_vars/02_functions/047.cf index c8c73e774ed..b6b1384ee9b 100644 --- a/tests/acceptance/01_vars/02_functions/047.cf +++ b/tests/acceptance/01_vars/02_functions/047.cf @@ -36,7 +36,8 @@ body delete init_delete bundle agent test { vars: - "nums" rlist => readreallist("$(G.testfile)", "NoComment", ",", 5, 100); + "nums" rlist => readreallist("$(G.testfile)", "NoComment", ",", 5, 100), + if => fileexists("$(G.testfile)"); "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/050.cf b/tests/acceptance/01_vars/02_functions/050.cf index b0d9b0b64db..b53302a9df0 100644 --- a/tests/acceptance/01_vars/02_functions/050.cf +++ b/tests/acceptance/01_vars/02_functions/050.cf @@ -36,7 +36,8 @@ body delete init_delete bundle agent test { vars: - "nums" rlist => readreallist("$(G.testfile)", "NoComment", "\.", 5, 100); + "nums" rlist => readreallist("$(G.testfile)", "NoComment", "\.", 5, 100), + if => fileexists("$(G.testfile)"); "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/400.cf b/tests/acceptance/01_vars/02_functions/400.cf index bc6edf6d783..da20512b37c 100644 --- a/tests/acceptance/01_vars/02_functions/400.cf +++ b/tests/acceptance/01_vars/02_functions/400.cf @@ -45,7 +45,8 @@ bundle agent test "cnt" int => readstringarray( "ary", "$(G.testfile)", "NoComment", ":", 10, 1000 - ); + ), + if => fileexists("$(G.testfile)"); "num" int => "3"; } diff --git a/tests/acceptance/01_vars/02_functions/401.cf b/tests/acceptance/01_vars/02_functions/401.cf index fd2f2da1be3..f06d4999a61 100644 --- a/tests/acceptance/01_vars/02_functions/401.cf +++ b/tests/acceptance/01_vars/02_functions/401.cf @@ -45,7 +45,8 @@ bundle agent test "cnt" int => readstringarray( "ary", "$(G.testfile)", "NoComment", ":", 10, 1000 - ); + ), + if => fileexists("$(G.testfile)"); "num" int => "3"; } diff --git a/tests/acceptance/01_vars/02_functions/410.cf b/tests/acceptance/01_vars/02_functions/410.cf index 2937dd75310..e05695088a1 100644 --- a/tests/acceptance/01_vars/02_functions/410.cf +++ b/tests/acceptance/01_vars/02_functions/410.cf @@ -48,7 +48,8 @@ body delete init_delete bundle agent test { vars: - "cnt" int => readstringarray("ary", "$(G.testfile)", "^#.*", ":+", 10, 14); + "cnt" int => readstringarray("ary", "$(G.testfile)", "^#.*", ":+", 10, 14), + if => fileexists("$(G.testfile)"); "num" int => "3"; } diff --git a/tests/acceptance/01_vars/02_functions/420.cf b/tests/acceptance/01_vars/02_functions/420.cf index 634072f50f1..122a91e0c22 100644 --- a/tests/acceptance/01_vars/02_functions/420.cf +++ b/tests/acceptance/01_vars/02_functions/420.cf @@ -42,7 +42,8 @@ body delete init_delete bundle agent test { vars: - "teststr" string => readfile("$(G.testfile)", 1000); + "teststr" string => readfile("$(G.testfile)", 1000), + if => fileexists("$(G.testfile)"); "cnt" int => parsestringarray("ary", "$(teststr)", "NoComment", ":", 10, 1000); diff --git a/tests/acceptance/01_vars/02_functions/421.cf b/tests/acceptance/01_vars/02_functions/421.cf index 9891f76758a..9c5fb087d24 100644 --- a/tests/acceptance/01_vars/02_functions/421.cf +++ b/tests/acceptance/01_vars/02_functions/421.cf @@ -42,7 +42,8 @@ body delete init_delete bundle agent test { vars: - "teststr" string => readfile("$(G.testfile)", 1000); + "teststr" string => readfile("$(G.testfile)", 1000), + if => fileexists("$(G.testfile)"); "cnt" int => parsestringarray("ary", "$(teststr)", "NoComment", ":", 10, 1000); diff --git a/tests/acceptance/01_vars/02_functions/440.cf b/tests/acceptance/01_vars/02_functions/440.cf index 3ffe141d7b8..93c2839d1c8 100644 --- a/tests/acceptance/01_vars/02_functions/440.cf +++ b/tests/acceptance/01_vars/02_functions/440.cf @@ -45,7 +45,8 @@ bundle agent test "cnt" int => readstringarrayidx( "ary", "$(G.testfile)", "NoComment", ":", 10, 1000 - ); + ), + if => fileexists("$(G.testfile)"); "num" int => "3"; } diff --git a/tests/acceptance/01_vars/02_functions/441.cf b/tests/acceptance/01_vars/02_functions/441.cf index 3a71cff5cd7..639d1e48cc5 100644 --- a/tests/acceptance/01_vars/02_functions/441.cf +++ b/tests/acceptance/01_vars/02_functions/441.cf @@ -45,7 +45,8 @@ bundle agent test "cnt" int => readstringarrayidx( "ary", "$(G.testfile)", "NoComment", ":", 10, 1000 - ); + ), + if => fileexists("$(G.testfile)"); "num" int => "3"; } diff --git a/tests/acceptance/01_vars/02_functions/442.cf b/tests/acceptance/01_vars/02_functions/442.cf index 284a6f7357c..bd9d0ae93fb 100644 --- a/tests/acceptance/01_vars/02_functions/442.cf +++ b/tests/acceptance/01_vars/02_functions/442.cf @@ -46,7 +46,8 @@ bundle agent test "cnt" int => readstringarrayidx( "ary", "$(G.testfile)", "NoComment", ":", 10, 1000 - ); + ), + if => fileexists("$(G.testfile)"); "num" int => "4"; } diff --git a/tests/acceptance/01_vars/02_functions/443.cf b/tests/acceptance/01_vars/02_functions/443.cf index 5663b905fb1..ef4bd364ef4 100644 --- a/tests/acceptance/01_vars/02_functions/443.cf +++ b/tests/acceptance/01_vars/02_functions/443.cf @@ -53,7 +53,8 @@ bundle agent test "cnt" int => readstringarrayidx( "ary", "$(G.testfile)", "NoComment", ":", 10, 1000 - ); + ), + if => fileexists("$(G.testfile)"); "num" int => "4"; } diff --git a/tests/acceptance/01_vars/02_functions/444.cf b/tests/acceptance/01_vars/02_functions/444.cf index 5e384aabbd9..2a138207d9f 100644 --- a/tests/acceptance/01_vars/02_functions/444.cf +++ b/tests/acceptance/01_vars/02_functions/444.cf @@ -51,7 +51,8 @@ bundle agent test "cnt" int => readstringarrayidx( "ary", "$(G.testfile)", "NoComment", ":", 10, 1000 - ); + ), + if => fileexists("$(G.testfile)"); "num" int => "9"; } diff --git a/tests/acceptance/01_vars/02_functions/445.cf b/tests/acceptance/01_vars/02_functions/445.cf index 82be099cc04..89b95d24738 100644 --- a/tests/acceptance/01_vars/02_functions/445.cf +++ b/tests/acceptance/01_vars/02_functions/445.cf @@ -54,7 +54,8 @@ bundle agent test "cnt" int => readstringarrayidx( "ary", "$(G.testfile)", "NoComment", ":", 10, 1000 - ); + ), + if => fileexists("$(G.testfile)"); "num" int => "9"; } diff --git a/tests/acceptance/01_vars/02_functions/447.cf b/tests/acceptance/01_vars/02_functions/447.cf index 517919c7918..0632d00fc67 100644 --- a/tests/acceptance/01_vars/02_functions/447.cf +++ b/tests/acceptance/01_vars/02_functions/447.cf @@ -48,7 +48,8 @@ body delete init_delete bundle agent test { vars: - "cnt" int => readstringarrayidx("ary", "$(G.testfile)", "", ":", 10, 1000); + "cnt" int => readstringarrayidx("ary", "$(G.testfile)", "", ":", 10, 1000), + if => fileexists("$(G.testfile)"); "num" int => "9"; } diff --git a/tests/acceptance/01_vars/02_functions/450.cf b/tests/acceptance/01_vars/02_functions/450.cf index c850c569dae..d686c41c1db 100644 --- a/tests/acceptance/01_vars/02_functions/450.cf +++ b/tests/acceptance/01_vars/02_functions/450.cf @@ -49,7 +49,8 @@ bundle agent test { vars: "cnt" - int => readstringarrayidx("ary", "$(G.testfile)", "^#.*", ":+", 10, 14); + int => readstringarrayidx("ary", "$(G.testfile)", "^#.*", ":+", 10, 14), + if => fileexists("$(G.testfile)"); "num" int => "3"; } diff --git a/tests/acceptance/01_vars/02_functions/500.cf b/tests/acceptance/01_vars/02_functions/500.cf index 205241c3089..01148598230 100644 --- a/tests/acceptance/01_vars/02_functions/500.cf +++ b/tests/acceptance/01_vars/02_functions/500.cf @@ -42,7 +42,8 @@ bundle agent test { vars: "cnt" - int => readintarray("ary", "$(G.testfile)", "NoComment", ":", 10, 1000); + int => readintarray("ary", "$(G.testfile)", "NoComment", ":", 10, 1000), + if => fileexists("$(G.testfile)"); "num" int => "3"; } diff --git a/tests/acceptance/01_vars/02_functions/501.cf b/tests/acceptance/01_vars/02_functions/501.cf index 7c3c982d76e..ddaba1ac6e5 100644 --- a/tests/acceptance/01_vars/02_functions/501.cf +++ b/tests/acceptance/01_vars/02_functions/501.cf @@ -42,7 +42,8 @@ bundle agent test { vars: "cnt" - int => readintarray("ary", "$(G.testfile)", "NoComment", ":", 10, 1000); + int => readintarray("ary", "$(G.testfile)", "NoComment", ":", 10, 1000), + if => fileexists("$(G.testfile)"); "num" int => "3"; } diff --git a/tests/acceptance/01_vars/02_functions/520.cf b/tests/acceptance/01_vars/02_functions/520.cf index b54fc402132..d1ab666bce3 100644 --- a/tests/acceptance/01_vars/02_functions/520.cf +++ b/tests/acceptance/01_vars/02_functions/520.cf @@ -41,7 +41,8 @@ body delete init_delete bundle agent test { vars: - "teststr" string => readfile("$(G.testfile)", 1000); + "teststr" string => readfile("$(G.testfile)", 1000), + if => fileexists("$(G.testfile)"); "cnt" int => parseintarray("ary", "$(teststr)", "NoComment", ":", 10, 1000); "num" int => "3"; } diff --git a/tests/acceptance/01_vars/02_functions/521.cf b/tests/acceptance/01_vars/02_functions/521.cf index 12424b904fc..84233e9db8b 100644 --- a/tests/acceptance/01_vars/02_functions/521.cf +++ b/tests/acceptance/01_vars/02_functions/521.cf @@ -41,7 +41,8 @@ body delete init_delete bundle agent test { vars: - "teststr" string => readfile("$(G.testfile)", 1000); + "teststr" string => readfile("$(G.testfile)", 1000), + if => fileexists("$(G.testfile)"); "cnt" int => parseintarray("ary", "$(teststr)", "NoComment", ":", 10, 1000); "num" int => "3"; } diff --git a/tests/acceptance/01_vars/02_functions/600.cf b/tests/acceptance/01_vars/02_functions/600.cf index fb48a433696..b402e6dd99f 100644 --- a/tests/acceptance/01_vars/02_functions/600.cf +++ b/tests/acceptance/01_vars/02_functions/600.cf @@ -42,7 +42,8 @@ bundle agent test { vars: "cnt" - int => readrealarray("ary", "$(G.testfile)", "NoComment", ":", 10, 1000); + int => readrealarray("ary", "$(G.testfile)", "NoComment", ":", 10, 1000), + if => fileexists("$(G.testfile)"); "num" int => "3"; } diff --git a/tests/acceptance/01_vars/02_functions/601.cf b/tests/acceptance/01_vars/02_functions/601.cf index e19a254a1b0..843d72d1219 100644 --- a/tests/acceptance/01_vars/02_functions/601.cf +++ b/tests/acceptance/01_vars/02_functions/601.cf @@ -42,7 +42,8 @@ bundle agent test { vars: "cnt" - int => readrealarray("ary", "$(G.testfile)", "NoComment", ":", 10, 1000); + int => readrealarray("ary", "$(G.testfile)", "NoComment", ":", 10, 1000), + if => fileexists("$(G.testfile)"); "num" int => "3"; } diff --git a/tests/acceptance/01_vars/02_functions/620.cf b/tests/acceptance/01_vars/02_functions/620.cf index 8ce3531136f..50f06d423e9 100644 --- a/tests/acceptance/01_vars/02_functions/620.cf +++ b/tests/acceptance/01_vars/02_functions/620.cf @@ -41,7 +41,8 @@ body delete init_delete bundle agent test { vars: - "teststr" string => readfile("$(G.testfile)", 1000); + "teststr" string => readfile("$(G.testfile)", 1000), + if => fileexists("$(G.testfile)"); "cnt" int => parserealarray("ary", "$(teststr)", "NoComment", ":", 10, 1000); diff --git a/tests/acceptance/01_vars/02_functions/621.cf b/tests/acceptance/01_vars/02_functions/621.cf index 59d8b7eb462..dc908d968cd 100644 --- a/tests/acceptance/01_vars/02_functions/621.cf +++ b/tests/acceptance/01_vars/02_functions/621.cf @@ -41,7 +41,8 @@ body delete init_delete bundle agent test { vars: - "teststr" string => readfile("$(G.testfile)", 1000); + "teststr" string => readfile("$(G.testfile)", 1000), + if => fileexists("$(G.testfile)"); "cnt" int => parserealarray("ary", "$(teststr)", "NoComment", ":", 10, 1000); diff --git a/tests/acceptance/01_vars/02_functions/classfilterdata_collecting.cf b/tests/acceptance/01_vars/02_functions/classfilterdata_collecting.cf index 88ea0d29e6d..8b2cbc66bc2 100644 --- a/tests/acceptance/01_vars/02_functions/classfilterdata_collecting.cf +++ b/tests/acceptance/01_vars/02_functions/classfilterdata_collecting.cf @@ -44,7 +44,8 @@ bundle agent test vars: "filtered" - data => classfilterdata(readjson("$(G.testfile).json"), "auto", "if"); + data => classfilterdata(readjson("$(G.testfile).json"), "auto", "if"), + if => fileexists("$(G.testfile).json"); } bundle agent check diff --git a/tests/acceptance/01_vars/02_functions/long_string_from_text_file.cf b/tests/acceptance/01_vars/02_functions/long_string_from_text_file.cf index 80ecfd7f317..25a0bbce723 100644 --- a/tests/acceptance/01_vars/02_functions/long_string_from_text_file.cf +++ b/tests/acceptance/01_vars/02_functions/long_string_from_text_file.cf @@ -26,7 +26,8 @@ bundle agent test { vars: "keyfile" string => "$(G.testfile).data"; - "keys" slist => readstringlist("$(keyfile)", "#[^\n]*", "\n", 10, 3072); + "keys" slist => readstringlist("$(keyfile)", "#[^\n]*", "\n", 10, 3072), + if => fileexists("$(keyfile)"); } ####################################################### diff --git a/tests/acceptance/01_vars/02_functions/parsestringarray_dontread_comment_duplicate_lastline2.cf b/tests/acceptance/01_vars/02_functions/parsestringarray_dontread_comment_duplicate_lastline2.cf index 643b67106ba..478a3eb0c63 100644 --- a/tests/acceptance/01_vars/02_functions/parsestringarray_dontread_comment_duplicate_lastline2.cf +++ b/tests/acceptance/01_vars/02_functions/parsestringarray_dontread_comment_duplicate_lastline2.cf @@ -51,7 +51,8 @@ bundle agent test "cnt" int => readstringarrayidx( "ary", "$(G.testfile)", "NoComment", ":", 6, 1000 - ); + ), + if => fileexists("$(G.testfile)"); "num" int => "6"; } diff --git a/tests/acceptance/01_vars/02_functions/parsestringarray_weird_indices_real_comments_noemptyfields2.cf b/tests/acceptance/01_vars/02_functions/parsestringarray_weird_indices_real_comments_noemptyfields2.cf index 801e3f09c2a..79539da135d 100644 --- a/tests/acceptance/01_vars/02_functions/parsestringarray_weird_indices_real_comments_noemptyfields2.cf +++ b/tests/acceptance/01_vars/02_functions/parsestringarray_weird_indices_real_comments_noemptyfields2.cf @@ -48,7 +48,8 @@ body delete init_delete bundle agent test { vars: - "teststr" string => readfile("$(G.testfile)", 1000); + "teststr" string => readfile("$(G.testfile)", 1000), + if => fileexists("$(G.testfile)"); "cnt" int => parsestringarray("ary", "$(teststr)", "^#.*", ":+", 10, 14); "num" int => "3"; } diff --git a/tests/acceptance/01_vars/02_functions/peers.cf b/tests/acceptance/01_vars/02_functions/peers.cf index 5b87f0b1cb4..e99d0373e91 100644 --- a/tests/acceptance/01_vars/02_functions/peers.cf +++ b/tests/acceptance/01_vars/02_functions/peers.cf @@ -56,10 +56,12 @@ bundle agent test "subtests" ilist => { "0", "1", "2", "3", "4", "5" }; "peers_$(tests)_$(subtests)" - slist => peers("$(G.testfile).$(tests)", "#.*", $(subtests)); + slist => peers("$(G.testfile).$(tests)", "#.*", $(subtests)), + if => fileexists("$(G.testfile).$(tests)"); "peerleaders_$(tests)_$(subtests)" - slist => peerleaders("$(G.testfile).$(tests)", "#.*", $(subtests)); + slist => peerleaders("$(G.testfile).$(tests)", "#.*", $(subtests)), + if => fileexists("$(G.testfile).$(tests)"); "actual_peers_$(tests)_$(subtests)" string => format("%S", "peers_$(tests)_$(subtests)"); @@ -68,7 +70,8 @@ bundle agent test string => format("%S", "peerleaders_$(tests)_$(subtests)"); "actual_peerleader_$(tests)_$(subtests)" - string => peerleader("$(G.testfile).$(tests)", "#.*", $(subtests)); + string => peerleader("$(G.testfile).$(tests)", "#.*", $(subtests)), + if => fileexists("$(G.testfile).$(tests)"); } ####################################################### diff --git a/tests/acceptance/01_vars/02_functions/read_empty_file.cf b/tests/acceptance/01_vars/02_functions/read_empty_file.cf index 1ce7d0bb4ca..d1f37354b8a 100644 --- a/tests/acceptance/01_vars/02_functions/read_empty_file.cf +++ b/tests/acceptance/01_vars/02_functions/read_empty_file.cf @@ -15,8 +15,10 @@ bundle agent init bundle agent test { vars: - "value1" string => readfile("$(G.testfile)", 10000); - "value2" string => readfile("$(G.testfile)", 0); + "value1" string => readfile("$(G.testfile)", 10000), + if => fileexists("$(G.testfile)"); + "value2" string => readfile("$(G.testfile)", 0), + if => fileexists("$(G.testfile)"); } bundle agent check diff --git a/tests/acceptance/01_vars/02_functions/readstringarray_dontread_comment_duplicatekey_lastline.cf b/tests/acceptance/01_vars/02_functions/readstringarray_dontread_comment_duplicatekey_lastline.cf index f9339fc69e5..2d9b30cc87b 100644 --- a/tests/acceptance/01_vars/02_functions/readstringarray_dontread_comment_duplicatekey_lastline.cf +++ b/tests/acceptance/01_vars/02_functions/readstringarray_dontread_comment_duplicatekey_lastline.cf @@ -49,7 +49,8 @@ bundle agent test { vars: "cnt" - int => readstringarray("ary", "$(G.testfile)", "NoComment", ":", 6, 1000); + int => readstringarray("ary", "$(G.testfile)", "NoComment", ":", 6, 1000), + if => fileexists("$(G.testfile)"); "num" int => "6"; } diff --git a/tests/acceptance/01_vars/02_functions/readstringarrayidx_order.cf b/tests/acceptance/01_vars/02_functions/readstringarrayidx_order.cf index 3d8236815ee..c8fd1b9a0b5 100644 --- a/tests/acceptance/01_vars/02_functions/readstringarrayidx_order.cf +++ b/tests/acceptance/01_vars/02_functions/readstringarrayidx_order.cf @@ -69,7 +69,8 @@ bundle agent test "num" int => readstringarrayidx( "mylines", "$(G.testfile).orig.txt", "\s*#[^\n]*", "\s*;;\s*", 50, 9999 - ); + ), + if => fileexists("$(G.testfile).orig.txt"); "file" slist => { diff --git a/tests/acceptance/01_vars/04_containers/readjson.cf b/tests/acceptance/01_vars/04_containers/readjson.cf index a4a1998f314..3317af28d2f 100644 --- a/tests/acceptance/01_vars/04_containers/readjson.cf +++ b/tests/acceptance/01_vars/04_containers/readjson.cf @@ -40,7 +40,8 @@ bundle edit_line init_insert_lines bundle agent test { vars: - "load" data => readjson("$(G.testfile).json", 1024); + "load" data => readjson("$(G.testfile).json", 1024), + if => fileexists("$(G.testfile).json"); files: "$(G.testfile).actual" diff --git a/tests/acceptance/01_vars/04_containers/readjson_arrays.cf b/tests/acceptance/01_vars/04_containers/readjson_arrays.cf index 004676f31d4..bc120e55e8a 100644 --- a/tests/acceptance/01_vars/04_containers/readjson_arrays.cf +++ b/tests/acceptance/01_vars/04_containers/readjson_arrays.cf @@ -43,7 +43,8 @@ bundle edit_line init_insert_lines bundle agent test { vars: - "load" data => readjson("$(G.testfile).json", 1024); + "load" data => readjson("$(G.testfile).json", 1024), + if => fileexists("$(G.testfile).json"); files: "$(G.testfile).actual" diff --git a/tests/acceptance/01_vars/04_containers/readjson_new.cf b/tests/acceptance/01_vars/04_containers/readjson_new.cf index 6d453e4a67e..a411f6614b9 100644 --- a/tests/acceptance/01_vars/04_containers/readjson_new.cf +++ b/tests/acceptance/01_vars/04_containers/readjson_new.cf @@ -40,7 +40,8 @@ bundle edit_line init_insert_lines bundle agent test { vars: - "load" data => readjson("$(G.testfile).json"); + "load" data => readjson("$(G.testfile).json"), + if => fileexists("$(G.testfile).json"); files: "$(G.testfile).actual" diff --git a/tests/acceptance/01_vars/04_containers/readjson_null.cf b/tests/acceptance/01_vars/04_containers/readjson_null.cf index fed055cb2e3..92309aa6386 100644 --- a/tests/acceptance/01_vars/04_containers/readjson_null.cf +++ b/tests/acceptance/01_vars/04_containers/readjson_null.cf @@ -39,7 +39,8 @@ bundle edit_line init_insert_lines bundle agent test { vars: - "load" data => readjson("$(G.testfile).json", 1024); + "load" data => readjson("$(G.testfile).json", 1024), + if => fileexists("$(G.testfile).json"); files: "$(G.testfile).actual" diff --git a/tests/acceptance/01_vars/04_containers/readjson_objects.cf b/tests/acceptance/01_vars/04_containers/readjson_objects.cf index 137670afd03..54422b46662 100644 --- a/tests/acceptance/01_vars/04_containers/readjson_objects.cf +++ b/tests/acceptance/01_vars/04_containers/readjson_objects.cf @@ -40,7 +40,8 @@ bundle edit_line init_insert_lines bundle agent test { vars: - "load" data => readjson("$(G.testfile).json", 1024); + "load" data => readjson("$(G.testfile).json", 1024), + if => fileexists("$(G.testfile).json"); files: "$(G.testfile).actual" diff --git a/tests/acceptance/01_vars/04_containers/readjson_scalar.cf b/tests/acceptance/01_vars/04_containers/readjson_scalar.cf index f1fe8bc9172..ba32e03860b 100644 --- a/tests/acceptance/01_vars/04_containers/readjson_scalar.cf +++ b/tests/acceptance/01_vars/04_containers/readjson_scalar.cf @@ -39,7 +39,8 @@ bundle edit_line init_insert_lines bundle agent test { vars: - "load" data => readjson("$(G.testfile).json", 1024); + "load" data => readjson("$(G.testfile).json", 1024), + if => fileexists("$(G.testfile).json"); files: "$(G.testfile).actual" diff --git a/tests/acceptance/01_vars/04_containers/readjson_subindex.cf b/tests/acceptance/01_vars/04_containers/readjson_subindex.cf index 7cbdf379d2d..bd669b3ddae 100644 --- a/tests/acceptance/01_vars/04_containers/readjson_subindex.cf +++ b/tests/acceptance/01_vars/04_containers/readjson_subindex.cf @@ -41,7 +41,8 @@ bundle edit_line init_insert_lines bundle agent test { vars: - "load" data => readjson("$(G.testfile).json", 1024); + "load" data => readjson("$(G.testfile).json", 1024), + if => fileexists("$(G.testfile).json"); files: "$(G.testfile).actual" diff --git a/tests/acceptance/01_vars/04_containers/readjson_subindex_quoted.cf b/tests/acceptance/01_vars/04_containers/readjson_subindex_quoted.cf index 39e203f37df..17d8c7fadf2 100644 --- a/tests/acceptance/01_vars/04_containers/readjson_subindex_quoted.cf +++ b/tests/acceptance/01_vars/04_containers/readjson_subindex_quoted.cf @@ -41,7 +41,8 @@ bundle edit_line init_insert_lines bundle agent test { vars: - "load" data => readjson("$(G.testfile).json", 1024); + "load" data => readjson("$(G.testfile).json", 1024), + if => fileexists("$(G.testfile).json"); files: "$(G.testfile).actual" diff --git a/tests/acceptance/08_commands/arglist.cf b/tests/acceptance/08_commands/arglist.cf index c86411e7173..1948f33e815 100644 --- a/tests/acceptance/08_commands/arglist.cf +++ b/tests/acceptance/08_commands/arglist.cf @@ -46,7 +46,8 @@ bundle agent test bundle agent check { vars: - "actual" string => readfile("$(G.testfile).actual"); + "actual" string => readfile("$(G.testfile).actual"), + if => fileexists("$(G.testfile).actual"); "expected" string => "one two three diff --git a/tests/acceptance/10_files/09_insert_lines/preserve_block_blank_lines.cf b/tests/acceptance/10_files/09_insert_lines/preserve_block_blank_lines.cf index 79810047971..d39a6f50b73 100644 --- a/tests/acceptance/10_files/09_insert_lines/preserve_block_blank_lines.cf +++ b/tests/acceptance/10_files/09_insert_lines/preserve_block_blank_lines.cf @@ -38,7 +38,8 @@ bundle agent check Bad 3 "; - "actual" string => readfile("$(init.test_file)", "inf"); + "actual" string => readfile("$(init.test_file)", "inf"), + if => fileexists("$(init.test_file)"); classes: "ok" expression => strcmp("$(expected)", "$(actual)"); diff --git a/tests/acceptance/10_files/templating/empty_template_empty_file.cf b/tests/acceptance/10_files/templating/empty_template_empty_file.cf index de9a28342b7..38cc6730655 100644 --- a/tests/acceptance/10_files/templating/empty_template_empty_file.cf +++ b/tests/acceptance/10_files/templating/empty_template_empty_file.cf @@ -53,7 +53,8 @@ bundle agent check { vars: "expect" string => ""; - "actual" string => readfile("$(G.testfile)", 1000); + "actual" string => readfile("$(G.testfile)", 1000), + if => fileexists("$(G.testfile)"); classes: "ok" expression => regcmp("$(expect)", "$(actual)"); diff --git a/tests/acceptance/10_files/templating/mustache_abuse.cf b/tests/acceptance/10_files/templating/mustache_abuse.cf index a2b6eaa47d1..01ae5a2c531 100644 --- a/tests/acceptance/10_files/templating/mustache_abuse.cf +++ b/tests/acceptance/10_files/templating/mustache_abuse.cf @@ -99,7 +99,8 @@ bundle agent check ); "actual_$(init.tests)" - string => readfile("$(G.testfile).$(init.tests)", 10000); + string => readfile("$(G.testfile).$(init.tests)", 10000), + if => fileexists("$(G.testfile).$(init.tests)"); classes: "ok_$(init.tests)" diff --git a/tests/acceptance/10_files/templating/mustache_datastate_demo.cf b/tests/acceptance/10_files/templating/mustache_datastate_demo.cf index 0725484f444..43f2cc0a920 100644 --- a/tests/acceptance/10_files/templating/mustache_datastate_demo.cf +++ b/tests/acceptance/10_files/templating/mustache_datastate_demo.cf @@ -101,7 +101,8 @@ bundle agent check }" '; - "actual" string => readfile("$(G.testfile)", inf); + "actual" string => readfile("$(G.testfile)", inf), + if => fileexists("$(G.testfile)"); classes: "ok" expression => strcmp($(expect), $(actual)); diff --git a/tests/acceptance/10_files/templating/mustache_demo.cf b/tests/acceptance/10_files/templating/mustache_demo.cf index 76bffa647e4..3b016edaedb 100644 --- a/tests/acceptance/10_files/templating/mustache_demo.cf +++ b/tests/acceptance/10_files/templating/mustache_demo.cf @@ -49,7 +49,8 @@ bundle agent check { vars: "expect" string => readfile("$(init.origtestdir)/demo.expected", 10000); - "actual" string => readfile("$(G.testfile)", 10000); + "actual" string => readfile("$(G.testfile)", 10000), + if => fileexists("$(G.testfile)"); classes: "ok" expression => regcmp("$(expect)", "$(actual)"); diff --git a/tests/acceptance/10_files/templating/mustache_expect_list_find_string.cf b/tests/acceptance/10_files/templating/mustache_expect_list_find_string.cf index 7c69a7d9619..52b0077414c 100644 --- a/tests/acceptance/10_files/templating/mustache_expect_list_find_string.cf +++ b/tests/acceptance/10_files/templating/mustache_expect_list_find_string.cf @@ -85,8 +85,10 @@ bundle agent test vars: "template" string => "$(this.promise_filename).mustache"; - "actual_good" string => readfile("$(G.testfile).good", 4096); - "actual_bad" string => readfile("$(G.testfile).bad", 4096); + "actual_good" string => readfile("$(G.testfile).good", 4096), + if => fileexists("$(G.testfile).good"); + "actual_bad" string => readfile("$(G.testfile).bad", 4096), + if => fileexists("$(G.testfile).bad"); } ####################################################### diff --git a/tests/acceptance/10_files/templating/mustache_html_escape.cf b/tests/acceptance/10_files/templating/mustache_html_escape.cf index decc658f9ff..2f4a3b958eb 100644 --- a/tests/acceptance/10_files/templating/mustache_html_escape.cf +++ b/tests/acceptance/10_files/templating/mustache_html_escape.cf @@ -54,7 +54,8 @@ bundle agent check { vars: "expect" string => readfile("$(this.promise_filename).expected", 10000); - "actual" string => readfile("$(G.testfile)", 10000); + "actual" string => readfile("$(G.testfile)", 10000), + if => fileexists("$(G.testfile)"); classes: "ok" expression => strcmp("$(expect)", "$(actual)"); diff --git a/tests/acceptance/10_files/templating/mustache_inline_demo.cf b/tests/acceptance/10_files/templating/mustache_inline_demo.cf index d03e2d90681..6ae16b65a4d 100644 --- a/tests/acceptance/10_files/templating/mustache_inline_demo.cf +++ b/tests/acceptance/10_files/templating/mustache_inline_demo.cf @@ -52,7 +52,8 @@ bundle agent check "expect" string => readfile("$(init.origtestdir)/inline_demo.expected", 10000); - "actual" string => readfile("$(G.testfile)", 10000); + "actual" string => readfile("$(G.testfile)", 10000), + if => fileexists("$(G.testfile)"); classes: "ok" expression => regcmp("$(expect)", "$(actual)"); diff --git a/tests/acceptance/10_files/templating/mustache_render_quote.cf b/tests/acceptance/10_files/templating/mustache_render_quote.cf index 5ba4ba3ae9a..4def7b9364b 100644 --- a/tests/acceptance/10_files/templating/mustache_render_quote.cf +++ b/tests/acceptance/10_files/templating/mustache_render_quote.cf @@ -54,7 +54,8 @@ bundle agent check { vars: "expect" string => readfile("$(this.promise_filename).expected", 4000); - "actual" string => readfile("$(G.testfile)", 4000); + "actual" string => readfile("$(G.testfile)", 4000), + if => fileexists("$(G.testfile)"); classes: "ok" expression => regcmp("$(expect)", "$(actual)"); diff --git a/tests/acceptance/10_files/templating/mustache_repair_existing.cf b/tests/acceptance/10_files/templating/mustache_repair_existing.cf index e2a1991d973..2429e350ed6 100644 --- a/tests/acceptance/10_files/templating/mustache_repair_existing.cf +++ b/tests/acceptance/10_files/templating/mustache_repair_existing.cf @@ -50,7 +50,8 @@ bundle agent check { vars: "expect" string => readfile("$(init.origtestdir)/demo.expected", 4096); - "actual" string => readfile("$(G.testfile)", 4096); + "actual" string => readfile("$(G.testfile)", 4096), + if => fileexists("$(G.testfile)"); classes: "content_ok" expression => regcmp("$(expect)", "$(actual)"); diff --git a/tests/acceptance/31_tickets/CFE-3866/test.cf b/tests/acceptance/31_tickets/CFE-3866/test.cf index 5a8dd626451..c90c082ed48 100644 --- a/tests/acceptance/31_tickets/CFE-3866/test.cf +++ b/tests/acceptance/31_tickets/CFE-3866/test.cf @@ -68,7 +68,8 @@ bundle agent check "expected" string => "[section] key=value "; - "actual" string => readfile("$(G.testfile)", "1000"); + "actual" string => readfile("$(G.testfile)", "1000"), + if => fileexists("$(G.testfile)"); classes: "ok" expression => strcmp("$(expected)", "$(actual)"); From 5398b14d94424c30608c11a2fe89797ef45e7fd3 Mon Sep 17 00:00:00 2001 From: Ihor Aleksandrychiev Date: Thu, 15 Oct 2026 14:44:08 +0300 Subject: [PATCH 07/39] Indented command output in dcs_passif_output() DEBUG report Errors printed by the command were reported on lines starting with "error:", so testall mistook them for errors of the test itself. Ticket: CFE-3041 Signed-off-by: Ihor Aleksandrychiev --- tests/acceptance/dcs.sub.cf | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/acceptance/dcs.sub.cf b/tests/acceptance/dcs.sub.cf index e752cf24c7d..33dd9422428 100644 --- a/tests/acceptance/dcs.sub.cf +++ b/tests/acceptance/dcs.sub.cf @@ -1097,6 +1097,10 @@ bundle agent dcs_passif_output(wanted, unwanted, command, test) string => execresult($(command), "useshell"), meta => { "simulate_safe" }; + # Indent the command output in the DEBUG report, so that errors printed + # by the command are not mistaken for errors of the test by testall + "subout_indented" string => regex_replace($(subout), "^", " | ", "gm"); + classes: "__passif_output_unwanted" expression => regcmp($(unwanted), $(subout)); "__passif_output_wanted" expression => regcmp($(wanted), $(subout)); @@ -1128,7 +1132,7 @@ bundle agent dcs_passif_output(wanted, unwanted, command, test) if => "!__passif_output_unwanted"; DEBUG:: - "$(this.bundle): the output of command '$(command)' was: '$(subout)'"; + "$(this.bundle): the output of command '$(command)' was: '$(subout_indented)'"; } bundle agent dcs_passif_output1(wanted, command, test) From bbf547b37c937d509bede432d0dceaa471e19429 Mon Sep 17 00:00:00 2001 From: Ihor Aleksandrychiev Date: Thu, 15 Oct 2026 14:50:11 +0300 Subject: [PATCH 08/39] Added guards to reads of files created later in acceptance tests These tests read files and directories created by their own policy, but pre-evaluation calls the functions before they exist, logging errors which now fail regular tests. Ticket: CFE-3041 Signed-off-by: Ihor Aleksandrychiev --- .../01_vars/02_functions/findfiles_up.cf | 18 ++++++++++++------ .../01_vars/02_functions/getfields.cf | 3 ++- .../01_vars/02_functions/regextract.cf | 3 ++- .../cancel_attribute_persistent_lmdb.cf | 6 ++++-- .../persistent_timer_policy_default_lmdb.cf | 9 ++++++--- .../02_functions/classesmatching_inherit_2.cf | 3 ++- .../09_insert_lines/multi-files-dirs.cf | 9 ++++++--- .../templating/large_template_blocks.cf | 3 ++- .../mustache_container_serialization.cf | 3 ++- .../classic_evaluation_long_policy.cf | 6 ++++-- .../top_down_evaluation_long_policy.cf | 6 ++++-- .../simulate_safe_functions.cf | 3 +++ 12 files changed, 49 insertions(+), 23 deletions(-) diff --git a/tests/acceptance/01_vars/02_functions/findfiles_up.cf b/tests/acceptance/01_vars/02_functions/findfiles_up.cf index f8ac71214c2..faf55b5abb3 100755 --- a/tests/acceptance/01_vars/02_functions/findfiles_up.cf +++ b/tests/acceptance/01_vars/02_functions/findfiles_up.cf @@ -46,27 +46,33 @@ bundle agent test "t1" data => findfiles_up( "$(G.testdir)/core/libntech/libutils/", ".gitignore", "inf" - ); + ), + if => isdir("$(G.testdir)/core/libntech/libutils/"); "t2" - data => findfiles_up("$(G.testdir)/core/libntech/libutils/", "string.?"); + data => findfiles_up("$(G.testdir)/core/libntech/libutils/", "string.?"), + if => isdir("$(G.testdir)/core/libntech/libutils/"); - "t3" data => findfiles_up("$(G.testdir)/core/libntech/libutils/", ".git/"); + "t3" data => findfiles_up("$(G.testdir)/core/libntech/libutils/", ".git/"), + if => isdir("$(G.testdir)/core/libntech/libutils/"); "t4" data => findfiles_up( "$(G.testdir)/core/libntech/libutils/", ".git/", "1" - ); + ), + if => isdir("$(G.testdir)/core/libntech/libutils/"); "t5" data => findfiles_up( "$(G.testdir)/core/libntech/libutils/", ".git/config" - ); + ), + if => isdir("$(G.testdir)/core/libntech/libutils/"); "t6" data => findfiles_up( "$(G.testdir)/core/libntech/libutils/", "*/cf?{lex,parse}.[ly]" - ); + ), + if => isdir("$(G.testdir)/core/libntech/libutils/"); } bundle agent check diff --git a/tests/acceptance/01_vars/02_functions/getfields.cf b/tests/acceptance/01_vars/02_functions/getfields.cf index 7af6fdbd12d..b1f1adc32f8 100644 --- a/tests/acceptance/01_vars/02_functions/getfields.cf +++ b/tests/acceptance/01_vars/02_functions/getfields.cf @@ -41,7 +41,8 @@ body delete init_delete bundle agent test { vars: - "num_matching" int => getfields("t.*", "$(G.testfile)", ":", "fields"); + "num_matching" int => getfields("t.*", "$(G.testfile)", ":", "fields"), + if => fileexists("$(G.testfile)"); } ####################################################### diff --git a/tests/acceptance/01_vars/02_functions/regextract.cf b/tests/acceptance/01_vars/02_functions/regextract.cf index ee882bc0969..e356e5f0879 100644 --- a/tests/acceptance/01_vars/02_functions/regextract.cf +++ b/tests/acceptance/01_vars/02_functions/regextract.cf @@ -32,7 +32,8 @@ bundle agent test "lefts" string => "$(init.pair[1])"; "lefti" int => "$(init.pair[1])"; "rights" string => "$(init.pair[2])"; - "rightr" real => "$(init.pair[2])"; + "rightr" real => "$(init.pair[2])", + if => isvariable("init.pair[2]"); } ####################################################### diff --git a/tests/acceptance/02_classes/01_basic/cancel_attribute_persistent_lmdb.cf b/tests/acceptance/02_classes/01_basic/cancel_attribute_persistent_lmdb.cf index 27f78438256..d520a35347d 100644 --- a/tests/acceptance/02_classes/01_basic/cancel_attribute_persistent_lmdb.cf +++ b/tests/acceptance/02_classes/01_basic/cancel_attribute_persistent_lmdb.cf @@ -58,8 +58,10 @@ bundle agent test bundle agent check { vars: - "before" string => readfile("$(G.testdir)/cancel_lmdb_before", 4096); - "after" string => readfile("$(G.testdir)/cancel_lmdb_after", 4096); + "before" string => readfile("$(G.testdir)/cancel_lmdb_before", 4096), + if => fileexists("$(G.testdir)/cancel_lmdb_before"); + "after" string => readfile("$(G.testdir)/cancel_lmdb_after", 4096), + if => fileexists("$(G.testdir)/cancel_lmdb_after"); classes: # The class was stored in the LMDB by run 1 ... diff --git a/tests/acceptance/02_classes/01_basic/persistent_timer_policy_default_lmdb.cf b/tests/acceptance/02_classes/01_basic/persistent_timer_policy_default_lmdb.cf index 775c583ef04..080fc04affa 100644 --- a/tests/acceptance/02_classes/01_basic/persistent_timer_policy_default_lmdb.cf +++ b/tests/acceptance/02_classes/01_basic/persistent_timer_policy_default_lmdb.cf @@ -78,9 +78,12 @@ bundle agent test bundle agent check { vars: - "policy" string => readfile("$(G.testdir)/lmdb_policy", 4096); - "e1" string => readfile("$(G.testdir)/lmdb_expires1", 4096); - "e2" string => readfile("$(G.testdir)/lmdb_expires2", 4096); + "policy" string => readfile("$(G.testdir)/lmdb_policy", 4096), + if => fileexists("$(G.testdir)/lmdb_policy"); + "e1" string => readfile("$(G.testdir)/lmdb_expires1", 4096), + if => fileexists("$(G.testdir)/lmdb_expires1"); + "e2" string => readfile("$(G.testdir)/lmdb_expires2", 4096), + if => fileexists("$(G.testdir)/lmdb_expires2"); classes: # #1 The default classes: promise stored its persistent class with diff --git a/tests/acceptance/02_classes/02_functions/classesmatching_inherit_2.cf b/tests/acceptance/02_classes/02_functions/classesmatching_inherit_2.cf index f0b25fa0685..ad2062ed2d1 100644 --- a/tests/acceptance/02_classes/02_functions/classesmatching_inherit_2.cf +++ b/tests/acceptance/02_classes/02_functions/classesmatching_inherit_2.cf @@ -59,7 +59,8 @@ bundle agent check "defined_classes: defined_in_second$(const.n)" ); - "actual" string => readfile("$(common.logfile)", inf); + "actual" string => readfile("$(common.logfile)", inf), + if => fileexists("$(common.logfile)"); reports: "$(this.promise_filename) Pass" if => strcmp($(expected), $(actual)); diff --git a/tests/acceptance/10_files/09_insert_lines/multi-files-dirs.cf b/tests/acceptance/10_files/09_insert_lines/multi-files-dirs.cf index 310c8a68553..43b9fac0d5d 100644 --- a/tests/acceptance/10_files/09_insert_lines/multi-files-dirs.cf +++ b/tests/acceptance/10_files/09_insert_lines/multi-files-dirs.cf @@ -54,9 +54,12 @@ bundle agent check vars: "expect" string => "one two three test"; "results" slist => { "resultA", "resultB", "resultC" }; - "resultA" string => readfile("$(G.testdir)/dirA/testfa", "33"); - "resultB" string => readfile("$(G.testdir)/dirB/testfb", "33"); - "resultC" string => readfile("$(G.testdir)/dirC/testfc", "33"); + "resultA" string => readfile("$(G.testdir)/dirA/testfa", "33"), + if => fileexists("$(G.testdir)/dirA/testfa"); + "resultB" string => readfile("$(G.testdir)/dirB/testfb", "33"), + if => fileexists("$(G.testdir)/dirB/testfb"); + "resultC" string => readfile("$(G.testdir)/dirC/testfc", "33"), + if => fileexists("$(G.testdir)/dirC/testfc"); classes: "ok_A" expression => strcmp("$(expect)", "$(resultA)"); diff --git a/tests/acceptance/10_files/templating/large_template_blocks.cf b/tests/acceptance/10_files/templating/large_template_blocks.cf index 398a1f3028a..2f3fedeba3a 100644 --- a/tests/acceptance/10_files/templating/large_template_blocks.cf +++ b/tests/acceptance/10_files/templating/large_template_blocks.cf @@ -50,7 +50,8 @@ bundle agent check { vars: "expected" int => "110"; - "actual" int => countlinesmatching(".*0123456789.*", "$(G.testfile)"); + "actual" int => countlinesmatching(".*0123456789.*", "$(G.testfile)"), + if => fileexists("$(G.testfile)"); classes: "ok" expression => strcmp("$(expected)", "$(actual)"); diff --git a/tests/acceptance/10_files/templating/mustache_container_serialization.cf b/tests/acceptance/10_files/templating/mustache_container_serialization.cf index e6fdfb8cbe0..d41dcf9e398 100644 --- a/tests/acceptance/10_files/templating/mustache_container_serialization.cf +++ b/tests/acceptance/10_files/templating/mustache_container_serialization.cf @@ -64,7 +64,8 @@ bundle edit_line readthem { vars: "test" slist => { @(test.test) }; - "read_$(test)" string => readfile("$(G.testdir)/$(test)", 1k); + "read_$(test)" string => readfile("$(G.testdir)/$(test)", 1k), + if => fileexists("$(G.testdir)/$(test)"); insert_lines: "$(read_$(test))"; diff --git a/tests/acceptance/15_control/01_common/classic_evaluation_long_policy.cf b/tests/acceptance/15_control/01_common/classic_evaluation_long_policy.cf index 077fffdbd95..3fedb3a4bcd 100644 --- a/tests/acceptance/15_control/01_common/classic_evaluation_long_policy.cf +++ b/tests/acceptance/15_control/01_common/classic_evaluation_long_policy.cf @@ -34,7 +34,8 @@ bundle agent test "/tmp/example" content => "fourth"; vars: - "content" string => readfile("/tmp/example"); + "content" string => readfile("/tmp/example"), + if => fileexists("/tmp/example"); "result" string => concat("$(result)", ", $(content)"); classes: @@ -48,7 +49,8 @@ bundle agent test "/tmp/otherfile" content => "something"; vars: - "othercontent" string => readfile("/tmp/otherfile"); + "othercontent" string => readfile("/tmp/otherfile"), + if => fileexists("/tmp/otherfile"); files: "/tmp/otherfile" delete => tidy; diff --git a/tests/acceptance/15_control/01_common/top_down_evaluation_long_policy.cf b/tests/acceptance/15_control/01_common/top_down_evaluation_long_policy.cf index 5d85ecbb5a9..a60342fd22b 100644 --- a/tests/acceptance/15_control/01_common/top_down_evaluation_long_policy.cf +++ b/tests/acceptance/15_control/01_common/top_down_evaluation_long_policy.cf @@ -34,7 +34,8 @@ bundle agent test "/tmp/example" content => "fourth"; vars: - "content" string => readfile("/tmp/example"); + "content" string => readfile("/tmp/example"), + if => fileexists("/tmp/example"); "result" string => concat("$(result)", ", $(content)"); classes: @@ -48,7 +49,8 @@ bundle agent test "/tmp/otherfile" content => "something"; vars: - "othercontent" string => readfile("/tmp/otherfile"); + "othercontent" string => readfile("/tmp/otherfile"), + if => fileexists("/tmp/otherfile"); files: "/tmp/otherfile" delete => tidy; diff --git a/tests/acceptance/29_simulate_mode/simulate_safe_functions.cf b/tests/acceptance/29_simulate_mode/simulate_safe_functions.cf index 289f5811d5a..484869b968b 100644 --- a/tests/acceptance/29_simulate_mode/simulate_safe_functions.cf +++ b/tests/acceptance/29_simulate_mode/simulate_safe_functions.cf @@ -56,6 +56,9 @@ bundle agent check "result" string => readfile( "$(sys.workdir)$(const.dirsep)state$(const.dirsep)agent.log" + ), + if => fileexists( + "$(sys.workdir)$(const.dirsep)state$(const.dirsep)agent.log" ); methods: From 8af7a04c8f509bc55ea766e9335db56bed02c512 Mon Sep 17 00:00:00 2001 From: Ihor Aleksandrychiev Date: Thu, 15 Oct 2026 14:56:07 +0300 Subject: [PATCH 09/39] Renamed 00_basics/def.json test directory to def_json The agent loads def.json from the directory of the input policy file, so tests in 00_basics/ tried to read this directory as their augments file and logged "Could not open JSON file" errors. Ticket: CFE-3041 Signed-off-by: Ihor Aleksandrychiev --- tests/acceptance/00_basics/{def.json => def_json}/augments.cf | 0 .../00_basics/{def.json => def_json}/augments.cf.augmenter.json | 0 .../acceptance/00_basics/{def.json => def_json}/augments.cf.json | 0 .../{def.json => def_json}/augments_classes/augments_classes.cf | 0 .../00_basics/{def.json => def_json}/augments_classes/def.json | 0 .../acceptance/00_basics/{def.json => def_json}/augments_order.cf | 0 .../{def.json => def_json}/augments_order.cf.augmenter.json | 0 .../00_basics/{def.json => def_json}/augments_order.cf.json | 0 tests/acceptance/00_basics/{def.json => def_json}/bad-json.cf | 0 .../00_basics/{def.json => def_json}/bad-json.cf.x.json | 0 .../{def.json => def_json}/class_from_classexpression.cf | 0 .../{def.json => def_json}/class_from_classexpression.cf.json | 0 tests/acceptance/00_basics/{def.json => def_json}/classes.cf | 0 tests/acceptance/00_basics/{def.json => def_json}/classes.cf.json | 0 .../00_basics/{def.json => def_json}/classes_with_ns.cf | 0 .../00_basics/{def.json => def_json}/classes_with_ns.cf.json | 0 .../00_basics/{def.json => def_json}/classes_with_ns_tags.cf | 0 .../00_basics/{def.json => def_json}/classes_with_ns_tags.cf.json | 0 .../concurrent-vars-and-variables-keys/both-can-define-vars.cf | 0 .../concurrent-vars-and-variables-keys/def.json | 0 .../variables-wins-variables-listed-first/def.json | 0 .../variables-wins-variables-listed-first/variables-wins.cf | 0 .../concurrent-vars-and-variables-keys/variables-wins.cf | 0 tests/acceptance/00_basics/{def.json => def_json}/def.json | 0 .../00_basics/{def.json => def_json}/def_preferred.json/def.json | 0 .../{def.json => def_json}/def_preferred.json/def_preferred.cf | 0 .../{def.json => def_json}/def_preferred.json/def_preferred.json | 0 tests/acceptance/00_basics/{def.json => def_json}/inputs.cf | 0 tests/acceptance/00_basics/{def.json => def_json}/inputs.cf.json | 0 .../00_basics/{def.json => def_json}/json-inputs-not-array.cf | 0 .../{def.json => def_json}/json-inputs-not-array.cf.json | 0 .../{def.json => def_json}/json-inputs-not-auto-applied.cf | 0 .../{def.json => def_json}/json-inputs-not-auto-applied.cf.json | 0 .../00_basics/{def.json => def_json}/policy_server_classes.cf | 0 .../{def.json => def_json}/policy_server_classes.cf.json | 0 .../acceptance/00_basics/{def.json => def_json}/show_vars_JSON.cf | 0 .../00_basics/{def.json => def_json}/show_vars_JSON.cf.json | 0 tests/acceptance/00_basics/{def.json => def_json}/state.cf | 0 .../00_basics/{def.json => def_json}/state.cf.expected.json | 0 tests/acceptance/00_basics/{def.json => def_json}/variables.cf | 0 .../acceptance/00_basics/{def.json => def_json}/variables.cf.json | 0 .../00_basics/{def.json => def_json}/variables_bare_array.cf | 0 .../00_basics/{def.json => def_json}/variables_bare_array.cf.json | 0 .../00_basics/{def.json => def_json}/variables_bare_string.cf | 0 .../{def.json => def_json}/variables_bare_string.cf.json | 0 .../00_basics/{def.json => def_json}/variables_with_bundle.cf | 0 .../{def.json => def_json}/variables_with_bundle.cf.json | 0 .../00_basics/{def.json => def_json}/variables_with_ns.cf | 0 .../00_basics/{def.json => def_json}/variables_with_ns.cf.json | 0 tests/acceptance/00_basics/{def.json => def_json}/vars.cf | 0 tests/acceptance/00_basics/{def.json => def_json}/vars.cf.json | 0 .../00_basics/{def.json => def_json}/vars_with_bundle.cf | 0 .../00_basics/{def.json => def_json}/vars_with_bundle.cf.json | 0 tests/acceptance/00_basics/{def.json => def_json}/vars_with_ns.cf | 0 .../00_basics/{def.json => def_json}/vars_with_ns.cf.json | 0 55 files changed, 0 insertions(+), 0 deletions(-) rename tests/acceptance/00_basics/{def.json => def_json}/augments.cf (100%) rename tests/acceptance/00_basics/{def.json => def_json}/augments.cf.augmenter.json (100%) rename tests/acceptance/00_basics/{def.json => def_json}/augments.cf.json (100%) rename tests/acceptance/00_basics/{def.json => def_json}/augments_classes/augments_classes.cf (100%) rename tests/acceptance/00_basics/{def.json => def_json}/augments_classes/def.json (100%) rename tests/acceptance/00_basics/{def.json => def_json}/augments_order.cf (100%) rename tests/acceptance/00_basics/{def.json => def_json}/augments_order.cf.augmenter.json (100%) rename tests/acceptance/00_basics/{def.json => def_json}/augments_order.cf.json (100%) rename tests/acceptance/00_basics/{def.json => def_json}/bad-json.cf (100%) rename tests/acceptance/00_basics/{def.json => def_json}/bad-json.cf.x.json (100%) rename tests/acceptance/00_basics/{def.json => def_json}/class_from_classexpression.cf (100%) rename tests/acceptance/00_basics/{def.json => def_json}/class_from_classexpression.cf.json (100%) rename tests/acceptance/00_basics/{def.json => def_json}/classes.cf (100%) rename tests/acceptance/00_basics/{def.json => def_json}/classes.cf.json (100%) rename tests/acceptance/00_basics/{def.json => def_json}/classes_with_ns.cf (100%) rename tests/acceptance/00_basics/{def.json => def_json}/classes_with_ns.cf.json (100%) rename tests/acceptance/00_basics/{def.json => def_json}/classes_with_ns_tags.cf (100%) rename tests/acceptance/00_basics/{def.json => def_json}/classes_with_ns_tags.cf.json (100%) rename tests/acceptance/00_basics/{def.json => def_json}/concurrent-vars-and-variables-keys/both-can-define-vars.cf (100%) rename tests/acceptance/00_basics/{def.json => def_json}/concurrent-vars-and-variables-keys/def.json (100%) rename tests/acceptance/00_basics/{def.json => def_json}/concurrent-vars-and-variables-keys/variables-wins-variables-listed-first/def.json (100%) rename tests/acceptance/00_basics/{def.json => def_json}/concurrent-vars-and-variables-keys/variables-wins-variables-listed-first/variables-wins.cf (100%) rename tests/acceptance/00_basics/{def.json => def_json}/concurrent-vars-and-variables-keys/variables-wins.cf (100%) rename tests/acceptance/00_basics/{def.json => def_json}/def.json (100%) rename tests/acceptance/00_basics/{def.json => def_json}/def_preferred.json/def.json (100%) rename tests/acceptance/00_basics/{def.json => def_json}/def_preferred.json/def_preferred.cf (100%) rename tests/acceptance/00_basics/{def.json => def_json}/def_preferred.json/def_preferred.json (100%) rename tests/acceptance/00_basics/{def.json => def_json}/inputs.cf (100%) rename tests/acceptance/00_basics/{def.json => def_json}/inputs.cf.json (100%) rename tests/acceptance/00_basics/{def.json => def_json}/json-inputs-not-array.cf (100%) rename tests/acceptance/00_basics/{def.json => def_json}/json-inputs-not-array.cf.json (100%) rename tests/acceptance/00_basics/{def.json => def_json}/json-inputs-not-auto-applied.cf (100%) rename tests/acceptance/00_basics/{def.json => def_json}/json-inputs-not-auto-applied.cf.json (100%) rename tests/acceptance/00_basics/{def.json => def_json}/policy_server_classes.cf (100%) rename tests/acceptance/00_basics/{def.json => def_json}/policy_server_classes.cf.json (100%) rename tests/acceptance/00_basics/{def.json => def_json}/show_vars_JSON.cf (100%) rename tests/acceptance/00_basics/{def.json => def_json}/show_vars_JSON.cf.json (100%) rename tests/acceptance/00_basics/{def.json => def_json}/state.cf (100%) rename tests/acceptance/00_basics/{def.json => def_json}/state.cf.expected.json (100%) rename tests/acceptance/00_basics/{def.json => def_json}/variables.cf (100%) rename tests/acceptance/00_basics/{def.json => def_json}/variables.cf.json (100%) rename tests/acceptance/00_basics/{def.json => def_json}/variables_bare_array.cf (100%) rename tests/acceptance/00_basics/{def.json => def_json}/variables_bare_array.cf.json (100%) rename tests/acceptance/00_basics/{def.json => def_json}/variables_bare_string.cf (100%) rename tests/acceptance/00_basics/{def.json => def_json}/variables_bare_string.cf.json (100%) rename tests/acceptance/00_basics/{def.json => def_json}/variables_with_bundle.cf (100%) rename tests/acceptance/00_basics/{def.json => def_json}/variables_with_bundle.cf.json (100%) rename tests/acceptance/00_basics/{def.json => def_json}/variables_with_ns.cf (100%) rename tests/acceptance/00_basics/{def.json => def_json}/variables_with_ns.cf.json (100%) rename tests/acceptance/00_basics/{def.json => def_json}/vars.cf (100%) rename tests/acceptance/00_basics/{def.json => def_json}/vars.cf.json (100%) rename tests/acceptance/00_basics/{def.json => def_json}/vars_with_bundle.cf (100%) rename tests/acceptance/00_basics/{def.json => def_json}/vars_with_bundle.cf.json (100%) rename tests/acceptance/00_basics/{def.json => def_json}/vars_with_ns.cf (100%) rename tests/acceptance/00_basics/{def.json => def_json}/vars_with_ns.cf.json (100%) diff --git a/tests/acceptance/00_basics/def.json/augments.cf b/tests/acceptance/00_basics/def_json/augments.cf similarity index 100% rename from tests/acceptance/00_basics/def.json/augments.cf rename to tests/acceptance/00_basics/def_json/augments.cf diff --git a/tests/acceptance/00_basics/def.json/augments.cf.augmenter.json b/tests/acceptance/00_basics/def_json/augments.cf.augmenter.json similarity index 100% rename from tests/acceptance/00_basics/def.json/augments.cf.augmenter.json rename to tests/acceptance/00_basics/def_json/augments.cf.augmenter.json diff --git a/tests/acceptance/00_basics/def.json/augments.cf.json b/tests/acceptance/00_basics/def_json/augments.cf.json similarity index 100% rename from tests/acceptance/00_basics/def.json/augments.cf.json rename to tests/acceptance/00_basics/def_json/augments.cf.json diff --git a/tests/acceptance/00_basics/def.json/augments_classes/augments_classes.cf b/tests/acceptance/00_basics/def_json/augments_classes/augments_classes.cf similarity index 100% rename from tests/acceptance/00_basics/def.json/augments_classes/augments_classes.cf rename to tests/acceptance/00_basics/def_json/augments_classes/augments_classes.cf diff --git a/tests/acceptance/00_basics/def.json/augments_classes/def.json b/tests/acceptance/00_basics/def_json/augments_classes/def.json similarity index 100% rename from tests/acceptance/00_basics/def.json/augments_classes/def.json rename to tests/acceptance/00_basics/def_json/augments_classes/def.json diff --git a/tests/acceptance/00_basics/def.json/augments_order.cf b/tests/acceptance/00_basics/def_json/augments_order.cf similarity index 100% rename from tests/acceptance/00_basics/def.json/augments_order.cf rename to tests/acceptance/00_basics/def_json/augments_order.cf diff --git a/tests/acceptance/00_basics/def.json/augments_order.cf.augmenter.json b/tests/acceptance/00_basics/def_json/augments_order.cf.augmenter.json similarity index 100% rename from tests/acceptance/00_basics/def.json/augments_order.cf.augmenter.json rename to tests/acceptance/00_basics/def_json/augments_order.cf.augmenter.json diff --git a/tests/acceptance/00_basics/def.json/augments_order.cf.json b/tests/acceptance/00_basics/def_json/augments_order.cf.json similarity index 100% rename from tests/acceptance/00_basics/def.json/augments_order.cf.json rename to tests/acceptance/00_basics/def_json/augments_order.cf.json diff --git a/tests/acceptance/00_basics/def.json/bad-json.cf b/tests/acceptance/00_basics/def_json/bad-json.cf similarity index 100% rename from tests/acceptance/00_basics/def.json/bad-json.cf rename to tests/acceptance/00_basics/def_json/bad-json.cf diff --git a/tests/acceptance/00_basics/def.json/bad-json.cf.x.json b/tests/acceptance/00_basics/def_json/bad-json.cf.x.json similarity index 100% rename from tests/acceptance/00_basics/def.json/bad-json.cf.x.json rename to tests/acceptance/00_basics/def_json/bad-json.cf.x.json diff --git a/tests/acceptance/00_basics/def.json/class_from_classexpression.cf b/tests/acceptance/00_basics/def_json/class_from_classexpression.cf similarity index 100% rename from tests/acceptance/00_basics/def.json/class_from_classexpression.cf rename to tests/acceptance/00_basics/def_json/class_from_classexpression.cf diff --git a/tests/acceptance/00_basics/def.json/class_from_classexpression.cf.json b/tests/acceptance/00_basics/def_json/class_from_classexpression.cf.json similarity index 100% rename from tests/acceptance/00_basics/def.json/class_from_classexpression.cf.json rename to tests/acceptance/00_basics/def_json/class_from_classexpression.cf.json diff --git a/tests/acceptance/00_basics/def.json/classes.cf b/tests/acceptance/00_basics/def_json/classes.cf similarity index 100% rename from tests/acceptance/00_basics/def.json/classes.cf rename to tests/acceptance/00_basics/def_json/classes.cf diff --git a/tests/acceptance/00_basics/def.json/classes.cf.json b/tests/acceptance/00_basics/def_json/classes.cf.json similarity index 100% rename from tests/acceptance/00_basics/def.json/classes.cf.json rename to tests/acceptance/00_basics/def_json/classes.cf.json diff --git a/tests/acceptance/00_basics/def.json/classes_with_ns.cf b/tests/acceptance/00_basics/def_json/classes_with_ns.cf similarity index 100% rename from tests/acceptance/00_basics/def.json/classes_with_ns.cf rename to tests/acceptance/00_basics/def_json/classes_with_ns.cf diff --git a/tests/acceptance/00_basics/def.json/classes_with_ns.cf.json b/tests/acceptance/00_basics/def_json/classes_with_ns.cf.json similarity index 100% rename from tests/acceptance/00_basics/def.json/classes_with_ns.cf.json rename to tests/acceptance/00_basics/def_json/classes_with_ns.cf.json diff --git a/tests/acceptance/00_basics/def.json/classes_with_ns_tags.cf b/tests/acceptance/00_basics/def_json/classes_with_ns_tags.cf similarity index 100% rename from tests/acceptance/00_basics/def.json/classes_with_ns_tags.cf rename to tests/acceptance/00_basics/def_json/classes_with_ns_tags.cf diff --git a/tests/acceptance/00_basics/def.json/classes_with_ns_tags.cf.json b/tests/acceptance/00_basics/def_json/classes_with_ns_tags.cf.json similarity index 100% rename from tests/acceptance/00_basics/def.json/classes_with_ns_tags.cf.json rename to tests/acceptance/00_basics/def_json/classes_with_ns_tags.cf.json diff --git a/tests/acceptance/00_basics/def.json/concurrent-vars-and-variables-keys/both-can-define-vars.cf b/tests/acceptance/00_basics/def_json/concurrent-vars-and-variables-keys/both-can-define-vars.cf similarity index 100% rename from tests/acceptance/00_basics/def.json/concurrent-vars-and-variables-keys/both-can-define-vars.cf rename to tests/acceptance/00_basics/def_json/concurrent-vars-and-variables-keys/both-can-define-vars.cf diff --git a/tests/acceptance/00_basics/def.json/concurrent-vars-and-variables-keys/def.json b/tests/acceptance/00_basics/def_json/concurrent-vars-and-variables-keys/def.json similarity index 100% rename from tests/acceptance/00_basics/def.json/concurrent-vars-and-variables-keys/def.json rename to tests/acceptance/00_basics/def_json/concurrent-vars-and-variables-keys/def.json diff --git a/tests/acceptance/00_basics/def.json/concurrent-vars-and-variables-keys/variables-wins-variables-listed-first/def.json b/tests/acceptance/00_basics/def_json/concurrent-vars-and-variables-keys/variables-wins-variables-listed-first/def.json similarity index 100% rename from tests/acceptance/00_basics/def.json/concurrent-vars-and-variables-keys/variables-wins-variables-listed-first/def.json rename to tests/acceptance/00_basics/def_json/concurrent-vars-and-variables-keys/variables-wins-variables-listed-first/def.json diff --git a/tests/acceptance/00_basics/def.json/concurrent-vars-and-variables-keys/variables-wins-variables-listed-first/variables-wins.cf b/tests/acceptance/00_basics/def_json/concurrent-vars-and-variables-keys/variables-wins-variables-listed-first/variables-wins.cf similarity index 100% rename from tests/acceptance/00_basics/def.json/concurrent-vars-and-variables-keys/variables-wins-variables-listed-first/variables-wins.cf rename to tests/acceptance/00_basics/def_json/concurrent-vars-and-variables-keys/variables-wins-variables-listed-first/variables-wins.cf diff --git a/tests/acceptance/00_basics/def.json/concurrent-vars-and-variables-keys/variables-wins.cf b/tests/acceptance/00_basics/def_json/concurrent-vars-and-variables-keys/variables-wins.cf similarity index 100% rename from tests/acceptance/00_basics/def.json/concurrent-vars-and-variables-keys/variables-wins.cf rename to tests/acceptance/00_basics/def_json/concurrent-vars-and-variables-keys/variables-wins.cf diff --git a/tests/acceptance/00_basics/def.json/def.json b/tests/acceptance/00_basics/def_json/def.json similarity index 100% rename from tests/acceptance/00_basics/def.json/def.json rename to tests/acceptance/00_basics/def_json/def.json diff --git a/tests/acceptance/00_basics/def.json/def_preferred.json/def.json b/tests/acceptance/00_basics/def_json/def_preferred.json/def.json similarity index 100% rename from tests/acceptance/00_basics/def.json/def_preferred.json/def.json rename to tests/acceptance/00_basics/def_json/def_preferred.json/def.json diff --git a/tests/acceptance/00_basics/def.json/def_preferred.json/def_preferred.cf b/tests/acceptance/00_basics/def_json/def_preferred.json/def_preferred.cf similarity index 100% rename from tests/acceptance/00_basics/def.json/def_preferred.json/def_preferred.cf rename to tests/acceptance/00_basics/def_json/def_preferred.json/def_preferred.cf diff --git a/tests/acceptance/00_basics/def.json/def_preferred.json/def_preferred.json b/tests/acceptance/00_basics/def_json/def_preferred.json/def_preferred.json similarity index 100% rename from tests/acceptance/00_basics/def.json/def_preferred.json/def_preferred.json rename to tests/acceptance/00_basics/def_json/def_preferred.json/def_preferred.json diff --git a/tests/acceptance/00_basics/def.json/inputs.cf b/tests/acceptance/00_basics/def_json/inputs.cf similarity index 100% rename from tests/acceptance/00_basics/def.json/inputs.cf rename to tests/acceptance/00_basics/def_json/inputs.cf diff --git a/tests/acceptance/00_basics/def.json/inputs.cf.json b/tests/acceptance/00_basics/def_json/inputs.cf.json similarity index 100% rename from tests/acceptance/00_basics/def.json/inputs.cf.json rename to tests/acceptance/00_basics/def_json/inputs.cf.json diff --git a/tests/acceptance/00_basics/def.json/json-inputs-not-array.cf b/tests/acceptance/00_basics/def_json/json-inputs-not-array.cf similarity index 100% rename from tests/acceptance/00_basics/def.json/json-inputs-not-array.cf rename to tests/acceptance/00_basics/def_json/json-inputs-not-array.cf diff --git a/tests/acceptance/00_basics/def.json/json-inputs-not-array.cf.json b/tests/acceptance/00_basics/def_json/json-inputs-not-array.cf.json similarity index 100% rename from tests/acceptance/00_basics/def.json/json-inputs-not-array.cf.json rename to tests/acceptance/00_basics/def_json/json-inputs-not-array.cf.json diff --git a/tests/acceptance/00_basics/def.json/json-inputs-not-auto-applied.cf b/tests/acceptance/00_basics/def_json/json-inputs-not-auto-applied.cf similarity index 100% rename from tests/acceptance/00_basics/def.json/json-inputs-not-auto-applied.cf rename to tests/acceptance/00_basics/def_json/json-inputs-not-auto-applied.cf diff --git a/tests/acceptance/00_basics/def.json/json-inputs-not-auto-applied.cf.json b/tests/acceptance/00_basics/def_json/json-inputs-not-auto-applied.cf.json similarity index 100% rename from tests/acceptance/00_basics/def.json/json-inputs-not-auto-applied.cf.json rename to tests/acceptance/00_basics/def_json/json-inputs-not-auto-applied.cf.json diff --git a/tests/acceptance/00_basics/def.json/policy_server_classes.cf b/tests/acceptance/00_basics/def_json/policy_server_classes.cf similarity index 100% rename from tests/acceptance/00_basics/def.json/policy_server_classes.cf rename to tests/acceptance/00_basics/def_json/policy_server_classes.cf diff --git a/tests/acceptance/00_basics/def.json/policy_server_classes.cf.json b/tests/acceptance/00_basics/def_json/policy_server_classes.cf.json similarity index 100% rename from tests/acceptance/00_basics/def.json/policy_server_classes.cf.json rename to tests/acceptance/00_basics/def_json/policy_server_classes.cf.json diff --git a/tests/acceptance/00_basics/def.json/show_vars_JSON.cf b/tests/acceptance/00_basics/def_json/show_vars_JSON.cf similarity index 100% rename from tests/acceptance/00_basics/def.json/show_vars_JSON.cf rename to tests/acceptance/00_basics/def_json/show_vars_JSON.cf diff --git a/tests/acceptance/00_basics/def.json/show_vars_JSON.cf.json b/tests/acceptance/00_basics/def_json/show_vars_JSON.cf.json similarity index 100% rename from tests/acceptance/00_basics/def.json/show_vars_JSON.cf.json rename to tests/acceptance/00_basics/def_json/show_vars_JSON.cf.json diff --git a/tests/acceptance/00_basics/def.json/state.cf b/tests/acceptance/00_basics/def_json/state.cf similarity index 100% rename from tests/acceptance/00_basics/def.json/state.cf rename to tests/acceptance/00_basics/def_json/state.cf diff --git a/tests/acceptance/00_basics/def.json/state.cf.expected.json b/tests/acceptance/00_basics/def_json/state.cf.expected.json similarity index 100% rename from tests/acceptance/00_basics/def.json/state.cf.expected.json rename to tests/acceptance/00_basics/def_json/state.cf.expected.json diff --git a/tests/acceptance/00_basics/def.json/variables.cf b/tests/acceptance/00_basics/def_json/variables.cf similarity index 100% rename from tests/acceptance/00_basics/def.json/variables.cf rename to tests/acceptance/00_basics/def_json/variables.cf diff --git a/tests/acceptance/00_basics/def.json/variables.cf.json b/tests/acceptance/00_basics/def_json/variables.cf.json similarity index 100% rename from tests/acceptance/00_basics/def.json/variables.cf.json rename to tests/acceptance/00_basics/def_json/variables.cf.json diff --git a/tests/acceptance/00_basics/def.json/variables_bare_array.cf b/tests/acceptance/00_basics/def_json/variables_bare_array.cf similarity index 100% rename from tests/acceptance/00_basics/def.json/variables_bare_array.cf rename to tests/acceptance/00_basics/def_json/variables_bare_array.cf diff --git a/tests/acceptance/00_basics/def.json/variables_bare_array.cf.json b/tests/acceptance/00_basics/def_json/variables_bare_array.cf.json similarity index 100% rename from tests/acceptance/00_basics/def.json/variables_bare_array.cf.json rename to tests/acceptance/00_basics/def_json/variables_bare_array.cf.json diff --git a/tests/acceptance/00_basics/def.json/variables_bare_string.cf b/tests/acceptance/00_basics/def_json/variables_bare_string.cf similarity index 100% rename from tests/acceptance/00_basics/def.json/variables_bare_string.cf rename to tests/acceptance/00_basics/def_json/variables_bare_string.cf diff --git a/tests/acceptance/00_basics/def.json/variables_bare_string.cf.json b/tests/acceptance/00_basics/def_json/variables_bare_string.cf.json similarity index 100% rename from tests/acceptance/00_basics/def.json/variables_bare_string.cf.json rename to tests/acceptance/00_basics/def_json/variables_bare_string.cf.json diff --git a/tests/acceptance/00_basics/def.json/variables_with_bundle.cf b/tests/acceptance/00_basics/def_json/variables_with_bundle.cf similarity index 100% rename from tests/acceptance/00_basics/def.json/variables_with_bundle.cf rename to tests/acceptance/00_basics/def_json/variables_with_bundle.cf diff --git a/tests/acceptance/00_basics/def.json/variables_with_bundle.cf.json b/tests/acceptance/00_basics/def_json/variables_with_bundle.cf.json similarity index 100% rename from tests/acceptance/00_basics/def.json/variables_with_bundle.cf.json rename to tests/acceptance/00_basics/def_json/variables_with_bundle.cf.json diff --git a/tests/acceptance/00_basics/def.json/variables_with_ns.cf b/tests/acceptance/00_basics/def_json/variables_with_ns.cf similarity index 100% rename from tests/acceptance/00_basics/def.json/variables_with_ns.cf rename to tests/acceptance/00_basics/def_json/variables_with_ns.cf diff --git a/tests/acceptance/00_basics/def.json/variables_with_ns.cf.json b/tests/acceptance/00_basics/def_json/variables_with_ns.cf.json similarity index 100% rename from tests/acceptance/00_basics/def.json/variables_with_ns.cf.json rename to tests/acceptance/00_basics/def_json/variables_with_ns.cf.json diff --git a/tests/acceptance/00_basics/def.json/vars.cf b/tests/acceptance/00_basics/def_json/vars.cf similarity index 100% rename from tests/acceptance/00_basics/def.json/vars.cf rename to tests/acceptance/00_basics/def_json/vars.cf diff --git a/tests/acceptance/00_basics/def.json/vars.cf.json b/tests/acceptance/00_basics/def_json/vars.cf.json similarity index 100% rename from tests/acceptance/00_basics/def.json/vars.cf.json rename to tests/acceptance/00_basics/def_json/vars.cf.json diff --git a/tests/acceptance/00_basics/def.json/vars_with_bundle.cf b/tests/acceptance/00_basics/def_json/vars_with_bundle.cf similarity index 100% rename from tests/acceptance/00_basics/def.json/vars_with_bundle.cf rename to tests/acceptance/00_basics/def_json/vars_with_bundle.cf diff --git a/tests/acceptance/00_basics/def.json/vars_with_bundle.cf.json b/tests/acceptance/00_basics/def_json/vars_with_bundle.cf.json similarity index 100% rename from tests/acceptance/00_basics/def.json/vars_with_bundle.cf.json rename to tests/acceptance/00_basics/def_json/vars_with_bundle.cf.json diff --git a/tests/acceptance/00_basics/def.json/vars_with_ns.cf b/tests/acceptance/00_basics/def_json/vars_with_ns.cf similarity index 100% rename from tests/acceptance/00_basics/def.json/vars_with_ns.cf rename to tests/acceptance/00_basics/def_json/vars_with_ns.cf diff --git a/tests/acceptance/00_basics/def.json/vars_with_ns.cf.json b/tests/acceptance/00_basics/def_json/vars_with_ns.cf.json similarity index 100% rename from tests/acceptance/00_basics/def.json/vars_with_ns.cf.json rename to tests/acceptance/00_basics/def_json/vars_with_ns.cf.json From cb51dff0b28de94efbe94ed8d3a7cfed70ca82d6 Mon Sep 17 00:00:00 2001 From: Ihor Aleksandrychiev Date: Thu, 15 Oct 2026 15:03:29 +0300 Subject: [PATCH 10/39] Fixed execresult_action_immediate.cf logging errors The test used the 'immediate' body from plucked.sub.cf before it was loaded during pre-evaluation, so the promise is now skipped until the test framework is loaded. Ticket: CFE-3041 Signed-off-by: Ihor Aleksandrychiev --- .../execresult_action_immediate.cf | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/tests/acceptance/01_vars/02_functions/execresult_action_immediate.cf b/tests/acceptance/01_vars/02_functions/execresult_action_immediate.cf index 0181e9569e6..1e0634a6098 100644 --- a/tests/acceptance/01_vars/02_functions/execresult_action_immediate.cf +++ b/tests/acceptance/01_vars/02_functions/execresult_action_immediate.cf @@ -7,14 +7,23 @@ body common control version => "1.0"; } +# The 'immediate' body comes from plucked.sub.cf, which is not loaded yet when +# the policy is pre-evaluated, so promises using it are skipped until then +bundle common framework +{ + classes: + "framework_loaded" expression => isvariable("G.testdir"); +} + bundle agent check_date(x) { vars: "reports_file" string => "$(G.testdir)/execresult_action_immediate_report"; - "date" - string => execresult("date; sleep 1", "useshell"), - action => immediate; + framework_loaded:: + "date" + string => execresult("date; sleep 1", "useshell"), + action => immediate; reports: "Date for ${x}: ${date}" report_to_file => "$(reports_file)"; @@ -41,7 +50,8 @@ bundle agent check "content" slist => readstringlist( "$(check_date.reports_file)", "", '$(const.n)', inf, inf - ); + ), + if => fileexists("$(check_date.reports_file)"); "count" int => length(content); From f5197a41378fde0e3a1767f55c2ab5950f4925ea Mon Sep 17 00:00:00 2001 From: Ihor Aleksandrychiev Date: Thu, 15 Oct 2026 15:03:30 +0300 Subject: [PATCH 11/39] Fixed classic_evaluation_custom_promise_types.cf logging errors The test referred to a promise module which never existed and did not run its init and cleanup bundles. Ticket: CFE-3041 Signed-off-by: Ihor Aleksandrychiev --- ...classic_evaluation_custom_promise_types.cf | 10 +++-- .../01_common/dummy_promise_type.py | 40 +++++++++++++++++++ 2 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 tests/acceptance/15_control/01_common/dummy_promise_type.py diff --git a/tests/acceptance/15_control/01_common/classic_evaluation_custom_promise_types.cf b/tests/acceptance/15_control/01_common/classic_evaluation_custom_promise_types.cf index 379663d0b9a..4976b216f4c 100644 --- a/tests/acceptance/15_control/01_common/classic_evaluation_custom_promise_types.cf +++ b/tests/acceptance/15_control/01_common/classic_evaluation_custom_promise_types.cf @@ -1,13 +1,13 @@ body common control { inputs => { "../../default.sub.cf" }; - bundlesequence => { "test" }; + bundlesequence => { "init", "test", "cleanup" }; evaluation_order => "classic"; } promise agent dummy { - path => "$(this.promise_dirname)/top_down/dummy_promise_type.py"; + path => "$(this.promise_dirname)/dummy_promise_type.py"; interpreter => "/usr/bin/python3"; } @@ -23,13 +23,15 @@ bundle agent test "/tmp/dummyfile" smth => "hello"; vars: - "content" string => readfile("/tmp/dummyfile"); + "content" string => readfile("/tmp/dummyfile"), + if => fileexists("/tmp/dummyfile"); files: "/tmp/dummyfile" content => "ok"; vars: - "content" string => readfile("/tmp/dummyfile"); + "content" string => readfile("/tmp/dummyfile"), + if => fileexists("/tmp/dummyfile"); classes: "ok" expression => strcmp("$(content)", "ok"); diff --git a/tests/acceptance/15_control/01_common/dummy_promise_type.py b/tests/acceptance/15_control/01_common/dummy_promise_type.py new file mode 100644 index 00000000000..506733d056a --- /dev/null +++ b/tests/acceptance/15_control/01_common/dummy_promise_type.py @@ -0,0 +1,40 @@ +#!/usr/bin/python3 +# +# Minimal custom promise module which accepts any promise and does nothing, +# used to have a custom promise type in evaluation order tests. + +import sys + + +def read_request(): + request = {} + for line in sys.stdin: + line = line.rstrip("\n") + if not line: + return request + key, _, value = line.partition("=") + request[key] = value + sys.exit(0) + + +def write_response(operation, result): + sys.stdout.write("operation=%s\nresult=%s\n\n" % (operation, result)) + sys.stdout.flush() + + +# Skip the header from the agent and send ours +read_request() +sys.stdout.write("dummy_promise_type 0.0.1 v1 line_based\n\n") +sys.stdout.flush() + +while True: + operation = read_request().get("operation") + if operation == "validate_promise": + write_response(operation, "valid") + elif operation == "evaluate_promise": + write_response(operation, "kept") + elif operation == "terminate": + write_response(operation, "success") + sys.exit(0) + else: + write_response(operation, "error") From 26fc0146a6e56bc5b69e72b1a1bb2ad8b52fc4f9 Mon Sep 17 00:00:00 2001 From: Ihor Aleksandrychiev Date: Thu, 15 Oct 2026 15:51:01 +0300 Subject: [PATCH 12/39] Fixed changes_silent.cf logging errors The check bundle counted lines in files which do not exist until the test bundle has run, but the agent evaluates the functions of all promises before any bundle runs. Ticket: CFE-3041 Signed-off-by: Ihor Aleksandrychiev --- .../10_files/02_maintain/changes_silent.cf | 52 +++++++++++-------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/tests/acceptance/10_files/02_maintain/changes_silent.cf b/tests/acceptance/10_files/02_maintain/changes_silent.cf index db87d61d5c6..0a27de9e1cf 100644 --- a/tests/acceptance/10_files/02_maintain/changes_silent.cf +++ b/tests/acceptance/10_files/02_maintain/changes_silent.cf @@ -95,38 +95,47 @@ bundle agent check "n_quiet_content" int => countlinesmatching( ".*quiet_content\.txt,C,Content changed.*", "$(log)" - ); + ), + if => fileexists("$(log)"); "n_quiet_all_content" int => countlinesmatching( ".*quiet_all\.txt,C,Content changed.*", "$(log)" - ); + ), + if => fileexists("$(log)"); "n_quiet_all_stats" - int => countlinesmatching(".*quiet_all\.txt,S,.*", "$(log)"); + int => countlinesmatching(".*quiet_all\.txt,S,.*", "$(log)"), + if => fileexists("$(log)"); classes: - "leaked" - expression => isgreaterthan( - countlinesmatching(".*$(must_be_absent).*", "$(test.output)"), "0" - ); - - "missing" - expression => islessthan( - countlinesmatching(".*$(must_be_present).*", "$(test.output)"), "1" - ); - - "audit_ok" - and => { - isgreaterthan("$(n_quiet_content)", "0"), - isgreaterthan("$(n_quiet_all_content)", "0"), - isgreaterthan("$(n_quiet_all_stats)", "0"), - }; + # The output is read only once it exists, since the functions are also + # evaluated before the test bundle runs + "output_exists" expression => fileexists("$(test.output)"); + + output_exists:: + "leaked" + expression => isgreaterthan( + countlinesmatching(".*$(must_be_absent).*", "$(test.output)"), "0" + ); + + "missing" + expression => islessthan( + countlinesmatching(".*$(must_be_present).*", "$(test.output)"), "1" + ); + + any:: + "audit_ok" + and => { + isgreaterthan("$(n_quiet_content)", "0"), + isgreaterthan("$(n_quiet_all_content)", "0"), + isgreaterthan("$(n_quiet_all_stats)", "0"), + }; - "ok" and => { "!leaked", "!missing", "audit_ok" }; + "ok" and => { "output_exists", "!leaked", "!missing", "audit_ok" }; reports: - DEBUG:: + DEBUG.output_exists:: "silence leaked an alert matching '$(must_be_absent)'" if => isgreaterthan( countlinesmatching(".*$(must_be_absent).*", "$(test.output)"), "0" @@ -137,6 +146,7 @@ bundle agent check countlinesmatching(".*$(must_be_present).*", "$(test.output)"), "1" ); + DEBUG:: "Output of $(this.promise_filename).sub is in '$(test.output)'"; DEBUG.!audit_ok:: From dd9336855aef2a90ec596c493e1c9fe9dd78e77d Mon Sep 17 00:00:00 2001 From: Ihor Aleksandrychiev Date: Thu, 15 Oct 2026 16:00:33 +0300 Subject: [PATCH 13/39] Fixed wrong-bundle-type.cf and ifelse.cf logging errors wrong-bundle-type.cf printed the sub-agent output in its DEBUG report, so the sub-agent errors were mistaken for errors of the test, and ifelse.cf used invalid class expressions as false conditions. Ticket: CFE-3041 Signed-off-by: Ihor Aleksandrychiev --- tests/acceptance/00_basics/04_bundles/wrong-bundle-type.cf | 6 +++++- tests/acceptance/01_vars/02_functions/ifelse.cf | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/acceptance/00_basics/04_bundles/wrong-bundle-type.cf b/tests/acceptance/00_basics/04_bundles/wrong-bundle-type.cf index db2641cbe6d..e1e1e57b980 100644 --- a/tests/acceptance/00_basics/04_bundles/wrong-bundle-type.cf +++ b/tests/acceptance/00_basics/04_bundles/wrong-bundle-type.cf @@ -20,6 +20,10 @@ bundle agent test "${sys.cf_agent} -Kf $(this.promise_dirname)/wrong-bundle-type.sub.x.cf", "noshell" ); + + # Indent the output in the DEBUG report, so that errors printed by the + # sub-agent are not mistaken for errors of this test by testall + "subout_indented" string => regex_replace($(subout), "^", " | ", "gm"); } bundle agent check @@ -29,7 +33,7 @@ bundle agent check reports: DEBUG:: - "$(test.subout)"; + "$(test.subout_indented)"; ok:: "$(this.promise_filename) Pass"; diff --git a/tests/acceptance/01_vars/02_functions/ifelse.cf b/tests/acceptance/01_vars/02_functions/ifelse.cf index bc3ffe9fadb..55a6d7b9910 100644 --- a/tests/acceptance/01_vars/02_functions/ifelse.cf +++ b/tests/acceptance/01_vars/02_functions/ifelse.cf @@ -35,9 +35,9 @@ bundle agent test "five" string => ifelse( - "this is not true", + "this_is_not_true", "5 parameters broken", - "this is also not true", + "this_is_also_not_true", "5 parameters broken 2", "5 parameters OK" ); From 350760c93ac2197f33888bd9acd41381970d1e63 Mon Sep 17 00:00:00 2001 From: Ihor Aleksandrychiev Date: Thu, 15 Oct 2026 16:00:33 +0300 Subject: [PATCH 14/39] Renamed acceptance tests which log errors on purpose to .error.pass.cf These tests intentionally exercise error paths, the reason is documented in the header of each test. Ticket: CFE-3041 Signed-off-by: Ihor Aleksandrychiev --- .../{string_contexts.cf => string_contexts.error.pass.cf} | 4 ++++ ...ected.json => string_contexts.error.pass.cf.expected.json} | 0 .../acceptance/01_vars/01_basic/{013.cf => 013.error.pass.cf} | 4 ++++ ... can_not_define_variables_in_remote_bundles.error.pass.cf} | 4 ++++ .../01_vars/02_functions/{006.cf => 006.error.pass.cf} | 3 +++ .../02_functions/{CFE-2704-0.cf => CFE-2704-0.error.pass.cf} | 4 ++++ .../02_functions/{CFE-2704-1.cf => CFE-2704-1.error.pass.cf} | 4 ++++ .../02_functions/countlinesmatching_errors_on_absent_file.cf | 2 +- ...inesmatching_returns_0_on_inaccessable_file.error.pass.cf} | 3 +++ .../01_vars/02_functions/{lsdir.cf => lsdir.error.pass.cf} | 3 +++ .../{nth_datacontainer.cf => nth_datacontainer.error.pass.cf} | 4 ++++ ...r.cf.expected => nth_datacontainer.error.pass.cf.expected} | 0 ...container.cf.json => nth_datacontainer.error.pass.cf.json} | 0 ...e-endless-loop.cf => read-file-endless-loop.error.pass.cf} | 4 ++++ .../02_functions/{readdata.cf => readdata.error.pass.cf} | 4 ++++ .../{readdata.cf.csv => readdata.error.pass.cf.csv} | 0 ...readdata.cf.csv.guess => readdata.error.pass.cf.csv.guess} | 0 .../{readdata.cf.env => readdata.error.pass.cf.env} | 2 +- ....cf.expected.json => readdata.error.pass.cf.expected.json} | 0 .../{readdata.cf.json => readdata.error.pass.cf.json} | 0 ...addata.cf.json.guess => readdata.error.pass.cf.json.guess} | 0 .../{readdata_yaml.cf => readdata_yaml.error.pass.cf} | 4 ++++ ...xpected.json => readdata_yaml.error.pass.cf.expected.json} | 0 ...readdata_yaml.cf.yaml => readdata_yaml.error.pass.cf.yaml} | 0 ...l.cf.yaml.guess => readdata_yaml.error.pass.cf.yaml.guess} | 0 .../{readdata_yaml.cf.yml => readdata_yaml.error.pass.cf.yml} | 0 ...iner_conflict.cf => mergecontainer_conflict.error.pass.cf} | 3 +++ .../{parseyaml_abuse.cf => parseyaml_abuse.error.pass.cf} | 3 +++ ...cf => common_bundle_select_class_empty_list.error.pass.cf} | 3 +++ ...le_select_class_variable_expands_empty_list.error.pass.cf} | 3 +++ ...subnet-valid-ip.cf => isipinsubnet-valid-ip.error.pass.cf} | 3 +++ ...select_fncalls.cf => process_select_fncalls.error.pass.cf} | 3 +++ 32 files changed, 65 insertions(+), 2 deletions(-) rename tests/acceptance/00_basics/01_compiler/{string_contexts.cf => string_contexts.error.pass.cf} (93%) rename tests/acceptance/00_basics/01_compiler/{string_contexts.cf.expected.json => string_contexts.error.pass.cf.expected.json} (100%) rename tests/acceptance/01_vars/01_basic/{013.cf => 013.error.pass.cf} (88%) rename tests/acceptance/01_vars/01_basic/{can_not_define_variables_in_remote_bundles.cf => can_not_define_variables_in_remote_bundles.error.pass.cf} (93%) rename tests/acceptance/01_vars/02_functions/{006.cf => 006.error.pass.cf} (91%) rename tests/acceptance/01_vars/02_functions/{CFE-2704-0.cf => CFE-2704-0.error.pass.cf} (74%) rename tests/acceptance/01_vars/02_functions/{CFE-2704-1.cf => CFE-2704-1.error.pass.cf} (74%) rename tests/acceptance/01_vars/02_functions/{countlinesmatching_returns_0_on_inaccessable_file.cf => countlinesmatching_returns_0_on_inaccessable_file.error.pass.cf} (89%) rename tests/acceptance/01_vars/02_functions/{lsdir.cf => lsdir.error.pass.cf} (94%) rename tests/acceptance/01_vars/02_functions/{nth_datacontainer.cf => nth_datacontainer.error.pass.cf} (94%) rename tests/acceptance/01_vars/02_functions/{nth_datacontainer.cf.expected => nth_datacontainer.error.pass.cf.expected} (100%) rename tests/acceptance/01_vars/02_functions/{nth_datacontainer.cf.json => nth_datacontainer.error.pass.cf.json} (100%) rename tests/acceptance/01_vars/02_functions/{read-file-endless-loop.cf => read-file-endless-loop.error.pass.cf} (77%) rename tests/acceptance/01_vars/02_functions/{readdata.cf => readdata.error.pass.cf} (91%) rename tests/acceptance/01_vars/02_functions/{readdata.cf.csv => readdata.error.pass.cf.csv} (100%) rename tests/acceptance/01_vars/02_functions/{readdata.cf.csv.guess => readdata.error.pass.cf.csv.guess} (100%) rename tests/acceptance/01_vars/02_functions/{readdata.cf.env => readdata.error.pass.cf.env} (93%) rename tests/acceptance/01_vars/02_functions/{readdata.cf.expected.json => readdata.error.pass.cf.expected.json} (100%) rename tests/acceptance/01_vars/02_functions/{readdata.cf.json => readdata.error.pass.cf.json} (100%) rename tests/acceptance/01_vars/02_functions/{readdata.cf.json.guess => readdata.error.pass.cf.json.guess} (100%) rename tests/acceptance/01_vars/02_functions/{readdata_yaml.cf => readdata_yaml.error.pass.cf} (87%) rename tests/acceptance/01_vars/02_functions/{readdata_yaml.cf.expected.json => readdata_yaml.error.pass.cf.expected.json} (100%) rename tests/acceptance/01_vars/02_functions/{readdata_yaml.cf.yaml => readdata_yaml.error.pass.cf.yaml} (100%) rename tests/acceptance/01_vars/02_functions/{readdata_yaml.cf.yaml.guess => readdata_yaml.error.pass.cf.yaml.guess} (100%) rename tests/acceptance/01_vars/02_functions/{readdata_yaml.cf.yml => readdata_yaml.error.pass.cf.yml} (100%) rename tests/acceptance/01_vars/04_containers/{mergecontainer_conflict.cf => mergecontainer_conflict.error.pass.cf} (90%) rename tests/acceptance/01_vars/04_containers/{parseyaml_abuse.cf => parseyaml_abuse.error.pass.cf} (87%) rename tests/acceptance/02_classes/01_basic/{common_bundle_select_class_empty_list.cf => common_bundle_select_class_empty_list.error.pass.cf} (86%) rename tests/acceptance/02_classes/01_basic/{common_bundle_select_class_variable_expands_empty_list.cf => common_bundle_select_class_variable_expands_empty_list.error.pass.cf} (81%) rename tests/acceptance/02_classes/02_functions/{isipinsubnet-valid-ip.cf => isipinsubnet-valid-ip.error.pass.cf} (92%) rename tests/acceptance/05_processes/01_matching/{process_select_fncalls.cf => process_select_fncalls.error.pass.cf} (95%) diff --git a/tests/acceptance/00_basics/01_compiler/string_contexts.cf b/tests/acceptance/00_basics/01_compiler/string_contexts.error.pass.cf similarity index 93% rename from tests/acceptance/00_basics/01_compiler/string_contexts.cf rename to tests/acceptance/00_basics/01_compiler/string_contexts.error.pass.cf index 0bf5503ac25..3d3f99d453b 100644 --- a/tests/acceptance/00_basics/01_compiler/string_contexts.cf +++ b/tests/acceptance/00_basics/01_compiler/string_contexts.error.pass.cf @@ -1,5 +1,9 @@ # fixes https://dev.cfengine.com/issues/2504 # using variables in string contexts +# +# This is an .error.pass.cf test, because the 'cf engine' class context +# (words separated by whitespace without an operator) is invalid on +# purpose and logs an error. body common control { inputs => { "../../default.sub.cf" }; diff --git a/tests/acceptance/00_basics/01_compiler/string_contexts.cf.expected.json b/tests/acceptance/00_basics/01_compiler/string_contexts.error.pass.cf.expected.json similarity index 100% rename from tests/acceptance/00_basics/01_compiler/string_contexts.cf.expected.json rename to tests/acceptance/00_basics/01_compiler/string_contexts.error.pass.cf.expected.json diff --git a/tests/acceptance/01_vars/01_basic/013.cf b/tests/acceptance/01_vars/01_basic/013.error.pass.cf similarity index 88% rename from tests/acceptance/01_vars/01_basic/013.cf rename to tests/acceptance/01_vars/01_basic/013.error.pass.cf index 4bf5fdfc56c..87d40432ef9 100644 --- a/tests/acceptance/01_vars/01_basic/013.cf +++ b/tests/acceptance/01_vars/01_basic/013.error.pass.cf @@ -2,6 +2,10 @@ # # Test that 'classes' body works on 'vars' promises # +# This is an .error.pass.cf test, because execresult() of the +# non-existent '/nonexisting' fails on purpose and logs errors, to test +# that repair_failed classes are set. +# ####################################################### body common control { diff --git a/tests/acceptance/01_vars/01_basic/can_not_define_variables_in_remote_bundles.cf b/tests/acceptance/01_vars/01_basic/can_not_define_variables_in_remote_bundles.error.pass.cf similarity index 93% rename from tests/acceptance/01_vars/01_basic/can_not_define_variables_in_remote_bundles.cf rename to tests/acceptance/01_vars/01_basic/can_not_define_variables_in_remote_bundles.error.pass.cf index ea9f92b962f..aba335f5e66 100644 --- a/tests/acceptance/01_vars/01_basic/can_not_define_variables_in_remote_bundles.cf +++ b/tests/acceptance/01_vars/01_basic/can_not_define_variables_in_remote_bundles.error.pass.cf @@ -2,6 +2,10 @@ # # Test that it is invalid to define variables in remote bundles # +# This is an .error.pass.cf test, because defining a variable in a +# remote bundle is rejected with errors, which is what this test checks +# (CFE-1915). +# ####################################################### body common control { diff --git a/tests/acceptance/01_vars/02_functions/006.cf b/tests/acceptance/01_vars/02_functions/006.error.pass.cf similarity index 91% rename from tests/acceptance/01_vars/02_functions/006.cf rename to tests/acceptance/01_vars/02_functions/006.error.pass.cf index 62914fdb892..63d85cbeb29 100644 --- a/tests/acceptance/01_vars/02_functions/006.cf +++ b/tests/acceptance/01_vars/02_functions/006.error.pass.cf @@ -2,6 +2,9 @@ # # Test diskfree() # +# This is an .error.pass.cf test, because diskfree() is called on the +# non-existent path '/lkjqeroiu' on purpose and logs an error. +# ####################################################### body common control { diff --git a/tests/acceptance/01_vars/02_functions/CFE-2704-0.cf b/tests/acceptance/01_vars/02_functions/CFE-2704-0.error.pass.cf similarity index 74% rename from tests/acceptance/01_vars/02_functions/CFE-2704-0.cf rename to tests/acceptance/01_vars/02_functions/CFE-2704-0.error.pass.cf index 27b521a02bc..06279efded8 100644 --- a/tests/acceptance/01_vars/02_functions/CFE-2704-0.cf +++ b/tests/acceptance/01_vars/02_functions/CFE-2704-0.error.pass.cf @@ -1,3 +1,7 @@ +# This is an .error.pass.cf test, because mergedata() is given data +# which is not a container on purpose and logs an error, the test checks +# that the agent does not crash. + body common control { inputs => { "../../default.sub.cf" }; diff --git a/tests/acceptance/01_vars/02_functions/CFE-2704-1.cf b/tests/acceptance/01_vars/02_functions/CFE-2704-1.error.pass.cf similarity index 74% rename from tests/acceptance/01_vars/02_functions/CFE-2704-1.cf rename to tests/acceptance/01_vars/02_functions/CFE-2704-1.error.pass.cf index a475b51d68f..10acfccee9a 100644 --- a/tests/acceptance/01_vars/02_functions/CFE-2704-1.cf +++ b/tests/acceptance/01_vars/02_functions/CFE-2704-1.error.pass.cf @@ -1,3 +1,7 @@ +# This is an .error.pass.cf test, because mergedata() is given data +# which is not a container on purpose and logs an error, the test checks +# that the agent does not crash. + body common control { inputs => { "../../default.sub.cf" }; diff --git a/tests/acceptance/01_vars/02_functions/countlinesmatching_errors_on_absent_file.cf b/tests/acceptance/01_vars/02_functions/countlinesmatching_errors_on_absent_file.cf index 7df7778733f..3b2766f3932 100644 --- a/tests/acceptance/01_vars/02_functions/countlinesmatching_errors_on_absent_file.cf +++ b/tests/acceptance/01_vars/02_functions/countlinesmatching_errors_on_absent_file.cf @@ -25,7 +25,7 @@ bundle agent test vars: "subout" string => execresult( - "$(sys.cf_agent) -Kv --define AUTO -f $(this.promise_dirname)/countlinesmatching_returns_0_on_inaccessable_file.cf 2>&1 | $(G.grep) countlinesmatching", + "$(sys.cf_agent) -Kv --define AUTO -f $(this.promise_dirname)/countlinesmatching_returns_0_on_inaccessable_file.error.pass.cf 2>&1 | $(G.grep) countlinesmatching", "useshell" ); } diff --git a/tests/acceptance/01_vars/02_functions/countlinesmatching_returns_0_on_inaccessable_file.cf b/tests/acceptance/01_vars/02_functions/countlinesmatching_returns_0_on_inaccessable_file.error.pass.cf similarity index 89% rename from tests/acceptance/01_vars/02_functions/countlinesmatching_returns_0_on_inaccessable_file.cf rename to tests/acceptance/01_vars/02_functions/countlinesmatching_returns_0_on_inaccessable_file.error.pass.cf index 514d65a20aa..87f5a3769c7 100644 --- a/tests/acceptance/01_vars/02_functions/countlinesmatching_returns_0_on_inaccessable_file.cf +++ b/tests/acceptance/01_vars/02_functions/countlinesmatching_returns_0_on_inaccessable_file.error.pass.cf @@ -2,6 +2,9 @@ # # Test countlinesmatching() with some kind of failure expected # +# This is an .error.pass.cf test, because countlinesmatching() is called +# on an inaccessible file on purpose and logs an error. +# ####################################################### body common control { diff --git a/tests/acceptance/01_vars/02_functions/lsdir.cf b/tests/acceptance/01_vars/02_functions/lsdir.error.pass.cf similarity index 94% rename from tests/acceptance/01_vars/02_functions/lsdir.cf rename to tests/acceptance/01_vars/02_functions/lsdir.error.pass.cf index 50c103319b2..773dfd6caa2 100644 --- a/tests/acceptance/01_vars/02_functions/lsdir.cf +++ b/tests/acceptance/01_vars/02_functions/lsdir.error.pass.cf @@ -2,6 +2,9 @@ # # Test lsdir() # +# This is an .error.pass.cf test, because lsdir() is called on the +# non-existent directory '$(G.testdir)/b' on purpose and logs an error. +# ####################################################### body common control { diff --git a/tests/acceptance/01_vars/02_functions/nth_datacontainer.cf b/tests/acceptance/01_vars/02_functions/nth_datacontainer.error.pass.cf similarity index 94% rename from tests/acceptance/01_vars/02_functions/nth_datacontainer.cf rename to tests/acceptance/01_vars/02_functions/nth_datacontainer.error.pass.cf index e6090255eeb..6b5101c360d 100644 --- a/tests/acceptance/01_vars/02_functions/nth_datacontainer.cf +++ b/tests/acceptance/01_vars/02_functions/nth_datacontainer.error.pass.cf @@ -2,6 +2,10 @@ # # Test nth() with data container input # +# This is an .error.pass.cf test, because nth() is called with keys +# which are not valid list indices (e.g. 'foo' or '') on purpose and +# logs errors. +# ####################################################### body common control { diff --git a/tests/acceptance/01_vars/02_functions/nth_datacontainer.cf.expected b/tests/acceptance/01_vars/02_functions/nth_datacontainer.error.pass.cf.expected similarity index 100% rename from tests/acceptance/01_vars/02_functions/nth_datacontainer.cf.expected rename to tests/acceptance/01_vars/02_functions/nth_datacontainer.error.pass.cf.expected diff --git a/tests/acceptance/01_vars/02_functions/nth_datacontainer.cf.json b/tests/acceptance/01_vars/02_functions/nth_datacontainer.error.pass.cf.json similarity index 100% rename from tests/acceptance/01_vars/02_functions/nth_datacontainer.cf.json rename to tests/acceptance/01_vars/02_functions/nth_datacontainer.error.pass.cf.json diff --git a/tests/acceptance/01_vars/02_functions/read-file-endless-loop.cf b/tests/acceptance/01_vars/02_functions/read-file-endless-loop.error.pass.cf similarity index 77% rename from tests/acceptance/01_vars/02_functions/read-file-endless-loop.cf rename to tests/acceptance/01_vars/02_functions/read-file-endless-loop.error.pass.cf index 1cfaa98e160..46fe379f29d 100644 --- a/tests/acceptance/01_vars/02_functions/read-file-endless-loop.cf +++ b/tests/acceptance/01_vars/02_functions/read-file-endless-loop.error.pass.cf @@ -1,5 +1,9 @@ # Test that regline, getfields and countlinesmatching do not loop endlessly if # supplied with a directory (Redmine #2453) +# +# This is an .error.pass.cf test, because regline(), getfields() and +# countlinesmatching() are given the directory '/' on purpose and log +# errors. body common control { inputs => { "../../default.sub.cf" }; diff --git a/tests/acceptance/01_vars/02_functions/readdata.cf b/tests/acceptance/01_vars/02_functions/readdata.error.pass.cf similarity index 91% rename from tests/acceptance/01_vars/02_functions/readdata.cf rename to tests/acceptance/01_vars/02_functions/readdata.error.pass.cf index 59767849337..09bba95c9ec 100644 --- a/tests/acceptance/01_vars/02_functions/readdata.cf +++ b/tests/acceptance/01_vars/02_functions/readdata.error.pass.cf @@ -2,6 +2,10 @@ # # Test readdata() with YAML # +# This is an .error.pass.cf test, because readdata() is given data in a +# format it cannot parse on purpose (the failed_* and guess_csv +# variables) and logs errors. +# ########################################################### body common control { diff --git a/tests/acceptance/01_vars/02_functions/readdata.cf.csv b/tests/acceptance/01_vars/02_functions/readdata.error.pass.cf.csv similarity index 100% rename from tests/acceptance/01_vars/02_functions/readdata.cf.csv rename to tests/acceptance/01_vars/02_functions/readdata.error.pass.cf.csv diff --git a/tests/acceptance/01_vars/02_functions/readdata.cf.csv.guess b/tests/acceptance/01_vars/02_functions/readdata.error.pass.cf.csv.guess similarity index 100% rename from tests/acceptance/01_vars/02_functions/readdata.cf.csv.guess rename to tests/acceptance/01_vars/02_functions/readdata.error.pass.cf.csv.guess diff --git a/tests/acceptance/01_vars/02_functions/readdata.cf.env b/tests/acceptance/01_vars/02_functions/readdata.error.pass.cf.env similarity index 93% rename from tests/acceptance/01_vars/02_functions/readdata.cf.env rename to tests/acceptance/01_vars/02_functions/readdata.error.pass.cf.env index 71aaa7dd272..ac93f45f3d2 100644 --- a/tests/acceptance/01_vars/02_functions/readdata.cf.env +++ b/tests/acceptance/01_vars/02_functions/readdata.error.pass.cf.env @@ -1,4 +1,4 @@ -# Example env file used for acceptance test readdata.cf +# Example env file used for acceptance test readdata.error.pass.cf # We can't test for all weird possibilites, # but this should serve most use cases diff --git a/tests/acceptance/01_vars/02_functions/readdata.cf.expected.json b/tests/acceptance/01_vars/02_functions/readdata.error.pass.cf.expected.json similarity index 100% rename from tests/acceptance/01_vars/02_functions/readdata.cf.expected.json rename to tests/acceptance/01_vars/02_functions/readdata.error.pass.cf.expected.json diff --git a/tests/acceptance/01_vars/02_functions/readdata.cf.json b/tests/acceptance/01_vars/02_functions/readdata.error.pass.cf.json similarity index 100% rename from tests/acceptance/01_vars/02_functions/readdata.cf.json rename to tests/acceptance/01_vars/02_functions/readdata.error.pass.cf.json diff --git a/tests/acceptance/01_vars/02_functions/readdata.cf.json.guess b/tests/acceptance/01_vars/02_functions/readdata.error.pass.cf.json.guess similarity index 100% rename from tests/acceptance/01_vars/02_functions/readdata.cf.json.guess rename to tests/acceptance/01_vars/02_functions/readdata.error.pass.cf.json.guess diff --git a/tests/acceptance/01_vars/02_functions/readdata_yaml.cf b/tests/acceptance/01_vars/02_functions/readdata_yaml.error.pass.cf similarity index 87% rename from tests/acceptance/01_vars/02_functions/readdata_yaml.cf rename to tests/acceptance/01_vars/02_functions/readdata_yaml.error.pass.cf index 7e3fc3edd97..84922593d62 100644 --- a/tests/acceptance/01_vars/02_functions/readdata_yaml.cf +++ b/tests/acceptance/01_vars/02_functions/readdata_yaml.error.pass.cf @@ -2,6 +2,10 @@ # # Test readdata() with YAML # +# This is an .error.pass.cf test, because readdata() is given data in a +# format it cannot parse on purpose (the failed_explicit_yaml and +# guess_yaml variables) and logs errors. +# ########################################################### body common control { diff --git a/tests/acceptance/01_vars/02_functions/readdata_yaml.cf.expected.json b/tests/acceptance/01_vars/02_functions/readdata_yaml.error.pass.cf.expected.json similarity index 100% rename from tests/acceptance/01_vars/02_functions/readdata_yaml.cf.expected.json rename to tests/acceptance/01_vars/02_functions/readdata_yaml.error.pass.cf.expected.json diff --git a/tests/acceptance/01_vars/02_functions/readdata_yaml.cf.yaml b/tests/acceptance/01_vars/02_functions/readdata_yaml.error.pass.cf.yaml similarity index 100% rename from tests/acceptance/01_vars/02_functions/readdata_yaml.cf.yaml rename to tests/acceptance/01_vars/02_functions/readdata_yaml.error.pass.cf.yaml diff --git a/tests/acceptance/01_vars/02_functions/readdata_yaml.cf.yaml.guess b/tests/acceptance/01_vars/02_functions/readdata_yaml.error.pass.cf.yaml.guess similarity index 100% rename from tests/acceptance/01_vars/02_functions/readdata_yaml.cf.yaml.guess rename to tests/acceptance/01_vars/02_functions/readdata_yaml.error.pass.cf.yaml.guess diff --git a/tests/acceptance/01_vars/02_functions/readdata_yaml.cf.yml b/tests/acceptance/01_vars/02_functions/readdata_yaml.error.pass.cf.yml similarity index 100% rename from tests/acceptance/01_vars/02_functions/readdata_yaml.cf.yml rename to tests/acceptance/01_vars/02_functions/readdata_yaml.error.pass.cf.yml diff --git a/tests/acceptance/01_vars/04_containers/mergecontainer_conflict.cf b/tests/acceptance/01_vars/04_containers/mergecontainer_conflict.error.pass.cf similarity index 90% rename from tests/acceptance/01_vars/04_containers/mergecontainer_conflict.cf rename to tests/acceptance/01_vars/04_containers/mergecontainer_conflict.error.pass.cf index 64c72b206a4..cf578d5dbdb 100644 --- a/tests/acceptance/01_vars/04_containers/mergecontainer_conflict.cf +++ b/tests/acceptance/01_vars/04_containers/mergecontainer_conflict.error.pass.cf @@ -2,6 +2,9 @@ # # Test mergejson() with mismatched datas # +# This is an .error.pass.cf test, because parsejson() is given invalid +# JSON on purpose and logs an error, so that mergedata() fails. +# ####################################################### body common control { diff --git a/tests/acceptance/01_vars/04_containers/parseyaml_abuse.cf b/tests/acceptance/01_vars/04_containers/parseyaml_abuse.error.pass.cf similarity index 87% rename from tests/acceptance/01_vars/04_containers/parseyaml_abuse.cf rename to tests/acceptance/01_vars/04_containers/parseyaml_abuse.error.pass.cf index 316b0ac7576..0878b53f51a 100644 --- a/tests/acceptance/01_vars/04_containers/parseyaml_abuse.cf +++ b/tests/acceptance/01_vars/04_containers/parseyaml_abuse.error.pass.cf @@ -2,6 +2,9 @@ # # Abuse parseyaml() # +# This is an .error.pass.cf test, because parseyaml() is given strings +# which are not valid YAML containers on purpose and logs errors. +# ####################################################### body common control { diff --git a/tests/acceptance/02_classes/01_basic/common_bundle_select_class_empty_list.cf b/tests/acceptance/02_classes/01_basic/common_bundle_select_class_empty_list.error.pass.cf similarity index 86% rename from tests/acceptance/02_classes/01_basic/common_bundle_select_class_empty_list.cf rename to tests/acceptance/02_classes/01_basic/common_bundle_select_class_empty_list.error.pass.cf index d8e0d02a920..deabdd53c7e 100644 --- a/tests/acceptance/02_classes/01_basic/common_bundle_select_class_empty_list.cf +++ b/tests/acceptance/02_classes/01_basic/common_bundle_select_class_empty_list.error.pass.cf @@ -1,4 +1,7 @@ # Test that select_class is skipped when no classes are given +# +# This is an .error.pass.cf test, because select_class is given an empty +# list on purpose and logs an error. body common control { inputs => { "../../default.sub.cf" }; diff --git a/tests/acceptance/02_classes/01_basic/common_bundle_select_class_variable_expands_empty_list.cf b/tests/acceptance/02_classes/01_basic/common_bundle_select_class_variable_expands_empty_list.error.pass.cf similarity index 81% rename from tests/acceptance/02_classes/01_basic/common_bundle_select_class_variable_expands_empty_list.cf rename to tests/acceptance/02_classes/01_basic/common_bundle_select_class_variable_expands_empty_list.error.pass.cf index 833304f5120..cdf9cd73d8b 100644 --- a/tests/acceptance/02_classes/01_basic/common_bundle_select_class_variable_expands_empty_list.cf +++ b/tests/acceptance/02_classes/01_basic/common_bundle_select_class_variable_expands_empty_list.error.pass.cf @@ -1,4 +1,7 @@ # Test that select class is skipped when the list of classes is empty +# +# This is an .error.pass.cf test, because select_class is given a list +# variable which expands to an empty list on purpose and logs an error. body common control { inputs => { "../../default.sub.cf" }; diff --git a/tests/acceptance/02_classes/02_functions/isipinsubnet-valid-ip.cf b/tests/acceptance/02_classes/02_functions/isipinsubnet-valid-ip.error.pass.cf similarity index 92% rename from tests/acceptance/02_classes/02_functions/isipinsubnet-valid-ip.cf rename to tests/acceptance/02_classes/02_functions/isipinsubnet-valid-ip.error.pass.cf index c23da722aea..d1929a2a910 100644 --- a/tests/acceptance/02_classes/02_functions/isipinsubnet-valid-ip.cf +++ b/tests/acceptance/02_classes/02_functions/isipinsubnet-valid-ip.error.pass.cf @@ -2,6 +2,9 @@ # # Test isipinsubnet() # +# This is an .error.pass.cf test, because isipinsubnet() is given +# 'not-an-ip-address' on purpose and logs an error. +# ####################################################### body common control { diff --git a/tests/acceptance/05_processes/01_matching/process_select_fncalls.cf b/tests/acceptance/05_processes/01_matching/process_select_fncalls.error.pass.cf similarity index 95% rename from tests/acceptance/05_processes/01_matching/process_select_fncalls.cf rename to tests/acceptance/05_processes/01_matching/process_select_fncalls.error.pass.cf index 027efcc2828..bba2f72dacd 100644 --- a/tests/acceptance/05_processes/01_matching/process_select_fncalls.cf +++ b/tests/acceptance/05_processes/01_matching/process_select_fncalls.error.pass.cf @@ -1,3 +1,6 @@ +# This is an .error.pass.cf test, because getuid() is called for the +# non-existent user 'nosuchuser' on purpose and logs errors (CFE-1968). + body common control { inputs => { "../../default.sub.cf" }; From 22cab402bd836266f983eb258fb1df32260a414e Mon Sep 17 00:00:00 2001 From: Ihor Aleksandrychiev Date: Thu, 15 Oct 2026 16:18:37 +0300 Subject: [PATCH 15/39] Fixed linting issues Signed-off-by: Ihor Aleksandrychiev --- tests/acceptance/01_vars/02_functions/011.cf | 4 +++- tests/acceptance/01_vars/02_functions/012.cf | 4 +++- tests/acceptance/01_vars/02_functions/013.cf | 4 +++- tests/acceptance/01_vars/02_functions/014.cf | 4 +++- tests/acceptance/01_vars/02_functions/015.cf | 4 +++- tests/acceptance/01_vars/02_functions/016.cf | 4 +++- tests/acceptance/01_vars/02_functions/017.cf | 4 +++- tests/acceptance/01_vars/02_functions/018.cf | 4 +++- tests/acceptance/01_vars/02_functions/019.cf | 4 +++- tests/acceptance/01_vars/02_functions/020.cf | 4 +++- tests/acceptance/01_vars/02_functions/021.cf | 4 +++- tests/acceptance/01_vars/02_functions/024.cf | 4 +++- tests/acceptance/01_vars/02_functions/025.cf | 4 +++- tests/acceptance/01_vars/02_functions/026.cf | 4 +++- tests/acceptance/01_vars/02_functions/027.cf | 4 +++- tests/acceptance/01_vars/02_functions/028.cf | 4 +++- tests/acceptance/01_vars/02_functions/029.cf | 4 +++- tests/acceptance/01_vars/02_functions/030.cf | 4 +++- tests/acceptance/01_vars/02_functions/031.cf | 4 +++- tests/acceptance/01_vars/02_functions/032.cf | 4 +++- tests/acceptance/01_vars/02_functions/033.cf | 4 +++- tests/acceptance/01_vars/02_functions/034.cf | 4 +++- tests/acceptance/01_vars/02_functions/037.cf | 4 +++- tests/acceptance/01_vars/02_functions/038.cf | 4 +++- tests/acceptance/01_vars/02_functions/039.cf | 4 +++- tests/acceptance/01_vars/02_functions/040.cf | 4 +++- tests/acceptance/01_vars/02_functions/041.cf | 4 +++- tests/acceptance/01_vars/02_functions/042.cf | 4 +++- tests/acceptance/01_vars/02_functions/043.cf | 4 +++- tests/acceptance/01_vars/02_functions/044.cf | 4 +++- tests/acceptance/01_vars/02_functions/045.cf | 4 +++- tests/acceptance/01_vars/02_functions/046.cf | 4 +++- tests/acceptance/01_vars/02_functions/047.cf | 4 +++- tests/acceptance/01_vars/02_functions/050.cf | 4 +++- tests/acceptance/01_vars/02_functions/410.cf | 4 +++- tests/acceptance/01_vars/02_functions/420.cf | 3 ++- tests/acceptance/01_vars/02_functions/421.cf | 3 ++- tests/acceptance/01_vars/02_functions/447.cf | 4 +++- tests/acceptance/01_vars/02_functions/520.cf | 4 +++- tests/acceptance/01_vars/02_functions/521.cf | 4 +++- tests/acceptance/01_vars/02_functions/620.cf | 3 ++- tests/acceptance/01_vars/02_functions/621.cf | 3 ++- .../01_vars/02_functions/CFE-2704-0.error.pass.cf | 1 - .../01_vars/02_functions/CFE-2704-1.error.pass.cf | 1 - .../acceptance/01_vars/02_functions/findfiles_up.cf | 3 ++- tests/acceptance/01_vars/02_functions/getfields.cf | 3 ++- .../02_functions/long_string_from_text_file.cf | 4 +++- ...ray_weird_indices_real_comments_noemptyfields2.cf | 4 +++- .../01_vars/02_functions/read_empty_file.cf | 7 +++++-- tests/acceptance/01_vars/02_functions/regextract.cf | 4 +++- tests/acceptance/01_vars/04_containers/readjson.cf | 3 ++- .../01_vars/04_containers/readjson_arrays.cf | 3 ++- .../acceptance/01_vars/04_containers/readjson_new.cf | 3 ++- .../01_vars/04_containers/readjson_null.cf | 3 ++- .../01_vars/04_containers/readjson_objects.cf | 3 ++- .../01_vars/04_containers/readjson_scalar.cf | 3 ++- .../01_vars/04_containers/readjson_subindex.cf | 3 ++- .../04_containers/readjson_subindex_quoted.cf | 3 ++- .../01_basic/cancel_attribute_persistent_lmdb.cf | 7 +++++-- .../01_basic/persistent_timer_policy_default_lmdb.cf | 11 ++++++++--- .../02_functions/classesmatching_inherit_2.cf | 3 ++- .../01_matching/process_select_fncalls.error.pass.cf | 1 - tests/acceptance/08_commands/arglist.cf | 4 +++- .../10_files/09_insert_lines/multi-files-dirs.cf | 12 +++++++++--- .../09_insert_lines/preserve_block_blank_lines.cf | 4 +++- .../10_files/templating/empty_template_empty_file.cf | 4 +++- .../10_files/templating/large_template_blocks.cf | 4 +++- .../templating/mustache_container_serialization.cf | 4 +++- .../10_files/templating/mustache_datastate_demo.cf | 3 ++- .../acceptance/10_files/templating/mustache_demo.cf | 4 +++- .../templating/mustache_expect_list_find_string.cf | 8 ++++++-- .../10_files/templating/mustache_html_escape.cf | 4 +++- .../10_files/templating/mustache_inline_demo.cf | 3 ++- .../10_files/templating/mustache_render_quote.cf | 4 +++- .../10_files/templating/mustache_repair_existing.cf | 4 +++- .../classic_evaluation_custom_promise_types.cf | 6 ++++-- .../01_common/classic_evaluation_long_policy.cf | 7 +++++-- .../01_common/top_down_evaluation_long_policy.cf | 7 +++++-- tests/acceptance/31_tickets/CFE-3866/test.cf | 4 +++- 79 files changed, 234 insertions(+), 89 deletions(-) diff --git a/tests/acceptance/01_vars/02_functions/011.cf b/tests/acceptance/01_vars/02_functions/011.cf index 93a5a1c3384..b9a7aebe1e6 100644 --- a/tests/acceptance/01_vars/02_functions/011.cf +++ b/tests/acceptance/01_vars/02_functions/011.cf @@ -37,8 +37,10 @@ body delete init_delete bundle agent test { vars: - "nums" slist => readstringlist("$(G.testfile)", "NoComment", "\s+", 5, 100), + "nums" + slist => readstringlist("$(G.testfile)", "NoComment", "\s+", 5, 100), if => fileexists("$(G.testfile)"); + "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/012.cf b/tests/acceptance/01_vars/02_functions/012.cf index 55de4ce5573..7ce4aa0c051 100644 --- a/tests/acceptance/01_vars/02_functions/012.cf +++ b/tests/acceptance/01_vars/02_functions/012.cf @@ -38,8 +38,10 @@ body delete init_delete bundle agent test { vars: - "nums" slist => readstringlist("$(G.testfile)", "NoComment", "\s+", 5, 100), + "nums" + slist => readstringlist("$(G.testfile)", "NoComment", "\s+", 5, 100), if => fileexists("$(G.testfile)"); + "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/013.cf b/tests/acceptance/01_vars/02_functions/013.cf index 4e493478c13..37821656b07 100644 --- a/tests/acceptance/01_vars/02_functions/013.cf +++ b/tests/acceptance/01_vars/02_functions/013.cf @@ -37,8 +37,10 @@ body delete init_delete bundle agent test { vars: - "nums" slist => readstringlist("$(G.testfile)", "NoComment", "\s+", 5, 100), + "nums" + slist => readstringlist("$(G.testfile)", "NoComment", "\s+", 5, 100), if => fileexists("$(G.testfile)"); + "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/014.cf b/tests/acceptance/01_vars/02_functions/014.cf index c981a70bac4..ba82a13c2bc 100644 --- a/tests/acceptance/01_vars/02_functions/014.cf +++ b/tests/acceptance/01_vars/02_functions/014.cf @@ -37,8 +37,10 @@ body delete init_delete bundle agent test { vars: - "nums" slist => readstringlist("$(G.testfile)", "NoComment", "\.", 5, 100), + "nums" + slist => readstringlist("$(G.testfile)", "NoComment", "\.", 5, 100), if => fileexists("$(G.testfile)"); + "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/015.cf b/tests/acceptance/01_vars/02_functions/015.cf index f96df7ab224..9071d657bdc 100644 --- a/tests/acceptance/01_vars/02_functions/015.cf +++ b/tests/acceptance/01_vars/02_functions/015.cf @@ -37,8 +37,10 @@ body delete init_delete bundle agent test { vars: - "nums" slist => readstringlist("$(G.testfile)", "NoComment", "\s+", 5, 100), + "nums" + slist => readstringlist("$(G.testfile)", "NoComment", "\s+", 5, 100), if => fileexists("$(G.testfile)"); + "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/016.cf b/tests/acceptance/01_vars/02_functions/016.cf index 2b7482ddb8f..c646ecc710f 100644 --- a/tests/acceptance/01_vars/02_functions/016.cf +++ b/tests/acceptance/01_vars/02_functions/016.cf @@ -38,8 +38,10 @@ body delete init_delete bundle agent test { vars: - "nums" slist => readstringlist("$(G.testfile)", "NoComment", "\s+", 5, 100), + "nums" + slist => readstringlist("$(G.testfile)", "NoComment", "\s+", 5, 100), if => fileexists("$(G.testfile)"); + "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/017.cf b/tests/acceptance/01_vars/02_functions/017.cf index 0b15619d31e..3a61a27d7e5 100644 --- a/tests/acceptance/01_vars/02_functions/017.cf +++ b/tests/acceptance/01_vars/02_functions/017.cf @@ -38,8 +38,10 @@ body delete init_delete bundle agent test { vars: - "nums" slist => readstringlist("$(G.testfile)", "NoComment", "\s+", 5, 100), + "nums" + slist => readstringlist("$(G.testfile)", "NoComment", "\s+", 5, 100), if => fileexists("$(G.testfile)"); + "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/018.cf b/tests/acceptance/01_vars/02_functions/018.cf index 4173999135b..29a8a437490 100644 --- a/tests/acceptance/01_vars/02_functions/018.cf +++ b/tests/acceptance/01_vars/02_functions/018.cf @@ -37,8 +37,10 @@ body delete init_delete bundle agent test { vars: - "nums" slist => readstringlist("$(G.testfile)", "NoComment", "\s+", 5, 100), + "nums" + slist => readstringlist("$(G.testfile)", "NoComment", "\s+", 5, 100), if => fileexists("$(G.testfile)"); + "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/019.cf b/tests/acceptance/01_vars/02_functions/019.cf index d269fda0c69..ce2cd9145e0 100644 --- a/tests/acceptance/01_vars/02_functions/019.cf +++ b/tests/acceptance/01_vars/02_functions/019.cf @@ -37,8 +37,10 @@ body delete init_delete bundle agent test { vars: - "nums" slist => readstringlist("$(G.testfile)", "NoComment", "X", 5, 100), + "nums" + slist => readstringlist("$(G.testfile)", "NoComment", "X", 5, 100), if => fileexists("$(G.testfile)"); + "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/020.cf b/tests/acceptance/01_vars/02_functions/020.cf index 3a1a1fe0723..2429c9eb059 100644 --- a/tests/acceptance/01_vars/02_functions/020.cf +++ b/tests/acceptance/01_vars/02_functions/020.cf @@ -37,8 +37,10 @@ body delete init_delete bundle agent test { vars: - "nums" slist => readstringlist("$(G.testfile)", "NoComment", "\s", 5, 100), + "nums" + slist => readstringlist("$(G.testfile)", "NoComment", "\s", 5, 100), if => fileexists("$(G.testfile)"); + "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/021.cf b/tests/acceptance/01_vars/02_functions/021.cf index f62d85462bb..1e86c7e129e 100644 --- a/tests/acceptance/01_vars/02_functions/021.cf +++ b/tests/acceptance/01_vars/02_functions/021.cf @@ -37,8 +37,10 @@ body delete init_delete bundle agent test { vars: - "nums" slist => readstringlist("$(G.testfile)", "NoComment", ",", 5, 100), + "nums" + slist => readstringlist("$(G.testfile)", "NoComment", ",", 5, 100), if => fileexists("$(G.testfile)"); + "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/024.cf b/tests/acceptance/01_vars/02_functions/024.cf index 6f7382d12d2..fa2da9fc34b 100644 --- a/tests/acceptance/01_vars/02_functions/024.cf +++ b/tests/acceptance/01_vars/02_functions/024.cf @@ -36,8 +36,10 @@ body delete init_delete bundle agent test { vars: - "nums" ilist => readintlist("$(G.testfile)", "NoComment", "\s+", 5, 100), + "nums" + ilist => readintlist("$(G.testfile)", "NoComment", "\s+", 5, 100), if => fileexists("$(G.testfile)"); + "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/025.cf b/tests/acceptance/01_vars/02_functions/025.cf index 4c7c07f1079..b138c0f236c 100644 --- a/tests/acceptance/01_vars/02_functions/025.cf +++ b/tests/acceptance/01_vars/02_functions/025.cf @@ -37,8 +37,10 @@ body delete init_delete bundle agent test { vars: - "nums" ilist => readintlist("$(G.testfile)", "NoComment", "\s+", 5, 100), + "nums" + ilist => readintlist("$(G.testfile)", "NoComment", "\s+", 5, 100), if => fileexists("$(G.testfile)"); + "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/026.cf b/tests/acceptance/01_vars/02_functions/026.cf index 5e0ea912cc8..20a3158df7a 100644 --- a/tests/acceptance/01_vars/02_functions/026.cf +++ b/tests/acceptance/01_vars/02_functions/026.cf @@ -36,8 +36,10 @@ body delete init_delete bundle agent test { vars: - "nums" ilist => readintlist("$(G.testfile)", "NoComment", "\s+", 5, 100), + "nums" + ilist => readintlist("$(G.testfile)", "NoComment", "\s+", 5, 100), if => fileexists("$(G.testfile)"); + "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/027.cf b/tests/acceptance/01_vars/02_functions/027.cf index 75e7c539cd5..84930ea5a8a 100644 --- a/tests/acceptance/01_vars/02_functions/027.cf +++ b/tests/acceptance/01_vars/02_functions/027.cf @@ -36,8 +36,10 @@ body delete init_delete bundle agent test { vars: - "nums" ilist => readintlist("$(G.testfile)", "NoComment", "\.", 5, 100), + "nums" + ilist => readintlist("$(G.testfile)", "NoComment", "\.", 5, 100), if => fileexists("$(G.testfile)"); + "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/028.cf b/tests/acceptance/01_vars/02_functions/028.cf index 850cbb5fc44..7ac8f774d9b 100644 --- a/tests/acceptance/01_vars/02_functions/028.cf +++ b/tests/acceptance/01_vars/02_functions/028.cf @@ -36,8 +36,10 @@ body delete init_delete bundle agent test { vars: - "nums" ilist => readintlist("$(G.testfile)", "NoComment", "\s+", 5, 100), + "nums" + ilist => readintlist("$(G.testfile)", "NoComment", "\s+", 5, 100), if => fileexists("$(G.testfile)"); + "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/029.cf b/tests/acceptance/01_vars/02_functions/029.cf index b15d19dcffa..09ff4b92689 100644 --- a/tests/acceptance/01_vars/02_functions/029.cf +++ b/tests/acceptance/01_vars/02_functions/029.cf @@ -37,8 +37,10 @@ body delete init_delete bundle agent test { vars: - "nums" ilist => readintlist("$(G.testfile)", "NoComment", "\s+", 5, 100), + "nums" + ilist => readintlist("$(G.testfile)", "NoComment", "\s+", 5, 100), if => fileexists("$(G.testfile)"); + "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/030.cf b/tests/acceptance/01_vars/02_functions/030.cf index 3938eda2acb..83d89216bf1 100644 --- a/tests/acceptance/01_vars/02_functions/030.cf +++ b/tests/acceptance/01_vars/02_functions/030.cf @@ -37,8 +37,10 @@ body delete init_delete bundle agent test { vars: - "nums" ilist => readintlist("$(G.testfile)", "NoComment", "\s+", 5, 100), + "nums" + ilist => readintlist("$(G.testfile)", "NoComment", "\s+", 5, 100), if => fileexists("$(G.testfile)"); + "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/031.cf b/tests/acceptance/01_vars/02_functions/031.cf index dd199a7d122..2fb7d1e63f9 100644 --- a/tests/acceptance/01_vars/02_functions/031.cf +++ b/tests/acceptance/01_vars/02_functions/031.cf @@ -36,8 +36,10 @@ body delete init_delete bundle agent test { vars: - "nums" ilist => readintlist("$(G.testfile)", "NoComment", "\s+", 5, 100), + "nums" + ilist => readintlist("$(G.testfile)", "NoComment", "\s+", 5, 100), if => fileexists("$(G.testfile)"); + "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/032.cf b/tests/acceptance/01_vars/02_functions/032.cf index 2c0d4cf6c0f..2827c7dd1b5 100644 --- a/tests/acceptance/01_vars/02_functions/032.cf +++ b/tests/acceptance/01_vars/02_functions/032.cf @@ -36,8 +36,10 @@ body delete init_delete bundle agent test { vars: - "nums" ilist => readintlist("$(G.testfile)", "NoComment", "X", 5, 100), + "nums" + ilist => readintlist("$(G.testfile)", "NoComment", "X", 5, 100), if => fileexists("$(G.testfile)"); + "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/033.cf b/tests/acceptance/01_vars/02_functions/033.cf index 7e3a5d367d3..59680fe18f8 100644 --- a/tests/acceptance/01_vars/02_functions/033.cf +++ b/tests/acceptance/01_vars/02_functions/033.cf @@ -36,8 +36,10 @@ body delete init_delete bundle agent test { vars: - "nums" ilist => readintlist("$(G.testfile)", "NoComment", "\s", 5, 100), + "nums" + ilist => readintlist("$(G.testfile)", "NoComment", "\s", 5, 100), if => fileexists("$(G.testfile)"); + "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/034.cf b/tests/acceptance/01_vars/02_functions/034.cf index 38abced469c..7ac2dcfaef1 100644 --- a/tests/acceptance/01_vars/02_functions/034.cf +++ b/tests/acceptance/01_vars/02_functions/034.cf @@ -36,8 +36,10 @@ body delete init_delete bundle agent test { vars: - "nums" ilist => readintlist("$(G.testfile)", "NoComment", ",", 5, 100), + "nums" + ilist => readintlist("$(G.testfile)", "NoComment", ",", 5, 100), if => fileexists("$(G.testfile)"); + "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/037.cf b/tests/acceptance/01_vars/02_functions/037.cf index 6e65a785ceb..860710e89d7 100644 --- a/tests/acceptance/01_vars/02_functions/037.cf +++ b/tests/acceptance/01_vars/02_functions/037.cf @@ -36,8 +36,10 @@ body delete init_delete bundle agent test { vars: - "nums" rlist => readreallist("$(G.testfile)", "NoComment", "\s+", 5, 100), + "nums" + rlist => readreallist("$(G.testfile)", "NoComment", "\s+", 5, 100), if => fileexists("$(G.testfile)"); + "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/038.cf b/tests/acceptance/01_vars/02_functions/038.cf index 4fc8fb18a79..303a3915e56 100644 --- a/tests/acceptance/01_vars/02_functions/038.cf +++ b/tests/acceptance/01_vars/02_functions/038.cf @@ -37,8 +37,10 @@ body delete init_delete bundle agent test { vars: - "nums" rlist => readreallist("$(G.testfile)", "NoComment", "\s+", 5, 100), + "nums" + rlist => readreallist("$(G.testfile)", "NoComment", "\s+", 5, 100), if => fileexists("$(G.testfile)"); + "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/039.cf b/tests/acceptance/01_vars/02_functions/039.cf index 6f72f753c8c..0e67007ee63 100644 --- a/tests/acceptance/01_vars/02_functions/039.cf +++ b/tests/acceptance/01_vars/02_functions/039.cf @@ -36,8 +36,10 @@ body delete init_delete bundle agent test { vars: - "nums" rlist => readreallist("$(G.testfile)", "NoComment", "\s+", 5, 100), + "nums" + rlist => readreallist("$(G.testfile)", "NoComment", "\s+", 5, 100), if => fileexists("$(G.testfile)"); + "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/040.cf b/tests/acceptance/01_vars/02_functions/040.cf index 4c10aaa8d9d..5b8cee5c36a 100644 --- a/tests/acceptance/01_vars/02_functions/040.cf +++ b/tests/acceptance/01_vars/02_functions/040.cf @@ -36,8 +36,10 @@ body delete init_delete bundle agent test { vars: - "nums" rlist => readreallist("$(G.testfile)", "NoComment", "\.", 5, 100), + "nums" + rlist => readreallist("$(G.testfile)", "NoComment", "\.", 5, 100), if => fileexists("$(G.testfile)"); + "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/041.cf b/tests/acceptance/01_vars/02_functions/041.cf index 7fefc1cb209..99c50764f8e 100644 --- a/tests/acceptance/01_vars/02_functions/041.cf +++ b/tests/acceptance/01_vars/02_functions/041.cf @@ -36,8 +36,10 @@ body delete init_delete bundle agent test { vars: - "nums" rlist => readreallist("$(G.testfile)", "NoComment", "\s+", 5, 100), + "nums" + rlist => readreallist("$(G.testfile)", "NoComment", "\s+", 5, 100), if => fileexists("$(G.testfile)"); + "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/042.cf b/tests/acceptance/01_vars/02_functions/042.cf index a1e160b2a42..bbd55f03c90 100644 --- a/tests/acceptance/01_vars/02_functions/042.cf +++ b/tests/acceptance/01_vars/02_functions/042.cf @@ -37,8 +37,10 @@ body delete init_delete bundle agent test { vars: - "nums" rlist => readreallist("$(G.testfile)", "NoComment", "\s+", 5, 100), + "nums" + rlist => readreallist("$(G.testfile)", "NoComment", "\s+", 5, 100), if => fileexists("$(G.testfile)"); + "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/043.cf b/tests/acceptance/01_vars/02_functions/043.cf index 54b5bff2c65..27fcc3ddfb3 100644 --- a/tests/acceptance/01_vars/02_functions/043.cf +++ b/tests/acceptance/01_vars/02_functions/043.cf @@ -37,8 +37,10 @@ body delete init_delete bundle agent test { vars: - "nums" rlist => readreallist("$(G.testfile)", "NoComment", "\s+", 5, 100), + "nums" + rlist => readreallist("$(G.testfile)", "NoComment", "\s+", 5, 100), if => fileexists("$(G.testfile)"); + "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/044.cf b/tests/acceptance/01_vars/02_functions/044.cf index a28458dcc12..81690b5133d 100644 --- a/tests/acceptance/01_vars/02_functions/044.cf +++ b/tests/acceptance/01_vars/02_functions/044.cf @@ -36,8 +36,10 @@ body delete init_delete bundle agent test { vars: - "nums" rlist => readreallist("$(G.testfile)", "NoComment", "\s+", 5, 100), + "nums" + rlist => readreallist("$(G.testfile)", "NoComment", "\s+", 5, 100), if => fileexists("$(G.testfile)"); + "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/045.cf b/tests/acceptance/01_vars/02_functions/045.cf index 4aaa3c1fd7f..5fe7c79764e 100644 --- a/tests/acceptance/01_vars/02_functions/045.cf +++ b/tests/acceptance/01_vars/02_functions/045.cf @@ -36,8 +36,10 @@ body delete init_delete bundle agent test { vars: - "nums" rlist => readreallist("$(G.testfile)", "NoComment", "X", 5, 100), + "nums" + rlist => readreallist("$(G.testfile)", "NoComment", "X", 5, 100), if => fileexists("$(G.testfile)"); + "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/046.cf b/tests/acceptance/01_vars/02_functions/046.cf index 251535cd8bb..895e665f796 100644 --- a/tests/acceptance/01_vars/02_functions/046.cf +++ b/tests/acceptance/01_vars/02_functions/046.cf @@ -36,8 +36,10 @@ body delete init_delete bundle agent test { vars: - "nums" rlist => readreallist("$(G.testfile)", "NoComment", "\s", 5, 100), + "nums" + rlist => readreallist("$(G.testfile)", "NoComment", "\s", 5, 100), if => fileexists("$(G.testfile)"); + "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/047.cf b/tests/acceptance/01_vars/02_functions/047.cf index b6b1384ee9b..456b7637def 100644 --- a/tests/acceptance/01_vars/02_functions/047.cf +++ b/tests/acceptance/01_vars/02_functions/047.cf @@ -36,8 +36,10 @@ body delete init_delete bundle agent test { vars: - "nums" rlist => readreallist("$(G.testfile)", "NoComment", ",", 5, 100), + "nums" + rlist => readreallist("$(G.testfile)", "NoComment", ",", 5, 100), if => fileexists("$(G.testfile)"); + "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/050.cf b/tests/acceptance/01_vars/02_functions/050.cf index b53302a9df0..659225ef5d5 100644 --- a/tests/acceptance/01_vars/02_functions/050.cf +++ b/tests/acceptance/01_vars/02_functions/050.cf @@ -36,8 +36,10 @@ body delete init_delete bundle agent test { vars: - "nums" rlist => readreallist("$(G.testfile)", "NoComment", "\.", 5, 100), + "nums" + rlist => readreallist("$(G.testfile)", "NoComment", "\.", 5, 100), if => fileexists("$(G.testfile)"); + "sum" real => sum("nums"); } diff --git a/tests/acceptance/01_vars/02_functions/410.cf b/tests/acceptance/01_vars/02_functions/410.cf index e05695088a1..3a0fa32e4bf 100644 --- a/tests/acceptance/01_vars/02_functions/410.cf +++ b/tests/acceptance/01_vars/02_functions/410.cf @@ -48,8 +48,10 @@ body delete init_delete bundle agent test { vars: - "cnt" int => readstringarray("ary", "$(G.testfile)", "^#.*", ":+", 10, 14), + "cnt" + int => readstringarray("ary", "$(G.testfile)", "^#.*", ":+", 10, 14), if => fileexists("$(G.testfile)"); + "num" int => "3"; } diff --git a/tests/acceptance/01_vars/02_functions/420.cf b/tests/acceptance/01_vars/02_functions/420.cf index 122a91e0c22..fb6947473ea 100644 --- a/tests/acceptance/01_vars/02_functions/420.cf +++ b/tests/acceptance/01_vars/02_functions/420.cf @@ -42,7 +42,8 @@ body delete init_delete bundle agent test { vars: - "teststr" string => readfile("$(G.testfile)", 1000), + "teststr" + string => readfile("$(G.testfile)", 1000), if => fileexists("$(G.testfile)"); "cnt" diff --git a/tests/acceptance/01_vars/02_functions/421.cf b/tests/acceptance/01_vars/02_functions/421.cf index 9c5fb087d24..d571a65a372 100644 --- a/tests/acceptance/01_vars/02_functions/421.cf +++ b/tests/acceptance/01_vars/02_functions/421.cf @@ -42,7 +42,8 @@ body delete init_delete bundle agent test { vars: - "teststr" string => readfile("$(G.testfile)", 1000), + "teststr" + string => readfile("$(G.testfile)", 1000), if => fileexists("$(G.testfile)"); "cnt" diff --git a/tests/acceptance/01_vars/02_functions/447.cf b/tests/acceptance/01_vars/02_functions/447.cf index 0632d00fc67..43379594bbf 100644 --- a/tests/acceptance/01_vars/02_functions/447.cf +++ b/tests/acceptance/01_vars/02_functions/447.cf @@ -48,8 +48,10 @@ body delete init_delete bundle agent test { vars: - "cnt" int => readstringarrayidx("ary", "$(G.testfile)", "", ":", 10, 1000), + "cnt" + int => readstringarrayidx("ary", "$(G.testfile)", "", ":", 10, 1000), if => fileexists("$(G.testfile)"); + "num" int => "9"; } diff --git a/tests/acceptance/01_vars/02_functions/520.cf b/tests/acceptance/01_vars/02_functions/520.cf index d1ab666bce3..b592f86c158 100644 --- a/tests/acceptance/01_vars/02_functions/520.cf +++ b/tests/acceptance/01_vars/02_functions/520.cf @@ -41,8 +41,10 @@ body delete init_delete bundle agent test { vars: - "teststr" string => readfile("$(G.testfile)", 1000), + "teststr" + string => readfile("$(G.testfile)", 1000), if => fileexists("$(G.testfile)"); + "cnt" int => parseintarray("ary", "$(teststr)", "NoComment", ":", 10, 1000); "num" int => "3"; } diff --git a/tests/acceptance/01_vars/02_functions/521.cf b/tests/acceptance/01_vars/02_functions/521.cf index 84233e9db8b..79bc5877efe 100644 --- a/tests/acceptance/01_vars/02_functions/521.cf +++ b/tests/acceptance/01_vars/02_functions/521.cf @@ -41,8 +41,10 @@ body delete init_delete bundle agent test { vars: - "teststr" string => readfile("$(G.testfile)", 1000), + "teststr" + string => readfile("$(G.testfile)", 1000), if => fileexists("$(G.testfile)"); + "cnt" int => parseintarray("ary", "$(teststr)", "NoComment", ":", 10, 1000); "num" int => "3"; } diff --git a/tests/acceptance/01_vars/02_functions/620.cf b/tests/acceptance/01_vars/02_functions/620.cf index 50f06d423e9..cdcb767c6ea 100644 --- a/tests/acceptance/01_vars/02_functions/620.cf +++ b/tests/acceptance/01_vars/02_functions/620.cf @@ -41,7 +41,8 @@ body delete init_delete bundle agent test { vars: - "teststr" string => readfile("$(G.testfile)", 1000), + "teststr" + string => readfile("$(G.testfile)", 1000), if => fileexists("$(G.testfile)"); "cnt" diff --git a/tests/acceptance/01_vars/02_functions/621.cf b/tests/acceptance/01_vars/02_functions/621.cf index dc908d968cd..db38a789d46 100644 --- a/tests/acceptance/01_vars/02_functions/621.cf +++ b/tests/acceptance/01_vars/02_functions/621.cf @@ -41,7 +41,8 @@ body delete init_delete bundle agent test { vars: - "teststr" string => readfile("$(G.testfile)", 1000), + "teststr" + string => readfile("$(G.testfile)", 1000), if => fileexists("$(G.testfile)"); "cnt" diff --git a/tests/acceptance/01_vars/02_functions/CFE-2704-0.error.pass.cf b/tests/acceptance/01_vars/02_functions/CFE-2704-0.error.pass.cf index 06279efded8..8ea6f4a21ca 100644 --- a/tests/acceptance/01_vars/02_functions/CFE-2704-0.error.pass.cf +++ b/tests/acceptance/01_vars/02_functions/CFE-2704-0.error.pass.cf @@ -1,7 +1,6 @@ # This is an .error.pass.cf test, because mergedata() is given data # which is not a container on purpose and logs an error, the test checks # that the agent does not crash. - body common control { inputs => { "../../default.sub.cf" }; diff --git a/tests/acceptance/01_vars/02_functions/CFE-2704-1.error.pass.cf b/tests/acceptance/01_vars/02_functions/CFE-2704-1.error.pass.cf index 10acfccee9a..7538a59b762 100644 --- a/tests/acceptance/01_vars/02_functions/CFE-2704-1.error.pass.cf +++ b/tests/acceptance/01_vars/02_functions/CFE-2704-1.error.pass.cf @@ -1,7 +1,6 @@ # This is an .error.pass.cf test, because mergedata() is given data # which is not a container on purpose and logs an error, the test checks # that the agent does not crash. - body common control { inputs => { "../../default.sub.cf" }; diff --git a/tests/acceptance/01_vars/02_functions/findfiles_up.cf b/tests/acceptance/01_vars/02_functions/findfiles_up.cf index faf55b5abb3..3cfd153bb36 100755 --- a/tests/acceptance/01_vars/02_functions/findfiles_up.cf +++ b/tests/acceptance/01_vars/02_functions/findfiles_up.cf @@ -53,7 +53,8 @@ bundle agent test data => findfiles_up("$(G.testdir)/core/libntech/libutils/", "string.?"), if => isdir("$(G.testdir)/core/libntech/libutils/"); - "t3" data => findfiles_up("$(G.testdir)/core/libntech/libutils/", ".git/"), + "t3" + data => findfiles_up("$(G.testdir)/core/libntech/libutils/", ".git/"), if => isdir("$(G.testdir)/core/libntech/libutils/"); "t4" diff --git a/tests/acceptance/01_vars/02_functions/getfields.cf b/tests/acceptance/01_vars/02_functions/getfields.cf index b1f1adc32f8..037a0e86e59 100644 --- a/tests/acceptance/01_vars/02_functions/getfields.cf +++ b/tests/acceptance/01_vars/02_functions/getfields.cf @@ -41,7 +41,8 @@ body delete init_delete bundle agent test { vars: - "num_matching" int => getfields("t.*", "$(G.testfile)", ":", "fields"), + "num_matching" + int => getfields("t.*", "$(G.testfile)", ":", "fields"), if => fileexists("$(G.testfile)"); } diff --git a/tests/acceptance/01_vars/02_functions/long_string_from_text_file.cf b/tests/acceptance/01_vars/02_functions/long_string_from_text_file.cf index 25a0bbce723..9c0ff0128b3 100644 --- a/tests/acceptance/01_vars/02_functions/long_string_from_text_file.cf +++ b/tests/acceptance/01_vars/02_functions/long_string_from_text_file.cf @@ -26,7 +26,9 @@ bundle agent test { vars: "keyfile" string => "$(G.testfile).data"; - "keys" slist => readstringlist("$(keyfile)", "#[^\n]*", "\n", 10, 3072), + + "keys" + slist => readstringlist("$(keyfile)", "#[^\n]*", "\n", 10, 3072), if => fileexists("$(keyfile)"); } diff --git a/tests/acceptance/01_vars/02_functions/parsestringarray_weird_indices_real_comments_noemptyfields2.cf b/tests/acceptance/01_vars/02_functions/parsestringarray_weird_indices_real_comments_noemptyfields2.cf index 79539da135d..6443272ee0f 100644 --- a/tests/acceptance/01_vars/02_functions/parsestringarray_weird_indices_real_comments_noemptyfields2.cf +++ b/tests/acceptance/01_vars/02_functions/parsestringarray_weird_indices_real_comments_noemptyfields2.cf @@ -48,8 +48,10 @@ body delete init_delete bundle agent test { vars: - "teststr" string => readfile("$(G.testfile)", 1000), + "teststr" + string => readfile("$(G.testfile)", 1000), if => fileexists("$(G.testfile)"); + "cnt" int => parsestringarray("ary", "$(teststr)", "^#.*", ":+", 10, 14); "num" int => "3"; } diff --git a/tests/acceptance/01_vars/02_functions/read_empty_file.cf b/tests/acceptance/01_vars/02_functions/read_empty_file.cf index d1f37354b8a..ca4281153a6 100644 --- a/tests/acceptance/01_vars/02_functions/read_empty_file.cf +++ b/tests/acceptance/01_vars/02_functions/read_empty_file.cf @@ -15,9 +15,12 @@ bundle agent init bundle agent test { vars: - "value1" string => readfile("$(G.testfile)", 10000), + "value1" + string => readfile("$(G.testfile)", 10000), if => fileexists("$(G.testfile)"); - "value2" string => readfile("$(G.testfile)", 0), + + "value2" + string => readfile("$(G.testfile)", 0), if => fileexists("$(G.testfile)"); } diff --git a/tests/acceptance/01_vars/02_functions/regextract.cf b/tests/acceptance/01_vars/02_functions/regextract.cf index e356e5f0879..ff7c86c7c9f 100644 --- a/tests/acceptance/01_vars/02_functions/regextract.cf +++ b/tests/acceptance/01_vars/02_functions/regextract.cf @@ -32,7 +32,9 @@ bundle agent test "lefts" string => "$(init.pair[1])"; "lefti" int => "$(init.pair[1])"; "rights" string => "$(init.pair[2])"; - "rightr" real => "$(init.pair[2])", + + "rightr" + real => "$(init.pair[2])", if => isvariable("init.pair[2]"); } diff --git a/tests/acceptance/01_vars/04_containers/readjson.cf b/tests/acceptance/01_vars/04_containers/readjson.cf index 3317af28d2f..4774201ddf4 100644 --- a/tests/acceptance/01_vars/04_containers/readjson.cf +++ b/tests/acceptance/01_vars/04_containers/readjson.cf @@ -40,7 +40,8 @@ bundle edit_line init_insert_lines bundle agent test { vars: - "load" data => readjson("$(G.testfile).json", 1024), + "load" + data => readjson("$(G.testfile).json", 1024), if => fileexists("$(G.testfile).json"); files: diff --git a/tests/acceptance/01_vars/04_containers/readjson_arrays.cf b/tests/acceptance/01_vars/04_containers/readjson_arrays.cf index bc120e55e8a..6e96734d8ca 100644 --- a/tests/acceptance/01_vars/04_containers/readjson_arrays.cf +++ b/tests/acceptance/01_vars/04_containers/readjson_arrays.cf @@ -43,7 +43,8 @@ bundle edit_line init_insert_lines bundle agent test { vars: - "load" data => readjson("$(G.testfile).json", 1024), + "load" + data => readjson("$(G.testfile).json", 1024), if => fileexists("$(G.testfile).json"); files: diff --git a/tests/acceptance/01_vars/04_containers/readjson_new.cf b/tests/acceptance/01_vars/04_containers/readjson_new.cf index a411f6614b9..ebc1f19ff6b 100644 --- a/tests/acceptance/01_vars/04_containers/readjson_new.cf +++ b/tests/acceptance/01_vars/04_containers/readjson_new.cf @@ -40,7 +40,8 @@ bundle edit_line init_insert_lines bundle agent test { vars: - "load" data => readjson("$(G.testfile).json"), + "load" + data => readjson("$(G.testfile).json"), if => fileexists("$(G.testfile).json"); files: diff --git a/tests/acceptance/01_vars/04_containers/readjson_null.cf b/tests/acceptance/01_vars/04_containers/readjson_null.cf index 92309aa6386..e9115b410cc 100644 --- a/tests/acceptance/01_vars/04_containers/readjson_null.cf +++ b/tests/acceptance/01_vars/04_containers/readjson_null.cf @@ -39,7 +39,8 @@ bundle edit_line init_insert_lines bundle agent test { vars: - "load" data => readjson("$(G.testfile).json", 1024), + "load" + data => readjson("$(G.testfile).json", 1024), if => fileexists("$(G.testfile).json"); files: diff --git a/tests/acceptance/01_vars/04_containers/readjson_objects.cf b/tests/acceptance/01_vars/04_containers/readjson_objects.cf index 54422b46662..8ba8cf47110 100644 --- a/tests/acceptance/01_vars/04_containers/readjson_objects.cf +++ b/tests/acceptance/01_vars/04_containers/readjson_objects.cf @@ -40,7 +40,8 @@ bundle edit_line init_insert_lines bundle agent test { vars: - "load" data => readjson("$(G.testfile).json", 1024), + "load" + data => readjson("$(G.testfile).json", 1024), if => fileexists("$(G.testfile).json"); files: diff --git a/tests/acceptance/01_vars/04_containers/readjson_scalar.cf b/tests/acceptance/01_vars/04_containers/readjson_scalar.cf index ba32e03860b..859aee42cc2 100644 --- a/tests/acceptance/01_vars/04_containers/readjson_scalar.cf +++ b/tests/acceptance/01_vars/04_containers/readjson_scalar.cf @@ -39,7 +39,8 @@ bundle edit_line init_insert_lines bundle agent test { vars: - "load" data => readjson("$(G.testfile).json", 1024), + "load" + data => readjson("$(G.testfile).json", 1024), if => fileexists("$(G.testfile).json"); files: diff --git a/tests/acceptance/01_vars/04_containers/readjson_subindex.cf b/tests/acceptance/01_vars/04_containers/readjson_subindex.cf index bd669b3ddae..51f0ae06df6 100644 --- a/tests/acceptance/01_vars/04_containers/readjson_subindex.cf +++ b/tests/acceptance/01_vars/04_containers/readjson_subindex.cf @@ -41,7 +41,8 @@ bundle edit_line init_insert_lines bundle agent test { vars: - "load" data => readjson("$(G.testfile).json", 1024), + "load" + data => readjson("$(G.testfile).json", 1024), if => fileexists("$(G.testfile).json"); files: diff --git a/tests/acceptance/01_vars/04_containers/readjson_subindex_quoted.cf b/tests/acceptance/01_vars/04_containers/readjson_subindex_quoted.cf index 17d8c7fadf2..dce9a2b4bf7 100644 --- a/tests/acceptance/01_vars/04_containers/readjson_subindex_quoted.cf +++ b/tests/acceptance/01_vars/04_containers/readjson_subindex_quoted.cf @@ -41,7 +41,8 @@ bundle edit_line init_insert_lines bundle agent test { vars: - "load" data => readjson("$(G.testfile).json", 1024), + "load" + data => readjson("$(G.testfile).json", 1024), if => fileexists("$(G.testfile).json"); files: diff --git a/tests/acceptance/02_classes/01_basic/cancel_attribute_persistent_lmdb.cf b/tests/acceptance/02_classes/01_basic/cancel_attribute_persistent_lmdb.cf index d520a35347d..e1f4ea95d87 100644 --- a/tests/acceptance/02_classes/01_basic/cancel_attribute_persistent_lmdb.cf +++ b/tests/acceptance/02_classes/01_basic/cancel_attribute_persistent_lmdb.cf @@ -58,9 +58,12 @@ bundle agent test bundle agent check { vars: - "before" string => readfile("$(G.testdir)/cancel_lmdb_before", 4096), + "before" + string => readfile("$(G.testdir)/cancel_lmdb_before", 4096), if => fileexists("$(G.testdir)/cancel_lmdb_before"); - "after" string => readfile("$(G.testdir)/cancel_lmdb_after", 4096), + + "after" + string => readfile("$(G.testdir)/cancel_lmdb_after", 4096), if => fileexists("$(G.testdir)/cancel_lmdb_after"); classes: diff --git a/tests/acceptance/02_classes/01_basic/persistent_timer_policy_default_lmdb.cf b/tests/acceptance/02_classes/01_basic/persistent_timer_policy_default_lmdb.cf index 080fc04affa..d4e4841e2a5 100644 --- a/tests/acceptance/02_classes/01_basic/persistent_timer_policy_default_lmdb.cf +++ b/tests/acceptance/02_classes/01_basic/persistent_timer_policy_default_lmdb.cf @@ -78,11 +78,16 @@ bundle agent test bundle agent check { vars: - "policy" string => readfile("$(G.testdir)/lmdb_policy", 4096), + "policy" + string => readfile("$(G.testdir)/lmdb_policy", 4096), if => fileexists("$(G.testdir)/lmdb_policy"); - "e1" string => readfile("$(G.testdir)/lmdb_expires1", 4096), + + "e1" + string => readfile("$(G.testdir)/lmdb_expires1", 4096), if => fileexists("$(G.testdir)/lmdb_expires1"); - "e2" string => readfile("$(G.testdir)/lmdb_expires2", 4096), + + "e2" + string => readfile("$(G.testdir)/lmdb_expires2", 4096), if => fileexists("$(G.testdir)/lmdb_expires2"); classes: diff --git a/tests/acceptance/02_classes/02_functions/classesmatching_inherit_2.cf b/tests/acceptance/02_classes/02_functions/classesmatching_inherit_2.cf index ad2062ed2d1..8f661fa559d 100644 --- a/tests/acceptance/02_classes/02_functions/classesmatching_inherit_2.cf +++ b/tests/acceptance/02_classes/02_functions/classesmatching_inherit_2.cf @@ -59,7 +59,8 @@ bundle agent check "defined_classes: defined_in_second$(const.n)" ); - "actual" string => readfile("$(common.logfile)", inf), + "actual" + string => readfile("$(common.logfile)", inf), if => fileexists("$(common.logfile)"); reports: diff --git a/tests/acceptance/05_processes/01_matching/process_select_fncalls.error.pass.cf b/tests/acceptance/05_processes/01_matching/process_select_fncalls.error.pass.cf index bba2f72dacd..cccdc262618 100644 --- a/tests/acceptance/05_processes/01_matching/process_select_fncalls.error.pass.cf +++ b/tests/acceptance/05_processes/01_matching/process_select_fncalls.error.pass.cf @@ -1,6 +1,5 @@ # This is an .error.pass.cf test, because getuid() is called for the # non-existent user 'nosuchuser' on purpose and logs errors (CFE-1968). - body common control { inputs => { "../../default.sub.cf" }; diff --git a/tests/acceptance/08_commands/arglist.cf b/tests/acceptance/08_commands/arglist.cf index 1948f33e815..bbf52686c0d 100644 --- a/tests/acceptance/08_commands/arglist.cf +++ b/tests/acceptance/08_commands/arglist.cf @@ -46,8 +46,10 @@ bundle agent test bundle agent check { vars: - "actual" string => readfile("$(G.testfile).actual"), + "actual" + string => readfile("$(G.testfile).actual"), if => fileexists("$(G.testfile).actual"); + "expected" string => "one two three diff --git a/tests/acceptance/10_files/09_insert_lines/multi-files-dirs.cf b/tests/acceptance/10_files/09_insert_lines/multi-files-dirs.cf index 43b9fac0d5d..9f0836b75d8 100644 --- a/tests/acceptance/10_files/09_insert_lines/multi-files-dirs.cf +++ b/tests/acceptance/10_files/09_insert_lines/multi-files-dirs.cf @@ -54,11 +54,17 @@ bundle agent check vars: "expect" string => "one two three test"; "results" slist => { "resultA", "resultB", "resultC" }; - "resultA" string => readfile("$(G.testdir)/dirA/testfa", "33"), + + "resultA" + string => readfile("$(G.testdir)/dirA/testfa", "33"), if => fileexists("$(G.testdir)/dirA/testfa"); - "resultB" string => readfile("$(G.testdir)/dirB/testfb", "33"), + + "resultB" + string => readfile("$(G.testdir)/dirB/testfb", "33"), if => fileexists("$(G.testdir)/dirB/testfb"); - "resultC" string => readfile("$(G.testdir)/dirC/testfc", "33"), + + "resultC" + string => readfile("$(G.testdir)/dirC/testfc", "33"), if => fileexists("$(G.testdir)/dirC/testfc"); classes: diff --git a/tests/acceptance/10_files/09_insert_lines/preserve_block_blank_lines.cf b/tests/acceptance/10_files/09_insert_lines/preserve_block_blank_lines.cf index d39a6f50b73..c2c4e60f067 100644 --- a/tests/acceptance/10_files/09_insert_lines/preserve_block_blank_lines.cf +++ b/tests/acceptance/10_files/09_insert_lines/preserve_block_blank_lines.cf @@ -38,7 +38,9 @@ bundle agent check Bad 3 "; - "actual" string => readfile("$(init.test_file)", "inf"), + + "actual" + string => readfile("$(init.test_file)", "inf"), if => fileexists("$(init.test_file)"); classes: diff --git a/tests/acceptance/10_files/templating/empty_template_empty_file.cf b/tests/acceptance/10_files/templating/empty_template_empty_file.cf index 38cc6730655..f41409d8de4 100644 --- a/tests/acceptance/10_files/templating/empty_template_empty_file.cf +++ b/tests/acceptance/10_files/templating/empty_template_empty_file.cf @@ -53,7 +53,9 @@ bundle agent check { vars: "expect" string => ""; - "actual" string => readfile("$(G.testfile)", 1000), + + "actual" + string => readfile("$(G.testfile)", 1000), if => fileexists("$(G.testfile)"); classes: diff --git a/tests/acceptance/10_files/templating/large_template_blocks.cf b/tests/acceptance/10_files/templating/large_template_blocks.cf index 2f3fedeba3a..c6c77f527aa 100644 --- a/tests/acceptance/10_files/templating/large_template_blocks.cf +++ b/tests/acceptance/10_files/templating/large_template_blocks.cf @@ -50,7 +50,9 @@ bundle agent check { vars: "expected" int => "110"; - "actual" int => countlinesmatching(".*0123456789.*", "$(G.testfile)"), + + "actual" + int => countlinesmatching(".*0123456789.*", "$(G.testfile)"), if => fileexists("$(G.testfile)"); classes: diff --git a/tests/acceptance/10_files/templating/mustache_container_serialization.cf b/tests/acceptance/10_files/templating/mustache_container_serialization.cf index d41dcf9e398..b626ce3cea3 100644 --- a/tests/acceptance/10_files/templating/mustache_container_serialization.cf +++ b/tests/acceptance/10_files/templating/mustache_container_serialization.cf @@ -64,7 +64,9 @@ bundle edit_line readthem { vars: "test" slist => { @(test.test) }; - "read_$(test)" string => readfile("$(G.testdir)/$(test)", 1k), + + "read_$(test)" + string => readfile("$(G.testdir)/$(test)", 1k), if => fileexists("$(G.testdir)/$(test)"); insert_lines: diff --git a/tests/acceptance/10_files/templating/mustache_datastate_demo.cf b/tests/acceptance/10_files/templating/mustache_datastate_demo.cf index 43f2cc0a920..ee5724997ab 100644 --- a/tests/acceptance/10_files/templating/mustache_datastate_demo.cf +++ b/tests/acceptance/10_files/templating/mustache_datastate_demo.cf @@ -101,7 +101,8 @@ bundle agent check }" '; - "actual" string => readfile("$(G.testfile)", inf), + "actual" + string => readfile("$(G.testfile)", inf), if => fileexists("$(G.testfile)"); classes: diff --git a/tests/acceptance/10_files/templating/mustache_demo.cf b/tests/acceptance/10_files/templating/mustache_demo.cf index 3b016edaedb..1e321f5bbb5 100644 --- a/tests/acceptance/10_files/templating/mustache_demo.cf +++ b/tests/acceptance/10_files/templating/mustache_demo.cf @@ -49,7 +49,9 @@ bundle agent check { vars: "expect" string => readfile("$(init.origtestdir)/demo.expected", 10000); - "actual" string => readfile("$(G.testfile)", 10000), + + "actual" + string => readfile("$(G.testfile)", 10000), if => fileexists("$(G.testfile)"); classes: diff --git a/tests/acceptance/10_files/templating/mustache_expect_list_find_string.cf b/tests/acceptance/10_files/templating/mustache_expect_list_find_string.cf index 52b0077414c..3092114d1d9 100644 --- a/tests/acceptance/10_files/templating/mustache_expect_list_find_string.cf +++ b/tests/acceptance/10_files/templating/mustache_expect_list_find_string.cf @@ -85,9 +85,13 @@ bundle agent test vars: "template" string => "$(this.promise_filename).mustache"; - "actual_good" string => readfile("$(G.testfile).good", 4096), + + "actual_good" + string => readfile("$(G.testfile).good", 4096), if => fileexists("$(G.testfile).good"); - "actual_bad" string => readfile("$(G.testfile).bad", 4096), + + "actual_bad" + string => readfile("$(G.testfile).bad", 4096), if => fileexists("$(G.testfile).bad"); } diff --git a/tests/acceptance/10_files/templating/mustache_html_escape.cf b/tests/acceptance/10_files/templating/mustache_html_escape.cf index 2f4a3b958eb..e3d85d91240 100644 --- a/tests/acceptance/10_files/templating/mustache_html_escape.cf +++ b/tests/acceptance/10_files/templating/mustache_html_escape.cf @@ -54,7 +54,9 @@ bundle agent check { vars: "expect" string => readfile("$(this.promise_filename).expected", 10000); - "actual" string => readfile("$(G.testfile)", 10000), + + "actual" + string => readfile("$(G.testfile)", 10000), if => fileexists("$(G.testfile)"); classes: diff --git a/tests/acceptance/10_files/templating/mustache_inline_demo.cf b/tests/acceptance/10_files/templating/mustache_inline_demo.cf index 6ae16b65a4d..97c841e004a 100644 --- a/tests/acceptance/10_files/templating/mustache_inline_demo.cf +++ b/tests/acceptance/10_files/templating/mustache_inline_demo.cf @@ -52,7 +52,8 @@ bundle agent check "expect" string => readfile("$(init.origtestdir)/inline_demo.expected", 10000); - "actual" string => readfile("$(G.testfile)", 10000), + "actual" + string => readfile("$(G.testfile)", 10000), if => fileexists("$(G.testfile)"); classes: diff --git a/tests/acceptance/10_files/templating/mustache_render_quote.cf b/tests/acceptance/10_files/templating/mustache_render_quote.cf index 4def7b9364b..1d70e421b53 100644 --- a/tests/acceptance/10_files/templating/mustache_render_quote.cf +++ b/tests/acceptance/10_files/templating/mustache_render_quote.cf @@ -54,7 +54,9 @@ bundle agent check { vars: "expect" string => readfile("$(this.promise_filename).expected", 4000); - "actual" string => readfile("$(G.testfile)", 4000), + + "actual" + string => readfile("$(G.testfile)", 4000), if => fileexists("$(G.testfile)"); classes: diff --git a/tests/acceptance/10_files/templating/mustache_repair_existing.cf b/tests/acceptance/10_files/templating/mustache_repair_existing.cf index 2429e350ed6..c7c78943fed 100644 --- a/tests/acceptance/10_files/templating/mustache_repair_existing.cf +++ b/tests/acceptance/10_files/templating/mustache_repair_existing.cf @@ -50,7 +50,9 @@ bundle agent check { vars: "expect" string => readfile("$(init.origtestdir)/demo.expected", 4096); - "actual" string => readfile("$(G.testfile)", 4096), + + "actual" + string => readfile("$(G.testfile)", 4096), if => fileexists("$(G.testfile)"); classes: diff --git a/tests/acceptance/15_control/01_common/classic_evaluation_custom_promise_types.cf b/tests/acceptance/15_control/01_common/classic_evaluation_custom_promise_types.cf index 4976b216f4c..d5ea9e47962 100644 --- a/tests/acceptance/15_control/01_common/classic_evaluation_custom_promise_types.cf +++ b/tests/acceptance/15_control/01_common/classic_evaluation_custom_promise_types.cf @@ -23,14 +23,16 @@ bundle agent test "/tmp/dummyfile" smth => "hello"; vars: - "content" string => readfile("/tmp/dummyfile"), + "content" + string => readfile("/tmp/dummyfile"), if => fileexists("/tmp/dummyfile"); files: "/tmp/dummyfile" content => "ok"; vars: - "content" string => readfile("/tmp/dummyfile"), + "content" + string => readfile("/tmp/dummyfile"), if => fileexists("/tmp/dummyfile"); classes: diff --git a/tests/acceptance/15_control/01_common/classic_evaluation_long_policy.cf b/tests/acceptance/15_control/01_common/classic_evaluation_long_policy.cf index 3fedb3a4bcd..1a06957f2e9 100644 --- a/tests/acceptance/15_control/01_common/classic_evaluation_long_policy.cf +++ b/tests/acceptance/15_control/01_common/classic_evaluation_long_policy.cf @@ -34,8 +34,10 @@ bundle agent test "/tmp/example" content => "fourth"; vars: - "content" string => readfile("/tmp/example"), + "content" + string => readfile("/tmp/example"), if => fileexists("/tmp/example"); + "result" string => concat("$(result)", ", $(content)"); classes: @@ -49,7 +51,8 @@ bundle agent test "/tmp/otherfile" content => "something"; vars: - "othercontent" string => readfile("/tmp/otherfile"), + "othercontent" + string => readfile("/tmp/otherfile"), if => fileexists("/tmp/otherfile"); files: diff --git a/tests/acceptance/15_control/01_common/top_down_evaluation_long_policy.cf b/tests/acceptance/15_control/01_common/top_down_evaluation_long_policy.cf index a60342fd22b..01151c1248f 100644 --- a/tests/acceptance/15_control/01_common/top_down_evaluation_long_policy.cf +++ b/tests/acceptance/15_control/01_common/top_down_evaluation_long_policy.cf @@ -34,8 +34,10 @@ bundle agent test "/tmp/example" content => "fourth"; vars: - "content" string => readfile("/tmp/example"), + "content" + string => readfile("/tmp/example"), if => fileexists("/tmp/example"); + "result" string => concat("$(result)", ", $(content)"); classes: @@ -49,7 +51,8 @@ bundle agent test "/tmp/otherfile" content => "something"; vars: - "othercontent" string => readfile("/tmp/otherfile"), + "othercontent" + string => readfile("/tmp/otherfile"), if => fileexists("/tmp/otherfile"); files: diff --git a/tests/acceptance/31_tickets/CFE-3866/test.cf b/tests/acceptance/31_tickets/CFE-3866/test.cf index c90c082ed48..dd8c0a1d98d 100644 --- a/tests/acceptance/31_tickets/CFE-3866/test.cf +++ b/tests/acceptance/31_tickets/CFE-3866/test.cf @@ -68,7 +68,9 @@ bundle agent check "expected" string => "[section] key=value "; - "actual" string => readfile("$(G.testfile)", "1000"), + + "actual" + string => readfile("$(G.testfile)", "1000"), if => fileexists("$(G.testfile)"); classes: From 14691f584c114467f91efa76f944458f7104589f Mon Sep 17 00:00:00 2001 From: Nick Anderson Date: Thu, 22 Oct 2026 16:00:02 -0500 Subject: [PATCH 16/39] Fixed unsafe and check_syntax.cf acceptance tests logging errors Ticket: CFE-3041 Signed-off-by: Nick Anderson --- tests/acceptance/04_examples/syntax/check_syntax.cf | 2 +- tests/acceptance/10_files/unsafe/02_immutable.cf | 3 ++- tests/acceptance/10_files/unsafe/03_immutable.cf | 3 ++- tests/acceptance/10_files/unsafe/05_immutable.cf | 3 ++- tests/acceptance/10_files/unsafe/06_immutable.cf | 3 ++- tests/acceptance/10_files/unsafe/09_immutable.cf | 3 ++- tests/acceptance/10_files/unsafe/10_immutable.cf | 3 ++- tests/acceptance/10_files/unsafe/14_immutable_content.cf | 6 +++++- tests/acceptance/10_files/unsafe/15_immutable_edit_line.cf | 6 +++++- tests/acceptance/10_files/unsafe/16_immutable_copy_from.cf | 6 +++++- .../10_files/unsafe/17_immutable_template_mustache.cf | 6 +++++- .../10_files/unsafe/18_immutable_template_cfengine.cf | 6 +++++- tests/acceptance/10_files/unsafe/19_immutable_edit_xml.cf | 6 +++++- .../unsafe/20_immutable_template_inline_mustache.cf | 6 +++++- ...irst-found-group-perms-if-no-listed-candidate-matches.cf | 3 ++- ...first-found-user-perms-if-no-listed-candidate-matches.cf | 3 ++- 16 files changed, 52 insertions(+), 16 deletions(-) diff --git a/tests/acceptance/04_examples/syntax/check_syntax.cf b/tests/acceptance/04_examples/syntax/check_syntax.cf index 347329a35a5..420f58e4f94 100644 --- a/tests/acceptance/04_examples/syntax/check_syntax.cf +++ b/tests/acceptance/04_examples/syntax/check_syntax.cf @@ -124,7 +124,7 @@ bundle agent test_example(file) classes: "failure_$(cfile)" - not => returnszero("$(checker) $(file)", "noshell"), + not => returnszero("$(checker) $(file) >/dev/null 2>&1", "useshell"), scope => "namespace"; reports: diff --git a/tests/acceptance/10_files/unsafe/02_immutable.cf b/tests/acceptance/10_files/unsafe/02_immutable.cf index e078b05411d..edfb5f49db5 100644 --- a/tests/acceptance/10_files/unsafe/02_immutable.cf +++ b/tests/acceptance/10_files/unsafe/02_immutable.cf @@ -49,7 +49,8 @@ bundle agent check { vars: "expected" string => "But agent can override"; - "actual" string => readfile("$(global.testfile)"); + "actual" string => readfile("$(global.testfile)"), + if => fileexists("$(global.testfile)"); classes: "ok" expression => strcmp("$(actual)", "$(expected)"); diff --git a/tests/acceptance/10_files/unsafe/03_immutable.cf b/tests/acceptance/10_files/unsafe/03_immutable.cf index 97c0f81d88a..a24fd68d6aa 100644 --- a/tests/acceptance/10_files/unsafe/03_immutable.cf +++ b/tests/acceptance/10_files/unsafe/03_immutable.cf @@ -50,7 +50,8 @@ bundle agent check { vars: "expected" string => "But agent can override"; - "actual" string => readfile("$(global.testfile)"); + "actual" string => readfile("$(global.testfile)"), + if => fileexists("$(global.testfile)"); classes: "ok" expression => strcmp("$(actual)", "$(expected)"); diff --git a/tests/acceptance/10_files/unsafe/05_immutable.cf b/tests/acceptance/10_files/unsafe/05_immutable.cf index e96b3b9dba1..2f4efe522b4 100644 --- a/tests/acceptance/10_files/unsafe/05_immutable.cf +++ b/tests/acceptance/10_files/unsafe/05_immutable.cf @@ -57,7 +57,8 @@ bundle agent check "expected" string => "I'm immutable$(const.n)But agent can override$(const.n)"; - "actual" string => readfile("$(global.testfile)"); + "actual" string => readfile("$(global.testfile)"), + if => fileexists("$(global.testfile)"); classes: "ok" expression => strcmp("$(actual)", "$(expected)"); diff --git a/tests/acceptance/10_files/unsafe/06_immutable.cf b/tests/acceptance/10_files/unsafe/06_immutable.cf index f105c62fcb3..d27447c4181 100644 --- a/tests/acceptance/10_files/unsafe/06_immutable.cf +++ b/tests/acceptance/10_files/unsafe/06_immutable.cf @@ -56,7 +56,8 @@ bundle agent check "expected" string => '$(const.n)But agent can override$(const.n)'; - "actual" string => readfile("$(global.testfile)"); + "actual" string => readfile("$(global.testfile)"), + if => fileexists("$(global.testfile)"); classes: "ok" expression => strcmp("$(actual)", "$(expected)"); diff --git a/tests/acceptance/10_files/unsafe/09_immutable.cf b/tests/acceptance/10_files/unsafe/09_immutable.cf index 4b96b6acbe5..0671ce93604 100644 --- a/tests/acceptance/10_files/unsafe/09_immutable.cf +++ b/tests/acceptance/10_files/unsafe/09_immutable.cf @@ -56,7 +56,8 @@ bundle agent check { vars: "expected" string => "Hello larsewi!"; - "actual" string => readfile("$(global.testfile)"); + "actual" string => readfile("$(global.testfile)"), + if => fileexists("$(global.testfile)"); classes: "ok" expression => strcmp("$(actual)", "$(expected)"); diff --git a/tests/acceptance/10_files/unsafe/10_immutable.cf b/tests/acceptance/10_files/unsafe/10_immutable.cf index 855e245f777..fdf7af314f6 100644 --- a/tests/acceptance/10_files/unsafe/10_immutable.cf +++ b/tests/acceptance/10_files/unsafe/10_immutable.cf @@ -62,7 +62,8 @@ bundle agent check { vars: "expected" string => ".*user:root:rwx.*"; - "acls" slist => getacls("$(global.testfile)", "access"); + "acls" slist => getacls("$(global.testfile)", "access"), + if => fileexists("$(global.testfile)"); classes: "ok" expression => some("$(expected)", "acls"); diff --git a/tests/acceptance/10_files/unsafe/14_immutable_content.cf b/tests/acceptance/10_files/unsafe/14_immutable_content.cf index ffaab2545df..5b3b7fc15a3 100644 --- a/tests/acceptance/10_files/unsafe/14_immutable_content.cf +++ b/tests/acceptance/10_files/unsafe/14_immutable_content.cf @@ -46,6 +46,10 @@ bundle agent check ), with => regex_replace("$(this.promise_filename)", "\.cf$", ".sub.cf", ""); + # Indent the sub-agent output in the DEBUG report, so that errors it + # prints are not mistaken for errors of the test by testall + "output_indented" string => regex_replace("$(run[output])", "^", " | ", "gm"); + classes: "ok" expression => regcmp( @@ -61,7 +65,7 @@ bundle agent check DEBUG:: "$(this.bundle): agent exited '$(run[exit_code])', output was:"; - "$(run[output])"; + "$(output_indented)"; } bundle agent destroy diff --git a/tests/acceptance/10_files/unsafe/15_immutable_edit_line.cf b/tests/acceptance/10_files/unsafe/15_immutable_edit_line.cf index 45859a7fcdf..15ada3f246d 100644 --- a/tests/acceptance/10_files/unsafe/15_immutable_edit_line.cf +++ b/tests/acceptance/10_files/unsafe/15_immutable_edit_line.cf @@ -48,6 +48,10 @@ bundle agent check ), with => regex_replace("$(this.promise_filename)", "\.cf$", ".sub.cf", ""); + # Indent the sub-agent output in the DEBUG report, so that errors it + # prints are not mistaken for errors of the test by testall + "output_indented" string => regex_replace("$(run[output])", "^", " | ", "gm"); + classes: "ok" expression => regcmp( @@ -63,7 +67,7 @@ bundle agent check DEBUG:: "$(this.bundle): agent exited '$(run[exit_code])', output was:"; - "$(run[output])"; + "$(output_indented)"; } bundle agent destroy diff --git a/tests/acceptance/10_files/unsafe/16_immutable_copy_from.cf b/tests/acceptance/10_files/unsafe/16_immutable_copy_from.cf index 0c8865bdecb..a4af0e32ffd 100644 --- a/tests/acceptance/10_files/unsafe/16_immutable_copy_from.cf +++ b/tests/acceptance/10_files/unsafe/16_immutable_copy_from.cf @@ -49,6 +49,10 @@ bundle agent check ), with => regex_replace("$(this.promise_filename)", "\.cf$", ".sub.cf", ""); + # Indent the sub-agent output in the DEBUG report, so that errors it + # prints are not mistaken for errors of the test by testall + "output_indented" string => regex_replace("$(run[output])", "^", " | ", "gm"); + classes: "ok" expression => regcmp( @@ -64,7 +68,7 @@ bundle agent check DEBUG:: "$(this.bundle): agent exited '$(run[exit_code])', output was:"; - "$(run[output])"; + "$(output_indented)"; } bundle agent destroy diff --git a/tests/acceptance/10_files/unsafe/17_immutable_template_mustache.cf b/tests/acceptance/10_files/unsafe/17_immutable_template_mustache.cf index b1f3963649a..3040e15f0aa 100644 --- a/tests/acceptance/10_files/unsafe/17_immutable_template_mustache.cf +++ b/tests/acceptance/10_files/unsafe/17_immutable_template_mustache.cf @@ -49,6 +49,10 @@ bundle agent check ), with => regex_replace("$(this.promise_filename)", "\.cf$", ".sub.cf", ""); + # Indent the sub-agent output in the DEBUG report, so that errors it + # prints are not mistaken for errors of the test by testall + "output_indented" string => regex_replace("$(run[output])", "^", " | ", "gm"); + classes: "ok" expression => regcmp( @@ -64,7 +68,7 @@ bundle agent check DEBUG:: "$(this.bundle): agent exited '$(run[exit_code])', output was:"; - "$(run[output])"; + "$(output_indented)"; } bundle agent destroy diff --git a/tests/acceptance/10_files/unsafe/18_immutable_template_cfengine.cf b/tests/acceptance/10_files/unsafe/18_immutable_template_cfengine.cf index 49beabe0694..723656fd63b 100644 --- a/tests/acceptance/10_files/unsafe/18_immutable_template_cfengine.cf +++ b/tests/acceptance/10_files/unsafe/18_immutable_template_cfengine.cf @@ -50,6 +50,10 @@ bundle agent check ), with => regex_replace("$(this.promise_filename)", "\.cf$", ".sub.cf", ""); + # Indent the sub-agent output in the DEBUG report, so that errors it + # prints are not mistaken for errors of the test by testall + "output_indented" string => regex_replace("$(run[output])", "^", " | ", "gm"); + classes: "ok" expression => regcmp( @@ -65,7 +69,7 @@ bundle agent check DEBUG:: "$(this.bundle): agent exited '$(run[exit_code])', output was:"; - "$(run[output])"; + "$(output_indented)"; } bundle agent destroy diff --git a/tests/acceptance/10_files/unsafe/19_immutable_edit_xml.cf b/tests/acceptance/10_files/unsafe/19_immutable_edit_xml.cf index 4f08284cfac..df580fc39a5 100644 --- a/tests/acceptance/10_files/unsafe/19_immutable_edit_xml.cf +++ b/tests/acceptance/10_files/unsafe/19_immutable_edit_xml.cf @@ -48,6 +48,10 @@ bundle agent check ), with => regex_replace("$(this.promise_filename)", "\.cf$", ".sub.cf", ""); + # Indent the sub-agent output in the DEBUG report, so that errors it + # prints are not mistaken for errors of the test by testall + "output_indented" string => regex_replace("$(run[output])", "^", " | ", "gm"); + classes: "ok" expression => regcmp( @@ -63,7 +67,7 @@ bundle agent check DEBUG:: "$(this.bundle): agent exited '$(run[exit_code])', output was:"; - "$(run[output])"; + "$(output_indented)"; } bundle agent destroy diff --git a/tests/acceptance/10_files/unsafe/20_immutable_template_inline_mustache.cf b/tests/acceptance/10_files/unsafe/20_immutable_template_inline_mustache.cf index 2adaad5c3e3..a4d1b208c35 100644 --- a/tests/acceptance/10_files/unsafe/20_immutable_template_inline_mustache.cf +++ b/tests/acceptance/10_files/unsafe/20_immutable_template_inline_mustache.cf @@ -49,6 +49,10 @@ bundle agent check ), with => regex_replace("$(this.promise_filename)", "\.cf$", ".sub.cf", ""); + # Indent the sub-agent output in the DEBUG report, so that errors it + # prints are not mistaken for errors of the test by testall + "output_indented" string => regex_replace("$(run[output])", "^", " | ", "gm"); + classes: "ok" expression => regcmp( @@ -64,7 +68,7 @@ bundle agent check DEBUG:: "$(this.bundle): agent exited '$(run[exit_code])', output was:"; - "$(run[output])"; + "$(output_indented)"; } bundle agent destroy diff --git a/tests/acceptance/10_files/unsafe/multiple-group-candidates-first-found-group-perms-if-no-listed-candidate-matches.cf b/tests/acceptance/10_files/unsafe/multiple-group-candidates-first-found-group-perms-if-no-listed-candidate-matches.cf index 00a8a5afc08..8c3f908cd70 100644 --- a/tests/acceptance/10_files/unsafe/multiple-group-candidates-first-found-group-perms-if-no-listed-candidate-matches.cf +++ b/tests/acceptance/10_files/unsafe/multiple-group-candidates-first-found-group-perms-if-no-listed-candidate-matches.cf @@ -69,7 +69,8 @@ bundle agent check { vars: "observed_gid" string => filestat($(G.testfile), gid); - "desired_gid" int => getgid("pr_gr_1"); + "desired_gid" int => getgid("pr_gr_1"), + if => groupexists("pr_gr_1"); reports: "$(this.promise_filename) Pass" diff --git a/tests/acceptance/10_files/unsafe/multiple-owner-candidates-first-found-user-perms-if-no-listed-candidate-matches.cf b/tests/acceptance/10_files/unsafe/multiple-owner-candidates-first-found-user-perms-if-no-listed-candidate-matches.cf index 2d7325fc70a..c1cad67424c 100644 --- a/tests/acceptance/10_files/unsafe/multiple-owner-candidates-first-found-user-perms-if-no-listed-candidate-matches.cf +++ b/tests/acceptance/10_files/unsafe/multiple-owner-candidates-first-found-user-perms-if-no-listed-candidate-matches.cf @@ -39,7 +39,8 @@ bundle agent check { vars: "observed_uid" string => filestat($(G.testfile), uid); - "desired_uid" int => getuid("pr_us_1"); + "desired_uid" int => getuid("pr_us_1"), + if => userexists("pr_us_1"); reports: "$(this.promise_filename) Pass" From 5c6c04321f31cb4d36e6eb4bb43b9dbcabbdd774 Mon Sep 17 00:00:00 2001 From: Nick Anderson Date: Thu, 22 Oct 2026 16:04:47 -0500 Subject: [PATCH 17/39] Fixed formatting of acceptance tests Ticket: CFE-3041 Signed-off-by: Nick Anderson --- tests/acceptance/10_files/unsafe/02_immutable.cf | 4 +++- tests/acceptance/10_files/unsafe/03_immutable.cf | 4 +++- tests/acceptance/10_files/unsafe/05_immutable.cf | 3 ++- tests/acceptance/10_files/unsafe/06_immutable.cf | 3 ++- tests/acceptance/10_files/unsafe/09_immutable.cf | 4 +++- tests/acceptance/10_files/unsafe/10_immutable.cf | 4 +++- tests/acceptance/10_files/unsafe/14_immutable_content.cf | 3 ++- tests/acceptance/10_files/unsafe/15_immutable_edit_line.cf | 3 ++- tests/acceptance/10_files/unsafe/16_immutable_copy_from.cf | 3 ++- .../10_files/unsafe/17_immutable_template_mustache.cf | 3 ++- .../10_files/unsafe/18_immutable_template_cfengine.cf | 3 ++- tests/acceptance/10_files/unsafe/19_immutable_edit_xml.cf | 3 ++- .../10_files/unsafe/20_immutable_template_inline_mustache.cf | 3 ++- ...-first-found-group-perms-if-no-listed-candidate-matches.cf | 4 +++- ...s-first-found-user-perms-if-no-listed-candidate-matches.cf | 4 +++- 15 files changed, 36 insertions(+), 15 deletions(-) diff --git a/tests/acceptance/10_files/unsafe/02_immutable.cf b/tests/acceptance/10_files/unsafe/02_immutable.cf index edfb5f49db5..47a1dc2ea8a 100644 --- a/tests/acceptance/10_files/unsafe/02_immutable.cf +++ b/tests/acceptance/10_files/unsafe/02_immutable.cf @@ -49,7 +49,9 @@ bundle agent check { vars: "expected" string => "But agent can override"; - "actual" string => readfile("$(global.testfile)"), + + "actual" + string => readfile("$(global.testfile)"), if => fileexists("$(global.testfile)"); classes: diff --git a/tests/acceptance/10_files/unsafe/03_immutable.cf b/tests/acceptance/10_files/unsafe/03_immutable.cf index a24fd68d6aa..4e6ddaa683c 100644 --- a/tests/acceptance/10_files/unsafe/03_immutable.cf +++ b/tests/acceptance/10_files/unsafe/03_immutable.cf @@ -50,7 +50,9 @@ bundle agent check { vars: "expected" string => "But agent can override"; - "actual" string => readfile("$(global.testfile)"), + + "actual" + string => readfile("$(global.testfile)"), if => fileexists("$(global.testfile)"); classes: diff --git a/tests/acceptance/10_files/unsafe/05_immutable.cf b/tests/acceptance/10_files/unsafe/05_immutable.cf index 2f4efe522b4..87d2c85ddf5 100644 --- a/tests/acceptance/10_files/unsafe/05_immutable.cf +++ b/tests/acceptance/10_files/unsafe/05_immutable.cf @@ -57,7 +57,8 @@ bundle agent check "expected" string => "I'm immutable$(const.n)But agent can override$(const.n)"; - "actual" string => readfile("$(global.testfile)"), + "actual" + string => readfile("$(global.testfile)"), if => fileexists("$(global.testfile)"); classes: diff --git a/tests/acceptance/10_files/unsafe/06_immutable.cf b/tests/acceptance/10_files/unsafe/06_immutable.cf index d27447c4181..c04b5c5f510 100644 --- a/tests/acceptance/10_files/unsafe/06_immutable.cf +++ b/tests/acceptance/10_files/unsafe/06_immutable.cf @@ -56,7 +56,8 @@ bundle agent check "expected" string => '$(const.n)But agent can override$(const.n)'; - "actual" string => readfile("$(global.testfile)"), + "actual" + string => readfile("$(global.testfile)"), if => fileexists("$(global.testfile)"); classes: diff --git a/tests/acceptance/10_files/unsafe/09_immutable.cf b/tests/acceptance/10_files/unsafe/09_immutable.cf index 0671ce93604..9b133625559 100644 --- a/tests/acceptance/10_files/unsafe/09_immutable.cf +++ b/tests/acceptance/10_files/unsafe/09_immutable.cf @@ -56,7 +56,9 @@ bundle agent check { vars: "expected" string => "Hello larsewi!"; - "actual" string => readfile("$(global.testfile)"), + + "actual" + string => readfile("$(global.testfile)"), if => fileexists("$(global.testfile)"); classes: diff --git a/tests/acceptance/10_files/unsafe/10_immutable.cf b/tests/acceptance/10_files/unsafe/10_immutable.cf index fdf7af314f6..9815ecc2621 100644 --- a/tests/acceptance/10_files/unsafe/10_immutable.cf +++ b/tests/acceptance/10_files/unsafe/10_immutable.cf @@ -62,7 +62,9 @@ bundle agent check { vars: "expected" string => ".*user:root:rwx.*"; - "acls" slist => getacls("$(global.testfile)", "access"), + + "acls" + slist => getacls("$(global.testfile)", "access"), if => fileexists("$(global.testfile)"); classes: diff --git a/tests/acceptance/10_files/unsafe/14_immutable_content.cf b/tests/acceptance/10_files/unsafe/14_immutable_content.cf index 5b3b7fc15a3..0b01e255768 100644 --- a/tests/acceptance/10_files/unsafe/14_immutable_content.cf +++ b/tests/acceptance/10_files/unsafe/14_immutable_content.cf @@ -48,7 +48,8 @@ bundle agent check # Indent the sub-agent output in the DEBUG report, so that errors it # prints are not mistaken for errors of the test by testall - "output_indented" string => regex_replace("$(run[output])", "^", " | ", "gm"); + "output_indented" + string => regex_replace("$(run[output])", "^", " | ", "gm"); classes: "ok" diff --git a/tests/acceptance/10_files/unsafe/15_immutable_edit_line.cf b/tests/acceptance/10_files/unsafe/15_immutable_edit_line.cf index 15ada3f246d..d3fbc9504bb 100644 --- a/tests/acceptance/10_files/unsafe/15_immutable_edit_line.cf +++ b/tests/acceptance/10_files/unsafe/15_immutable_edit_line.cf @@ -50,7 +50,8 @@ bundle agent check # Indent the sub-agent output in the DEBUG report, so that errors it # prints are not mistaken for errors of the test by testall - "output_indented" string => regex_replace("$(run[output])", "^", " | ", "gm"); + "output_indented" + string => regex_replace("$(run[output])", "^", " | ", "gm"); classes: "ok" diff --git a/tests/acceptance/10_files/unsafe/16_immutable_copy_from.cf b/tests/acceptance/10_files/unsafe/16_immutable_copy_from.cf index a4af0e32ffd..c718109c35a 100644 --- a/tests/acceptance/10_files/unsafe/16_immutable_copy_from.cf +++ b/tests/acceptance/10_files/unsafe/16_immutable_copy_from.cf @@ -51,7 +51,8 @@ bundle agent check # Indent the sub-agent output in the DEBUG report, so that errors it # prints are not mistaken for errors of the test by testall - "output_indented" string => regex_replace("$(run[output])", "^", " | ", "gm"); + "output_indented" + string => regex_replace("$(run[output])", "^", " | ", "gm"); classes: "ok" diff --git a/tests/acceptance/10_files/unsafe/17_immutable_template_mustache.cf b/tests/acceptance/10_files/unsafe/17_immutable_template_mustache.cf index 3040e15f0aa..5d2861bda61 100644 --- a/tests/acceptance/10_files/unsafe/17_immutable_template_mustache.cf +++ b/tests/acceptance/10_files/unsafe/17_immutable_template_mustache.cf @@ -51,7 +51,8 @@ bundle agent check # Indent the sub-agent output in the DEBUG report, so that errors it # prints are not mistaken for errors of the test by testall - "output_indented" string => regex_replace("$(run[output])", "^", " | ", "gm"); + "output_indented" + string => regex_replace("$(run[output])", "^", " | ", "gm"); classes: "ok" diff --git a/tests/acceptance/10_files/unsafe/18_immutable_template_cfengine.cf b/tests/acceptance/10_files/unsafe/18_immutable_template_cfengine.cf index 723656fd63b..a0a98401259 100644 --- a/tests/acceptance/10_files/unsafe/18_immutable_template_cfengine.cf +++ b/tests/acceptance/10_files/unsafe/18_immutable_template_cfengine.cf @@ -52,7 +52,8 @@ bundle agent check # Indent the sub-agent output in the DEBUG report, so that errors it # prints are not mistaken for errors of the test by testall - "output_indented" string => regex_replace("$(run[output])", "^", " | ", "gm"); + "output_indented" + string => regex_replace("$(run[output])", "^", " | ", "gm"); classes: "ok" diff --git a/tests/acceptance/10_files/unsafe/19_immutable_edit_xml.cf b/tests/acceptance/10_files/unsafe/19_immutable_edit_xml.cf index df580fc39a5..a5ee0e8177c 100644 --- a/tests/acceptance/10_files/unsafe/19_immutable_edit_xml.cf +++ b/tests/acceptance/10_files/unsafe/19_immutable_edit_xml.cf @@ -50,7 +50,8 @@ bundle agent check # Indent the sub-agent output in the DEBUG report, so that errors it # prints are not mistaken for errors of the test by testall - "output_indented" string => regex_replace("$(run[output])", "^", " | ", "gm"); + "output_indented" + string => regex_replace("$(run[output])", "^", " | ", "gm"); classes: "ok" diff --git a/tests/acceptance/10_files/unsafe/20_immutable_template_inline_mustache.cf b/tests/acceptance/10_files/unsafe/20_immutable_template_inline_mustache.cf index a4d1b208c35..115f1c6650e 100644 --- a/tests/acceptance/10_files/unsafe/20_immutable_template_inline_mustache.cf +++ b/tests/acceptance/10_files/unsafe/20_immutable_template_inline_mustache.cf @@ -51,7 +51,8 @@ bundle agent check # Indent the sub-agent output in the DEBUG report, so that errors it # prints are not mistaken for errors of the test by testall - "output_indented" string => regex_replace("$(run[output])", "^", " | ", "gm"); + "output_indented" + string => regex_replace("$(run[output])", "^", " | ", "gm"); classes: "ok" diff --git a/tests/acceptance/10_files/unsafe/multiple-group-candidates-first-found-group-perms-if-no-listed-candidate-matches.cf b/tests/acceptance/10_files/unsafe/multiple-group-candidates-first-found-group-perms-if-no-listed-candidate-matches.cf index 8c3f908cd70..ab2172503ed 100644 --- a/tests/acceptance/10_files/unsafe/multiple-group-candidates-first-found-group-perms-if-no-listed-candidate-matches.cf +++ b/tests/acceptance/10_files/unsafe/multiple-group-candidates-first-found-group-perms-if-no-listed-candidate-matches.cf @@ -69,7 +69,9 @@ bundle agent check { vars: "observed_gid" string => filestat($(G.testfile), gid); - "desired_gid" int => getgid("pr_gr_1"), + + "desired_gid" + int => getgid("pr_gr_1"), if => groupexists("pr_gr_1"); reports: diff --git a/tests/acceptance/10_files/unsafe/multiple-owner-candidates-first-found-user-perms-if-no-listed-candidate-matches.cf b/tests/acceptance/10_files/unsafe/multiple-owner-candidates-first-found-user-perms-if-no-listed-candidate-matches.cf index c1cad67424c..2da83d66422 100644 --- a/tests/acceptance/10_files/unsafe/multiple-owner-candidates-first-found-user-perms-if-no-listed-candidate-matches.cf +++ b/tests/acceptance/10_files/unsafe/multiple-owner-candidates-first-found-user-perms-if-no-listed-candidate-matches.cf @@ -39,7 +39,9 @@ bundle agent check { vars: "observed_uid" string => filestat($(G.testfile), uid); - "desired_uid" int => getuid("pr_us_1"), + + "desired_uid" + int => getuid("pr_us_1"), if => userexists("pr_us_1"); reports: From 3e5e69024b9781491c5576e364f9ed48364a22b9 Mon Sep 17 00:00:00 2001 From: Nick Anderson Date: Fri, 23 Oct 2026 14:10:52 -0500 Subject: [PATCH 18/39] Fixed mapdata_json_pipe.cf logging errors Ticket: CFE-3041 --- tests/acceptance/01_vars/02_functions/mapdata_json_pipe.cf | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/acceptance/01_vars/02_functions/mapdata_json_pipe.cf b/tests/acceptance/01_vars/02_functions/mapdata_json_pipe.cf index 1a3d32ece7d..3f354cc6b33 100644 --- a/tests/acceptance/01_vars/02_functions/mapdata_json_pipe.cf +++ b/tests/acceptance/01_vars/02_functions/mapdata_json_pipe.cf @@ -19,7 +19,12 @@ bundle agent test vars: "items" data => '{"user":"stedolan","titles":["JQ Primer", "More JQ"]}'; - "items_passthrough" data => mapdata("json_pipe", "$(G.cat)", items); + + # G comes from dynamically loaded dcs.sub.cf, so $(G.cat) is unresolved + # during pre-evaluation and json_pipe would execute it literally + "items_passthrough" + data => mapdata("json_pipe", "$(G.cat)", items), + if => isvariable("G.cat"); "items_jqinput" data => mapdata( From a73a0c1e00046bbc81fc93f19250a30d6ce74336 Mon Sep 17 00:00:00 2001 From: Ihor Aleksandrychiev Date: Mon, 26 Oct 2026 11:21:27 +0200 Subject: [PATCH 19/39] Made .error.pass.cf tests respect soft fails and skips The errorpass branch only checked for logged errors and the Pass message, so a test marked test_soft_fail or test_skip_unsupported was reported as FAIL (e.g. process_select_fncalls.error.pass.cf on Windows, which soft fails due to ENT-10217 and logs no errors there). Errorpass tests now go through the regular outcome handling and only differ in requiring at least one logged error on Pass. --- tests/acceptance/testall | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/tests/acceptance/testall b/tests/acceptance/testall index 4d40ebb301d..ed78891e731 100755 --- a/tests/acceptance/testall +++ b/tests/acceptance/testall @@ -576,26 +576,8 @@ export CFENGINE_TEST_OVERRIDE_WORKDIR TEMP CFENGINE_TEST_OVERRIDE_EXTENSION_LIBR RESULT=FAIL RESULT_MSG="${COLOR_FAILURE}FAIL (No errors printed)${COLOR_NORMAL}" fi - elif [ $TEST_TYPE = errorpass ] - then - ESCAPED_TEST="$(echo "($TEST|dcs.sub.cf)" | sed -e 's/\./\\./g')" - if [ $RETVAL != 0 ] - then - RESULT=FAIL - RESULT_MSG="${COLOR_FAILURE}FAIL (NON-ZERO EXIT CODE!)${COLOR_NORMAL}" - elif ! grep -F 'error: ' "$OUTFILE" > /dev/null - then - RESULT=FAIL - RESULT_MSG="${COLOR_FAILURE}FAIL (No error message!)${COLOR_NORMAL}" - elif ! grep -E "R: .*$ESCAPED_TEST Pass" $OUTFILE > /dev/null - then - RESULT=FAIL - RESULT_MSG="${COLOR_FAILURE}FAIL (Pass not printed!)${COLOR_NORMAL}" - else - RESULT=Pass - RESULT_MSG="${COLOR_SUCCESS}Pass${COLOR_NORMAL}" - fi - else # TEST_TYPE is not errorlog or errorexit or errorpass + else # TEST_TYPE is not errorlog or errorexit (errorpass is handled here + # too, so that soft fails and skips work for it) # We need to be careful when matching test outcomes. Because of convergence # passes, a test may output FAIL before it outputs Pass; in this case the # latter trumps the former. Also be careful when matching an [XS]FAIL; the @@ -650,7 +632,17 @@ export CFENGINE_TEST_OVERRIDE_WORKDIR TEMP CFENGINE_TEST_OVERRIDE_EXTENSION_LIBR then # Regular tests must not log errors, tests which are expected # to log errors should be named *.error.cf or *.error.pass.cf - if grep -E '^ *error: ' $OUTFILE > /dev/null + if [ $TEST_TYPE = errorpass ] + then + if grep -F 'error: ' "$OUTFILE" > /dev/null + then + RESULT=Pass + RESULT_MSG="${COLOR_SUCCESS}Pass${COLOR_NORMAL}" + else + RESULT=FAIL + RESULT_MSG="${COLOR_FAILURE}FAIL (No error message!)${COLOR_NORMAL}" + fi + elif grep -E '^ *error: ' $OUTFILE > /dev/null then RESULT=FAIL RESULT_MSG="${COLOR_FAILURE}FAIL (Error printed)${COLOR_NORMAL}" From 4cb9088142a6dc73e823925cfbd851dbd2124b7c Mon Sep 17 00:00:00 2001 From: Nick Anderson Date: Tue, 27 Oct 2026 21:34:20 -0500 Subject: [PATCH 20/39] Fixed diff_mode_ownership.cf logging errors Ticket: CFE-3041 Signed-off-by: Nick Anderson --- tests/acceptance/29_simulate_mode/diff_mode_ownership.cf | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/acceptance/29_simulate_mode/diff_mode_ownership.cf b/tests/acceptance/29_simulate_mode/diff_mode_ownership.cf index 2fcde3b7ab2..80fb53de40c 100644 --- a/tests/acceptance/29_simulate_mode/diff_mode_ownership.cf +++ b/tests/acceptance/29_simulate_mode/diff_mode_ownership.cf @@ -36,7 +36,9 @@ bundle agent test bundle agent check { vars: - "actual" string => readfile("$(this.promise_filename).actual", inf); + "actual" + string => readfile("$(this.promise_filename).actual", inf), + if => fileexists("$(this.promise_filename).actual"); classes: "has_owner_change" From bb0b18f9f1f1bda80754c8d72c2005cb14d8cf8f Mon Sep 17 00:00:00 2001 From: Dhanraj E Date: Sun, 18 Oct 2026 20:10:29 +0530 Subject: [PATCH 21/39] fix stack buffer overflow in SaveAsFile backup path construction Signed-off-by: Dhanraj E --- libpromises/files_operators.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/libpromises/files_operators.c b/libpromises/files_operators.c index d450b8a7e50..2c7432d12fd 100644 --- a/libpromises/files_operators.c +++ b/libpromises/files_operators.c @@ -209,18 +209,31 @@ bool SaveAsFile(EvalContext *ctx, SaveCallbackFn callback, void *param, const ch } } - strcpy(backup, BufferData(deref_file)); + const char *deref = BufferData(deref_file); + + strlcpy(backup, deref, sizeof(backup)); if (a->edits.backup == BACKUP_OPTION_TIMESTAMP) { snprintf(stamp, CF_BUFSIZE, "_%jd_%s", (intmax_t) CFSTARTTIME, CanonifyName(ctime(&stamp_now))); - strcat(backup, stamp); + strlcat(backup, stamp, sizeof(backup)); } - strcat(backup, ".cf-before-edit"); + if (strlcat(backup, ".cf-before-edit", sizeof(backup)) >= sizeof(backup)) + { + Log(LOG_LEVEL_ERR, + "Filename too long to create backup for editing: %s", + BufferData(pretty_file)); + goto end; + } - strcpy(new, BufferData(deref_file)); - strcat(new, ".cf-after-edit"); + if (strlcpy(new, deref, sizeof(new)) >= sizeof(new) || + strlcat(new, ".cf-after-edit", sizeof(new)) >= sizeof(new)) + { + Log(LOG_LEVEL_ERR, "Filename too long to edit: %s", + BufferData(pretty_file)); + goto end; + } unlink(new); /* Just in case of races */ if ((*callback)(new, param, new_line_mode) == false) From 72405c5c666e025021c906146929ead738f67cd8 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Thu, 29 Oct 2026 11:26:25 +0100 Subject: [PATCH 22/39] libpromises: Added empty package_module_wrapper.{c,h} Signed-off-by: Lars Erik Wik --- libpromises/Makefile.am | 1 + libpromises/package_module_wrapper.c | 25 +++++++++++++++++++++++++ libpromises/package_module_wrapper.h | 28 ++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 libpromises/package_module_wrapper.c create mode 100644 libpromises/package_module_wrapper.h diff --git a/libpromises/Makefile.am b/libpromises/Makefile.am index dc3fcf9dd77..99368a35df4 100644 --- a/libpromises/Makefile.am +++ b/libpromises/Makefile.am @@ -145,6 +145,7 @@ libpromises_la_SOURCES = \ parser_state.h \ patches.c \ pipes.h pipes.c \ + package_module_wrapper.c package_module_wrapper.h \ processes_select.c processes_select.h \ process_lib.h process_unix_priv.h \ promises.c promises.h \ diff --git a/libpromises/package_module_wrapper.c b/libpromises/package_module_wrapper.c new file mode 100644 index 00000000000..d3302eabd17 --- /dev/null +++ b/libpromises/package_module_wrapper.c @@ -0,0 +1,25 @@ +/* + Copyright 2026 Northern.tech AS + + This file is part of CFEngine 3 - written and maintained by Northern.tech AS. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; version 3. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + + To the extent this program is licensed as part of the Enterprise + versions of CFEngine, the applicable Commercial Open Source License + (COSL) may apply to this file if you as a licensee so wish it. See + included file COSL.txt. +*/ + +#include diff --git a/libpromises/package_module_wrapper.h b/libpromises/package_module_wrapper.h new file mode 100644 index 00000000000..a8fc96792dd --- /dev/null +++ b/libpromises/package_module_wrapper.h @@ -0,0 +1,28 @@ +/* + Copyright 2026 Northern.tech AS + + This file is part of CFEngine 3 - written and maintained by Northern.tech AS. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; version 3. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + + To the extent this program is licensed as part of the Enterprise + versions of CFEngine, the applicable Commercial Open Source License + (COSL) may apply to this file if you as a licensee so wish it. See + included file COSL.txt. +*/ + +#ifndef CFENGINE_PACKAGE_MODULE_WRAPPER_H +#define CFENGINE_PACKAGE_MODULE_WRAPPER_H + +#endif /* CFENGINE_PACKAGE_MODULE_WRAPPER_H */ From 28b3cc3b08162f975909d8362fc3dac6554bf1cb Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Thu, 29 Oct 2026 11:29:25 +0100 Subject: [PATCH 23/39] Moved package module wrapper code from cf-agent to libpromises Signed-off-by: Lars Erik Wik --- cf-agent/package_module.c | 213 -------------------------- cf-agent/package_module.h | 19 +-- libpromises/package_module_wrapper.c | 221 +++++++++++++++++++++++++++ libpromises/package_module_wrapper.h | 20 +++ 4 files changed, 242 insertions(+), 231 deletions(-) diff --git a/cf-agent/package_module.c b/cf-agent/package_module.c index 840483f71b9..200bf620f29 100644 --- a/cf-agent/package_module.c +++ b/cf-agent/package_module.c @@ -47,123 +47,6 @@ static bool UpdateSinglePackageModuleCache(EvalContext *ctx, const PackageModuleWrapper *module_wrapper, UpdateType type, bool force_update); -static void GetPackageModuleExecInfo(const PackageModuleBody *package_module, char **exec_path, - char **script_path, char **script_path_quoted, char **script_exec_opts); -static int NegotiateSupportedAPIVersion(PackageModuleWrapper *wrapper); - - -void DeletePackageModuleWrapper(PackageModuleWrapper *wrapper) -{ - if (wrapper != NULL) - { - free(wrapper->path); - free(wrapper->script_path); - free(wrapper->script_path_quoted); - free(wrapper->script_exec_opts); - free(wrapper->name); - free(wrapper); - } -} - -PackageModuleWrapper *NewPackageModuleWrapper(PackageModuleBody *package_module) -{ - assert(package_module && package_module->name); - - PackageModuleWrapper *wrapper = xmalloc(sizeof(PackageModuleWrapper)); - - GetPackageModuleExecInfo(package_module, &(wrapper->path), - &(wrapper->script_path), &(wrapper->script_path_quoted), - &(wrapper->script_exec_opts)); - wrapper->name = SafeStringDuplicate(package_module->name); - wrapper->package_module = package_module; - - if (wrapper->path == NULL) - { - Log(LOG_LEVEL_ERR, "No executable for the package module '%s'", package_module->name); - DeletePackageModuleWrapper(wrapper); - return NULL; - } - - /* Check if the given files exist and have the required permissions. */ - if (wrapper->script_path != NULL) - { - /* we were given a path to a script to execute with the given - * interpreter */ - const char *interpreter_path = wrapper->path; - const char *script_path = wrapper->script_path; - - if (access(interpreter_path, X_OK) != 0) - { - Log(LOG_LEVEL_ERR, - "Cannot find package module interpreter at location '%s'" - " or access to the file is restricted: %s", - wrapper->path, GetErrorStr()); - DeletePackageModuleWrapper(wrapper); - return NULL; - } - if (access(script_path, R_OK) != 0) - { - Log(LOG_LEVEL_ERR, - "Cannot find package module script at location '%s'" - " or access to the file is restricted: %s", - wrapper->script_path, GetErrorStr()); - DeletePackageModuleWrapper(wrapper); - return NULL; - } - } - else if (access(wrapper->path, X_OK) != 0) - { - /* no script path specified --> the given path has to be executable */ - Log(LOG_LEVEL_ERR, - "Cannot find package module at location '%s' or access to file is restricted: %s", - wrapper->path, GetErrorStr()); - DeletePackageModuleWrapper(wrapper); - return NULL; - } - - /* Negotiate API version */ - wrapper->supported_api_version = NegotiateSupportedAPIVersion(wrapper); - if (wrapper->supported_api_version != 1) - { - Log(LOG_LEVEL_ERR, - "Unsupported package module wrapper API version: %d", - wrapper->supported_api_version); - DeletePackageModuleWrapper(wrapper); - return NULL; - } - - Log(LOG_LEVEL_DEBUG, - "Successfully created package module wrapper for '%s' package module.", - package_module->name); - - return wrapper; -} - -static int PackageWrapperCommunicate(const PackageModuleWrapper *wrapper, const char *args, - const char *request, Rlist **response) -{ - char *all_args = NULL; - if (wrapper->script_path != NULL) - { - if (wrapper->script_exec_opts == NULL) - { - all_args = StringConcatenate(3, wrapper->script_path_quoted, " ", args); - args = all_args; - } - else - { - all_args = StringConcatenate(5, wrapper->script_exec_opts, " ", - wrapper->script_path_quoted, " ", args); - args = all_args; - } - } - int ret = PipeReadWriteData(wrapper->path, args, request, response, - PACKAGE_PROMISE_SCRIPT_TIMEOUT_SEC, - PACKAGE_PROMISE_TERMINATION_CHECK_SEC); - free(all_args); - - return ret; -} void UpdatePackagesCache(EvalContext *ctx, bool force_update) { @@ -278,24 +161,6 @@ static void FreePackageInfo(PackageInfo *package_info) } } -static char *ParseOptions(Rlist *options) -{ - if (RlistIsNullList(options)) - { - return SafeStringDuplicate(""); - } - - Buffer *data = BufferNew(); - for (Rlist *rp = options; rp != NULL; rp = rp->next) - { - char *value = RlistScalarValue(rp); - BufferAppendString(data, "options="); - BufferAppendString(data, value); - BufferAppendString(data, "\n"); - } - return BufferClose(data); -} - static PackageInfo *ParseAndCheckPackageDataReply(const Rlist *data) { PackageInfo * package_data = xcalloc(1, sizeof(PackageInfo)); @@ -386,35 +251,6 @@ static PackageInfo *ParseAndCheckPackageDataReply(const Rlist *data) return package_data; } -static int NegotiateSupportedAPIVersion(PackageModuleWrapper *wrapper) -{ - assert(wrapper); - - Log(LOG_LEVEL_DEBUG, "Getting supported API version."); - - int api_version = -1; - - Rlist *response = NULL; - if (PackageWrapperCommunicate(wrapper, "supports-api-version", "", - &response) != 0) - { - Log(LOG_LEVEL_INFO, - "Error occurred while getting supported API version."); - return -1; - } - - if (response) - { - if (RlistLen(response) == 1) - { - api_version = atoi(RlistScalarValue(response)); - Log(LOG_LEVEL_DEBUG, "package wrapper API version: %d", api_version); - } - RlistDestroy(response); - } - return api_version; -} - /* IMPORTANT: this might not return all the data we need like version or architecture but package name MUST be known. */ static @@ -473,55 +309,6 @@ PackageInfo *GetPackageData(const char *name, const char *version, return package_data; } -static void GetPackageModuleExecInfo(const PackageModuleBody *package_module, char **exec_path, - char **script_path, char **script_path_quoted, - char **script_exec_opts) -{ - - assert(exec_path != NULL); - assert(script_path != NULL); - assert(script_path_quoted != NULL); - - char *package_module_path = NULL; - - if (package_module->module_path != NULL && !StringEqual(package_module->module_path, "")) - { - package_module_path = xstrdup(package_module->module_path); - } - else - { - package_module_path = StringFormat("%s%c%s%c%s%c%s", GetWorkDir(), FILE_SEPARATOR, - "modules", FILE_SEPARATOR, "packages", FILE_SEPARATOR, - package_module->name); - } - - if (package_module->interpreter && !StringEqual(package_module->interpreter, "")) - { - *script_path = package_module_path; - *script_path_quoted = Path_GetQuoted(*script_path); - - if (strchr(package_module->interpreter, ' ') == NULL) - { - /* No spaces in the 'interpreter' string, easy! Just interpreter path given, no opts. */ - *exec_path = xstrdup(package_module->interpreter); - *script_exec_opts = NULL; - } - else - { - /* we need to split the interpreter command from the (potential) - * interpreter args */ - ArgGetExecutableAndArgs(package_module->interpreter, exec_path, script_exec_opts); - } - } - else - { - *exec_path = package_module_path; - *script_path = NULL; - *script_path_quoted = NULL; - *script_exec_opts = NULL; - } -} - static int IsPackageInCache(EvalContext *ctx, const PackageModuleWrapper *module_wrapper, const char *name, const char *ver, const char *arch) diff --git a/cf-agent/package_module.h b/cf-agent/package_module.h index b8372c96984..8bb797d4a55 100644 --- a/cf-agent/package_module.h +++ b/cf-agent/package_module.h @@ -26,10 +26,7 @@ #define PACKAGE_MODULE_H #include - -//TODO: use promise expireafter instead -#define PACKAGE_PROMISE_SCRIPT_TIMEOUT_SEC 4 * 3600 /* 4 hours timeout */ -#define PACKAGE_PROMISE_TERMINATION_CHECK_SEC 1 +#include #define GLOBAL_PACKAGE_PROMISE_LOCK_NAME "new_packages_promise_lock" @@ -54,17 +51,6 @@ typedef struct char *message; } PackageError; -typedef struct -{ - char *name; - char *path; - char *script_path; - char *script_path_quoted; - char *script_exec_opts; - PackageModuleBody *package_module; - int supported_api_version; -} PackageModuleWrapper; - typedef struct { CfLock g_lock; @@ -88,9 +74,6 @@ PromiseResult HandleAbsentPromiseAction(EvalContext *ctx, void UpdatePackagesCache(EvalContext *ctx, bool force_update); -PackageModuleWrapper *NewPackageModuleWrapper(PackageModuleBody *package_module); -void DeletePackageModuleWrapper(PackageModuleWrapper *wrapper); - PackagePromiseGlobalLock AcquireGlobalPackagePromiseLock(EvalContext *ctx); void YieldGlobalPackagePromiseLock(PackagePromiseGlobalLock lock); diff --git a/libpromises/package_module_wrapper.c b/libpromises/package_module_wrapper.c index d3302eabd17..edb616eb7e0 100644 --- a/libpromises/package_module_wrapper.c +++ b/libpromises/package_module_wrapper.c @@ -23,3 +23,224 @@ */ #include +#include +#include +#include +#include +#include +#include +#include +#include + +static void GetPackageModuleExecInfo(const PackageModuleBody *package_module, char **exec_path, + char **script_path, char **script_path_quoted, char **script_exec_opts); +static int NegotiateSupportedAPIVersion(PackageModuleWrapper *wrapper); + +void DeletePackageModuleWrapper(PackageModuleWrapper *wrapper) +{ + if (wrapper != NULL) + { + free(wrapper->path); + free(wrapper->script_path); + free(wrapper->script_path_quoted); + free(wrapper->script_exec_opts); + free(wrapper->name); + free(wrapper); + } +} + +PackageModuleWrapper *NewPackageModuleWrapper(PackageModuleBody *package_module) +{ + assert(package_module && package_module->name); + + PackageModuleWrapper *wrapper = xmalloc(sizeof(PackageModuleWrapper)); + + GetPackageModuleExecInfo(package_module, &(wrapper->path), + &(wrapper->script_path), &(wrapper->script_path_quoted), + &(wrapper->script_exec_opts)); + wrapper->name = SafeStringDuplicate(package_module->name); + wrapper->package_module = package_module; + + if (wrapper->path == NULL) + { + Log(LOG_LEVEL_ERR, "No executable for the package module '%s'", package_module->name); + DeletePackageModuleWrapper(wrapper); + return NULL; + } + + /* Check if the given files exist and have the required permissions. */ + if (wrapper->script_path != NULL) + { + /* we were given a path to a script to execute with the given + * interpreter */ + const char *interpreter_path = wrapper->path; + const char *script_path = wrapper->script_path; + + if (access(interpreter_path, X_OK) != 0) + { + Log(LOG_LEVEL_ERR, + "Cannot find package module interpreter at location '%s'" + " or access to the file is restricted: %s", + wrapper->path, GetErrorStr()); + DeletePackageModuleWrapper(wrapper); + return NULL; + } + if (access(script_path, R_OK) != 0) + { + Log(LOG_LEVEL_ERR, + "Cannot find package module script at location '%s'" + " or access to the file is restricted: %s", + wrapper->script_path, GetErrorStr()); + DeletePackageModuleWrapper(wrapper); + return NULL; + } + } + else if (access(wrapper->path, X_OK) != 0) + { + /* no script path specified --> the given path has to be executable */ + Log(LOG_LEVEL_ERR, + "Cannot find package module at location '%s' or access to file is restricted: %s", + wrapper->path, GetErrorStr()); + DeletePackageModuleWrapper(wrapper); + return NULL; + } + + /* Negotiate API version */ + wrapper->supported_api_version = NegotiateSupportedAPIVersion(wrapper); + if (wrapper->supported_api_version != 1) + { + Log(LOG_LEVEL_ERR, + "Unsupported package module wrapper API version: %d", + wrapper->supported_api_version); + DeletePackageModuleWrapper(wrapper); + return NULL; + } + + Log(LOG_LEVEL_DEBUG, + "Successfully created package module wrapper for '%s' package module.", + package_module->name); + + return wrapper; +} + +static int PackageWrapperCommunicate(const PackageModuleWrapper *wrapper, const char *args, + const char *request, Rlist **response) +{ + char *all_args = NULL; + if (wrapper->script_path != NULL) + { + if (wrapper->script_exec_opts == NULL) + { + all_args = StringConcatenate(3, wrapper->script_path_quoted, " ", args); + args = all_args; + } + else + { + all_args = StringConcatenate(5, wrapper->script_exec_opts, " ", + wrapper->script_path_quoted, " ", args); + args = all_args; + } + } + int ret = PipeReadWriteData(wrapper->path, args, request, response, + PACKAGE_PROMISE_SCRIPT_TIMEOUT_SEC, + PACKAGE_PROMISE_TERMINATION_CHECK_SEC); + free(all_args); + + return ret; +} + +static char *ParseOptions(Rlist *options) +{ + if (RlistIsNullList(options)) + { + return SafeStringDuplicate(""); + } + + Buffer *data = BufferNew(); + for (Rlist *rp = options; rp != NULL; rp = rp->next) + { + char *value = RlistScalarValue(rp); + BufferAppendString(data, "options="); + BufferAppendString(data, value); + BufferAppendString(data, "\n"); + } + return BufferClose(data); +} + +static int NegotiateSupportedAPIVersion(PackageModuleWrapper *wrapper) +{ + assert(wrapper); + + Log(LOG_LEVEL_DEBUG, "Getting supported API version."); + + int api_version = -1; + + Rlist *response = NULL; + if (PackageWrapperCommunicate(wrapper, "supports-api-version", "", + &response) != 0) + { + Log(LOG_LEVEL_INFO, + "Error occurred while getting supported API version."); + return -1; + } + + if (response) + { + if (RlistLen(response) == 1) + { + api_version = atoi(RlistScalarValue(response)); + Log(LOG_LEVEL_DEBUG, "package wrapper API version: %d", api_version); + } + RlistDestroy(response); + } + return api_version; +} + +static void GetPackageModuleExecInfo(const PackageModuleBody *package_module, char **exec_path, + char **script_path, char **script_path_quoted, + char **script_exec_opts) +{ + + assert(exec_path != NULL); + assert(script_path != NULL); + assert(script_path_quoted != NULL); + + char *package_module_path = NULL; + + if (package_module->module_path != NULL && !StringEqual(package_module->module_path, "")) + { + package_module_path = xstrdup(package_module->module_path); + } + else + { + package_module_path = StringFormat("%s%c%s%c%s%c%s", GetWorkDir(), FILE_SEPARATOR, + "modules", FILE_SEPARATOR, "packages", FILE_SEPARATOR, + package_module->name); + } + + if (package_module->interpreter && !StringEqual(package_module->interpreter, "")) + { + *script_path = package_module_path; + *script_path_quoted = Path_GetQuoted(*script_path); + + if (strchr(package_module->interpreter, ' ') == NULL) + { + /* No spaces in the 'interpreter' string, easy! Just interpreter path given, no opts. */ + *exec_path = xstrdup(package_module->interpreter); + *script_exec_opts = NULL; + } + else + { + /* we need to split the interpreter command from the (potential) + * interpreter args */ + ArgGetExecutableAndArgs(package_module->interpreter, exec_path, script_exec_opts); + } + } + else + { + *exec_path = package_module_path; + *script_path = NULL; + *script_path_quoted = NULL; + *script_exec_opts = NULL; + } +} diff --git a/libpromises/package_module_wrapper.h b/libpromises/package_module_wrapper.h index a8fc96792dd..f36ae674c9f 100644 --- a/libpromises/package_module_wrapper.h +++ b/libpromises/package_module_wrapper.h @@ -25,4 +25,24 @@ #ifndef CFENGINE_PACKAGE_MODULE_WRAPPER_H #define CFENGINE_PACKAGE_MODULE_WRAPPER_H +#include + +//TODO: use promise expireafter instead +#define PACKAGE_PROMISE_SCRIPT_TIMEOUT_SEC 4 * 3600 /* 4 hours timeout */ +#define PACKAGE_PROMISE_TERMINATION_CHECK_SEC 1 + +typedef struct +{ + char *name; + char *path; + char *script_path; + char *script_path_quoted; + char *script_exec_opts; + PackageModuleBody *package_module; + int supported_api_version; +} PackageModuleWrapper; + +PackageModuleWrapper *NewPackageModuleWrapper(PackageModuleBody *package_module); +void DeletePackageModuleWrapper(PackageModuleWrapper *wrapper); + #endif /* CFENGINE_PACKAGE_MODULE_WRAPPER_H */ From 16ad8db67edf0435fd5637d772efabbf0399c13a Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Thu, 29 Oct 2026 11:32:03 +0100 Subject: [PATCH 24/39] package_module_wrapper.c: Made PackageWrapperCommunicate() and ParseOptions() public Signed-off-by: Lars Erik Wik --- libpromises/package_module_wrapper.c | 6 +++--- libpromises/package_module_wrapper.h | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/libpromises/package_module_wrapper.c b/libpromises/package_module_wrapper.c index edb616eb7e0..1db66f34616 100644 --- a/libpromises/package_module_wrapper.c +++ b/libpromises/package_module_wrapper.c @@ -123,8 +123,8 @@ PackageModuleWrapper *NewPackageModuleWrapper(PackageModuleBody *package_module) return wrapper; } -static int PackageWrapperCommunicate(const PackageModuleWrapper *wrapper, const char *args, - const char *request, Rlist **response) +int PackageWrapperCommunicate(const PackageModuleWrapper *wrapper, const char *args, + const char *request, Rlist **response) { char *all_args = NULL; if (wrapper->script_path != NULL) @@ -149,7 +149,7 @@ static int PackageWrapperCommunicate(const PackageModuleWrapper *wrapper, const return ret; } -static char *ParseOptions(Rlist *options) +char *ParseOptions(Rlist *options) { if (RlistIsNullList(options)) { diff --git a/libpromises/package_module_wrapper.h b/libpromises/package_module_wrapper.h index f36ae674c9f..c6d7903e253 100644 --- a/libpromises/package_module_wrapper.h +++ b/libpromises/package_module_wrapper.h @@ -44,5 +44,8 @@ typedef struct PackageModuleWrapper *NewPackageModuleWrapper(PackageModuleBody *package_module); void DeletePackageModuleWrapper(PackageModuleWrapper *wrapper); +int PackageWrapperCommunicate(const PackageModuleWrapper *wrapper, const char *args, + const char *request, Rlist **response); +char *ParseOptions(Rlist *options); #endif /* CFENGINE_PACKAGE_MODULE_WRAPPER_H */ From f871307719b37cafc5886fa85a1e281d5702041a Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Thu, 29 Oct 2026 11:38:38 +0100 Subject: [PATCH 25/39] package_module_wrapper.h: Added doc comments Signed-off-by: Lars Erik Wik --- libpromises/package_module_wrapper.h | 37 ++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/libpromises/package_module_wrapper.h b/libpromises/package_module_wrapper.h index c6d7903e253..5abdf92a201 100644 --- a/libpromises/package_module_wrapper.h +++ b/libpromises/package_module_wrapper.h @@ -42,10 +42,47 @@ typedef struct int supported_api_version; } PackageModuleWrapper; +/** + * @brief Creates a wrapper to run a package module. + * + * Runs the package module once, to negotiate the API version. + * + * @param package_module The package module body, not copied, so it must + * outlive the wrapper + * @return The new wrapper, to be destroyed with DeletePackageModuleWrapper(), + * or NULL if the package module can't be run or doesn't support API + * version 1 + */ PackageModuleWrapper *NewPackageModuleWrapper(PackageModuleBody *package_module); + +/** + * @brief Destroys a package module wrapper. + * + * @param wrapper The wrapper, may be NULL + */ void DeletePackageModuleWrapper(PackageModuleWrapper *wrapper); + +/** + * @brief Runs the package module with a request. + * + * @param wrapper The wrapper of the package module + * @param args The arguments of the package module, e.g. "list-installed" + * @param request The request, written to the stdin of the package module + * @param[out] response The lines of the stdout of the package module, only + * set on success + * @return 0 on success, -1 if the package module couldn't be run or exited + * with a non-zero code + */ int PackageWrapperCommunicate(const PackageModuleWrapper *wrapper, const char *args, const char *request, Rlist **response); + +/** + * @brief Formats the options of a package module as request lines. + * + * @param options The options, may be NULL + * @return One "options=VALUE" line per option, or an empty string if there + * are none. To be freed by the caller. + */ char *ParseOptions(Rlist *options); #endif /* CFENGINE_PACKAGE_MODULE_WRAPPER_H */ From 6bba782e497a70c6401c4e5610fe8cc02f41b62b Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Thu, 29 Oct 2026 11:40:13 +0100 Subject: [PATCH 26/39] Renamed ParseOptions() to PackageModuleFormatOptions() Signed-off-by: Lars Erik Wik --- cf-agent/package_module.c | 8 ++++---- libpromises/package_module_wrapper.c | 2 +- libpromises/package_module_wrapper.h | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cf-agent/package_module.c b/cf-agent/package_module.c index 200bf620f29..09adaa66308 100644 --- a/cf-agent/package_module.c +++ b/cf-agent/package_module.c @@ -262,7 +262,7 @@ PackageInfo *GetPackageData(const char *name, const char *version, Log(LOG_LEVEL_DEBUG, "Getting package '%s' data.", name); - char *options_str = ParseOptions(options); + char *options_str = PackageModuleFormatOptions(options); char *ver = version ? StringFormat("Version=%s\n", version) : NULL; char *arch = architecture ? @@ -567,7 +567,7 @@ bool UpdateCache(Rlist* options, const PackageModuleWrapper *wrapper, Log(LOG_LEVEL_DEBUG, "Updating cache: %d", type); - char *options_str = ParseOptions(options); + char *options_str = PackageModuleFormatOptions(options); Rlist *response = NULL; const char *req_type = NULL; @@ -667,7 +667,7 @@ PromiseResult RemovePackage(const char *name, Rlist* options, Log(LOG_LEVEL_DEBUG, "Removing package '%s'", name); - char *options_str = ParseOptions(options); + char *options_str = PackageModuleFormatOptions(options); char *ver = version ? StringFormat("Version=%s\n", version) : NULL; char *arch = architecture ? @@ -712,7 +712,7 @@ static PromiseResult InstallPackageGeneric(Rlist *options, type == PACKAGE_TYPE_FILE ? "file" : "repo", packages_list_formatted); - char *options_str = ParseOptions(options); + char *options_str = PackageModuleFormatOptions(options); char *request = StringFormat("%s%s", options_str, packages_list_formatted); PromiseResult res = PROMISE_RESULT_CHANGE; diff --git a/libpromises/package_module_wrapper.c b/libpromises/package_module_wrapper.c index 1db66f34616..389eb7a30c9 100644 --- a/libpromises/package_module_wrapper.c +++ b/libpromises/package_module_wrapper.c @@ -149,7 +149,7 @@ int PackageWrapperCommunicate(const PackageModuleWrapper *wrapper, const char *a return ret; } -char *ParseOptions(Rlist *options) +char *PackageModuleFormatOptions(Rlist *options) { if (RlistIsNullList(options)) { diff --git a/libpromises/package_module_wrapper.h b/libpromises/package_module_wrapper.h index 5abdf92a201..d6b58beeef3 100644 --- a/libpromises/package_module_wrapper.h +++ b/libpromises/package_module_wrapper.h @@ -83,6 +83,6 @@ int PackageWrapperCommunicate(const PackageModuleWrapper *wrapper, const char *a * @return One "options=VALUE" line per option, or an empty string if there * are none. To be freed by the caller. */ -char *ParseOptions(Rlist *options); +char *PackageModuleFormatOptions(Rlist *options); #endif /* CFENGINE_PACKAGE_MODULE_WRAPPER_H */ From eba270c863ec865461062411d5b6e4894b62c8b6 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Thu, 29 Oct 2026 11:42:11 +0100 Subject: [PATCH 27/39] Added timeout parameter to NewPackageModuleWrapper() Signed-off-by: Lars Erik Wik --- cf-agent/package_module.c | 3 ++- cf-agent/package_module.h | 3 +++ cf-agent/verify_new_packages.c | 3 ++- libpromises/package_module_wrapper.c | 6 ++++-- libpromises/package_module_wrapper.h | 7 ++++--- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/cf-agent/package_module.c b/cf-agent/package_module.c index 09adaa66308..a07ae0e905d 100644 --- a/cf-agent/package_module.c +++ b/cf-agent/package_module.c @@ -76,7 +76,8 @@ void UpdatePackagesCache(EvalContext *ctx, bool force_update) continue; } - PackageModuleWrapper *module_wrapper = NewPackageModuleWrapper(module); + PackageModuleWrapper *module_wrapper = + NewPackageModuleWrapper(module, PACKAGE_PROMISE_SCRIPT_TIMEOUT_SEC); if (!module_wrapper) { diff --git a/cf-agent/package_module.h b/cf-agent/package_module.h index 8bb797d4a55..bbae854a92a 100644 --- a/cf-agent/package_module.h +++ b/cf-agent/package_module.h @@ -28,6 +28,9 @@ #include #include +//TODO: use promise expireafter instead +#define PACKAGE_PROMISE_SCRIPT_TIMEOUT_SEC 4 * 3600 /* 4 hours timeout */ + #define GLOBAL_PACKAGE_PROMISE_LOCK_NAME "new_packages_promise_lock" typedef enum diff --git a/cf-agent/verify_new_packages.c b/cf-agent/verify_new_packages.c index 82985a40f9b..3dcd9a010e3 100644 --- a/cf-agent/verify_new_packages.c +++ b/cf-agent/verify_new_packages.c @@ -100,7 +100,8 @@ PromiseResult HandleNewPackagePromiseType(EvalContext *ctx, const Promise *pp, c } PackageModuleWrapper *package_module = - NewPackageModuleWrapper(a->new_packages.module_body); + NewPackageModuleWrapper(a->new_packages.module_body, + PACKAGE_PROMISE_SCRIPT_TIMEOUT_SEC); if (package_module == NULL) { diff --git a/libpromises/package_module_wrapper.c b/libpromises/package_module_wrapper.c index 389eb7a30c9..7dc4a68086d 100644 --- a/libpromises/package_module_wrapper.c +++ b/libpromises/package_module_wrapper.c @@ -49,7 +49,8 @@ void DeletePackageModuleWrapper(PackageModuleWrapper *wrapper) } } -PackageModuleWrapper *NewPackageModuleWrapper(PackageModuleBody *package_module) +PackageModuleWrapper *NewPackageModuleWrapper(PackageModuleBody *package_module, + int timeout_secs) { assert(package_module && package_module->name); @@ -60,6 +61,7 @@ PackageModuleWrapper *NewPackageModuleWrapper(PackageModuleBody *package_module) &(wrapper->script_exec_opts)); wrapper->name = SafeStringDuplicate(package_module->name); wrapper->package_module = package_module; + wrapper->timeout_secs = timeout_secs; if (wrapper->path == NULL) { @@ -142,7 +144,7 @@ int PackageWrapperCommunicate(const PackageModuleWrapper *wrapper, const char *a } } int ret = PipeReadWriteData(wrapper->path, args, request, response, - PACKAGE_PROMISE_SCRIPT_TIMEOUT_SEC, + wrapper->timeout_secs, PACKAGE_PROMISE_TERMINATION_CHECK_SEC); free(all_args); diff --git a/libpromises/package_module_wrapper.h b/libpromises/package_module_wrapper.h index d6b58beeef3..0a6b12f0aac 100644 --- a/libpromises/package_module_wrapper.h +++ b/libpromises/package_module_wrapper.h @@ -27,8 +27,6 @@ #include -//TODO: use promise expireafter instead -#define PACKAGE_PROMISE_SCRIPT_TIMEOUT_SEC 4 * 3600 /* 4 hours timeout */ #define PACKAGE_PROMISE_TERMINATION_CHECK_SEC 1 typedef struct @@ -40,6 +38,7 @@ typedef struct char *script_exec_opts; PackageModuleBody *package_module; int supported_api_version; + int timeout_secs; /**< Timeout of each run of the package module */ } PackageModuleWrapper; /** @@ -49,11 +48,13 @@ typedef struct * * @param package_module The package module body, not copied, so it must * outlive the wrapper + * @param timeout_secs The timeout of each run of the package module * @return The new wrapper, to be destroyed with DeletePackageModuleWrapper(), * or NULL if the package module can't be run or doesn't support API * version 1 */ -PackageModuleWrapper *NewPackageModuleWrapper(PackageModuleBody *package_module); +PackageModuleWrapper *NewPackageModuleWrapper(PackageModuleBody *package_module, + int timeout_secs); /** * @brief Destroys a package module wrapper. From 045402d1fe23f327fd2ffcafaa951eb7787722ca Mon Sep 17 00:00:00 2001 From: Victor Moene Date: Wed, 28 Oct 2026 16:12:38 +0100 Subject: [PATCH 28/39] Fixed cf-reactor users test failing when run as root The test promised the current user with policy "present" and expected the promise to be kept. For an existing user, "present" also means "not locked". When run as root, cf-reactor can read /etc/shadow, and if the account's password hash starts with '!' (as root's does on some systems), it is considered locked and gets unlocked. The promise was then repaired instead of kept, and the test modified the root account. As a normal user, /etc/shadow is unreadable, so the account was considered unlocked and the test passed. Instead, we modify the policy to always return "kept" Signed-off-by: Victor Moene --- tests/reactor/tests/02_then_bundles/005_users.cf | 16 ++++++++-------- tests/reactor/tests/02_then_bundles/005_users.sh | 3 --- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/tests/reactor/tests/02_then_bundles/005_users.cf b/tests/reactor/tests/02_then_bundles/005_users.cf index 29bbb8063fd..d696e8ecefe 100644 --- a/tests/reactor/tests/02_then_bundles/005_users.cf +++ b/tests/reactor/tests/02_then_bundles/005_users.cf @@ -15,12 +15,15 @@ body when deleted(file) file_deleted => "$(file)"; } -bundle reactor run_users(user) +bundle reactor run_users { users: - # the user running the test, so that it is kept without being root - "$(user)" - policy => "present", + # a user that doesn't exist, so that the promise is kept without changing + # anything, whether or not the test runs as root. An existing user with + # policy "present" is unlocked if its password is locked, which happens + # to root on some systems. + "cf-reactor-test-no-such-user" + policy => "absent", classes => then_outcome("users"); } @@ -29,13 +32,10 @@ bundle reactor test vars: "test" string => getenv("TESTFILE", 999); "events_file" string => getenv("EVENTS_FILE", 999); - "user" string => getenv("TEST_USER", 999); "promise_name" string => basename("$(this.promise_filename)", ".cf"); events: "$(promise_name)" when => deleted("$(test)"), - then => { - run_users("$(user)"), record_then_outcome("$(events_file)", "users") - }; + then => { run_users, record_then_outcome("$(events_file)", "users") }; } diff --git a/tests/reactor/tests/02_then_bundles/005_users.sh b/tests/reactor/tests/02_then_bundles/005_users.sh index 84c8a509110..9601df9f8dd 100644 --- a/tests/reactor/tests/02_then_bundles/005_users.sh +++ b/tests/reactor/tests/02_then_bundles/005_users.sh @@ -13,9 +13,6 @@ EVENTS_FILE="$WORKDIR/tmp/events" export TESTFILE EVENTS_FILE -TEST_USER=$(id -un) -export TEST_USER - touch "$TESTFILE" start_reactor "$POLICY_FILE" From 6c124767fef5db4c023e9182efc0ba9295cfd726 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Thu, 29 Oct 2026 11:56:22 +0100 Subject: [PATCH 29/39] package_module_wrapper.c: Added asserts for pointer arguments Signed-off-by: Lars Erik Wik --- libpromises/package_module_wrapper.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libpromises/package_module_wrapper.c b/libpromises/package_module_wrapper.c index 7dc4a68086d..f288396bf9f 100644 --- a/libpromises/package_module_wrapper.c +++ b/libpromises/package_module_wrapper.c @@ -52,7 +52,8 @@ void DeletePackageModuleWrapper(PackageModuleWrapper *wrapper) PackageModuleWrapper *NewPackageModuleWrapper(PackageModuleBody *package_module, int timeout_secs) { - assert(package_module && package_module->name); + assert(package_module != NULL); + assert(package_module->name != NULL); PackageModuleWrapper *wrapper = xmalloc(sizeof(PackageModuleWrapper)); @@ -128,6 +129,8 @@ PackageModuleWrapper *NewPackageModuleWrapper(PackageModuleBody *package_module, int PackageWrapperCommunicate(const PackageModuleWrapper *wrapper, const char *args, const char *request, Rlist **response) { + assert(wrapper != NULL); + char *all_args = NULL; if (wrapper->script_path != NULL) { @@ -203,6 +206,7 @@ static void GetPackageModuleExecInfo(const PackageModuleBody *package_module, ch char **script_exec_opts) { + assert(package_module != NULL); assert(exec_path != NULL); assert(script_path != NULL); assert(script_path_quoted != NULL); From 9b841d11f2f3c5e61f17821dfee7126d7d491196 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Thu, 29 Oct 2026 12:44:30 +0100 Subject: [PATCH 30/39] cf-reactor: Passed EvalContext to watcher state constructors Signed-off-by: Lars Erik Wik --- cf-reactor/file_watcher.c | 4 ++-- cf-reactor/file_watcher.h | 4 ++-- cf-reactor/reactor_transform.c | 7 ++++--- cf-reactor/watcher.h | 5 ++++- tests/unit/file_watcher_test.c | 2 +- tests/unit/watcher_test.c | 2 +- 6 files changed, 14 insertions(+), 10 deletions(-) diff --git a/cf-reactor/file_watcher.c b/cf-reactor/file_watcher.c index b44730355ea..fa4f6d54809 100644 --- a/cf-reactor/file_watcher.c +++ b/cf-reactor/file_watcher.c @@ -82,7 +82,7 @@ typedef struct } FileWatcherState; -void *FileWatcherStateNew(const Rlist *args) +void *FileWatcherStateNew(ARG_UNUSED const EvalContext *ctx, const Rlist *args) { assert(args != NULL); const char *path = RlistScalarValue(args); @@ -93,7 +93,7 @@ void *FileWatcherStateNew(const Rlist *args) return fws; } -void *FileWatcherSizeStateNew(const Rlist *args) +void *FileWatcherSizeStateNew(ARG_UNUSED const EvalContext *ctx, const Rlist *args) { assert(args != NULL && args->next != NULL); const char *path = RlistScalarValue(args); diff --git a/cf-reactor/file_watcher.h b/cf-reactor/file_watcher.h index b184d3651f0..9c426883da7 100644 --- a/cf-reactor/file_watcher.h +++ b/cf-reactor/file_watcher.h @@ -29,8 +29,8 @@ #include /* WatcherCheckResult */ -void *FileWatcherStateNew(const Rlist *args); -void *FileWatcherSizeStateNew(const Rlist *args); +void *FileWatcherStateNew(const EvalContext *ctx, const Rlist *args); +void *FileWatcherSizeStateNew(const EvalContext *ctx, const Rlist *args); void FileWatcherStateDestroy(void *state); WatcherCheckResult FileWatcherCheckFileDeleted(void *state); diff --git a/cf-reactor/reactor_transform.c b/cf-reactor/reactor_transform.c index 565e5a1094f..7fe69c98360 100644 --- a/cf-reactor/reactor_transform.c +++ b/cf-reactor/reactor_transform.c @@ -264,8 +264,9 @@ static bool EventsPromiseGetInterval(const Promise *pp, time_t *interval) return true; } -static bool ResolveWhenBody(const Promise *pp, WatcherOptions *opt) +static bool ResolveWhenBody(const EvalContext *ctx, const Promise *pp, WatcherOptions *opt) { + assert(ctx != NULL); assert(pp != NULL); assert(opt != NULL); // Get the event and its arg @@ -336,7 +337,7 @@ static bool ResolveWhenBody(const Promise *pp, WatcherOptions *opt) return false; } - opt->state = event->new_state(args); + opt->state = event->new_state(ctx, args); opt->check_callback = event->check; opt->destroy_state = event->destroy_state; RlistDestroy(args); @@ -364,7 +365,7 @@ static PromiseResult KeepEventsPromise(EvalContext *ctx, const Promise *pp) } WatcherOptions opt; - if (!ResolveWhenBody(pp, &opt)) + if (!ResolveWhenBody(ctx, pp, &opt)) { return PROMISE_RESULT_FAIL; } diff --git a/cf-reactor/watcher.h b/cf-reactor/watcher.h index bf12a91f63c..18991bc885d 100644 --- a/cf-reactor/watcher.h +++ b/cf-reactor/watcher.h @@ -35,7 +35,10 @@ typedef enum WATCHER_CHECK_ERROR, /* unable to tell whether the event happened */ } WatcherCheckResult; -typedef void *(*WatcherStateNewFn)(const Rlist *args); +/* Called on the main thread when the policy is evaluated. ctx must not be + * kept in the state: the EvalContext is not thread safe, so the watcher + * thread can't use it. */ +typedef void *(*WatcherStateNewFn)(const EvalContext *ctx, const Rlist *args); typedef WatcherCheckResult (*WatcherCheckFn)(void *state); typedef void (*WatcherStateDestroyFn)(void *state); diff --git a/tests/unit/file_watcher_test.c b/tests/unit/file_watcher_test.c index 51bdb0ccf4f..9ff463f88bb 100644 --- a/tests/unit/file_watcher_test.c +++ b/tests/unit/file_watcher_test.c @@ -28,7 +28,7 @@ static void *NewFileDeletedState(const char *path) { Rlist *args = NULL; RlistAppendScalar(&args, path); - void *state = FileWatcherStateNew(args); + void *state = FileWatcherStateNew(NULL, args); RlistDestroy(args); return state; } diff --git a/tests/unit/watcher_test.c b/tests/unit/watcher_test.c index c297793698f..b74308b8901 100644 --- a/tests/unit/watcher_test.c +++ b/tests/unit/watcher_test.c @@ -30,7 +30,7 @@ static WatcherOptions *FileDeletedOptions(const char *path, time_t interval) Rlist *args = NULL; RlistAppendScalar(&args, path); opt = (WatcherOptions) { - .state = FileWatcherStateNew(args), + .state = FileWatcherStateNew(NULL, args), .check_callback = FileWatcherCheckFileDeleted, .destroy_state = FileWatcherStateDestroy, .interval = interval, From 00b2d52b03c9601965f0ea98914df173704e23ae Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Thu, 29 Oct 2026 12:58:49 +0100 Subject: [PATCH 31/39] reactor_transform.c: Added optional extra args to event types Signed-off-by: Lars Erik Wik --- cf-reactor/reactor_transform.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/cf-reactor/reactor_transform.c b/cf-reactor/reactor_transform.c index 7fe69c98360..3b360b2da4e 100644 --- a/cf-reactor/reactor_transform.c +++ b/cf-reactor/reactor_transform.c @@ -132,11 +132,13 @@ static const Rlist *GetThenBundles(const Promise *pp) /*****************************************************************************/ /* A constraint of the 'when' body passed to the watcher of an event, with the - * type of value it accepts */ + * type of value it accepts. An absent optional constraint isn't passed, so + * optional ones must come after the required ones. */ typedef struct { const char *name; RvalType type; + bool optional; } EventArg; typedef struct @@ -151,13 +153,13 @@ typedef struct static const EventArg NO_EXTRA_ARGS[] = { - { NULL, RVAL_TYPE_NOPROMISEE } + { NULL, RVAL_TYPE_NOPROMISEE, false } }; static const EventArg FILE_SIZE_EXCEEDS_ARGS[] = { - { REACTOR_SIZE_THRESHOLD, RVAL_TYPE_SCALAR }, - { NULL, RVAL_TYPE_NOPROMISEE } + { REACTOR_SIZE_THRESHOLD, RVAL_TYPE_SCALAR, false }, + { NULL, RVAL_TYPE_NOPROMISEE, false } }; #define EventTypeNew(name, type, args, new_state, destroy_state, check) \ @@ -280,9 +282,20 @@ static bool ResolveWhenBody(const EvalContext *ctx, const Promise *pp, WatcherOp } // If the event has additional args, add them to the list of args + NDEBUG_UNUSED bool seen_optional = false; for (const EventArg *extra_arg = event->extra_args; extra_arg->name != NULL; extra_arg++) { + /* The state constructors read args by position. So optional args + * must come last: an absent one then only shortens the list, instead + * of shifting the args after it. */ + assert(!seen_optional || extra_arg->optional); + seen_optional = seen_optional || extra_arg->optional; + const Constraint *con = PromiseGetConstraint(pp, extra_arg->name); + if (con == NULL && extra_arg->optional) + { + continue; + } if (con == NULL) { Log(LOG_LEVEL_ERR, From 92f7d8f59204ee89cfb88597f51042b80d208fa0 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Thu, 29 Oct 2026 13:02:35 +0100 Subject: [PATCH 32/39] reactor_transform.c: Now fails events promise if watcher state can't be created Signed-off-by: Lars Erik Wik --- cf-reactor/reactor_transform.c | 7 ++++++- cf-reactor/watcher.h | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/cf-reactor/reactor_transform.c b/cf-reactor/reactor_transform.c index 3b360b2da4e..23650035ef8 100644 --- a/cf-reactor/reactor_transform.c +++ b/cf-reactor/reactor_transform.c @@ -351,9 +351,14 @@ static bool ResolveWhenBody(const EvalContext *ctx, const Promise *pp, WatcherOp } opt->state = event->new_state(ctx, args); + RlistDestroy(args); + if (opt->state == NULL) + { + /* The state constructor logs why */ + return false; + } opt->check_callback = event->check; opt->destroy_state = event->destroy_state; - RlistDestroy(args); return true; } diff --git a/cf-reactor/watcher.h b/cf-reactor/watcher.h index 18991bc885d..46f1ef6c137 100644 --- a/cf-reactor/watcher.h +++ b/cf-reactor/watcher.h @@ -37,7 +37,8 @@ typedef enum /* Called on the main thread when the policy is evaluated. ctx must not be * kept in the state: the EvalContext is not thread safe, so the watcher - * thread can't use it. */ + * thread can't use it. Returns NULL, after logging why, if the state can't + * be created. */ typedef void *(*WatcherStateNewFn)(const EvalContext *ctx, const Rlist *args); typedef WatcherCheckResult (*WatcherCheckFn)(void *state); typedef void (*WatcherStateDestroyFn)(void *state); From cc474c0e29a4036607203422d4051566955c4516 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Thu, 29 Oct 2026 14:11:14 +0100 Subject: [PATCH 33/39] Moved FreePackageManager() from eval_context.c to package_module_wrapper.c Signed-off-by: Lars Erik Wik --- libpromises/eval_context.c | 12 ------------ libpromises/package_module_wrapper.c | 12 ++++++++++++ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/libpromises/eval_context.c b/libpromises/eval_context.c index 0acf39b326f..5333fa7589b 100644 --- a/libpromises/eval_context.c +++ b/libpromises/eval_context.c @@ -1149,18 +1149,6 @@ static void StackFrameDestroy(StackFrame *frame) } } -static -void FreePackageManager(PackageModuleBody *manager) -{ - assert(manager != NULL); - - free(manager->name); - free(manager->interpreter); - free(manager->module_path); - RlistDestroy(manager->options); - free(manager); -} - static PackagePromiseContext *PackagePromiseConfigNew() { diff --git a/libpromises/package_module_wrapper.c b/libpromises/package_module_wrapper.c index f288396bf9f..06fbc641e1d 100644 --- a/libpromises/package_module_wrapper.c +++ b/libpromises/package_module_wrapper.c @@ -250,3 +250,15 @@ static void GetPackageModuleExecInfo(const PackageModuleBody *package_module, ch *script_exec_opts = NULL; } } + +static +void FreePackageManager(PackageModuleBody *manager) +{ + assert(manager != NULL); + + free(manager->name); + free(manager->interpreter); + free(manager->module_path); + RlistDestroy(manager->options); + free(manager); +} From 073fd6da537e9515cc2beda64e530dea50dd1a1d Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Thu, 29 Oct 2026 14:11:41 +0100 Subject: [PATCH 34/39] package_module_wrapper.c: Made FreePackageManager() public Signed-off-by: Lars Erik Wik --- libpromises/eval_context.c | 1 + libpromises/package_module_wrapper.c | 1 - libpromises/package_module_wrapper.h | 2 ++ 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/libpromises/eval_context.c b/libpromises/eval_context.c index 5333fa7589b..e0fab116b48 100644 --- a/libpromises/eval_context.c +++ b/libpromises/eval_context.c @@ -51,6 +51,7 @@ #include #include /* DataTypeIsIterable */ #include +#include /* If we need to put a scoped variable into a special scope, use the string * below to replace the original scope separator. diff --git a/libpromises/package_module_wrapper.c b/libpromises/package_module_wrapper.c index 06fbc641e1d..86599f189fb 100644 --- a/libpromises/package_module_wrapper.c +++ b/libpromises/package_module_wrapper.c @@ -251,7 +251,6 @@ static void GetPackageModuleExecInfo(const PackageModuleBody *package_module, ch } } -static void FreePackageManager(PackageModuleBody *manager) { assert(manager != NULL); diff --git a/libpromises/package_module_wrapper.h b/libpromises/package_module_wrapper.h index 0a6b12f0aac..71fc18cd3f8 100644 --- a/libpromises/package_module_wrapper.h +++ b/libpromises/package_module_wrapper.h @@ -86,4 +86,6 @@ int PackageWrapperCommunicate(const PackageModuleWrapper *wrapper, const char *a */ char *PackageModuleFormatOptions(Rlist *options); +void FreePackageManager(PackageModuleBody *manager); + #endif /* CFENGINE_PACKAGE_MODULE_WRAPPER_H */ From ca1ff8ee8473db521fd58b04b3a1fa9c035ef347 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Thu, 29 Oct 2026 14:12:05 +0100 Subject: [PATCH 35/39] Renamed FreePackageManager() to PackageModuleBodyDestroy() Signed-off-by: Lars Erik Wik --- libpromises/eval_context.c | 2 +- libpromises/package_module_wrapper.c | 2 +- libpromises/package_module_wrapper.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libpromises/eval_context.c b/libpromises/eval_context.c index e0fab116b48..b2e2bb701e1 100644 --- a/libpromises/eval_context.c +++ b/libpromises/eval_context.c @@ -1158,7 +1158,7 @@ PackagePromiseContext *PackagePromiseConfigNew() package_promise_defaults->control_package_module = NULL; package_promise_defaults->control_package_inventory = NULL; package_promise_defaults->package_modules_bodies = - SeqNew(5, FreePackageManager); + SeqNew(5, PackageModuleBodyDestroy); return package_promise_defaults; } diff --git a/libpromises/package_module_wrapper.c b/libpromises/package_module_wrapper.c index 86599f189fb..6fa7b28423b 100644 --- a/libpromises/package_module_wrapper.c +++ b/libpromises/package_module_wrapper.c @@ -251,7 +251,7 @@ static void GetPackageModuleExecInfo(const PackageModuleBody *package_module, ch } } -void FreePackageManager(PackageModuleBody *manager) +void PackageModuleBodyDestroy(PackageModuleBody *manager) { assert(manager != NULL); diff --git a/libpromises/package_module_wrapper.h b/libpromises/package_module_wrapper.h index 71fc18cd3f8..638eadcf274 100644 --- a/libpromises/package_module_wrapper.h +++ b/libpromises/package_module_wrapper.h @@ -86,6 +86,6 @@ int PackageWrapperCommunicate(const PackageModuleWrapper *wrapper, const char *a */ char *PackageModuleFormatOptions(Rlist *options); -void FreePackageManager(PackageModuleBody *manager); +void PackageModuleBodyDestroy(PackageModuleBody *manager); #endif /* CFENGINE_PACKAGE_MODULE_WRAPPER_H */ From 52782b0b8e55bf38d7b94b03c0aa7f386bc2397a Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Thu, 29 Oct 2026 14:12:29 +0100 Subject: [PATCH 36/39] package_module_wrapper.c: PackageModuleBodyDestroy() now accepts NULL Signed-off-by: Lars Erik Wik --- libpromises/package_module_wrapper.c | 15 ++++++++------- libpromises/package_module_wrapper.h | 5 +++++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/libpromises/package_module_wrapper.c b/libpromises/package_module_wrapper.c index 6fa7b28423b..267543ac101 100644 --- a/libpromises/package_module_wrapper.c +++ b/libpromises/package_module_wrapper.c @@ -253,11 +253,12 @@ static void GetPackageModuleExecInfo(const PackageModuleBody *package_module, ch void PackageModuleBodyDestroy(PackageModuleBody *manager) { - assert(manager != NULL); - - free(manager->name); - free(manager->interpreter); - free(manager->module_path); - RlistDestroy(manager->options); - free(manager); + if (manager != NULL) + { + free(manager->name); + free(manager->interpreter); + free(manager->module_path); + RlistDestroy(manager->options); + free(manager); + } } diff --git a/libpromises/package_module_wrapper.h b/libpromises/package_module_wrapper.h index 638eadcf274..5f0950b8a4e 100644 --- a/libpromises/package_module_wrapper.h +++ b/libpromises/package_module_wrapper.h @@ -86,6 +86,11 @@ int PackageWrapperCommunicate(const PackageModuleWrapper *wrapper, const char *a */ char *PackageModuleFormatOptions(Rlist *options); +/** + * @brief Destroys a package module body. + * + * @param manager The package module body, may be NULL + */ void PackageModuleBodyDestroy(PackageModuleBody *manager); #endif /* CFENGINE_PACKAGE_MODULE_WRAPPER_H */ From f381917a1a1176194a528b3278a4633c3a3cb740 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Thu, 29 Oct 2026 14:12:53 +0100 Subject: [PATCH 37/39] package_module_wrapper.c: Added PackageModuleBodyCopy() Signed-off-by: Lars Erik Wik --- libpromises/package_module_wrapper.c | 14 ++++++++++++++ libpromises/package_module_wrapper.h | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/libpromises/package_module_wrapper.c b/libpromises/package_module_wrapper.c index 267543ac101..cb94a54a221 100644 --- a/libpromises/package_module_wrapper.c +++ b/libpromises/package_module_wrapper.c @@ -251,6 +251,20 @@ static void GetPackageModuleExecInfo(const PackageModuleBody *package_module, ch } } +PackageModuleBody *PackageModuleBodyCopy(const PackageModuleBody *manager) +{ + assert(manager != NULL); + + PackageModuleBody *copy = xmalloc(sizeof(PackageModuleBody)); + copy->name = SafeStringDuplicate(manager->name); + copy->updates_ifelapsed = manager->updates_ifelapsed; + copy->installed_ifelapsed = manager->installed_ifelapsed; + copy->options = RlistCopy(manager->options); + copy->interpreter = SafeStringDuplicate(manager->interpreter); + copy->module_path = SafeStringDuplicate(manager->module_path); + return copy; +} + void PackageModuleBodyDestroy(PackageModuleBody *manager) { if (manager != NULL) diff --git a/libpromises/package_module_wrapper.h b/libpromises/package_module_wrapper.h index 5f0950b8a4e..365acd650fa 100644 --- a/libpromises/package_module_wrapper.h +++ b/libpromises/package_module_wrapper.h @@ -86,6 +86,14 @@ int PackageWrapperCommunicate(const PackageModuleWrapper *wrapper, const char *a */ char *PackageModuleFormatOptions(Rlist *options); +/** + * @brief Copies a package module body. + * + * @param manager The package module body + * @return The copy, to be destroyed with PackageModuleBodyDestroy() + */ +PackageModuleBody *PackageModuleBodyCopy(const PackageModuleBody *manager); + /** * @brief Destroys a package module body. * From fc371747fd34dea4a2a5965b29d66a5376b23fa7 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Tue, 27 Oct 2026 14:54:44 +0100 Subject: [PATCH 38/39] cf-reactor: Added user_added and user_removed events Ticket: ENT-14765 Changelog: `cf-reactor` can now react to a user being added or removed, with the `user_added` and `user_removed` attributes of `when` bodies Signed-off-by: Lars Erik Wik --- .github/workflows/reactor_tests.yml | 2 +- cf-reactor/Makefile.am | 1 + cf-reactor/reactor_transform.c | 7 + cf-reactor/user_watcher.c | 286 ++++++++++++++++++ cf-reactor/user_watcher.h | 37 +++ libpromises/mod_reactor.c | 2 + libpromises/mod_reactor.h | 2 + .../01_event_types/unsafe/008_user_events.cf | 38 +++ .../01_event_types/unsafe/008_user_events.sh | 45 +++ tests/unit/Makefile.am | 3 + tests/unit/user_watcher_test.c | 252 +++++++++++++++ 11 files changed, 674 insertions(+), 1 deletion(-) create mode 100644 cf-reactor/user_watcher.c create mode 100644 cf-reactor/user_watcher.h create mode 100644 tests/reactor/tests/01_event_types/unsafe/008_user_events.cf create mode 100644 tests/reactor/tests/01_event_types/unsafe/008_user_events.sh create mode 100644 tests/unit/user_watcher_test.c diff --git a/.github/workflows/reactor_tests.yml b/.github/workflows/reactor_tests.yml index b182dbe6796..5c3e8779b03 100644 --- a/.github/workflows/reactor_tests.yml +++ b/.github/workflows/reactor_tests.yml @@ -22,4 +22,4 @@ jobs: ln -s "$PWD/cf-reactor/cf-reactor" "$PWD/cf-promises/cf-promises" "$RUNNER_TEMP/bin/" cd tests/reactor chmod -R go-w . - CF_BINDIR="$RUNNER_TEMP/bin" sh run.sh + CF_BINDIR="$RUNNER_TEMP/bin" sh run.sh --unsafe diff --git a/cf-reactor/Makefile.am b/cf-reactor/Makefile.am index 4036d272376..3c84df15546 100644 --- a/cf-reactor/Makefile.am +++ b/cf-reactor/Makefile.am @@ -45,6 +45,7 @@ libcf_reactor_la_SOURCES = \ reactor_context.c reactor_context.h \ reactor_transform.c reactor_transform.h \ stoppable_thread.c stoppable_thread.h \ + user_watcher.c user_watcher.h \ wakeup_channel.c wakeup_channel.h \ watcher.c watcher.h diff --git a/cf-reactor/reactor_transform.c b/cf-reactor/reactor_transform.c index 23650035ef8..451a68adf5c 100644 --- a/cf-reactor/reactor_transform.c +++ b/cf-reactor/reactor_transform.c @@ -42,6 +42,7 @@ #include // REACTOR_INTERVAL_RANGE, REACTOR_FILE_DELETED, REACTOR_*_TYPES, BundleIsReactorEventsBundle() #include // CheckConstraintTypeMatch(), PromiseTypeSyntaxGet(), BodySyntaxGetConstraintSyntax() #include +#include #include /* Resolves the agent, common or reactor bundle (looked up in that order) @@ -170,6 +171,10 @@ static const EventArg FILE_SIZE_EXCEEDS_ARGS[] = #define FileEventTypeNew(name, check) \ EventTypeNew(name, RVAL_TYPE_SCALAR, NO_EXTRA_ARGS, FileWatcherStateNew, FileWatcherStateDestroy, check) +/* A user event, about the user with the name of its constraint */ +#define UserEventTypeNew(name, check) \ + EventTypeNew(name, RVAL_TYPE_SCALAR, NO_EXTRA_ARGS, UserWatcherStateNew, UserWatcherStateDestroy, check) + static const EventType EVENT_TABLE[] = { FileEventTypeNew(REACTOR_FILE_DELETED, FileWatcherCheckFileDeleted), @@ -180,6 +185,8 @@ static const EventType EVENT_TABLE[] = FileEventTypeNew(REACTOR_FILE_OWNER_CHANGED, FileWatcherCheckFileOwnerChanged), EventTypeNew(REACTOR_FILE_SIZE_EXCEEDS, RVAL_TYPE_SCALAR, FILE_SIZE_EXCEEDS_ARGS, FileWatcherSizeStateNew, FileWatcherStateDestroy, FileWatcherCheckFileSizeExceeds), + UserEventTypeNew(REACTOR_USER_ADDED, UserWatcherCheckUserAdded), + UserEventTypeNew(REACTOR_USER_REMOVED, UserWatcherCheckUserRemoved), EventTypeNewNull() }; diff --git a/cf-reactor/user_watcher.c b/cf-reactor/user_watcher.c new file mode 100644 index 00000000000..083846a3be5 --- /dev/null +++ b/cf-reactor/user_watcher.c @@ -0,0 +1,286 @@ +/* + Copyright 2026 Northern.tech AS + + This file is part of CFEngine 3 - written and maintained by Northern.tech AS. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; version 3. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + + To the extent this program is licensed as part of the Enterprise + versions of CFEngine, the applicable Commercial Open Source License + (COSL) may apply to this file if you as a licensee so wish it. See + included file COSL.txt. +*/ + +#include +#include +#include +#include +#include +#include + +#ifdef __MINGW32__ +#include +#else +#include +#endif + +/* Minimum time between two logs of a persisting failure to look up the user, + * since the user is looked up on every poll */ +#define CHECK_ERROR_LOG_INTERVAL_SECS 60 + +typedef struct +{ + char *name; + time_t last_checked; /* Time of the last successful check, 0 if none yet */ + time_t + last_error_logged; /* Time the last error was logged, 0 if no errors */ + + /* What the last successful check observed */ + bool last_exists; +} UserWatcherState; + + +/** + * @brief Creates the state of a user_added or user_removed watcher. + * + * @param ctx Unused + * @param args The arguments of the event, the name of the user to watch + * @return The new state, to be destroyed with UserWatcherStateDestroy() + */ +void *UserWatcherStateNew(ARG_UNUSED const EvalContext *ctx, const Rlist *args) +{ + assert(args != NULL); + const char *name = RlistScalarValue(args); + + UserWatcherState *state = + (UserWatcherState *) xcalloc(1, sizeof(UserWatcherState)); + state->name = xstrdup(name); + + return state; +} + +/** + * @brief Destroys the state of a user watcher. + * + * @param state The watcher state, may be NULL + */ +void UserWatcherStateDestroy(void *_state) +{ + UserWatcherState *state = _state; + if (state != NULL) + { + free(state->name); + free(state); + } +} + +/** + * @brief Logs the error message of a failed operation performed by the + * watcher. + * + * A persisting failure is logged at most once every + * CHECK_ERROR_LOG_INTERVAL_SECS. + * + * @param state The watcher state + * @param operation The operation (e.g., LookupAccountName() or getpwnam_r()) + * @param err The error code (errno on Unix, Win32 error code on Windows) + */ +static void LogCheckError( + UserWatcherState *state, const char *operation, int err) +{ + assert(state != NULL); + + const time_t now = time(NULL); + if ((state->last_error_logged == 0) + || (now - state->last_error_logged >= CHECK_ERROR_LOG_INTERVAL_SECS)) + { + Log(LOG_LEVEL_ERR, + "Unable to look up user '%s' while checking for user events (%s: %s)", + state->name, + operation, + GetErrorStrFromCode(err)); + state->last_error_logged = now; + } +} + +/** + * @brief Checks whether the user of the watcher exists. + * + * Looks up the one name only, without listing all users, so it is safe to + * call while the main thread runs bundles. On Windows, only user accounts + * count, not groups or built-in accounts such as SYSTEM. + * + * @param state The watcher state + * @param[out] exists Whether user exists + * @return false on error + */ +static bool UserLookup(UserWatcherState *state, bool *exists) +{ + assert(state != NULL); + assert(exists != NULL); + +#ifdef __MINGW32__ + char sid[CF_MAXSIDSIZE]; + SID_NAME_USE type; + DWORD error = NovaWin_LookupAccountName( + state->name, (SID *) sid, sizeof(sid), &type); + if (error == ERROR_SUCCESS) + { + *exists = (type == SidTypeUser); + } + else if (NovaWin_IsAccountNotFound(error)) + { + *exists = false; + } + else + { + LogCheckError(state, "LookupAccountName", error); + return false; + } +#else + struct passwd pwd; + struct passwd *result = NULL; + char buf[GETPW_R_SIZE_MAX]; + int ret = getpwnam_r(state->name, &pwd, buf, sizeof(buf), &result); + if (result != NULL) + { + *exists = true; + } + else if (ret == 0) + { + /* POSIX: not found is a NULL result with a return value of 0. Any + * other return value is an error, so the user is not taken as + * removed on a failing lookup. */ + *exists = false; + } + else + { + LogCheckError(state, "getpwnam_r", ret); + return false; + } +#endif + + state->last_error_logged = 0; + return true; +} + +/** + * @brief Records the result of a successful check. + * + * The first successful check is only the reference for the next ones, so it + * never fires. + * + * @param state The watcher state + * @param exists Whether the user exists + * @param happened Whether the event happened since the last check + * @param event The name of the event for logging (e.g. "removal") + * @return WATCHER_CHECK_EVENT if the event fired, WATCHER_CHECK_NO_EVENT + * otherwise + */ +static WatcherCheckResult UserWatcherRecordObservation( + UserWatcherState *state, bool exists, bool happened, const char *event) +{ + assert(state != NULL); + assert(event != NULL); + + const time_t now = time(NULL); + happened = happened && (state->last_checked != 0); + + if (happened) + { + char last_checked_str[26]; + const char *last_checked_ts = + cf_strtimestamp_local(state->last_checked, last_checked_str); + + char now_str[26]; + const char *now_ts = cf_strtimestamp_local(now, now_str); + + Log(LOG_LEVEL_VERBOSE, + "Observed %s of user '%s' at %s (last checked at %s)", + event, + state->name, + (now_ts != NULL) ? now_ts : "unknown time", + (last_checked_ts != NULL) ? last_checked_ts : "unknown time"); + } + + state->last_checked = now; + state->last_exists = exists; + return happened ? WATCHER_CHECK_EVENT : WATCHER_CHECK_NO_EVENT; +} + +/** + * @brief Checks for the user_added event. + * + * Fires once when the user goes from absent to present. + * + * @param state The watcher state + * @return WATCHER_CHECK_EVENT if the user was added since the last check, + * WATCHER_CHECK_ERROR if the lookup failed, WATCHER_CHECK_NO_EVENT + * otherwise + */ +WatcherCheckResult UserWatcherCheckUserAdded(void *_state) +{ + assert(_state != NULL); + UserWatcherState *state = _state; + + bool exists; + if (!UserLookup(state, &exists)) + { + /* Unknown state, keep the last observation as is */ + return WATCHER_CHECK_ERROR; + } + + if (!exists && (state->last_exists || state->last_checked == 0)) + { + Log(LOG_LEVEL_VERBOSE, + "User '%s' is absent, watching for its addition", + state->name); + } + + bool added = !state->last_exists && exists; + return UserWatcherRecordObservation(state, exists, added, "addition"); +} + +/** + * @brief Checks for the user_removed event. + * + * Fires once when the user goes from present to absent. + * + * @param state The watcher state + * @return WATCHER_CHECK_EVENT if the user was removed since the last check, + * WATCHER_CHECK_ERROR if the lookup failed, WATCHER_CHECK_NO_EVENT + * otherwise + */ +WatcherCheckResult UserWatcherCheckUserRemoved(void *_state) +{ + assert(_state != NULL); + UserWatcherState *state = _state; + + bool exists; + if (!UserLookup(state, &exists)) + { + /* Unknown state, keep the last observation as is */ + return WATCHER_CHECK_ERROR; + } + + if (exists && !state->last_exists) + { + Log(LOG_LEVEL_VERBOSE, + "User '%s' is present, watching for its removal", + state->name); + } + + bool removed = state->last_exists && !exists; + return UserWatcherRecordObservation(state, exists, removed, "removal"); +} diff --git a/cf-reactor/user_watcher.h b/cf-reactor/user_watcher.h new file mode 100644 index 00000000000..5c0d92be277 --- /dev/null +++ b/cf-reactor/user_watcher.h @@ -0,0 +1,37 @@ +/* + Copyright 2026 Northern.tech AS + + This file is part of CFEngine 3 - written and maintained by Northern.tech AS. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; version 3. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + + To the extent this program is licensed as part of the Enterprise + versions of CFEngine, the applicable Commercial Open Source License + (COSL) may apply to this file if you as a licensee so wish it. See + included file COSL.txt. +*/ + +#ifndef CFENGINE_USER_WATCHER_H +#define CFENGINE_USER_WATCHER_H + +#include +#include + + +void *UserWatcherStateNew(const EvalContext *ctx, const Rlist *args); +WatcherCheckResult UserWatcherCheckUserAdded(void *state); +WatcherCheckResult UserWatcherCheckUserRemoved(void *state); +void UserWatcherStateDestroy(void *state); + +#endif diff --git a/libpromises/mod_reactor.c b/libpromises/mod_reactor.c index 4ad4b49f8a4..ea1f8c6b616 100644 --- a/libpromises/mod_reactor.c +++ b/libpromises/mod_reactor.c @@ -51,6 +51,8 @@ static const ConstraintSyntax when_constraints[] = ConstraintSyntaxNewString(REACTOR_FILE_OWNER_CHANGED, CF_ANYSTRING, "File to react for on change of its owning user or group", SYNTAX_STATUS_NORMAL), ConstraintSyntaxNewString(REACTOR_FILE_SIZE_EXCEEDS, CF_ANYSTRING, "File to react for when its size grows above '" REACTOR_SIZE_THRESHOLD "'", SYNTAX_STATUS_NORMAL), ConstraintSyntaxNewInt(REACTOR_SIZE_THRESHOLD, CF_VALRANGE, "Size in bytes above which '" REACTOR_FILE_SIZE_EXCEEDS "' fires", SYNTAX_STATUS_NORMAL), + ConstraintSyntaxNewString(REACTOR_USER_ADDED, CF_ANYSTRING, "User to react for on addition", SYNTAX_STATUS_NORMAL), + ConstraintSyntaxNewString(REACTOR_USER_REMOVED, CF_ANYSTRING, "User to react for on removal", SYNTAX_STATUS_NORMAL), ConstraintSyntaxNewInt("interval", REACTOR_INTERVAL_RANGE, "Seconds between two checks for the event", SYNTAX_STATUS_NORMAL), ConstraintSyntaxNewNull() }; diff --git a/libpromises/mod_reactor.h b/libpromises/mod_reactor.h index 839a72721bb..eeb5380a122 100644 --- a/libpromises/mod_reactor.h +++ b/libpromises/mod_reactor.h @@ -36,6 +36,8 @@ #define REACTOR_FILE_OWNER_CHANGED "file_owner_changed" #define REACTOR_FILE_SIZE_EXCEEDS "file_size_exceeds" #define REACTOR_SIZE_THRESHOLD "size_threshold" +#define REACTOR_USER_ADDED "user_added" +#define REACTOR_USER_REMOVED "user_removed" /* Range of the 'interval' attribute of the 'when' body of events promises */ #define REACTOR_INTERVAL_RANGE "1,99999999999" diff --git a/tests/reactor/tests/01_event_types/unsafe/008_user_events.cf b/tests/reactor/tests/01_event_types/unsafe/008_user_events.cf new file mode 100644 index 00000000000..3e2352168fa --- /dev/null +++ b/tests/reactor/tests/01_event_types/unsafe/008_user_events.cf @@ -0,0 +1,38 @@ +####################################################### +# +# Test the user_added and user_removed events +# +####################################################### +body common control +{ + inputs => { "../../../lib.cf" }; + bundlesequence => { "test" }; + version => "1.0"; +} + +body when added(user) +{ + user_added => "$(user)"; +} + +body when removed(user) +{ + user_removed => "$(user)"; +} + +bundle reactor test +{ + vars: + "test_user" string => getenv("TEST_USER", 999); + "events_file" string => getenv("EVENTS_FILE", 999); + "promise_name" string => basename("$(this.promise_filename)", ".cf"); + + events: + "$(promise_name)_added" + when => added("$(test_user)"), + then => record_event("$(events_file)", "added"); + + "$(promise_name)_removed" + when => removed("$(test_user)"), + then => record_event("$(events_file)", "removed"); +} diff --git a/tests/reactor/tests/01_event_types/unsafe/008_user_events.sh b/tests/reactor/tests/01_event_types/unsafe/008_user_events.sh new file mode 100644 index 00000000000..dd271c696e6 --- /dev/null +++ b/tests/reactor/tests/01_event_types/unsafe/008_user_events.sh @@ -0,0 +1,45 @@ +#!/bin/sh + +# check that user_added and user_removed fire once when a user is added and +# removed. Adds and removes a user with sudo. + +set -ex + +. "$(dirname "$0")/../../../lib.sh" + +POLICY_FILE="$1" + +TEST_USER="cfreactortest" +EVENTS_FILE="$WORKDIR/tmp/events" +export TEST_USER EVENTS_FILE + +# never touch an existing user +if id "$TEST_USER" >/dev/null 2>&1 +then + echo "User '$TEST_USER' already exists" >&2 + exit 1 +fi + +start_reactor "$POLICY_FILE" + +# replaces the trap of start_reactor +cleanup() { + stop_reactor + sudo userdel "$TEST_USER" 2>/dev/null || true +} +trap cleanup EXIT + +wait_for_watchers 2 + +# checked on registration +wait_for_log "User '$TEST_USER' is absent, watching for its addition" + +sudo useradd -M "$TEST_USER" +wait_for_lines "$EVENTS_FILE" 1 +check_event "$EVENTS_FILE" 1 "added" + +wait_for_log "User '$TEST_USER' is present, watching for its removal" + +sudo userdel "$TEST_USER" +wait_for_lines "$EVENTS_FILE" 2 +check_event "$EVENTS_FILE" 2 "removed" diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am index 42e9128a522..d5084bafb22 100644 --- a/tests/unit/Makefile.am +++ b/tests/unit/Makefile.am @@ -159,6 +159,7 @@ check_PROGRAMS = \ client_code_test \ watcher_test \ file_watcher_test \ + user_watcher_test \ stoppable_thread_test \ wakeup_channel_test @@ -241,6 +242,8 @@ watcher_test_SOURCES = watcher_test.c \ file_watcher_test_SOURCES = file_watcher_test.c \ ../../cf-reactor/file_watcher.c +user_watcher_test_SOURCES = user_watcher_test.c + stoppable_thread_test_SOURCES = stoppable_thread_test.c \ ../../cf-reactor/stoppable_thread.c diff --git a/tests/unit/user_watcher_test.c b/tests/unit/user_watcher_test.c new file mode 100644 index 00000000000..e57124e443f --- /dev/null +++ b/tests/unit/user_watcher_test.c @@ -0,0 +1,252 @@ +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +/* Unix only, like file_watcher_test. Tells what the lookup found from the + * verbose log of the first check, since the first check never fires. The + * .c file is included so that tests can fake an earlier check. */ + +#define ABSENT_USER "cfengine_user_watcher_test_absent" + +typedef struct +{ + LoggingPrivContext ctx; + LogLevel old_level; + int count; /* Number of VERBOSE messages captured */ + char message[256]; /* Last VERBOSE message captured */ +} LogCapture; + +static char *CaptureVerboseLogHook( + LoggingPrivContext *pctx, LogLevel level, const char *message) +{ + if (level == LOG_LEVEL_VERBOSE) + { + LogCapture *capture = pctx->param; + capture->count++; + strlcpy(capture->message, message, sizeof(capture->message)); + } + return (char *) message; +} + +/* Captures VERBOSE messages with the log hook. The global level is set to + * CRIT so they aren't printed. force_hook_level still runs the hook for + * them. Stop with StopCapture(), which frees the returned capture. */ +static LogCapture *StartCapture(void) +{ + LogCapture *capture = xcalloc(1, sizeof(LogCapture)); + capture->ctx.log_hook = CaptureVerboseLogHook; + capture->ctx.param = capture; + capture->ctx.force_hook_level = LOG_LEVEL_VERBOSE; + LoggingPrivSetContext(&capture->ctx); + capture->old_level = LogGetGlobalLevel(); + LogSetGlobalLevel(LOG_LEVEL_CRIT); + return capture; +} + +static void StopCapture(LogCapture *capture) +{ + LogSetGlobalLevel(capture->old_level); + LoggingPrivSetContext(NULL); + free(capture); +} + +/* Copies the name of the user running the test, which always exists, to + * name */ +static void GetPresentUser(char *name, size_t name_size) +{ + const struct passwd *pw = getpwuid(getuid()); + assert_true(pw != NULL); + strlcpy(name, pw->pw_name, name_size); +} + +/* Returns a new state of a user watcher of the user with the given name */ +static void *NewUserState(const char *name) +{ + Rlist *args = NULL; + RlistAppendScalar(&args, name); + void *state = UserWatcherStateNew(NULL, args); + RlistDestroy(args); + return state; +} + +static void test_check_user_removed_present(void) +{ + char name[256]; + GetPresentUser(name, sizeof(name)); + char expected[512]; + snprintf( + expected, + sizeof(expected), + "User '%s' is present, watching for its removal", + name); + + LogCapture *capture = StartCapture(); + void *state = NewUserState(name); + + /* The first check is the reference, so it doesn't fire */ + assert_int_equal( + UserWatcherCheckUserRemoved(state), WATCHER_CHECK_NO_EVENT); + assert_int_equal(capture->count, 1); + assert_string_equal(capture->message, expected); + + /* Still present: not removed, and not logged again */ + assert_int_equal( + UserWatcherCheckUserRemoved(state), WATCHER_CHECK_NO_EVENT); + assert_int_equal(capture->count, 1); + + UserWatcherStateDestroy(state); + StopCapture(capture); +} + +static void test_check_user_removed_absent(void) +{ + LogCapture *capture = StartCapture(); + void *state = NewUserState(ABSENT_USER); + + /* Absent, so nothing to watch for yet and nothing logged */ + assert_int_equal( + UserWatcherCheckUserRemoved(state), WATCHER_CHECK_NO_EVENT); + assert_int_equal( + UserWatcherCheckUserRemoved(state), WATCHER_CHECK_NO_EVENT); + assert_int_equal(capture->count, 0); + + UserWatcherStateDestroy(state); + StopCapture(capture); +} + +static void test_check_user_added_absent(void) +{ + LogCapture *capture = StartCapture(); + void *state = NewUserState(ABSENT_USER); + + /* The first check is the reference, so it doesn't fire */ + assert_int_equal(UserWatcherCheckUserAdded(state), WATCHER_CHECK_NO_EVENT); + assert_int_equal(capture->count, 1); + assert_string_equal( + capture->message, + "User '" ABSENT_USER "' is absent, watching for its addition"); + + /* Still absent: not added, and not logged again */ + assert_int_equal(UserWatcherCheckUserAdded(state), WATCHER_CHECK_NO_EVENT); + assert_int_equal(capture->count, 1); + + UserWatcherStateDestroy(state); + StopCapture(capture); +} + +static void test_check_user_added_present(void) +{ + char name[256]; + GetPresentUser(name, sizeof(name)); + + LogCapture *capture = StartCapture(); + void *state = NewUserState(name); + + /* Present, so nothing to watch for yet and nothing logged */ + assert_int_equal(UserWatcherCheckUserAdded(state), WATCHER_CHECK_NO_EVENT); + assert_int_equal(UserWatcherCheckUserAdded(state), WATCHER_CHECK_NO_EVENT); + assert_int_equal(capture->count, 0); + + UserWatcherStateDestroy(state); + StopCapture(capture); +} + +static void test_check_user_added_fires(void) +{ + char name[256]; + GetPresentUser(name, sizeof(name)); + char expected[512]; + snprintf( + expected, + sizeof(expected), + "Observed addition of user '%s' at ", + name); + + LogCapture *capture = StartCapture(); + UserWatcherState *state = NewUserState(name); + + /* Fake an earlier check that saw the user absent */ + state->last_checked = time(NULL); + state->last_exists = false; + + assert_int_equal(UserWatcherCheckUserAdded(state), WATCHER_CHECK_EVENT); + assert_int_equal(capture->count, 1); + assert_true(StringStartsWith(capture->message, expected)); + + /* Fires only once */ + assert_int_equal(UserWatcherCheckUserAdded(state), WATCHER_CHECK_NO_EVENT); + assert_int_equal(capture->count, 1); + + UserWatcherStateDestroy(state); + StopCapture(capture); +} + +static void test_check_user_removed_fires(void) +{ + LogCapture *capture = StartCapture(); + UserWatcherState *state = NewUserState(ABSENT_USER); + + /* Fake an earlier check that saw the user present */ + state->last_checked = time(NULL); + state->last_exists = true; + + assert_int_equal( + UserWatcherCheckUserRemoved(state), WATCHER_CHECK_EVENT); + assert_int_equal(capture->count, 1); + assert_true(StringStartsWith( + capture->message, + "Observed removal of user '" ABSENT_USER "' at ")); + + /* Fires only once */ + assert_int_equal( + UserWatcherCheckUserRemoved(state), WATCHER_CHECK_NO_EVENT); + assert_int_equal(capture->count, 1); + + UserWatcherStateDestroy(state); + StopCapture(capture); +} + +static void test_check_empty_name(void) +{ + LogCapture *capture = StartCapture(); + + /* An empty name is a user that doesn't exist, not a lookup error */ + void *state = NewUserState(""); + assert_int_equal(UserWatcherCheckUserAdded(state), WATCHER_CHECK_NO_EVENT); + assert_int_equal(capture->count, 1); + assert_string_equal( + capture->message, "User '' is absent, watching for its addition"); + UserWatcherStateDestroy(state); + + StopCapture(capture); +} + +static void test_state_destroy_null(void) +{ + UserWatcherStateDestroy(NULL); +} + +int main() +{ + PRINT_TEST_BANNER(); + const UnitTest tests[] = { + unit_test(test_check_user_removed_present), + unit_test(test_check_user_removed_absent), + unit_test(test_check_user_added_absent), + unit_test(test_check_user_added_present), + unit_test(test_check_user_added_fires), + unit_test(test_check_user_removed_fires), + unit_test(test_check_empty_name), + unit_test(test_state_destroy_null), + }; + + return run_tests(tests); +} From 671a1c4c9b2ed9931ecf168d090d1ce30b47d32a Mon Sep 17 00:00:00 2001 From: Daniel JB Clark Date: Sun, 1 Nov 2026 11:44:15 -0500 Subject: [PATCH 39/39] Fixed simulate mode rewriting relative symlink targets In simulate mode MakeLink() passed every link target through ToChangesChroot(). A relative target is resolved against the link, which is already inside the chroot, so the link was created pointing at an absolute path under the chroot and the manifest reported 'Target: /x' instead of the 'x' written in the policy. Only absolute targets are now mapped into the chroot. Changelog: Title Ticket: none Signed-off-by: Daniel JB Clark --- libpromises/files_links.c | 4 +- .../symlink_relative_target.cf | 38 +++++++++++++++++++ .../symlink_relative_target.cf.sub | 14 +++++++ 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 tests/acceptance/29_simulate_mode/symlink_relative_target.cf create mode 100644 tests/acceptance/29_simulate_mode/symlink_relative_target.cf.sub diff --git a/libpromises/files_links.c b/libpromises/files_links.c index eda0be116b9..2657e620990 100644 --- a/libpromises/files_links.c +++ b/libpromises/files_links.c @@ -575,7 +575,9 @@ static bool MakeLink(EvalContext *ctx, const char *from, const char *to, const A { const char *changes_to = to; char *chroot_to = NULL; - if (ChrootChanges()) + /* A relative target is resolved relative to the link, which is + * already in the chroot, so it must be kept relative. */ + if (ChrootChanges() && IsAbsoluteFileName(to)) { /* Create a copy because the next call to ToChangesChroot() will * overwrite the value. */ diff --git a/tests/acceptance/29_simulate_mode/symlink_relative_target.cf b/tests/acceptance/29_simulate_mode/symlink_relative_target.cf new file mode 100644 index 00000000000..e5db17a4838 --- /dev/null +++ b/tests/acceptance/29_simulate_mode/symlink_relative_target.cf @@ -0,0 +1,38 @@ +body common control +{ + inputs => { "../default.sub.cf" }; + bundlesequence => { default("$(this.promise_filename)") }; + version => "1.0"; +} + +bundle agent test +{ + meta: + "test_soft_fail" + string => "(solaris|aix|hpux|windows)", + # ENT-6540 exotics fail to delete chroot + # ENT-10254 tests fail on Windows due to CRLF + meta => { "ENT-6540", "ENT-10254" }; + + "description" + string => "Test that --simulate=manifest shows a relative symlink target as written in the policy, not as an absolute path"; +} + +bundle agent check +{ + vars: + "command" + string => "$(sys.cf_agent) -Kf $(this.promise_filename).sub --simulate=manifest 2>&1"; + + "wanted" + string => ".*\Q'$(G.testroot)/relative-link' is a symbolic link\E\n(?:[^\n]*\n){0,7}\QTarget: 'relative-target'\E.*"; + + methods: + "check" + usebundle => dcs_passif_output( + $(wanted), + ".*Target: '/.*", + $(command), + $(this.promise_filename) + ); +} diff --git a/tests/acceptance/29_simulate_mode/symlink_relative_target.cf.sub b/tests/acceptance/29_simulate_mode/symlink_relative_target.cf.sub new file mode 100644 index 00000000000..961f69c3c9d --- /dev/null +++ b/tests/acceptance/29_simulate_mode/symlink_relative_target.cf.sub @@ -0,0 +1,14 @@ +body common control +{ + inputs => { "../default.sub.cf" }; +} + +bundle agent main +{ + files: + "$(G.testroot)/relative-target" + create => "true"; + + "$(G.testroot)/relative-link" + link_from => linkfrom("relative-target", "symlink"); +}