From 53ae7d351798bafd07dcc93b3edbf4b002e07dd2 Mon Sep 17 00:00:00 2001 From: Dhanraj E Date: Sat, 17 Oct 2026 17:51:17 +0530 Subject: [PATCH 01/70] Made format() reject specifiers that read unpassed printf arguments FnCallFormat() hands each format piece straight to snprintf() or BufferAppendF() with exactly one argument. The modifier denylist ("hLqjzt") lets through '*', which takes a width or precision from the argument list, and '$', which selects a positional argument, so format("%*d", 7) prints whatever is in the next vararg slot and format("%2$s", "a") or format("%*s", "a") dereference a slot that was never passed as a char *. 'l' on %s/%S makes printf read the char * argument as a wchar_t *, 4 bytes per character past the end of the string. The format argument is expanded before the function runs, so a variable interpolated into it (file contents, module output, data container values) can carry such a specifier. Changelog: Title Signed-off-by: Dhanraj E --- libpromises/evalfunction.c | 15 ++++++++++++++- tests/unit/evalfunction_test.c | 35 ++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/libpromises/evalfunction.c b/libpromises/evalfunction.c index 7707b18d0cb..35d39404dc1 100644 --- a/libpromises/evalfunction.c +++ b/libpromises/evalfunction.c @@ -6302,7 +6302,8 @@ static FnCallResult FnCallFormat(EvalContext *ctx, ARG_UNUSED const Policy *poli char piece[CF_BUFSIZE]; memset(piece, 0, CF_BUFSIZE); - const char bad_modifiers[] = "hLqjzt"; + /* '*' and '$' make printf fetch arguments we never pass */ + const char bad_modifiers[] = "hLqjzt*$"; const size_t length = strlen(bad_modifiers); for (size_t b = 0; b < length; b++) { @@ -6317,6 +6318,18 @@ static FnCallResult FnCallFormat(EvalContext *ctx, ARG_UNUSED const Policy *poli } } + /* "%ls" would read the char * argument as wchar_t * */ + if (strchr(format_piece, 'l') != NULL && + (strrchr(format_piece, 's') != NULL || + strrchr(format_piece, 'S') != NULL)) + { + Log(LOG_LEVEL_ERR, "format() does not allow modifier character 'l' in format specifier '%s'.", + format_piece); + BufferDestroy(buf); + SeqDestroy(s); + return FnFailure(); + } + if (strrchr(format_piece, 'd') != NULL || strrchr(format_piece, 'o') != NULL || strrchr(format_piece, 'x') != NULL) { long x = 0; diff --git a/tests/unit/evalfunction_test.c b/tests/unit/evalfunction_test.c index 32f004b8bb9..fcfd2f18a53 100644 --- a/tests/unit/evalfunction_test.c +++ b/tests/unit/evalfunction_test.c @@ -180,6 +180,40 @@ static void test_module_protocol_percent_no_delimiter(void) EvalContextDestroy(ctx); } +static FnCallResult format_single_testcase(const char *format, const char *arg) +{ + Rlist *args = NULL; + RlistAppendScalar(&args, format); + RlistAppendScalar(&args, arg); + FnCall *call = FnCallNew("format", args); + + FnCallResult res = FnCallFormat(NULL, NULL, call, args); + + FnCallDestroy(call); + return res; +} + +static void test_format_rejects_unpassed_arguments(void) +{ + FnCallResult res = format_single_testcase("%04d", "100"); + assert_int_equal(res.status, FNCALL_SUCCESS); + assert_string_equal("0100", (char *) res.rval.item); + RvalDestroy(res.rval); + + res = format_single_testcase("%-6s|", "abc"); + assert_int_equal(res.status, FNCALL_SUCCESS); + assert_string_equal("abc |", (char *) res.rval.item); + RvalDestroy(res.rval); + + /* Each of these makes printf read an argument that is never passed. */ + const char *const bad[] = { "%*d", "%.*f", "%*s", "%2$s", "%1$*2$d", "%ls", "%lS" }; + for (size_t i = 0; i < sizeof(bad) / sizeof(bad[0]); i++) + { + res = format_single_testcase(bad[i], "7"); + assert_int_equal(res.status, FNCALL_FAILURE); + } +} + int main() { PRINT_TEST_BANNER(); @@ -188,6 +222,7 @@ int main() unit_test(test_hostinnetgroup_not_found), unit_test(test_basename), unit_test(test_module_protocol_percent_no_delimiter), + unit_test(test_format_rejects_unpassed_arguments), }; return run_tests(tests); From 800f183a1efd1354f3564273e01eabfd379ce452 Mon Sep 17 00:00:00 2001 From: Dhanraj E Date: Mon, 19 Oct 2026 17:22:18 +0530 Subject: [PATCH 02/70] Fixed stack buffer overflow in GetServerLiteral for TLS VAR requests GetServerLiteral() zeroed and formatted CF_BUFSIZE bytes into the sendbuffer it was handed, but BusyWithNewProtocol() allocates that buffer as CF_BUFSIZE - CF_INBAND_OFFSET bytes (the most a single transaction can carry). Any VAR request admitted by the literals ACL therefore wrote 8 bytes past the end of the handler's stack buffer. Pass the buffer size into GetServerLiteral(), as DoExec2() already does, and bound the writes to it. Both callers pass sizeof(sendbuffer). Changelog: Title Signed-off-by: Dhanraj E --- cf-serverd/server_classic.c | 2 +- cf-serverd/server_common.c | 10 +++---- cf-serverd/server_common.h | 2 +- cf-serverd/server_tls.c | 2 +- tests/unit/protocol_test.c | 54 ++++++++++++++++++++++++++++++++++++- 5 files changed, 61 insertions(+), 9 deletions(-) diff --git a/cf-serverd/server_classic.c b/cf-serverd/server_classic.c index 8fc439cb10b..3f05f32552a 100644 --- a/cf-serverd/server_classic.c +++ b/cf-serverd/server_classic.c @@ -1538,7 +1538,7 @@ bool BusyWithClassicConnection(EvalContext *ctx, ServerConnectionState *conn) return false; } - GetServerLiteral(ctx, conn, sendbuffer, recvbuffer, encrypted); + GetServerLiteral(ctx, conn, sendbuffer, sizeof(sendbuffer), recvbuffer, encrypted); return true; case PROTOCOL_COMMAND_CONTEXT_SECURE: diff --git a/cf-serverd/server_common.c b/cf-serverd/server_common.c index 3d26e8ecddf..fb4b0b28b22 100644 --- a/cf-serverd/server_common.c +++ b/cf-serverd/server_common.c @@ -925,7 +925,7 @@ bool CompareLocalHash(const char *filename, const unsigned char digest[EVP_MAX_M } } -void GetServerLiteral(EvalContext *ctx, ServerConnectionState *conn, char *sendbuffer, char *recvbuffer, int encrypted) +void GetServerLiteral(EvalContext *ctx, ServerConnectionState *conn, char *sendbuffer, size_t sendbuffer_size, char *recvbuffer, int encrypted) { char handle[CF_BUFSIZE], out[CF_BUFSIZE]; int cipherlen; @@ -934,13 +934,13 @@ void GetServerLiteral(EvalContext *ctx, ServerConnectionState *conn, char *sendb if (ReturnLiteralData(ctx, handle, out)) { - memset(sendbuffer, 0, CF_BUFSIZE); - snprintf(sendbuffer, CF_BUFSIZE, "%s", out); + memset(sendbuffer, 0, sendbuffer_size); + snprintf(sendbuffer, sendbuffer_size, "%s", out); } else { - memset(sendbuffer, 0, CF_BUFSIZE); - snprintf(sendbuffer, CF_BUFSIZE, "BAD: Not found"); + memset(sendbuffer, 0, sendbuffer_size); + snprintf(sendbuffer, sendbuffer_size, "BAD: Not found"); } if (encrypted) diff --git a/cf-serverd/server_common.h b/cf-serverd/server_common.h index 4e41925e0b7..ab764ef95d8 100644 --- a/cf-serverd/server_common.h +++ b/cf-serverd/server_common.h @@ -48,7 +48,7 @@ int StatFile(ServerConnectionState *conn, char *sendbuffer, char *ofilename); void ReplyServerContext(ServerConnectionState *conn, int encrypted, Item *classes); int CfOpenDirectory(ServerConnectionState *conn, char *sendbuffer, char *oldDirname); int CfSecOpenDirectory(ServerConnectionState *conn, char *sendbuffer, char *dirname); -void GetServerLiteral(EvalContext *ctx, ServerConnectionState *conn, char *sendbuffer, char *recvbuffer, int encrypted); +void GetServerLiteral(EvalContext *ctx, ServerConnectionState *conn, char *sendbuffer, size_t sendbuffer_size, char *recvbuffer, int encrypted); bool GetServerQuery(ServerConnectionState *conn, char *recvbuffer, int encrypted); bool CompareLocalHash(const char *filename, const unsigned char digest[EVP_MAX_MD_SIZE + 1], char sendbuffer[CFD_FALSE_SIZE]); diff --git a/cf-serverd/server_tls.c b/cf-serverd/server_tls.c index c89ad3b4ab3..cae1e3bda02 100644 --- a/cf-serverd/server_tls.c +++ b/cf-serverd/server_tls.c @@ -1003,7 +1003,7 @@ bool BusyWithNewProtocol(EvalContext *ctx, ServerConnectionState *conn) return true; } - GetServerLiteral(ctx, conn, sendbuffer, recvbuffer, encrypted); + GetServerLiteral(ctx, conn, sendbuffer, sizeof(sendbuffer), recvbuffer, encrypted); return true; } case PROTOCOL_COMMAND_CONTEXT: diff --git a/tests/unit/protocol_test.c b/tests/unit/protocol_test.c index 29b30d31a5d..39829e3a694 100644 --- a/tests/unit/protocol_test.c +++ b/tests/unit/protocol_test.c @@ -8,6 +8,13 @@ #include /* GetCommandClassic */ +#include +#include +#include + +#include +#include + /* * The protocol consists of the following commands: @@ -450,13 +457,58 @@ static void test_user_name(void) assert_true(IsUserNameValid(valid_user_name)); } +/* + * BusyWithNewProtocol() hands GetServerLiteral() a sendbuffer of only + * CF_BUFSIZE - CF_INBAND_OFFSET bytes. The function must not write past the + * size it is given, so guard bytes placed right after a buffer of that size + * have to survive the call. + */ +static void test_get_server_literal_sendbuffer_bound(void) +{ + int sv[2]; + assert_int_equal(socketpair(AF_UNIX, SOCK_STREAM, 0, sv), 0); + + ServerConnectionState *conn = xcalloc(1, sizeof(*conn)); + conn->conn_info = ConnectionInfoNew(); + ConnectionInfoSetSocket(conn->conn_info, sv[0]); + ConnectionInfoSetProtocolVersion(conn->conn_info, CF_PROTOCOL_CLASSIC); + + ConnectionInfo *client = ConnectionInfoNew(); + ConnectionInfoSetSocket(client, sv[1]); + ConnectionInfoSetProtocolVersion(client, CF_PROTOCOL_CLASSIC); + + EvalContext *ctx = EvalContextNew(); + + char sendbuffer[CF_MSGSIZE + CF_INBAND_OFFSET]; + memset(sendbuffer, 0x5a, sizeof(sendbuffer)); + + char recvbuffer[] = "VAR literal_handle"; + GetServerLiteral(ctx, conn, sendbuffer, CF_MSGSIZE, recvbuffer, 0); + + for (size_t i = CF_MSGSIZE; i < sizeof(sendbuffer); i++) + { + assert_int_equal(sendbuffer[i], 0x5a); + } + + char reply[CF_BUFSIZE]; + int len = ReceiveTransaction(client, reply, NULL); + assert_true(len > 0); + assert_string_equal(reply, "BAD: Not found"); + + EvalContextDestroy(ctx); + ConnectionInfoDestroy(&client); + ConnectionInfoDestroy(&conn->conn_info); + free(conn); +} + int main() { PRINT_TEST_BANNER(); const UnitTest tests[] = { unit_test(test_command_parser), - unit_test(test_user_name) + unit_test(test_user_name), + unit_test(test_get_server_literal_sendbuffer_bound) }; return run_tests(tests); From 995e6fd3702b5cb9d34478bd13839ce8d157a646 Mon Sep 17 00:00:00 2001 From: Dhanraj E Date: Wed, 21 Oct 2026 13:41:04 +0530 Subject: [PATCH 03/70] Fixed out-of-bounds read of extended attribute values in filestat() The "xattr" branch of filestat() reads each extended attribute value into an uninitialized stack buffer and then uses it as a C string: char data[CF_BUFSIZE]; int datasize = lgetxattr(path, current, data, sizeof(data)); ... if (!StringIsPrintable(data)) ... BufferPrintf(printattr, "%s=%s", current, data); lgetxattr() returns raw bytes and never adds a terminating NUL. An unprivileged user can set user.* attributes on files they own, so when a policy run as root calls filestat() on such a file, a printable value of exactly 4096 bytes makes StringIsPrintable() read past the end of data. Shorter values are followed by whatever stale stack bytes come before the next NUL, which either makes a valid attribute get skipped as non-printable or copies stack contents into the returned string. Read at most sizeof(data) - 1 bytes and terminate the value at datasize. CopyFileExtendedAttributesDisk() in files_copy.c, the other lgetxattr() caller, handles values by length and is not affected. Changelog: Title Signed-off-by: Dhanraj E --- libpromises/evalfunction.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libpromises/evalfunction.c b/libpromises/evalfunction.c index 7707b18d0cb..01f1d455294 100644 --- a/libpromises/evalfunction.c +++ b/libpromises/evalfunction.c @@ -5193,7 +5193,7 @@ static FnCallResult FnCallFileStatDetails(ARG_UNUSED EvalContext *ctx, } char data[CF_BUFSIZE]; - int datasize = lgetxattr(path, current, data, sizeof(data)); + int datasize = lgetxattr(path, current, data, sizeof(data) - 1); if (datasize < 0) { if (errno == ENOTSUP) @@ -5208,6 +5208,8 @@ static FnCallResult FnCallFileStatDetails(ARG_UNUSED EvalContext *ctx, } else { + data[datasize] = '\0'; + if (!StringIsPrintable(data)) { Log(LOG_LEVEL_INFO, "Skipping extended attribute of '%s', it has non-printable data: '%s=%s'", From 80d3d5b865e68d18f6c0d49cf04f1b341d9be6fa Mon Sep 17 00:00:00 2001 From: Nick Anderson Date: Tue, 27 Oct 2026 17:22:27 -0500 Subject: [PATCH 04/70] Updated plucked.sub.cf from masterfiles Ticket: CFE-3898 Changelog: None Signed-off-by: Nick Anderson --- tests/acceptance/plucked.sub.cf | 58 +++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 13 deletions(-) diff --git a/tests/acceptance/plucked.sub.cf b/tests/acceptance/plucked.sub.cf index ef7bda18137..6b6c3eceecf 100644 --- a/tests/acceptance/plucked.sub.cf +++ b/tests/acceptance/plucked.sub.cf @@ -63,9 +63,9 @@ body contain in_dir_shell(dir) # ``` { chdir => "$(dir)"; - useshell => "true"; # canonical "useshell" but this is backwards-compatible + useshell => "true"; } body contain in_shell @@ -79,9 +79,8 @@ body contain in_shell # contain => in_shell; # ``` { - useshell => "true"; - # canonical "useshell" but this is backwards-compatible + useshell => "true"; } body contain in_shell_bg @@ -90,9 +89,8 @@ body contain in_shell_bg # parser strictness enhancements. Backgrounding is handeled by the body action # background attribute. { - useshell => "true"; - # canonical "useshell" but this is backwards-compatible + useshell => "true"; } body contain in_shell_and_silent @@ -107,9 +105,8 @@ body contain in_shell_and_silent # comment => "Silently run command in shell"; # ``` { - useshell => "true"; - # canonical "useshell" but this is backwards-compatible + useshell => "true"; no_output => "true"; } @@ -126,9 +123,8 @@ body contain in_dir_shell_and_silent(dir) # comment => "Silently run command in shell"; # ``` { - useshell => "true"; - # canonical "useshell" but this is backwards-compatible + useshell => "true"; no_output => "true"; chdir => "$(dir)"; } @@ -752,10 +748,18 @@ bundle edit_line manage_variable_values_ini(tab, sectionName) { vars: "index" slist => getindices("$(tab)[$(sectionName)]"); + "_escaped_section" string => escape("$(sectionName)"); + + classes: + "section_$(sectionName)_exists" + expression => regline("^\[$(_escaped_section)\]", "$(edit.filename)"), + if => fileexists("$(edit.filename)"), + comment => "Check if the section header already exists in the file"; delete_lines: ".*" select_region => INI_section(escape("$(sectionName)")), + if => canonify("section_$(sectionName)_exists"), comment => "Remove all entries in the region so there are no extra entries"; insert_lines: @@ -764,7 +768,12 @@ bundle edit_line manage_variable_values_ini(tab, sectionName) comment => "Insert lines"; "$(index)=$($(tab)[$(sectionName)][$(index)])" - select_region => INI_section(escape("$(sectionName)")); + select_region => INI_section(escape("$(sectionName)")), + if => canonify("section_$(sectionName)_exists"); + + "$(index)=$($(tab)[$(sectionName)][$(index)])" + location => after("^\[$(_escaped_section)\]"), + if => not(canonify("section_$(sectionName)_exists")); } bundle edit_line set_variable_values_ini(tab, sectionName) @@ -786,18 +795,26 @@ bundle edit_line set_variable_values_ini(tab, sectionName) # Be careful if the index string contains funny chars "cindex[$(index)]" string => canonify("$(index)"); + "_escaped_section" string => escape("$(sectionName)"); classes: "edit_$(cindex[$(index)])" not => strcmp("$($(tab)[$(sectionName)][$(index)])", "dontchange"), comment => "Create conditions to make changes"; + "section_$(sectionName)_exists" + expression => regline("^\[$(_escaped_section)\]", "$(edit.filename)"), + if => fileexists("$(edit.filename)"), + comment => "Check if the section header already exists in the file"; + field_edits: # If the line is there, but commented out, first uncomment it "#+\s*$(index)\s*=.*" select_region => INI_section(escape("$(sectionName)")), edit_field => col("\s*=\s*", "1", "$(index)", "set"), - if => "edit_$(cindex[$(index)])"; + if => and( + "edit_$(cindex[$(index)])", canonify("section_$(sectionName)_exists") + ); # match a line starting like the key something "\s*$(index)\s*=.*" @@ -808,7 +825,9 @@ bundle edit_line set_variable_values_ini(tab, sectionName) classes => results( "bundle", "set_variable_values_ini_not_$(cindex[$(index)])" ), - if => "edit_$(cindex[$(index)])"; + if => and( + "edit_$(cindex[$(index)])", canonify("section_$(sectionName)_exists") + ); insert_lines: "[$(sectionName)]" @@ -817,7 +836,20 @@ bundle edit_line set_variable_values_ini(tab, sectionName) "$(index)=$($(tab)[$(sectionName)][$(index)])" select_region => INI_section(escape("$(sectionName)")), - if => "!(set_variable_values_ini_not_$(cindex[$(index)])_kept|set_variable_values_ini_not_$(cindex[$(index)])_repaired).edit_$(cindex[$(index)])"; + if => and( + "!(set_variable_values_ini_not_$(cindex[$(index)])_kept|set_variable_values_ini_not_$(cindex[$(index)])_repaired)", + "edit_$(cindex[$(index)])", + canonify("section_$(sectionName)_exists") + ), + handle => "insert_key_in_existing_section_$(sectionName)_$(cindex[$(index)])"; + + "$(index)=$($(tab)[$(sectionName)][$(index)])" + location => after("^\[$(_escaped_section)\]"), + if => and( + "edit_$(cindex[$(index)])", + not(canonify("section_$(sectionName)_exists")) + ), + handle => "insert_key_in_new_section_$(sectionName)_$(cindex[$(index)])"; } bundle edit_line insert_ini_section(name, config) From 37beecab8080112418463640c97ae9a102d558ed Mon Sep 17 00:00:00 2001 From: Victor Moene Date: Tue, 27 Oct 2026 15:57:41 +0100 Subject: [PATCH 05/70] 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 06/70] 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 07/70] 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 08/70] 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 09/70] 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 10/70] 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 11/70] 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 12/70] 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 13/70] 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 14/70] 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 15/70] 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 16/70] 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 17/70] 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 18/70] 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 19/70] 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 20/70] 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 21/70] 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 22/70] 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 23/70] 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 24/70] 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 25/70] 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 26/70] 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 27/70] 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 28/70] 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 29/70] 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 30/70] 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 31/70] 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 32/70] 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 33/70] 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 34/70] 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 35/70] 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 36/70] 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 37/70] 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 38/70] 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 39/70] 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 40/70] 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 41/70] 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 42/70] 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 c4c352c9f62ac4327718ad67fe66f0ea91e61748 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Fri, 30 Oct 2026 13:50:10 +0100 Subject: [PATCH 43/70] cf-reactor: added package_installed and package_uninstalled Ticket: ENT-14766 Changelog: Added `package_installed` and `package_uninstalled` watchers to `cf-reactor` Signed-off-by: Lars Erik Wik --- cf-reactor/Makefile.am | 1 + cf-reactor/package_watcher.c | 675 +++++++++++++++++++++++++++++++++ cf-reactor/package_watcher.h | 70 ++++ cf-reactor/reactor_transform.c | 11 + libpromises/mod_reactor.c | 3 + libpromises/mod_reactor.h | 3 + 6 files changed, 763 insertions(+) create mode 100644 cf-reactor/package_watcher.c create mode 100644 cf-reactor/package_watcher.h diff --git a/cf-reactor/Makefile.am b/cf-reactor/Makefile.am index 3c84df15546..21bbd49a28e 100644 --- a/cf-reactor/Makefile.am +++ b/cf-reactor/Makefile.am @@ -42,6 +42,7 @@ libcf_reactor_la_LIBADD = ../libpromises/libpromises.la libcf_reactor_la_SOURCES = \ cf-reactor.c \ file_watcher.c file_watcher.h \ + package_watcher.c package_watcher.h \ reactor_context.c reactor_context.h \ reactor_transform.c reactor_transform.h \ stoppable_thread.c stoppable_thread.h \ diff --git a/cf-reactor/package_watcher.c b/cf-reactor/package_watcher.c new file mode 100644 index 00000000000..b6074eba5f7 --- /dev/null +++ b/cf-reactor/package_watcher.c @@ -0,0 +1,675 @@ +/* + 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 +#include +#include +#include +#include +#include +#include + +/* Timeout of a run of the package module. Only the listing thread of the + * module waits for it. Tests can define it before including this file. */ +#ifndef LISTING_TIMEOUT_SECS +#define LISTING_TIMEOUT_SECS 60 +#endif + +/* Minimum time between the starts of two listings of a package module, since + * a listing can take a while. Tests can define it before including this file. + */ +#ifndef LISTING_INTERVAL_SECS +#define LISTING_INTERVAL_SECS 10 +#endif + +/* Minimum time between two attempts to create the wrapper of a package + * module that can't be run. Longer, since each attempt logs errors. Tests can + * define it before including this file. */ +#ifndef LISTING_RETRY_INTERVAL_SECS +#define LISTING_RETRY_INTERVAL_SECS 60 +#endif + +/* How long to wait for a listing thread to stop before giving up on it */ +#define LISTING_THREAD_STOP_TIMEOUT_SECS 5 + +/* Minimum time between two logs of a persisting failure to list packages */ +#define LISTING_ERROR_LOG_INTERVAL_SECS 60 + +/* The installed packages of a package module, listed by its own thread. + * Shared by all watchers of the package module. */ +typedef struct +{ + char *key; /* see PackageModuleKey() */ + PackageModuleBody *module; /* copy of the package module body */ + size_t refcount; /* watchers using it, under listings_mutex */ + StoppableThread *thread; + time_t last_error_logged; /* only used by the listing thread */ + + pthread_mutex_t mutex; /* protects the fields below */ + StringSet *installed; /* names, NULL if the listing failed */ + time_t listed_at; /* start of the latest listing, 0 if none */ +} PackageListing; + +/* All listings, under listings_mutex. Only changed on the main thread. */ +static pthread_mutex_t listings_mutex = PTHREAD_MUTEX_INITIALIZER; +static Seq *listings = NULL; + +typedef struct +{ + char *name; + PackageListing *listing; + bool observed; /* whether a listing was observed yet */ + bool last_installed; /* what the last observed listing said */ +} PackageWatcherState; + +/** + * @brief Returns what tells two package modules apart when listing. + * + * Two bodies with the same name, path, interpreter and options list the + * same packages, so their watchers share a package listing. + * + * @param module The package module body + * @return The key, to be freed by the caller + */ +static char *PackageModuleKey(const PackageModuleBody *module) +{ + assert(module != NULL); + + char *options = PackageModuleFormatOptions(module->options); + char *key = StringFormat( + "%s\n%s\n%s\n%s", + module->name, + (module->module_path != NULL) ? module->module_path : "", + (module->interpreter != NULL) ? module->interpreter : "", + options); + free(options); + return key; +} + +/** + * @brief Logs a problem listing the packages of a package module. + * + * The caller logs the actual problem at verbose level. A persisting problem is + * logged at most once every LISTING_ERROR_LOG_INTERVAL_SECS. Only called by + * the listing thread. + * + * @param listing The package listing + */ +static void LogListingError(PackageListing *listing) +{ + assert(listing != NULL); + + const time_t now = time(NULL); + if ((listing->last_error_logged == 0) + || (now - listing->last_error_logged + >= LISTING_ERROR_LOG_INTERVAL_SECS)) + { + Log(LOG_LEVEL_ERR, + "Problem listing installed packages with package module '%s' while checking for package events, run with verbose logging for details", + listing->module->name); + listing->last_error_logged = now; + } +} + +/** + * @brief Adds the name of a record of a 'list-installed' reply. + * + * @param installed The names of the installed packages + * @param name The name of the record, may be NULL + * @param version The version of the record, may be NULL + * @param arch The architecture of the record, may be NULL + */ +static void AddInstalledPackage( + StringSet *installed, + const char *name, + const char *version, + const char *arch) +{ + assert(installed != NULL); + + if (name == NULL) + { + /* No record yet, i.e. before the first Name= line or an empty reply. + * Skipped, so that callers don't need to check. */ + return; + } + if (version == NULL || arch == NULL) + { + Log(LOG_LEVEL_VERBOSE, + "Malformed response from package module for package '%s'", + name); + return; + } + if (!StringSetContains(installed, name)) + { + StringSetAdd(installed, xstrdup(name)); + } +} + +/** + * @brief Parses a 'list-installed' reply of a package module. + * + * @param response The lines of the reply + * @param module_name The name of the package module, for logging + * @return The names of the installed packages, or NULL if the reply has + * errors + */ +static StringSet *ParseInstalledPackages( + const Rlist *response, const char *module_name) +{ + assert(module_name != NULL); + + StringSet *installed = StringSetNew(); + const char *name = NULL; + const char *version = NULL; + const char *arch = NULL; + bool failed = false; + for (const Rlist *rp = response; rp != NULL; rp = rp->next) + { + const char *line = RlistScalarValue(rp); + if (StringStartsWith(line, "Name=")) + { + /* A new record, meaning the previous one, is complete. If there is + * no previous one, then it's skipped. */ + AddInstalledPackage(installed, name, version, arch); + name = line + strlen("Name="); + version = NULL; + arch = NULL; + } + else if (StringStartsWith(line, "Version=")) + { + version = line + strlen("Version="); + } + else if (StringStartsWith(line, "Architecture=")) + { + arch = line + strlen("Architecture="); + } + else if ( + StringStartsWith(line, "Error=") + || StringStartsWith(line, "ErrorMessage=")) + { + Log(LOG_LEVEL_VERBOSE, + "Package module '%s' replied with an error: %s", + module_name, + line); + /* Not returning yet, so that all error lines get logged, e.g. an + * ErrorMessage= line with the details after an Error= line */ + failed = true; + } + } + /* The last record, if any */ + AddInstalledPackage(installed, name, version, arch); + + if (failed) + { + /* Never taken as "nothing installed" */ + StringSetDestroy(installed); + return NULL; + } + return installed; +} + +/** + * @brief Lists the installed packages with the package module. + * + * @param listing The listing + * @param wrapper The wrapper of the package module + * @return The names of the installed packages, or NULL on failure + */ +static StringSet *ListInstalledPackages( + PackageListing *listing, const PackageModuleWrapper *wrapper) +{ + assert(listing != NULL); + assert(wrapper != NULL); + + char *options = PackageModuleFormatOptions(listing->module->options); + Rlist *response = NULL; + const int ret = PackageWrapperCommunicate( + wrapper, "list-installed", options, &response); + free(options); + + if (ret != 0) + { + Log(LOG_LEVEL_VERBOSE, + "Package module '%s' failed to list installed packages", + listing->module->name); + LogListingError(listing); + return NULL; + } + + StringSet *installed = + ParseInstalledPackages(response, listing->module->name); + RlistDestroy(response); + + if (installed == NULL) + { + LogListingError(listing); + } + return installed; +} + +/** + * @brief The routine of the listing thread of a package module. + * + * Lists the installed packages ahead of the checks, every + * LISTING_INTERVAL_SECS, so that a check sees a recent listing whatever its + * interval. + * + * @param thread The listing thread + * @param arg The listing + */ +static void ListingThreadMain(StoppableThread *thread, void *arg) +{ +#ifndef __MINGW32__ + MaskTerminationSignalsInThread(); +#endif + + PackageListing *listing = arg; + assert(listing != NULL); + + /* Created on the first listing, so that negotiating the API version + * runs the package module on this thread, not on the main one */ + PackageModuleWrapper *wrapper = NULL; + + while (!StoppableThreadShouldStop(thread)) + { + const time_t start = time(NULL); + if (wrapper == NULL) + { + wrapper = + NewPackageModuleWrapper(listing->module, LISTING_TIMEOUT_SECS); + } + const time_t wait_secs = (wrapper != NULL) + ? LISTING_INTERVAL_SECS + : LISTING_RETRY_INTERVAL_SECS; + + StringSet *installed = NULL; + if (wrapper != NULL) + { + installed = ListInstalledPackages(listing, wrapper); + } + else + { + Log(LOG_LEVEL_VERBOSE, + "Package module '%s' can't be run", + listing->module->name); + LogListingError(listing); + } + + ThreadLock(&listing->mutex); + StringSetDestroy(listing->installed); + listing->installed = installed; + listing->listed_at = start; + ThreadUnlock(&listing->mutex); + + /* Counted from the start, so that a slow listing doesn't delay the + * next one. Sleeps in a loop, since a sleep can end early. */ + const time_t next = start + wait_secs; + time_t now; + while (!StoppableThreadShouldStop(thread) + && ((now = time(NULL)) < next)) + { + StoppableThreadSleep(thread, next - now); + } + } + + DeletePackageModuleWrapper(wrapper); +} + +/** + * @brief Destroys a listing whose thread has stopped. + * + * @param listing The listing + */ +static void PackageListingDestroy(PackageListing *listing) +{ + assert(listing != NULL); + + free(listing->key); + PackageModuleBodyDestroy(listing->module); + StringSetDestroy(listing->installed); + pthread_mutex_destroy(&listing->mutex); + free(listing); +} + +/** + * @brief Gets the listing of a package module, shared by its watchers. + * + * Creates it, and starts its thread, if no watcher uses the package module + * yet. Only called on the main thread. + * + * @param module The package module body, copied + * @return The listing, to be released with PackageListingRelease(), or NULL + * if its thread can't be started + */ +static PackageListing *PackageListingAcquire(const PackageModuleBody *module) +{ + assert(module != NULL); + + char *key = PackageModuleKey(module); + + ThreadLock(&listings_mutex); + if (listings == NULL) + { + listings = SeqNew(1, NULL); + } + + for (size_t i = 0; i < SeqLength(listings); i++) + { + PackageListing *listing = SeqAt(listings, i); + if (StringEqual(listing->key, key)) + { + listing->refcount++; + ThreadUnlock(&listings_mutex); + free(key); + return listing; + } + } + + PackageListing *listing = xcalloc(1, sizeof(PackageListing)); + listing->key = key; + listing->module = PackageModuleBodyCopy(module); + pthread_mutex_init(&listing->mutex, NULL); + listing->refcount = 1; + + listing->thread = StoppableThreadStart(ListingThreadMain, listing); + if (listing->thread == NULL) + { + ThreadUnlock(&listings_mutex); + PackageListingDestroy(listing); + return NULL; + } + + SeqAppend(listings, listing); + ThreadUnlock(&listings_mutex); + return listing; +} + +/** + * @brief Releases a listing got with PackageListingAcquire(). + * + * The last watcher to release it stops its thread and destroys it. If the + * thread doesn't stop in time, e.g. because the package module hangs, it's + * given up on, and the listing is leaked on purpose, since the thread may + * still use it. It's then only freed when cf-reactor exits. Only called on + * the main thread. + * + * @param listing The listing + */ +static void PackageListingRelease(PackageListing *listing) +{ + assert(listing != NULL); + + ThreadLock(&listings_mutex); + assert(listing->refcount > 0); + listing->refcount--; + if (listing->refcount > 0) + { + ThreadUnlock(&listings_mutex); + return; + } + + for (size_t i = 0; i < SeqLength(listings); i++) + { + if (SeqAt(listings, i) == listing) + { + SeqSoftRemove(listings, i); + break; + } + } + ThreadUnlock(&listings_mutex); + + if (StoppableThreadStop(listing->thread, LISTING_THREAD_STOP_TIMEOUT_SECS)) + { + PackageListingDestroy(listing); + } +} + +/** + * @brief Creates the state of a package watcher for the given package module. + * + * @param name The name of the package to watch + * @param module The package module body, copied + * @return The new state, or NULL if the listing thread can't be started + */ +static PackageWatcherState *PackageWatcherStateNewFromModule( + const char *name, const PackageModuleBody *module) +{ + assert(name != NULL); + assert(module != NULL); + + PackageListing *listing = PackageListingAcquire(module); + if (listing == NULL) + { + return NULL; + } + + PackageWatcherState *state = xcalloc(1, sizeof(PackageWatcherState)); + state->name = xstrdup(name); + state->listing = listing; + return state; +} + +void *PackageWatcherStateNew(const EvalContext *ctx, const Rlist *args) +{ + assert(ctx != NULL); + assert(args != NULL); + + const char *name = RlistScalarValue(args); + const PackageModuleBody *module = NULL; + if (args->next != NULL) + { + const char *module_name = RlistScalarValue(args->next); + module = GetPackageModuleFromContext(ctx, module_name); + if (module == NULL) + { + Log(LOG_LEVEL_ERR, + "No package module body '%s' to watch package '%s' with", + module_name, + name); + return NULL; + } + } + else + { + module = GetDefaultPackageModuleFromContext(ctx); + if (module == NULL) + { + Log(LOG_LEVEL_ERR, + "No default package module to watch package '%s' with, " + "set 'package_module' in the 'when' body or in body common control", + name); + return NULL; + } + } + + return PackageWatcherStateNewFromModule(name, module); +} + +void PackageWatcherStateDestroy(void *_state) +{ + PackageWatcherState *state = _state; + if (state != NULL) + { + PackageListingRelease(state->listing); + free(state->name); + free(state); + } +} + +/** + * @brief The body of PackageLookup(), only called by it, with the mutex of + * the listing held. + * + * @param listing The listing + * @param name The name of the package + * @param[out] listed Whether there is a listing yet + * @param[out] installed Whether the package is installed, only set if listed + * @return false if the latest listing failed + */ +static bool _PackageLookupInner( + const PackageListing *listing, + const char *name, + bool *listed, + bool *installed) +{ + assert(listing != NULL); + assert(name != NULL); + assert(listed != NULL); + assert(installed != NULL); + + *listed = (listing->listed_at != 0); + if (!*listed) + { + return true; + } + if (listing->installed == NULL) + { + return false; + } + *installed = StringSetContains(listing->installed, name); + return true; +} + +/** + * @brief Looks up the package in the latest listing of its package module. + * + * @param state The watcher state + * @param[out] listed Whether there is a listing yet + * @param[out] installed Whether the package is installed, only set if listed + * @return false if the latest listing failed + */ +static bool PackageLookup( + PackageWatcherState *state, bool *listed, bool *installed) +{ + assert(state != NULL); + + PackageListing *listing = state->listing; + ThreadLock(&listing->mutex); + const bool ok = + _PackageLookupInner(listing, state->name, listed, installed); + ThreadUnlock(&listing->mutex); + return ok; +} + +/** + * @brief Records an observed listing. + * + * The first observed listing is only the reference for the next ones, so it + * never fires. + * + * @param state The watcher state + * @param installed Whether the package is installed + * @param happened Whether the event happened since the last observation + * @param event The name of the event for logging (e.g. "installation") + * @return WATCHER_CHECK_EVENT if the event fired, WATCHER_CHECK_NO_EVENT + * otherwise + */ +static WatcherCheckResult PackageWatcherRecordObservation( + PackageWatcherState *state, + bool installed, + bool happened, + const char *event) +{ + assert(state != NULL); + assert(event != NULL); + + happened = happened && state->observed; + if (happened) + { + Log(LOG_LEVEL_VERBOSE, + "Observed %s of package '%s'", + event, + state->name); + } + + state->observed = true; + state->last_installed = installed; + return happened ? WATCHER_CHECK_EVENT : WATCHER_CHECK_NO_EVENT; +} + +WatcherCheckResult PackageWatcherCheckPackageInstalled(void *_state) +{ + assert(_state != NULL); + PackageWatcherState *state = _state; + + bool listed = false; + bool installed = false; + if (!PackageLookup(state, &listed, &installed)) + { + /* Unknown state, keep the last observation as is */ + return WATCHER_CHECK_ERROR; + } + if (!listed) + { + return WATCHER_CHECK_NO_EVENT; + } + + /* Logs only if the package was uninstalled, or on the first observation. + */ + if (!installed && (state->last_installed || !state->observed)) + { + Log(LOG_LEVEL_VERBOSE, + "Package '%s' is not installed, watching for its installation", + state->name); + } + + const bool happened = !state->last_installed && installed; + return PackageWatcherRecordObservation( + state, installed, happened, "installation"); +} + +WatcherCheckResult PackageWatcherCheckPackageUninstalled(void *_state) +{ + assert(_state != NULL); + PackageWatcherState *state = _state; + + bool listed = false; + bool installed = false; + if (!PackageLookup(state, &listed, &installed)) + { + /* Unknown state, keep the last observation as is */ + return WATCHER_CHECK_ERROR; + } + if (!listed) + { + return WATCHER_CHECK_NO_EVENT; + } + + if (installed && !state->last_installed) + { + Log(LOG_LEVEL_VERBOSE, + "Package '%s' is installed, watching for its uninstallation", + state->name); + } + + const bool happened = state->last_installed && !installed; + return PackageWatcherRecordObservation( + state, installed, happened, "uninstallation"); +} diff --git a/cf-reactor/package_watcher.h b/cf-reactor/package_watcher.h new file mode 100644 index 00000000000..cc9b26f3a81 --- /dev/null +++ b/cf-reactor/package_watcher.h @@ -0,0 +1,70 @@ +/* + 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_WATCHER_H +#define CFENGINE_PACKAGE_WATCHER_H + +#include +#include + +/** + * @brief Creates the state of a package_installed or package_uninstalled + * watcher. + * + * @param ctx The context, to look up the package module + * @param args The name of the package to watch, optionally followed by the + * name of the package module to list the packages with + * @return The new state, to be destroyed with PackageWatcherStateDestroy(), + * or NULL if there is no such package module + */ +void *PackageWatcherStateNew(const EvalContext *ctx, const Rlist *args); + +/** + * @brief Destroys the state of a package watcher. + * + * @param state The watcher state, may be NULL + */ +void PackageWatcherStateDestroy(void *state); + +/** + * @brief Checks for the package_installed event. + * + * @param state The watcher state + * @return WATCHER_CHECK_EVENT if the package was installed since the last + * check, WATCHER_CHECK_ERROR if the last listing failed, + * WATCHER_CHECK_NO_EVENT otherwise + */ +WatcherCheckResult PackageWatcherCheckPackageInstalled(void *state); + +/** + * @brief Checks for the package_uninstalled event. + * + * @param state The watcher state + * @return WATCHER_CHECK_EVENT if the package was uninstalled since the last + * check, WATCHER_CHECK_ERROR if the last listing failed, + * WATCHER_CHECK_NO_EVENT otherwise + */ +WatcherCheckResult PackageWatcherCheckPackageUninstalled(void *state); + +#endif /* CFENGINE_PACKAGE_WATCHER_H */ diff --git a/cf-reactor/reactor_transform.c b/cf-reactor/reactor_transform.c index 451a68adf5c..28ddd214e67 100644 --- a/cf-reactor/reactor_transform.c +++ b/cf-reactor/reactor_transform.c @@ -43,6 +43,7 @@ #include // CheckConstraintTypeMatch(), PromiseTypeSyntaxGet(), BodySyntaxGetConstraintSyntax() #include #include +#include #include /* Resolves the agent, common or reactor bundle (looked up in that order) @@ -163,6 +164,12 @@ static const EventArg FILE_SIZE_EXCEEDS_ARGS[] = { NULL, RVAL_TYPE_NOPROMISEE, false } }; +static const EventArg PACKAGE_ARGS[] = +{ + { REACTOR_PACKAGE_MODULE, RVAL_TYPE_SCALAR, true }, + { NULL, RVAL_TYPE_NOPROMISEE, false } +}; + #define EventTypeNew(name, type, args, new_state, destroy_state, check) \ { name, type, args, new_state, destroy_state, check } #define EventTypeNewNull() EventTypeNew(NULL, RVAL_TYPE_NOPROMISEE, NULL, NULL, NULL, NULL) @@ -187,6 +194,10 @@ static const EventType EVENT_TABLE[] = FileWatcherSizeStateNew, FileWatcherStateDestroy, FileWatcherCheckFileSizeExceeds), UserEventTypeNew(REACTOR_USER_ADDED, UserWatcherCheckUserAdded), UserEventTypeNew(REACTOR_USER_REMOVED, UserWatcherCheckUserRemoved), + EventTypeNew(REACTOR_PACKAGE_INSTALLED, RVAL_TYPE_SCALAR, PACKAGE_ARGS, + PackageWatcherStateNew, PackageWatcherStateDestroy, PackageWatcherCheckPackageInstalled), + EventTypeNew(REACTOR_PACKAGE_UNINSTALLED, RVAL_TYPE_SCALAR, PACKAGE_ARGS, + PackageWatcherStateNew, PackageWatcherStateDestroy, PackageWatcherCheckPackageUninstalled), EventTypeNewNull() }; diff --git a/libpromises/mod_reactor.c b/libpromises/mod_reactor.c index ea1f8c6b616..90e22410a58 100644 --- a/libpromises/mod_reactor.c +++ b/libpromises/mod_reactor.c @@ -53,6 +53,9 @@ static const ConstraintSyntax when_constraints[] = 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), + ConstraintSyntaxNewString(REACTOR_PACKAGE_INSTALLED, CF_ANYSTRING, "Package to react for on installation", SYNTAX_STATUS_NORMAL), + ConstraintSyntaxNewString(REACTOR_PACKAGE_UNINSTALLED, CF_ANYSTRING, "Package to react for on uninstallation", SYNTAX_STATUS_NORMAL), + ConstraintSyntaxNewString(REACTOR_PACKAGE_MODULE, ".*", "Package module to list the installed packages with, instead of the default one", 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 eeb5380a122..c7a815c91ab 100644 --- a/libpromises/mod_reactor.h +++ b/libpromises/mod_reactor.h @@ -38,6 +38,9 @@ #define REACTOR_SIZE_THRESHOLD "size_threshold" #define REACTOR_USER_ADDED "user_added" #define REACTOR_USER_REMOVED "user_removed" +#define REACTOR_PACKAGE_INSTALLED "package_installed" +#define REACTOR_PACKAGE_UNINSTALLED "package_uninstalled" +#define REACTOR_PACKAGE_MODULE "package_module" /* Range of the 'interval' attribute of the 'when' body of events promises */ #define REACTOR_INTERVAL_RANGE "1,99999999999" From de84f4f24bf8cfd57d7a69e64cb349e7103814ba Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Fri, 30 Oct 2026 14:55:10 +0100 Subject: [PATCH 44/70] package_watcher_test.c: Added unit tests for package watcher Ticket: ENT-14766 Signed-off-by: Lars Erik Wik --- tests/unit/Makefile.am | 5 + tests/unit/package_watcher_test.c | 329 ++++++++++++++++++++++++++++++ 2 files changed, 334 insertions(+) create mode 100644 tests/unit/package_watcher_test.c diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am index d5084bafb22..5a40e6ac708 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 \ + package_watcher_test \ user_watcher_test \ stoppable_thread_test \ wakeup_channel_test @@ -242,6 +243,10 @@ watcher_test_SOURCES = watcher_test.c \ file_watcher_test_SOURCES = file_watcher_test.c \ ../../cf-reactor/file_watcher.c +# package_watcher.c is included by the test, to test its static functions +package_watcher_test_SOURCES = package_watcher_test.c \ + ../../cf-reactor/stoppable_thread.c + user_watcher_test_SOURCES = user_watcher_test.c stoppable_thread_test_SOURCES = stoppable_thread_test.c \ diff --git a/tests/unit/package_watcher_test.c b/tests/unit/package_watcher_test.c new file mode 100644 index 00000000000..7f04817ec7b --- /dev/null +++ b/tests/unit/package_watcher_test.c @@ -0,0 +1,329 @@ +#include +#include + +/* Included, to test its static functions */ +#include + +#include + +/* How long to wait for the listing thread before failing */ +#define WAIT_TIMEOUT_SECS 10 + +/* Returns a body of a package module that doesn't exist, with the given + * option if not NULL. */ +static PackageModuleBody *NewMissingModuleBody(const char *option) +{ + PackageModuleBody *module = xcalloc(1, sizeof(PackageModuleBody)); + module->name = xstrdup("missing"); + module->module_path = xstrdup("/nonexistent/package_watcher_test"); + if (option != NULL) + { + RlistAppendScalar(&module->options, option); + } + return module; +} + +static bool IsListed(PackageListing *listing) +{ + ThreadLock(&listing->mutex); + const bool listed = (listing->listed_at != 0); + ThreadUnlock(&listing->mutex); + return listed; +} + +/* Waits until the listing thread has finished its first listing */ +static void WaitForFirstListing(PackageListing *listing) +{ + const time_t deadline = time(NULL) + WAIT_TIMEOUT_SECS; + while (!IsListed(listing)) + { + assert_true(time(NULL) < deadline); + usleep(10000); /* 20ms */ + } +} + +/* A listing without a thread, whose result the tests set */ +static PackageListing *NewFakeListing(void) +{ + PackageListing *listing = xcalloc(1, sizeof(PackageListing)); + pthread_mutex_init(&listing->mutex, NULL); + return listing; +} + +/* Sets the result of a fake listing: only name installed, or nothing if + * name is NULL */ +static void SetFakeListing(PackageListing *listing, const char *name) +{ + StringSetDestroy(listing->installed); + listing->installed = StringSetNew(); + if (name != NULL) + { + StringSetAdd(listing->installed, xstrdup(name)); + } + listing->listed_at = time(NULL); +} + +static void SetFakeListingFailed(PackageListing *listing) +{ + StringSetDestroy(listing->installed); + listing->installed = NULL; + listing->listed_at = time(NULL); +} + +/* Returns a state watching package foo in a fake listing */ +static PackageWatcherState *NewFakeState(void) +{ + PackageWatcherState *state = xcalloc(1, sizeof(PackageWatcherState)); + state->name = xstrdup("foo"); + state->listing = NewFakeListing(); + return state; +} + +static void DestroyFakeState(PackageWatcherState *state) +{ + PackageListingDestroy(state->listing); + free(state->name); + free(state); +} + +static void test_parse_installed_packages(void) +{ + Rlist *response = NULL; + RlistAppendScalar(&response, "Name=foo"); + RlistAppendScalar(&response, "Version=1.0"); + RlistAppendScalar(&response, "Architecture=amd64"); + RlistAppendScalar(&response, "Name=bar"); + RlistAppendScalar(&response, "Version=2.0"); + RlistAppendScalar(&response, "Architecture=amd64"); + /* The same package for another architecture */ + RlistAppendScalar(&response, "Name=bar"); + RlistAppendScalar(&response, "Version=2.0"); + RlistAppendScalar(&response, "Architecture=i386"); + + StringSet *installed = ParseInstalledPackages(response, "fake"); + assert_true(installed != NULL); + assert_int_equal(StringSetSize(installed), 2); + assert_true(StringSetContains(installed, "foo")); + assert_true(StringSetContains(installed, "bar")); + + StringSetDestroy(installed); + RlistDestroy(response); +} + +static void test_parse_skips_malformed_records(void) +{ + Rlist *response = NULL; + /* No architecture */ + RlistAppendScalar(&response, "Name=foo"); + RlistAppendScalar(&response, "Version=1.0"); + RlistAppendScalar(&response, "Name=bar"); + RlistAppendScalar(&response, "Version=2.0"); + RlistAppendScalar(&response, "Architecture=amd64"); + /* No version, in the last record */ + RlistAppendScalar(&response, "Name=baz"); + RlistAppendScalar(&response, "Architecture=amd64"); + + /* The malformed records of foo and baz are skipped, and the listing + * still succeeds with the complete record of bar */ + StringSet *installed = ParseInstalledPackages(response, "fake"); + assert_true(installed != NULL); + assert_int_equal(StringSetSize(installed), 1); + assert_true(StringSetContains(installed, "bar")); + + StringSetDestroy(installed); + RlistDestroy(response); +} + +static void test_parse_empty_reply(void) +{ + /* Nothing installed, not a failure */ + StringSet *installed = ParseInstalledPackages(NULL, "fake"); + assert_true(installed != NULL); + assert_int_equal(StringSetSize(installed), 0); + StringSetDestroy(installed); +} + +static void test_parse_error_reply(void) +{ + Rlist *response = NULL; + RlistAppendScalar(&response, "Name=foo"); + RlistAppendScalar(&response, "Version=1.0"); + RlistAppendScalar(&response, "Architecture=amd64"); + RlistAppendScalar(&response, "ErrorMessage=Something went wrong"); + + assert_true(ParseInstalledPackages(response, "fake") == NULL); + RlistDestroy(response); +} + +static void test_check_installed_transitions(void) +{ + PackageWatcherState *state = NewFakeState(); + + /* Not listed yet: no observation */ + assert_int_equal(PackageWatcherCheckPackageInstalled(state), WATCHER_CHECK_NO_EVENT); + assert_false(state->observed); + + /* Not installed (the first observation is the reference) */ + SetFakeListing(state->listing, NULL); + assert_int_equal(PackageWatcherCheckPackageInstalled(state), WATCHER_CHECK_NO_EVENT); + + /* Installed: the event happens once, not while it stays installed */ + SetFakeListing(state->listing, "foo"); + assert_int_equal(PackageWatcherCheckPackageInstalled(state), WATCHER_CHECK_EVENT); + assert_int_equal(PackageWatcherCheckPackageInstalled(state), WATCHER_CHECK_NO_EVENT); + + /* Uninstalled, then installed again: the event happens again */ + SetFakeListing(state->listing, NULL); + assert_int_equal(PackageWatcherCheckPackageInstalled(state), WATCHER_CHECK_NO_EVENT); + SetFakeListing(state->listing, "foo"); + assert_int_equal(PackageWatcherCheckPackageInstalled(state), WATCHER_CHECK_EVENT); + + /* Another package installed: no event */ + SetFakeListing(state->listing, NULL); + assert_int_equal(PackageWatcherCheckPackageInstalled(state), WATCHER_CHECK_NO_EVENT); + SetFakeListing(state->listing, "bar"); + assert_int_equal(PackageWatcherCheckPackageInstalled(state), WATCHER_CHECK_NO_EVENT); + + DestroyFakeState(state); +} + +static void test_check_installed_at_start(void) +{ + PackageWatcherState *state = NewFakeState(); + + /* Installed at the first observation: the reference, not an event */ + SetFakeListing(state->listing, "foo"); + assert_int_equal(PackageWatcherCheckPackageInstalled(state), WATCHER_CHECK_NO_EVENT); + assert_int_equal(PackageWatcherCheckPackageInstalled(state), WATCHER_CHECK_NO_EVENT); + + DestroyFakeState(state); +} + +static void test_check_uninstalled_transitions(void) +{ + PackageWatcherState *state = NewFakeState(); + + /* Installed (the first observation is the reference) */ + SetFakeListing(state->listing, "foo"); + assert_int_equal(PackageWatcherCheckPackageUninstalled(state), WATCHER_CHECK_NO_EVENT); + + /* Uninstalled: the event happens once, not while it stays uninstalled */ + SetFakeListing(state->listing, NULL); + assert_int_equal(PackageWatcherCheckPackageUninstalled(state), WATCHER_CHECK_EVENT); + assert_int_equal(PackageWatcherCheckPackageUninstalled(state), WATCHER_CHECK_NO_EVENT); + + /* Installed, then uninstalled again: the event happens again */ + SetFakeListing(state->listing, "foo"); + assert_int_equal(PackageWatcherCheckPackageUninstalled(state), WATCHER_CHECK_NO_EVENT); + SetFakeListing(state->listing, NULL); + assert_int_equal(PackageWatcherCheckPackageUninstalled(state), WATCHER_CHECK_EVENT); + + DestroyFakeState(state); +} + +static void test_check_uninstalled_absent_at_start(void) +{ + PackageWatcherState *state = NewFakeState(); + + /* Not installed at the first observation: the reference, not an event */ + SetFakeListing(state->listing, NULL); + assert_int_equal(PackageWatcherCheckPackageUninstalled(state), WATCHER_CHECK_NO_EVENT); + assert_int_equal(PackageWatcherCheckPackageUninstalled(state), WATCHER_CHECK_NO_EVENT); + + DestroyFakeState(state); +} + +static void test_check_failed_listing(void) +{ + PackageWatcherState *state = NewFakeState(); + + /* A failed first listing: an error, and no observation */ + SetFakeListingFailed(state->listing); + assert_int_equal(PackageWatcherCheckPackageInstalled(state), WATCHER_CHECK_ERROR); + assert_false(state->observed); + + /* Not installed (the reference) */ + SetFakeListing(state->listing, NULL); + assert_int_equal(PackageWatcherCheckPackageInstalled(state), WATCHER_CHECK_NO_EVENT); + + /* A failed listing is not taken as "nothing installed", and keeps the + * last observation, so the installation is seen after it */ + SetFakeListingFailed(state->listing); + assert_int_equal(PackageWatcherCheckPackageInstalled(state), WATCHER_CHECK_ERROR); + SetFakeListing(state->listing, "foo"); + assert_int_equal(PackageWatcherCheckPackageInstalled(state), WATCHER_CHECK_EVENT); + + /* Installed, then a failed listing: no uninstallation */ + SetFakeListingFailed(state->listing); + assert_int_equal(PackageWatcherCheckPackageUninstalled(state), WATCHER_CHECK_ERROR); + SetFakeListing(state->listing, "foo"); + assert_int_equal(PackageWatcherCheckPackageUninstalled(state), WATCHER_CHECK_NO_EVENT); + + DestroyFakeState(state); +} + +static void test_listings_shared(void) +{ + PackageModuleBody *module = NewMissingModuleBody(NULL); + PackageModuleBody *other = NewMissingModuleBody("option=1"); + + /* The same module shares a listing, other options don't */ + PackageListing *first = PackageListingAcquire(module); + PackageListing *second = PackageListingAcquire(module); + PackageListing *third = PackageListingAcquire(other); + assert_true(first != NULL); + assert_true(third != NULL); + assert_true(first == second); + assert_true(first != third); + assert_int_equal(first->refcount, 2); + assert_int_equal(SeqLength(listings), 2); + + /* Removed once the last watcher releases it */ + PackageListingRelease(first); + assert_int_equal(SeqLength(listings), 2); + PackageListingRelease(second); + assert_int_equal(SeqLength(listings), 1); + PackageListingRelease(third); + assert_int_equal(SeqLength(listings), 0); + + PackageModuleBodyDestroy(module); + PackageModuleBodyDestroy(other); +} + +static void test_listing_module_cannot_run(void) +{ + PackageModuleBody *module = NewMissingModuleBody(NULL); + + PackageWatcherState *state = PackageWatcherStateNewFromModule("foo", module); + assert_true(state != NULL); + + /* A failed listing, not "nothing installed" */ + WaitForFirstListing(state->listing); + assert_int_equal(PackageWatcherCheckPackageInstalled(state), WATCHER_CHECK_ERROR); + assert_false(state->observed); + + PackageWatcherStateDestroy(state); + assert_int_equal(SeqLength(listings), 0); + PackageModuleBodyDestroy(module); +} + +int main() +{ + PRINT_TEST_BANNER(); + const UnitTest tests[] = + { + unit_test(test_parse_installed_packages), + unit_test(test_parse_skips_malformed_records), + unit_test(test_parse_empty_reply), + unit_test(test_parse_error_reply), + unit_test(test_check_installed_transitions), + unit_test(test_check_installed_at_start), + unit_test(test_check_uninstalled_transitions), + unit_test(test_check_uninstalled_absent_at_start), + unit_test(test_check_failed_listing), + unit_test(test_listings_shared), + unit_test(test_listing_module_cannot_run), + }; + + return run_tests(tests); +} From d67e0b86680c99299fd7ba26e16035e62269b9ff Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Fri, 30 Oct 2026 16:02:51 +0100 Subject: [PATCH 45/70] tests/reactor: Added test for package events Ticket: ENT-14766 Signed-off-by: Lars Erik Wik --- tests/reactor/lib.sh | 39 ++++++++++++++++ .../01_event_types/009_package_events.cf | 46 +++++++++++++++++++ .../01_event_types/009_package_events.sh | 38 +++++++++++++++ 3 files changed, 123 insertions(+) create mode 100644 tests/reactor/tests/01_event_types/009_package_events.cf create mode 100644 tests/reactor/tests/01_event_types/009_package_events.sh diff --git a/tests/reactor/lib.sh b/tests/reactor/lib.sh index d9754155079..727f156abaf 100644 --- a/tests/reactor/lib.sh +++ b/tests/reactor/lib.sh @@ -138,6 +138,45 @@ check_events_unordered() { fi } +# Create package module $1 in $WORKDIR. It lists the packages in the file +# given as its option (default_options), see set_installed_packages. +create_package_module() { + mkdir -p "$WORKDIR/modules/packages" + cat > "$WORKDIR/modules/packages/$1" <<'MODULE' +#!/bin/sh +case "$1" in + supports-api-version) + echo 1 + ;; + list-installed) + while read -r line; do + case "$line" in + options=*) file=${line#options=} ;; + esac + done + if [ -f "$file" ]; then + cat "$file" + fi + ;; + *) + exit 1 + ;; +esac +MODULE + chmod 700 "$WORKDIR/modules/packages/$1" +} + +# Set the packages listed from file $1 to the remaining arguments. Replaces +# the file atomically, since the package module may read it meanwhile. +set_installed_packages() { + file=$1 + shift + for name in "$@"; do + printf 'Name=%s\nVersion=1.0\nArchitecture=generic\n' "$name" + done > "$file.tmp" + mv "$file.tmp" "$file" +} + # Start cf-reactor in the background with policy file $1, logging to $LOG. # It is stopped when the test exits. start_reactor() { diff --git a/tests/reactor/tests/01_event_types/009_package_events.cf b/tests/reactor/tests/01_event_types/009_package_events.cf new file mode 100644 index 00000000000..83bdfcd6e54 --- /dev/null +++ b/tests/reactor/tests/01_event_types/009_package_events.cf @@ -0,0 +1,46 @@ +####################################################### +# +# Test package_installed and package_uninstalled events +# +####################################################### +body common control +{ + inputs => { "../../lib.cf" }; + bundlesequence => { "test" }; + version => "1.0"; + package_module => "reactor_test"; +} + +# Lists the packages in the file given as option +body package_module reactor_test +{ + default_options => { "$(test.installed_file)" }; +} + +body when installed(name) +{ + package_installed => "$(name)"; +} + +body when uninstalled(name) +{ + package_uninstalled => "$(name)"; +} + +bundle reactor test +{ + vars: + "package" string => getenv("TEST_PACKAGE", 999); + "installed_file" string => getenv("INSTALLED_FILE", 999); + "events_file" string => getenv("EVENTS_FILE", 999); + "promise_name" string => basename("$(this.promise_filename)", ".cf"); + + events: + "$(promise_name)_installed" + when => installed("$(package)"), + then => record_event("$(events_file)", "installed"); + + "$(promise_name)_uninstalled" + when => uninstalled("$(package)"), + then => record_event("$(events_file)", "uninstalled"); +} diff --git a/tests/reactor/tests/01_event_types/009_package_events.sh b/tests/reactor/tests/01_event_types/009_package_events.sh new file mode 100644 index 00000000000..5e9fb35bec9 --- /dev/null +++ b/tests/reactor/tests/01_event_types/009_package_events.sh @@ -0,0 +1,38 @@ +#!/bin/sh + +# check that package_installed and package_uninstalled fire once when a +# package is installed and uninstalled, with the default package module of +# body common control. Only the exact name matches: another package whose +# name starts with it stays installed. + +set -ex + +. "$(dirname "$0")/../../lib.sh" + +POLICY_FILE="$1" + +TEST_PACKAGE="reactor_test_pkg" +OTHER_PACKAGE="reactor_test_pkg-dev" +INSTALLED_FILE="$WORKDIR/tmp/installed" +EVENTS_FILE="$WORKDIR/tmp/events" +export TEST_PACKAGE INSTALLED_FILE EVENTS_FILE + +create_package_module reactor_test +set_installed_packages "$INSTALLED_FILE" "$OTHER_PACKAGE" + +start_reactor "$POLICY_FILE" + +wait_for_watchers 2 + +# checked once the first listing is done +wait_for_log "Package '$TEST_PACKAGE' is not installed, watching for its installation" + +set_installed_packages "$INSTALLED_FILE" "$OTHER_PACKAGE" "$TEST_PACKAGE" +wait_for_lines "$EVENTS_FILE" 1 +check_event "$EVENTS_FILE" 1 "installed" + +wait_for_log "Package '$TEST_PACKAGE' is installed, watching for its uninstallation" + +set_installed_packages "$INSTALLED_FILE" "$OTHER_PACKAGE" +wait_for_lines "$EVENTS_FILE" 2 +check_event "$EVENTS_FILE" 2 "uninstalled" From 261415181214f42bb2cda060fc3bffae15749ee0 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Fri, 30 Oct 2026 16:03:04 +0100 Subject: [PATCH 46/70] tests/reactor: Added test for package_module attribute of package events Ticket: ENT-14766 Signed-off-by: Lars Erik Wik --- .../01_event_types/010_package_module.cf | 55 +++++++++++++++++++ .../01_event_types/010_package_module.sh | 34 ++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 tests/reactor/tests/01_event_types/010_package_module.cf create mode 100644 tests/reactor/tests/01_event_types/010_package_module.sh diff --git a/tests/reactor/tests/01_event_types/010_package_module.cf b/tests/reactor/tests/01_event_types/010_package_module.cf new file mode 100644 index 00000000000..c5e5601b252 --- /dev/null +++ b/tests/reactor/tests/01_event_types/010_package_module.cf @@ -0,0 +1,55 @@ +####################################################### +# +# Test the package_module attribute of package events +# +####################################################### +body common control +{ + inputs => { "../../lib.cf" }; + bundlesequence => { "test" }; + version => "1.0"; + + # no default package_module +} + +# Lists the packages in the file given as option +body package_module reactor_test +{ + default_options => { "$(test.installed_file)" }; +} + +body when installed(name) +{ + package_installed => "$(name)"; +} + +body when installed_with(name, module) +{ + package_installed => "$(name)"; + package_module => "$(module)"; +} + +bundle reactor test +{ + vars: + "package" string => getenv("TEST_PACKAGE", 999); + "installed_file" string => getenv("INSTALLED_FILE", 999); + "events_file" string => getenv("EVENTS_FILE", 999); + "promise_name" string => basename("$(this.promise_filename)", ".cf"); + + events: + # no package_module, and no default one + "$(promise_name)_no_default" + when => installed("$(package)"), + then => record_event("$(events_file)", "no default installed"); + + # a package module body that doesn't exist + "$(promise_name)_unknown" + when => installed_with("$(package)", "no_such_module"), + then => record_event("$(events_file)", "unknown installed"); + + # last, so that its log lines come after the errors of the others + "$(promise_name)_module" + when => installed_with("$(package)", "reactor_test"), + then => record_event("$(events_file)", "installed"); +} diff --git a/tests/reactor/tests/01_event_types/010_package_module.sh b/tests/reactor/tests/01_event_types/010_package_module.sh new file mode 100644 index 00000000000..52bc3ed1650 --- /dev/null +++ b/tests/reactor/tests/01_event_types/010_package_module.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +# check the package_module attribute of package events: the named package +# module is used, and the events promise fails if there is no default package +# module or no package module body of that name + +set -ex + +. "$(dirname "$0")/../../lib.sh" + +POLICY_FILE="$1" + +TEST_PACKAGE="reactor_test_pkg" +INSTALLED_FILE="$WORKDIR/tmp/installed" +EVENTS_FILE="$WORKDIR/tmp/events" +export TEST_PACKAGE INSTALLED_FILE EVENTS_FILE + +create_package_module reactor_test +set_installed_packages "$INSTALLED_FILE" + +start_reactor "$POLICY_FILE" + +# logged on registration, in the order of the promises +wait_for_log "No default package module to watch package '$TEST_PACKAGE' with" +wait_for_log "No package module body 'no_such_module' to watch package '$TEST_PACKAGE' with" + +# only the watcher with the existing package module +wait_for_watchers 1 + +wait_for_log "Package '$TEST_PACKAGE' is not installed, watching for its installation" + +set_installed_packages "$INSTALLED_FILE" "$TEST_PACKAGE" +wait_for_lines "$EVENTS_FILE" 1 +check_event "$EVENTS_FILE" 1 "installed" From 0a2e2343865318cfc21b54e0f13cb04949929ce9 Mon Sep 17 00:00:00 2001 From: Victor Moene Date: Mon, 2 Nov 2026 10:38:41 +0100 Subject: [PATCH 47/70] Followed up on adding reactor to make check Signed-off-by: Victor Moene --- tests/reactor/lib.sh | 26 ++++++++------------------ tests/reactor/run_test.sh | 6 ------ 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/tests/reactor/lib.sh b/tests/reactor/lib.sh index d9754155079..8fb65b0785b 100644 --- a/tests/reactor/lib.sh +++ b/tests/reactor/lib.sh @@ -1,8 +1,8 @@ # Helpers sourced by the tests. Expects CF_REACTOR and LOG to be exported by # 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). +# Only portable tools are used, as the tests are run on all the platforms (e.g. +# no timeout(1) or grep -m). # Seconds to wait for something before giving up WAIT_TIMEOUT=60 @@ -11,33 +11,23 @@ WAIT_TIMEOUT=60 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. +# every 0.1 second. 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 + polls=$((WAIT_TIMEOUT * 10)) until "$@"; do [ "$polls" -gt 0 ] || exit 1 polls=$((polls - 1)) - sleep "$interval" + sleep 0.1 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. +# Print the current time in seconds since the Epoch. now() { - t=$(date +%s 2>/dev/null) - case "$t" in - ''|*[!0-9]*) awk 'BEGIN { srand(); print srand() }' ;; - *) echo "$t" ;; - esac + date +%s } # Print the first line of the reactor log after line $1 that contains $2, diff --git a/tests/reactor/run_test.sh b/tests/reactor/run_test.sh index dc4b66fb79b..e1d78bb0135 100644 --- a/tests/reactor/run_test.sh +++ b/tests/reactor/run_test.sh @@ -25,12 +25,6 @@ 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 From 9d5c84daa1eb3e8ab10183180aee3b9f790b0097 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Tue, 3 Nov 2026 15:13:42 +0100 Subject: [PATCH 48/70] Added workflow to backport labeled PRs to LTS branches Co-Authored-By: Claude Opus 5.5 Signed-off-by: Lars Erik Wik --- .github/workflows/backport.yml | 101 +++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 .github/workflows/backport.yml diff --git a/.github/workflows/backport.yml b/.github/workflows/backport.yml new file mode 100644 index 00000000000..92ccc8fc3dd --- /dev/null +++ b/.github/workflows/backport.yml @@ -0,0 +1,101 @@ +name: Backport + +# Opens backport pull requests to the LTS branches when a pull request with the +# `cherry-pick?` label is merged to master. Commits are cherry-picked with `-x`. +# Each branch comments on the original pull request with the backport link, or +# says that a manual backport is needed. +# +# The label must be set before merging. + +on: + push: + branches: [master] + +permissions: + contents: write + pull-requests: write + +jobs: + backport: + if: github.repository == 'cfengine/core' + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + branch: [3.27.x, 3.24.x] + steps: + - name: Check for the label + id: find_pr + env: + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} + MERGE_SHA: ${{ github.sha }} + run: | + # For a commit on master, this returns the merged PR that added it. + pr=$(gh api "repos/$GH_REPO/commits/$MERGE_SHA/pulls" \ + --jq 'first(.[] | select(any(.labels[]; .name == "cherry-pick?")))') + if [ -z "$pr" ]; then + echo "No merged PR with the cherry-pick? label, nothing to do" + exit 0 + fi + echo "number=$(jq -r .number <<< "$pr")" >> "$GITHUB_OUTPUT" + echo "title=$(jq -r .title <<< "$pr")" >> "$GITHUB_OUTPUT" + echo "author=$(jq -r .user.login <<< "$pr")" >> "$GITHUB_OUTPUT" + + - uses: actions/checkout@v4 + if: steps.find_pr.outputs.number != '' + with: + ref: ${{ matrix.branch }} + # 0 means full history. It is needed to reach the merged commits. + fetch-depth: 0 + + - name: Cherry-pick + id: cherry_pick + if: steps.find_pr.outputs.number != '' + continue-on-error: true + env: + MERGE_SHA: ${{ github.sha }} + run: | + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + + # A merge commit has two parents: ^1 is master before the merge, ^2 is + # the tip of the PR branch. ^1..^2 is then the commits of the PR. + # shellcheck disable=SC2046 # word splitting is intended + if ! git cherry-pick -x $(git rev-list --reverse --no-merges "$MERGE_SHA^1..$MERGE_SHA^2"); then + git cherry-pick --abort || true + exit 1 + fi + + - name: Open a pull request + id: create_pr + if: steps.cherry_pick.outcome == 'success' + uses: cfengine/create-pull-request@v7.0.7a + with: + base: ${{ matrix.branch }} + branch: backport-${{ steps.find_pr.outputs.number }}-${{ matrix.branch }} + delete-branch: true + sign-commits: true + title: ${{ steps.find_pr.outputs.title }} (${{ matrix.branch }}) + body: | + Backport of #${{ steps.find_pr.outputs.number }} by @${{ steps.find_pr.outputs.author }} to ${{ matrix.branch }}. + + Opened automatically by [.github/workflows/backport.yml](${{ github.server_url }}/${{ github.repository }}/blob/master/.github/workflows/backport.yml). + + Pull requests opened with `GITHUB_TOKEN` do not trigger other workflows, so CI has not started on its own. + + - name: Comment on the original pull request + if: always() && steps.find_pr.outputs.number != '' + env: + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} + PR: ${{ steps.find_pr.outputs.number }} + BRANCH: ${{ matrix.branch }} + URL: ${{ steps.create_pr.outputs.pull-request-url }} + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + run: | + if [ -n "$URL" ]; then + gh pr comment "$PR" --body "Backport to $BRANCH: $URL" + else + gh pr comment "$PR" --body "Backport to $BRANCH failed, manual backport needed: $RUN_URL" + fi From 7b6260b8d57dbdb99b1d5006040b898025de0122 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Tue, 3 Nov 2026 16:26:24 +0100 Subject: [PATCH 49/70] Fixed typo in SECURITY.md Co-Authored-By: Claude Opus 5.5 Signed-off-by: Lars Erik Wik --- SECURITY.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SECURITY.md b/SECURITY.md index e516691923d..bc20f55af4b 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -2,7 +2,7 @@ ## Supported versions -For information about versions which are supported and recieving security patches see https://docs.cfengine.com +For information about versions which are supported and receiving security patches see https://docs.cfengine.com ## Reporting a vulnerability From 4dec79a0cc1bdeeb690fe0ce67a0575728b8cb0b Mon Sep 17 00:00:00 2001 From: Ihor Aleksandrychiev Date: Wed, 4 Nov 2026 10:30:02 +0200 Subject: [PATCH 50/70] Fixed cf-serverd crash when policy reload races with a new connection cf-serverd only checked ACTIVE_THREADS before reloading policy, but a connection is added to SERVER_ACCESS.connectionlist before its handler thread increments ACTIVE_THREADS and removed only after it decrements it. A reload in that window tripped the assertion in ClearAuthAndACLs(). Policy reload and shutdown cleanup now also wait for connections that are still in connectionlist. Ticket: ENT-14927 Changelog: Title Co-Authored-By: Claude Opus 5.5 Signed-off-by: Ihor Aleksandrychiev --- cf-serverd/cf-serverd-functions.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/cf-serverd/cf-serverd-functions.c b/cf-serverd/cf-serverd-functions.c index b52be4d7c79..ee6c0334bde 100644 --- a/cf-serverd/cf-serverd-functions.c +++ b/cf-serverd/cf-serverd-functions.c @@ -374,7 +374,7 @@ static void DeleteAuthList(Auth **list, Auth **list_tail) *list_tail = NULL; } -/* Must not be called unless ACTIVE_THREADS is zero: */ +/* Must not be called unless ConnectionsInFlight() is zero: */ static void ClearAuthAndACLs(void) { /* Must have no currently open connections to free the ACLs. */ @@ -674,6 +674,24 @@ static void GracefulStop() } #endif // HAVE_SYSTEMD_SD_DAEMON_H +/* Number of connections still being handled. + * + * A connection is added to SERVER_ACCESS.connectionlist before its handler + * thread increments ACTIVE_THREADS, and removed only after the thread has + * decremented it again, so ACTIVE_THREADS alone can be zero while a + * connection is still in flight. + * + * Must be called with cft_server_children locked. + */ +static int ConnectionsInFlight(void) +{ + ThreadLock(cft_count); + const int listed = (int) ListLen(SERVER_ACCESS.connectionlist); + ThreadUnlock(cft_count); + + return MAX(ACTIVE_THREADS, listed); +} + /* Wait for connection-handler threads to finish their work. * * @return Number of live threads remaining after waiting. @@ -684,7 +702,7 @@ static int WaitOnThreads(int graceful_time) for (int i = graceful_time; i > 0; i--) { ThreadLock(cft_server_children); - result = ACTIVE_THREADS; + result = ConnectionsInFlight(); ThreadUnlock(cft_server_children); if (result == 0) @@ -749,15 +767,15 @@ static void CollectCallIfDue(EvalContext *ctx) /* Check for new policy just before spawning a thread. * - * Server reconfiguration can only happen when no threads are active, - * so this is a good time to do it; but we do still have to check for - * running threads. */ + * Server reconfiguration can only happen when no connections are being + * handled, so this is a good time to do it; but we do still have to check + * for connections in flight. */ static void PolicyUpdateIfSafe(EvalContext *ctx, Policy **policy, GenericAgentConfig *config) { ThreadLock(cft_server_children); int prior = COLLECT_INTERVAL; - if (ACTIVE_THREADS == 0) + if (ConnectionsInFlight() == 0) { CheckFileChanges(ctx, policy, config); } From a58ea98926459a7faae4cb22ef33322d255f4d5a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 4 Nov 2026 11:49:07 +0000 Subject: [PATCH 51/70] [create-pull-request] automated change --- CHANGELOG.md | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1db4eedd974..00600e13c19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,97 @@ +## 3.29.0 + +- Added --no-lock long option to cf-runagent, matching the existing -K short option +- Added SELinux state and Federated Reporting transport metadata to cf-support + (ENT-14405) +- Added Termux for sys.os_name_human when running in Termux Linux Environment (Android) + (CFE-4427) +- Added `package_installed` and `package_uninstalled` watchers to `cf-reactor` + (ENT-14766) +- Added file_older_than policy function (ENT-6065) +- Added inventory tag `Short hostname` to sys.uqhost (ENT-11265) +- Added opt-in remount reconciliation for storage mount options + (CFE-1864, CFE-3366, CFE-90) +- Added sshd logs to the cf-support Federated Reporting collection + (ENT-14405) +- Added the `silence` attribute to `body changes`, which suppresses the alert output of selected file-change categories while still setting the change classes and writing the audit log. + (CFE-159) +- Added the parameters of string_mustache() to the syntax description + (CFE-4534) +- Added the promisee to verbose output for reports promises (CFE-4228) +- Added validfiledata policy function (ENT-8193) +- Adjusted IsReadable() to not use pthread_cancel() on Termux platform + (CFE-4401) +- Allowed modules to define empty lists (CFE-2139) +- Allowed modules to define lists with a trailing comma (CFE-2140) +- Allowed mount promises to target a specific server (CFE-2350) +- Community 'files' promises using hash => "best" now use SHA-512 (previously MD5+SHA1) and no longer report a content change on two consecutive agent runs. Affected files are re-baselined on the first run after upgrade. + (CFE-3725) +- Extended string_replace with list arguments (CFE-4694) +- Fix ipv6 mask check (CFE-2034) +- Fixed --simulate symlink errors to show the real target, not a chroot path + (ENT-14714) +- Fixed --simulate=diff to report permission and ownership changes + (ENT-14694) +- Fixed --simulate=diff to show the new target of a replaced symlink + (ENT-14713) +- Fixed Federated Reporting transport failing on RHEL 10 hubs + (ENT-14405) +- Fixed a bug regarding the resolution of namespaces inside function-calls + (ENT-10199) +- Fixed cf-agent assertion failure when reading /proc//stat + (CFE-4285) +- Fixed cf-check -V (--version) short option +- Fixed cf-net -t (--tls-version) and -c (--ciphers) short options +- Fixed cf-secret -v (--verbose), -g (--log-level) and -I (--inform) short options +- Fixed cf-serverd -L (--ld-library-path) to accept its argument +- Fixed insert_lines ignoring include_end_delimiter when locating the region + (CFE-3988) +- Fixed insert_lines prepending to the file instead of to the selected region + (CFE-3987) +- Fixed lmdb maxkeysize assertion for macos +- Fixed macOS process start-time/state detection (process_macos.c) and the macOS ps syntax bug in mon_processes_test.c + (ENT-14471) +- Fixed out-of-bounds read in RemoteDirList when parsing a listing +- Fixed out-of-bounds read of extended attribute values in filestat() +- Fixed process_select and file_select time ranges on Windows +- Fixed reports promise being kept when the report could not be written + (CFE-4699) +- Fixed simulate diff mode not reporting a removal with a version +- Fixed simulate mode reporting both removal and install of the same package + (CFE-4742) +- Fixed simulate mode swapping package version and architecture +- Fixed stack buffer overflow in GetServerLiteral for TLS VAR requests +- Fixed usemodule() reporting success when the module exited non-zero + (CFE-942) +- Increased the maximum number of cf-monitord measurement slots (CF_OBSERVABLES) from 100 to 300 + (ENT-6511) +- Made an unrecognized action_policy fatal instead of defaulting to fix + (CFE-1982) +- Made format function collect data container (CFE-3105) +- Maintained fstab entries for already-mounted filesystems (CFE-1539) +- Mounted a single filesystem surgically instead of running mount -a + (CFE-1863) +- Moved cf-reactor binary to core (ENT-14275) +- Raised cf-apache.service start timeout to avoid PID-file race + (ENT-11189) +- The source tarball is now reproducible +- `cf-reactor` can now react to a user being added or removed, with the `user_added` and `user_removed` attributes of `when` bodies + (ENT-14765) +- and(), or(), concat(), ifelse(), findfiles(), mergedata() and the classmatch() + family reported no parameters at all. Only the leading arguments are described, + as bundlesmatching() and format() already do, and CF_ANYSTRING keeps the + argument type check they activate as permissive as it was. (CFE-4714) +- cf-check dump reports measurement names instead of labelling them spare + (ENT-14329) +- cf-check: check LMDB value size before reading lastseen and lock structs +- cf-monitord no longer silently truncates the ts_key measurement name file + (ENT-14329) +- cf-monitord stores only in-use measurement slots (ENT-14329) +- cf-reactor: Fixed missing option description in --help output +- fix leak of uninitialized stack memory in CfGetFile refusal replies +- fix out-of-bounds read in FuzzySetMatch/FuzzyMatchParse octet scan +- fix stack buffer overflow parsing mount and netstat command output + ## 3.28.0 - Adapted date constraints to allow dates after Y2038 (CFE-4620) From 2e128b560bfa7854a166a1a85315a3c776d4edc8 Mon Sep 17 00:00:00 2001 From: Ihor Aleksandrychiev Date: Wed, 4 Nov 2026 14:24:42 +0200 Subject: [PATCH 52/70] Added RHEL 8 and 9 support to ci/dependencies.sh RHEL 8 and 9 arm64 build hosts have no published CFEngine package to install yet, so setup-cfengine-build-host.sh falls back to building core from source, and this script rejected anything older than RHEL 10. Ticket: ENT-14716 Changelog: none Signed-off-by: Ihor Aleksandrychiev --- ci/dependencies.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/dependencies.sh b/ci/dependencies.sh index cef2ea8f98a..f3563ab676f 100755 --- a/ci/dependencies.sh +++ b/ci/dependencies.sh @@ -49,7 +49,7 @@ if [ -f /etc/os-release ]; then build_lmdb build_librsync elif [ "$ID" = "rhel" ] || [[ "$ID_LIKE" =~ "rhel" ]]; then - if [ "$VERSION_MAJOR" -ge "10" ]; then + if [ "$VERSION_MAJOR" -ge "8" ]; then # note that having a redhat subscription makes things easier: lmdb-devel and librsync-devel are available from codeready-builder repo if subscription-manager status; then $GAINROOT subscription-manager config --rhsm.manage_repos=1 From 794c9b40dc541b8a7d137c5f45ab31e66f48bd72 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Wed, 4 Nov 2026 15:39:01 +0100 Subject: [PATCH 53/70] Curated 3.29.0 changelog entries shared with 3.27.x Co-Authored-By: Claude Opus 5.5 Signed-off-by: Lars Erik Wik --- CHANGELOG.md | 40 ++++++++++++++-------------------------- 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 00600e13c19..20c25587fb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,8 @@ ## 3.29.0 - Added --no-lock long option to cf-runagent, matching the existing -K short option -- Added SELinux state and Federated Reporting transport metadata to cf-support - (ENT-14405) -- Added Termux for sys.os_name_human when running in Termux Linux Environment (Android) - (CFE-4427) +- Added SELinux state and Federated Reporting transport metadata to `cf-support` (ENT-14405) +- Added Termux for `sys.os_name_human` when running in Termux Linux Environment (Android) (CFE-4427) - Added `package_installed` and `package_uninstalled` watchers to `cf-reactor` (ENT-14766) - Added file_older_than policy function (ENT-6065) @@ -15,8 +13,7 @@ (ENT-14405) - Added the `silence` attribute to `body changes`, which suppresses the alert output of selected file-change categories while still setting the change classes and writing the audit log. (CFE-159) -- Added the parameters of string_mustache() to the syntax description - (CFE-4534) +- Added the parameters of `string_mustache()` to the syntax description (CFE-4534) - Added the promisee to verbose output for reports promises (CFE-4228) - Added validfiledata policy function (ENT-8193) - Adjusted IsReadable() to not use pthread_cancel() on Termux platform @@ -27,42 +24,36 @@ - Community 'files' promises using hash => "best" now use SHA-512 (previously MD5+SHA1) and no longer report a content change on two consecutive agent runs. Affected files are re-baselined on the first run after upgrade. (CFE-3725) - Extended string_replace with list arguments (CFE-4694) -- Fix ipv6 mask check (CFE-2034) +- IPv6 masks in `iprange()` no longer need to be a multiple of 8 bits (CFE-2034) - Fixed --simulate symlink errors to show the real target, not a chroot path (ENT-14714) - Fixed --simulate=diff to report permission and ownership changes (ENT-14694) - Fixed --simulate=diff to show the new target of a replaced symlink (ENT-14713) -- Fixed Federated Reporting transport failing on RHEL 10 hubs - (ENT-14405) +- Fixed Federated Reporting transport failing on RHEL 10 hubs (ENT-14405) - Fixed a bug regarding the resolution of namespaces inside function-calls (ENT-10199) -- Fixed cf-agent assertion failure when reading /proc//stat - (CFE-4285) +- Fixed `cf-agent` assertion failure when reading `/proc//stat` (CFE-4285) - Fixed cf-check -V (--version) short option - Fixed cf-net -t (--tls-version) and -c (--ciphers) short options - Fixed cf-secret -v (--verbose), -g (--log-level) and -I (--inform) short options - Fixed cf-serverd -L (--ld-library-path) to accept its argument -- Fixed insert_lines ignoring include_end_delimiter when locating the region - (CFE-3988) -- Fixed insert_lines prepending to the file instead of to the selected region - (CFE-3987) +- Fixed `insert_lines` ignoring `include_end_delimiter` when locating the region (CFE-3988) +- Fixed `insert_lines` prepending to the file instead of to the selected region (CFE-3987) - Fixed lmdb maxkeysize assertion for macos - Fixed macOS process start-time/state detection (process_macos.c) and the macOS ps syntax bug in mon_processes_test.c (ENT-14471) - Fixed out-of-bounds read in RemoteDirList when parsing a listing - Fixed out-of-bounds read of extended attribute values in filestat() -- Fixed process_select and file_select time ranges on Windows +- Fixed `process_select` and `file_select` time ranges on Windows - Fixed reports promise being kept when the report could not be written (CFE-4699) - Fixed simulate diff mode not reporting a removal with a version -- Fixed simulate mode reporting both removal and install of the same package - (CFE-4742) +- Fixed simulate mode reporting both removal and install of the same package (CFE-4742) - Fixed simulate mode swapping package version and architecture - Fixed stack buffer overflow in GetServerLiteral for TLS VAR requests -- Fixed usemodule() reporting success when the module exited non-zero - (CFE-942) +- Fixed `usemodule()` reporting success when the module exited non-zero (CFE-942) - Increased the maximum number of cf-monitord measurement slots (CF_OBSERVABLES) from 100 to 300 (ENT-6511) - Made an unrecognized action_policy fatal instead of defaulting to fix @@ -72,15 +63,12 @@ - Mounted a single filesystem surgically instead of running mount -a (CFE-1863) - Moved cf-reactor binary to core (ENT-14275) -- Raised cf-apache.service start timeout to avoid PID-file race - (ENT-11189) +- Raised `cf-apache.service` start timeout to avoid PID-file race (ENT-11189) - The source tarball is now reproducible - `cf-reactor` can now react to a user being added or removed, with the `user_added` and `user_removed` attributes of `when` bodies (ENT-14765) -- and(), or(), concat(), ifelse(), findfiles(), mergedata() and the classmatch() - family reported no parameters at all. Only the leading arguments are described, - as bundlesmatching() and format() already do, and CF_ANYSTRING keeps the - argument type check they activate as permissive as it was. (CFE-4714) +- `and()`, `or()`, `concat()`, `ifelse()`, `findfiles()`, `mergedata()` and the `classmatch()` family reported no parameters at all. + Only the leading arguments are described, as `bundlesmatching()` and `format()` already do. (CFE-4714) - cf-check dump reports measurement names instead of labelling them spare (ENT-14329) - cf-check: check LMDB value size before reading lastseen and lock structs From 904852a5ca5ef01c6ffa3e0110dda5d2124ec823 Mon Sep 17 00:00:00 2001 From: Craig Comstock Date: Wed, 4 Nov 2026 15:13:50 -0600 Subject: [PATCH 54/70] Added support for OPTS environment variable to ci/configure.sh This enables buildscripts/ci/setup-cfengine-build-host.sh to use --with-pcre2=/opt/pcre2 for rhel-8 build hosts with insufficient version of pcre2. libntech needs 10.34+ Ticket: ENT-14716 Changelog: none --- ci/configure.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ci/configure.sh b/ci/configure.sh index e47d02b6e12..8a7d986415d 100755 --- a/ci/configure.sh +++ b/ci/configure.sh @@ -4,7 +4,8 @@ set -ex thisdir="$(dirname "$0")" cd "$thisdir"/.. -OPTS="--config-cache --enable-debug" +# include any existing OPTS in calling environment +OPTS="$OPTS --config-cache --enable-debug" if [ -f /etc/os-release ]; then source /etc/os-release From 96ed8374efec5a87a86d664426e0b85eb10deaa3 Mon Sep 17 00:00:00 2001 From: Craig Comstock Date: Wed, 4 Nov 2026 23:24:08 -0600 Subject: [PATCH 55/70] Added ldconfig to build_lmdb() in ci/dependencies.sh This is needed on systems like rhel-8 which prefer /lib64. build_lmdb() installs to /usr/lib and ldconfig takes care of linking things to /lib64 as it should. Ticket: ENT-14716 Changelog: none --- ci/dependencies.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/dependencies.sh b/ci/dependencies.sh index f3563ab676f..8d6d6af0181 100755 --- a/ci/dependencies.sh +++ b/ci/dependencies.sh @@ -24,6 +24,7 @@ build_lmdb() { cd lmdb/libraries/liblmdb make $GAINROOT make install prefix=/usr + $GAINROOT ldconfig ) } From 9495bd4d432d5b1155a8f9ac130553282052b1b0 Mon Sep 17 00:00:00 2001 From: Bastian Triller Date: Mon, 21 Sep 2026 09:34:05 +0200 Subject: [PATCH 56/70] cf-check: Fix segfault on missing state directory --- cf-check/dump.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cf-check/dump.c b/cf-check/dump.c index e1f8e2cd427..e6f5d3b7b49 100644 --- a/cf-check/dump.c +++ b/cf-check/dump.c @@ -556,6 +556,12 @@ int dump_main(int argc, const char *const *const argv) } Seq *files = argv_to_lmdb_files(argc, argv, offset); + if (files == NULL || SeqLength(files) == 0) + { + printf("No database files to dump.\n"); + return 1; + } + const int ret = dump_dbs(files, mode, tskey_filename); SeqDestroy(files); return ret; From 1a503613ab9f4da8a1ce8d59f29dca706837e1a7 Mon Sep 17 00:00:00 2001 From: Victor Moene Date: Wed, 4 Nov 2026 13:19:21 +0100 Subject: [PATCH 57/70] cf-reactor: fixed file owner detection on windows st_uid/st_gid are always 0 on Windows, so the owner SID is compared instead Signed-off-by: Victor Moene --- cf-reactor/file_watcher.c | 37 ++++++++++++++++++++++++++++++ libpromises/cf-windows-functions.h | 1 + 2 files changed, 38 insertions(+) diff --git a/cf-reactor/file_watcher.c b/cf-reactor/file_watcher.c index fa4f6d54809..76831199f1a 100644 --- a/cf-reactor/file_watcher.c +++ b/cf-reactor/file_watcher.c @@ -34,6 +34,10 @@ #include #include +#ifdef __MINGW32__ +#include /* NovaWin_GetFileOwnerSid() */ +#endif + /* Minimum time between two logs of a persisting failure to check the file, * since the file is checked on every poll */ #define CHECK_ERROR_LOG_INTERVAL_SECS 60 @@ -68,8 +72,15 @@ typedef struct /* FileWatcherCheckFileOwnerChanged() */ struct { +#ifdef __MINGW32__ + /* st_uid/st_gid are always 0 on Windows, so the owner SID is + * compared instead. Zero-padded, so it can be compared with + * memcmp(). */ + unsigned char sid[SECURITY_MAX_SID_SIZE]; +#else uid_t uid; gid_t gid; +#endif } owner; /* FileWatcherCheckFileSizeExceeds() */ @@ -395,6 +406,30 @@ WatcherCheckResult FileWatcherCheckFileOwnerChanged(void *state) return WATCHER_CHECK_ERROR; } +#ifdef __MINGW32__ + unsigned char sid[SECURITY_MAX_SID_SIZE] = { 0 }; + if (exists) + { + const DWORD status = NovaWin_GetFileOwnerSid(fws->path, (SID *) sid, + sizeof(sid)); + if (status == ERROR_FILE_NOT_FOUND || status == ERROR_PATH_NOT_FOUND) + { + exists = false; /* Deleted since lstat() */ + memset(sid, 0, sizeof(sid)); + } + else if (status != ERROR_SUCCESS) + { + LogCheckError(fws, "get the owner of", GetErrorStrFromCode(status)); + return WATCHER_CHECK_ERROR; + } + } + + /* Only changes of a file present at both checks */ + const bool changed = fws->last_exists && exists && + (memcmp(fws->last.owner.sid, sid, sizeof(sid)) != 0); + + memcpy(fws->last.owner.sid, sid, sizeof(sid)); +#else const uid_t uid = exists ? sb.st_uid : 0; const gid_t gid = exists ? sb.st_gid : 0; @@ -404,6 +439,8 @@ WatcherCheckResult FileWatcherCheckFileOwnerChanged(void *state) fws->last.owner.uid = uid; fws->last.owner.gid = gid; +#endif + return FileWatcherRecordObservation(fws, exists, changed, "owner change"); } diff --git a/libpromises/cf-windows-functions.h b/libpromises/cf-windows-functions.h index 733fa4e92e2..5adb72ff4af 100644 --- a/libpromises/cf-windows-functions.h +++ b/libpromises/cf-windows-functions.h @@ -39,6 +39,7 @@ bool NovaWin_FileExists(const char *fileName); bool NovaWin_IsDir(char *fileName); int NovaWin_TakeFileOwnership(char *path); int NovaWin_SetFileOwnership(char *path, SID *sid); +DWORD NovaWin_GetFileOwnerSid(const char *path, SID *sid, DWORD sid_sz); off_t NovaWin_GetDiskUsage(char *file, CfSize type); /* win_log.c */ From 8820b4f83c0f7c141621c1e1cf6bdf7ee05632e0 Mon Sep 17 00:00:00 2001 From: Victor Moene Date: Wed, 4 Nov 2026 12:47:40 +0100 Subject: [PATCH 58/70] cf-reactor: Fixed error messages of failed file checks on Windows LogCheckError() passed errno values to GetErrorStrFromCode(), which on Windows expects a Windows error code, so the logged reason was wrong. Signed-off-by: Victor Moene --- cf-reactor/file_watcher.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/cf-reactor/file_watcher.c b/cf-reactor/file_watcher.c index 76831199f1a..2ac95b7824d 100644 --- a/cf-reactor/file_watcher.c +++ b/cf-reactor/file_watcher.c @@ -129,19 +129,23 @@ void FileWatcherStateDestroy(void *state) // =========== code shared by the file event types =========== -/* Logs the failure of operation op (with errno err) on the file of the - * watcher. A persisting failure is logged at most once every - * CHECK_ERROR_LOG_INTERVAL_SECS. */ -static void LogCheckError(FileWatcherState *fws, const char *op, int err) +/* Logs the failure of operation op (with error message error) on the file of + * the watcher. A persisting failure is logged at most once every + * CHECK_ERROR_LOG_INTERVAL_SECS. + * + * Takes the message rather than an error code, since on Windows + * GetErrorStrFromCode() expects a Windows error code, not an errno value. */ +static void LogCheckError(FileWatcherState *fws, const char *op, const char *error) { assert(fws != NULL); + assert(error != NULL); const time_t now = time(NULL); if (fws->last_error_logged == 0 || now - fws->last_error_logged >= CHECK_ERROR_LOG_INTERVAL_SECS) { Log(LOG_LEVEL_ERR, "Unable to %s '%s' while checking for file events: %s", - op, fws->path, GetErrorStrFromCode(err)); + op, fws->path, error); fws->last_error_logged = now; } } @@ -173,7 +177,7 @@ static bool FileLstat(FileWatcherState *fws, bool *exists, struct stat *sb) return true; } - LogCheckError(fws, "lstat", errno); + LogCheckError(fws, "lstat", strerror(errno)); return false; } @@ -354,7 +358,7 @@ WatcherCheckResult FileWatcherCheckFileContentModified(void *state) } else if (errno != ENOENT && errno != ENOTDIR) /* Not deleted since lstat() */ { - LogCheckError(fws, "hash", errno); + LogCheckError(fws, "hash", strerror(errno)); return WATCHER_CHECK_ERROR; } } From b82206f81f035a0315c11db1ad6e00b8384e7e23 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Thu, 5 Nov 2026 12:09:58 +0100 Subject: [PATCH 59/70] job-backport.yml: renamed from backport.yml Signed-off-by: Lars Erik Wik --- .github/workflows/{backport.yml => job-backport.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{backport.yml => job-backport.yml} (100%) diff --git a/.github/workflows/backport.yml b/.github/workflows/job-backport.yml similarity index 100% rename from .github/workflows/backport.yml rename to .github/workflows/job-backport.yml From ed21ac60552929921f067f84fbf2a554fad025a9 Mon Sep 17 00:00:00 2001 From: Igor Aleksandrychev <16775360+aleksandrychev@users.noreply.github.com> Date: Thu, 5 Nov 2026 13:47:27 +0200 Subject: [PATCH 60/70] Apply batched suggestions from code review Co-authored-by: Lars Erik Wik <53906608+larsewi@users.noreply.github.com> --- CHANGELOG.md | 61 ++++++++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 20c25587fb9..f96f5f057b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,84 +1,85 @@ ## 3.29.0 -- Added --no-lock long option to cf-runagent, matching the existing -K short option +- Added `--no-lock` long option to `cf-runagent`, matching the existing `-K` short option - Added SELinux state and Federated Reporting transport metadata to `cf-support` (ENT-14405) - Added Termux for `sys.os_name_human` when running in Termux Linux Environment (Android) (CFE-4427) - Added `package_installed` and `package_uninstalled` watchers to `cf-reactor` (ENT-14766) -- Added file_older_than policy function (ENT-6065) +- Added `file_older_than()` policy function (ENT-6065) - Added inventory tag `Short hostname` to sys.uqhost (ENT-11265) - Added opt-in remount reconciliation for storage mount options (CFE-1864, CFE-3366, CFE-90) -- Added sshd logs to the cf-support Federated Reporting collection +- Added sshd logs to the `cf-support` Federated Reporting collection (ENT-14405) - Added the `silence` attribute to `body changes`, which suppresses the alert output of selected file-change categories while still setting the change classes and writing the audit log. (CFE-159) - Added the parameters of `string_mustache()` to the syntax description (CFE-4534) - Added the promisee to verbose output for reports promises (CFE-4228) -- Added validfiledata policy function (ENT-8193) -- Adjusted IsReadable() to not use pthread_cancel() on Termux platform +- Added `validfiledata()` policy function (ENT-8193) +- Fixed policy function `IsReadable()` on Termux platform (CFE-4401) - Allowed modules to define empty lists (CFE-2139) - Allowed modules to define lists with a trailing comma (CFE-2140) - Allowed mount promises to target a specific server (CFE-2350) -- Community 'files' promises using hash => "best" now use SHA-512 (previously MD5+SHA1) and no longer report a content change on two consecutive agent runs. Affected files are re-baselined on the first run after upgrade. +- Community `files` promises using `hash => "best"` now use SHA-512 (previously MD5+SHA1) and no longer report a content change on two consecutive agent runs. Affected files are re-baselined on the first run after upgrade. (CFE-3725) - Extended string_replace with list arguments (CFE-4694) - IPv6 masks in `iprange()` no longer need to be a multiple of 8 bits (CFE-2034) -- Fixed --simulate symlink errors to show the real target, not a chroot path +- Fixed `--simulate` symlink errors to show the real target, not a chroot path (ENT-14714) -- Fixed --simulate=diff to report permission and ownership changes +- Fixed `--simulate=diff` to report permission and ownership changes (ENT-14694) -- Fixed --simulate=diff to show the new target of a replaced symlink +- Fixed `--simulate=diff` to show the new target of a replaced symlink (ENT-14713) - Fixed Federated Reporting transport failing on RHEL 10 hubs (ENT-14405) - Fixed a bug regarding the resolution of namespaces inside function-calls (ENT-10199) - Fixed `cf-agent` assertion failure when reading `/proc//stat` (CFE-4285) -- Fixed cf-check -V (--version) short option -- Fixed cf-net -t (--tls-version) and -c (--ciphers) short options -- Fixed cf-secret -v (--verbose), -g (--log-level) and -I (--inform) short options -- Fixed cf-serverd -L (--ld-library-path) to accept its argument +- Fixed `cf-check -V` (`--version`) short option +- Fixed `cf-net -t` (`--tls-version`) and `-c` (`--ciphers`) short options +- Fixed `cf-secret -v` (`--verbose`), `-g` (`--log-level`) and `-I` (`--inform`) short options +- Fixed `cf-serverd -L` (`--ld-library-path`) to accept its argument - Fixed `insert_lines` ignoring `include_end_delimiter` when locating the region (CFE-3988) - Fixed `insert_lines` prepending to the file instead of to the selected region (CFE-3987) - Fixed lmdb maxkeysize assertion for macos -- Fixed macOS process start-time/state detection (process_macos.c) and the macOS ps syntax bug in mon_processes_test.c +- Fixed macOS process start-time/state detection (`process_macos.c`) and the macOS ps syntax bug in `mon_processes_test.c` (ENT-14471) -- Fixed out-of-bounds read in RemoteDirList when parsing a listing -- Fixed out-of-bounds read of extended attribute values in filestat() +- Fixed out-of-bounds read when parsing a remote directory listing +- Fixed out-of-bounds read of extended attribute values in policy function `filestat()` - Fixed `process_select` and `file_select` time ranges on Windows -- Fixed reports promise being kept when the report could not be written +- Fixed issue where reports promise was kept even though the report could not be written (CFE-4699) - Fixed simulate diff mode not reporting a removal with a version - Fixed simulate mode reporting both removal and install of the same package (CFE-4742) - Fixed simulate mode swapping package version and architecture -- Fixed stack buffer overflow in GetServerLiteral for TLS VAR requests +- Fixed stack buffer overflow in `cf-serverd` when serving `remotescalar()` and `hubknowledge()` requests - Fixed `usemodule()` reporting success when the module exited non-zero (CFE-942) -- Increased the maximum number of cf-monitord measurement slots (CF_OBSERVABLES) from 100 to 300 +- Increased the maximum number of `cf-monitord` measurement slots from 100 to 300 (ENT-6511) -- Made an unrecognized action_policy fatal instead of defaulting to fix +- Made an unrecognized `action_policy` fatal instead of defaulting to fix (CFE-1982) - Made format function collect data container (CFE-3105) - Maintained fstab entries for already-mounted filesystems (CFE-1539) -- Mounted a single filesystem surgically instead of running mount -a +- Now mounts a single filesystem surgically instead of running `mount -a` (CFE-1863) -- Moved cf-reactor binary to core (ENT-14275) +- `cf-reactor` is now a part of CFEngine Community (ENT-14275) - Raised `cf-apache.service` start timeout to avoid PID-file race (ENT-11189) - The source tarball is now reproducible - `cf-reactor` can now react to a user being added or removed, with the `user_added` and `user_removed` attributes of `when` bodies (ENT-14765) - `and()`, `or()`, `concat()`, `ifelse()`, `findfiles()`, `mergedata()` and the `classmatch()` family reported no parameters at all. Only the leading arguments are described, as `bundlesmatching()` and `format()` already do. (CFE-4714) -- cf-check dump reports measurement names instead of labelling them spare +- `cf-check` dump now reports measurement names instead of labeling them spare (ENT-14329) -- cf-check: check LMDB value size before reading lastseen and lock structs -- cf-monitord no longer silently truncates the ts_key measurement name file +- `cf-check` now checks LMDB value size before reading lastseen and lock structs +- `cf-monitord` no longer silently truncates the `ts_key` measurement name file (ENT-14329) -- cf-monitord stores only in-use measurement slots (ENT-14329) -- cf-reactor: Fixed missing option description in --help output -- fix leak of uninitialized stack memory in CfGetFile refusal replies -- fix out-of-bounds read in FuzzySetMatch/FuzzyMatchParse octet scan -- fix stack buffer overflow parsing mount and netstat command output +- `cf-monitord` now stores only in-use measurement slots (ENT-14329) +- Added missing option description in `--help` output of `cf-reactor` +- Fixed `cf-serverd` leaking uninitialized memory to clients when refusing a file copy request +- Fixed out-of-bounds read in `iprange()` and `isipinsubnet()` when the address is shorter than the range +- Fixed stack buffer overflow in `cf-agent` and `cf-monitord` on overly long lines in `mount` or `netstat` output +- Policy function `format()` now rejects format specifiers `*` and `$` ## 3.28.0 From 3836d6e95fde9f3d424f2d6f52c100428c4147bb Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Thu, 5 Nov 2026 12:49:13 +0100 Subject: [PATCH 61/70] job-backport.yml: made reusable, called from backport.yml Signed-off-by: Lars Erik Wik --- .github/workflows/backport.yml | 14 ++++++++++++++ .github/workflows/job-backport.yml | 12 ++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/backport.yml diff --git a/.github/workflows/backport.yml b/.github/workflows/backport.yml new file mode 100644 index 00000000000..46cf4aafc94 --- /dev/null +++ b/.github/workflows/backport.yml @@ -0,0 +1,14 @@ +name: Backport + +on: + push: + branches: [master] + +permissions: + contents: write + pull-requests: write + +jobs: + backport: + if: github.repository == 'cfengine/core' + uses: ./.github/workflows/job-backport.yml diff --git a/.github/workflows/job-backport.yml b/.github/workflows/job-backport.yml index 92ccc8fc3dd..b430c7b5816 100644 --- a/.github/workflows/job-backport.yml +++ b/.github/workflows/job-backport.yml @@ -6,18 +6,14 @@ name: Backport # says that a manual backport is needed. # # The label must be set before merging. +# +# Call it from a workflow triggered on push to master. The caller must grant +# `contents: write` and `pull-requests: write`. -on: - push: - branches: [master] - -permissions: - contents: write - pull-requests: write +on: workflow_call jobs: backport: - if: github.repository == 'cfengine/core' runs-on: ubuntu-latest strategy: fail-fast: false From dac3db2fbafd3d7626c378bddc4c0006605cd87a Mon Sep 17 00:00:00 2001 From: Dhanraj E Date: Fri, 6 Nov 2026 13:41:17 +0530 Subject: [PATCH 62/70] fix stack overflow building absolute path from relative symlink target cf-agent reconstructs the absolute target of a relative symbolic link by appending the readlink() result onto the link's directory name in a CF_BUFSIZE stack buffer. KillGhostLink() in files_links.c did this with an unbounded strcat(linkpath, linkbuf), and LinkCopy() in verify_files_utils.c with strncat(vbuff, linkbuf, CF_BUFSIZE - 1), whose third argument is the maximum number of bytes to take from the source, not the space left in the destination. readlink() returns up to CF_BUFSIZE - 1 bytes, so a symlink whose relative target is near CF_BUFSIZE, left by an unprivileged user in a directory that a root files promise walks (depth_search, perms, link copy), overflows the stack of the agent. KillGhostLink() runs on every symlink met during a recursive descent, before the dead-link stat(). Bound both appends with strlcat(..., sizeof(buf)), the same way ExpandLinks() in files_links.c already does. KillGhostLink() bails out with an "Internal limit reached" message and LinkCopy() fails the promise when the target does not fit, rather than truncating it into a link pointing somewhere else. Normal links are unchanged. The regression test is skipped when symlink() rejects the long target with ENAMETOOLONG, as macOS does. Changelog: Title Signed-off-by: Dhanraj E --- cf-agent/verify_files_utils.c | 18 +++++++++++---- libpromises/files_links.c | 8 ++++++- tests/unit/files_links_test.c | 41 ++++++++++++++++++++++++++++++++++- 3 files changed, 61 insertions(+), 6 deletions(-) diff --git a/cf-agent/verify_files_utils.c b/cf-agent/verify_files_utils.c index 7931ae87544..cf7ad2a0be1 100644 --- a/cf-agent/verify_files_utils.c +++ b/cf-agent/verify_files_utils.c @@ -1338,16 +1338,26 @@ static PromiseResult LinkCopy(EvalContext *ctx, char *sourcefile, char *destfile strlcpy(vbuff, changes_sourcefile, CF_BUFSIZE); ChopLastNode(vbuff); AddSlash(vbuff); - strncat(vbuff, chrooted_linkbuf, CF_BUFSIZE - 1); - strlcpy(chrooted_linkbuf, vbuff, CF_BUFSIZE - 1); + if (strlcat(vbuff, chrooted_linkbuf, sizeof(vbuff)) >= sizeof(vbuff) || + strlcpy(chrooted_linkbuf, vbuff, sizeof(chrooted_linkbuf)) >= sizeof(chrooted_linkbuf)) + { + RecordFailure(ctx, pp, attr, + "Absolute target of link '%s' is too long", sourcefile); + return PROMISE_RESULT_FAIL; + } } else { strlcpy(vbuff, sourcefile, CF_BUFSIZE); ChopLastNode(vbuff); AddSlash(vbuff); - strncat(vbuff, linkbuf, CF_BUFSIZE - 1); - strlcpy(linkbuf, vbuff, CF_BUFSIZE - 1); + if (strlcat(vbuff, linkbuf, sizeof(vbuff)) >= sizeof(vbuff) || + strlcpy(linkbuf, vbuff, sizeof(linkbuf)) >= sizeof(linkbuf)) + { + RecordFailure(ctx, pp, attr, + "Absolute target of link '%s' is too long", sourcefile); + return PROMISE_RESULT_FAIL; + } } } } diff --git a/libpromises/files_links.c b/libpromises/files_links.c index 62fd9b58a2a..33125e44c69 100644 --- a/libpromises/files_links.c +++ b/libpromises/files_links.c @@ -528,7 +528,13 @@ bool KillGhostLink(EvalContext *ctx, const char *name, const Attributes *attr, c } } - strcat(linkpath, linkbuf); + if (strlcat(linkpath, linkbuf, sizeof(linkpath)) >= sizeof(linkpath)) + { + Log(LOG_LEVEL_ERR, + "Internal limit reached in KillGhostLink()," + " path too long: '%s' + '%s'", linkpath, linkbuf); + return false; + } CompressPath(tmp, sizeof(tmp), linkpath); if (stat(tmp, &statbuf) == -1) /* link points nowhere */ diff --git a/tests/unit/files_links_test.c b/tests/unit/files_links_test.c index 6b2fae5739d..0b1eefc73c6 100644 --- a/tests/unit/files_links_test.c +++ b/tests/unit/files_links_test.c @@ -25,7 +25,10 @@ #include #include -#include /* ExpandLinks */ +#include /* ExpandLinks, KillGhostLink */ +#include /* Attributes */ +#include /* symlink, unlink */ +#include /* errno */ /* A single path component longer than the internal node buffer * (CF_MAXLINKSIZE) overflowed the stack in ExpandLinks(): the parse into @@ -44,12 +47,48 @@ static void test_expand_links_long_component(void) assert_false(ret); } +/* KillGhostLink() rebuilds the absolute target of a relative symlink by + * appending the readlink() result onto the link's directory in a CF_BUFSIZE + * buffer. The append was an unbounded strcat(), so a symlink whose relative + * target is near CF_BUFSIZE overflowed the stack. It must bail out instead. */ +static void test_kill_ghost_link_long_target(void) +{ + char tmpl[] = "/tmp/cfghostXXXXXX"; + const char *dir = mkdtemp(tmpl); + assert_true(dir != NULL); + + char linkpath[256]; + xsnprintf(linkpath, sizeof(linkpath), "%s/l", dir); + + char target[CF_BUFSIZE]; + memset(target, 'x', sizeof(target) - 1); + target[sizeof(target) - 1] = '\0'; + if (symlink(target, linkpath) != 0) + { + /* Some platforms (e.g. macOS) refuse targets this long, in which + * case the overflow cannot be reached and there's nothing to test. */ + assert_int_equal(errno, ENAMETOOLONG); + rmdir(dir); + return; + } + + Attributes attr = { 0 }; + attr.link.when_no_file = cfa_delete; + PromiseResult result = PROMISE_RESULT_NOOP; + + assert_false(KillGhostLink(NULL, linkpath, &attr, NULL, &result)); + + unlink(linkpath); + rmdir(dir); +} + int main() { PRINT_TEST_BANNER(); const UnitTest tests[] = { unit_test(test_expand_links_long_component), + unit_test(test_kill_ghost_link_long_target), }; return run_tests(tests); From 243e617ff277d66705d95a20e523c9428508728f Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Fri, 6 Nov 2026 13:35:56 +0100 Subject: [PATCH 63/70] Now removes the cherry-pick? label after successful backports Ticket: ENT-14717 Co-Authored-By: Claude Opus 5.5 Signed-off-by: Lars Erik Wik --- .github/workflows/job-backport.yml | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/.github/workflows/job-backport.yml b/.github/workflows/job-backport.yml index b430c7b5816..e93108a2bc5 100644 --- a/.github/workflows/job-backport.yml +++ b/.github/workflows/job-backport.yml @@ -3,7 +3,8 @@ name: Backport # Opens backport pull requests to the LTS branches when a pull request with the # `cherry-pick?` label is merged to master. Commits are cherry-picked with `-x`. # Each branch comments on the original pull request with the backport link, or -# says that a manual backport is needed. +# says that a manual backport is needed. If all branches succeed, the label is +# removed. # # The label must be set before merging. # @@ -94,4 +95,24 @@ jobs: gh pr comment "$PR" --body "Backport to $BRANCH: $URL" else gh pr comment "$PR" --body "Backport to $BRANCH failed, manual backport needed: $RUN_URL" + # Fail the job so the label is kept + exit 1 + fi + + remove_label: + needs: backport + runs-on: ubuntu-latest + steps: + - name: Remove the label + env: + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} + MERGE_SHA: ${{ github.sha }} + run: | + pr=$(gh api "repos/$GH_REPO/commits/$MERGE_SHA/pulls" \ + --jq 'first(.[] | select(any(.labels[]; .name == "cherry-pick?")) | .number)') + if [ -z "$pr" ]; then + echo "No merged PR with the cherry-pick? label, nothing to do" + exit 0 fi + gh pr edit "$pr" --remove-label "cherry-pick?" From 1b9190ce2f5263c380d3894becd4d9bd8452cfb2 Mon Sep 17 00:00:00 2001 From: Ihor Aleksandrychiev Date: Fri, 6 Nov 2026 20:05:45 +0200 Subject: [PATCH 64/70] Bumped .CFVERSION number to 3.30.0 Signed-off-by: Ihor Aleksandrychiev --- .CFVERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.CFVERSION b/.CFVERSION index c7c9773262c..1cfe511a3ed 100644 --- a/.CFVERSION +++ b/.CFVERSION @@ -1 +1 @@ -3.29.0 +3.30.0 From f532dd7347ef5bd070ef6c54efdaf422eda028d4 Mon Sep 17 00:00:00 2001 From: Victor Moene Date: Mon, 9 Nov 2026 15:23:35 +0100 Subject: [PATCH 65/70] Added isvalidip: function for validating IP addresses Ticket: CFE-3478 Signed-off-by: Victor Moene --- libpromises/evalfunction.c | 51 ++++++++ .../02_classes/02_functions/isvalidip.cf | 109 ++++++++++++++++++ .../02_functions/isvalidip_bad_version.x.cf | 29 +++++ 3 files changed, 189 insertions(+) create mode 100644 tests/acceptance/02_classes/02_functions/isvalidip.cf create mode 100644 tests/acceptance/02_classes/02_functions/isvalidip_bad_version.x.cf diff --git a/libpromises/evalfunction.c b/libpromises/evalfunction.c index d42df8c6fca..7f693714935 100644 --- a/libpromises/evalfunction.c +++ b/libpromises/evalfunction.c @@ -6571,6 +6571,48 @@ static FnCallResult FnCallIsIpInSubnet(ARG_UNUSED EvalContext *ctx, Log(LOG_LEVEL_DEBUG, "%s(%s): no match", fp->name, range); return FnReturnContext(false); } + +/*********************************************************************/ + +static FnCallResult FnCallIsValidIP(ARG_UNUSED EvalContext *ctx, + ARG_UNUSED const Policy *policy, + const FnCall *fp, const Rlist *finalargs) +{ + assert(fp != NULL); + + if (finalargs == NULL || + (finalargs->next != NULL && finalargs->next->next != NULL)) + { + Log(LOG_LEVEL_ERR, "Function '%s' requires one or two arguments", fp->name); + return FnFailure(); + } + + const char *address = RlistScalarValue(finalargs); + const char *version = (finalargs->next != NULL) + ? RlistScalarValue(finalargs->next) + : NULL; + + if (version != NULL && + !StringEqual(version, "ipv4") && !StringEqual(version, "ipv6")) + { + Log(LOG_LEVEL_ERR, + "Function '%s': invalid IP version '%s', expected 'ipv4' or 'ipv6'", + fp->name, version); + return FnFailure(); + } + + const bool check_ipv4 = (version == NULL || StringEqual(version, "ipv4")); + const bool check_ipv6 = (version == NULL || StringEqual(version, "ipv6")); + + unsigned char binary[sizeof(struct in6_addr)]; + const bool valid = + (check_ipv4 && inet_pton(AF_INET, address, binary) == 1) || + (check_ipv6 && inet_pton(AF_INET6, address, binary) == 1); + + Log(LOG_LEVEL_DEBUG, "%s(%s): %s", fp->name, address, valid ? "valid" : "invalid"); + return FnReturnContext(valid); +} + /*********************************************************************/ static FnCallResult FnCallHostRange(ARG_UNUSED EvalContext *ctx, ARG_UNUSED const Policy *policy, ARG_UNUSED const FnCall *fp, const Rlist *finalargs) @@ -11098,6 +11140,13 @@ static const FnCallArg IPRANGE_ARGS[] = {NULL, CF_DATA_TYPE_NONE, NULL} }; +static const FnCallArg ISVALIDIP_ARGS[] = +{ + {CF_ANYSTRING, CF_DATA_TYPE_STRING, "String to validate as an IP address"}, + {"ipv4,ipv6", CF_DATA_TYPE_OPTION, "Only accept this IP version"}, + {NULL, CF_DATA_TYPE_NONE, NULL} +}; + static const FnCallArg IRANGE_ARGS[] = { {CF_INTRANGE, CF_DATA_TYPE_INT, "Integer start of range"}, @@ -12004,6 +12053,8 @@ const FnCallType CF_FNCALL_TYPES[] = FNCALL_OPTION_VARARG, FNCALL_CATEGORY_COMM, SYNTAX_STATUS_NORMAL, ARGC(1, -1)), FnCallTypeNew("isipinsubnet", CF_DATA_TYPE_CONTEXT, IPRANGE_ARGS, &FnCallIsIpInSubnet, "True if an IP address specified in arg2, arg3, ... lies in the range of IP addresses specified in arg1", FNCALL_OPTION_VARARG, FNCALL_CATEGORY_COMM, SYNTAX_STATUS_NORMAL, ARGC(1, -1)), + FnCallTypeNew("isvalidip", CF_DATA_TYPE_CONTEXT, ISVALIDIP_ARGS, &FnCallIsValidIP, "True if arg1 is a valid IPv4 or IPv6 address (only the IP version arg2, if given)", + FNCALL_OPTION_VARARG, FNCALL_CATEGORY_COMM, SYNTAX_STATUS_NORMAL, ARGC(1, 2)), FnCallTypeNew("irange", CF_DATA_TYPE_INT_RANGE, IRANGE_ARGS, &FnCallIRange, "Define a range of integer values for cfengine internal use", FNCALL_OPTION_NONE, FNCALL_CATEGORY_DATA, SYNTAX_STATUS_NORMAL, DEFAULT_ARGC), FnCallTypeNew("isconnectable", CF_DATA_TYPE_CONTEXT, ISCONNECTABLE_ARGS, &FnCallIsConnectable, "Check if a port is connectable", diff --git a/tests/acceptance/02_classes/02_functions/isvalidip.cf b/tests/acceptance/02_classes/02_functions/isvalidip.cf new file mode 100644 index 00000000000..e2b92e4a469 --- /dev/null +++ b/tests/acceptance/02_classes/02_functions/isvalidip.cf @@ -0,0 +1,109 @@ +####################################################### +# +# Test isvalidip() +# +####################################################### +body common control +{ + inputs => { "../../default.sub.cf" }; + bundlesequence => { default("$(this.promise_filename)") }; + version => "1.0"; +} + +####################################################### +bundle agent test +{ + meta: + "description" -> { "CFE-3478" } + string => "Test that isvalidip() validates IPv4 and IPv6 addresses"; + + vars: + "valid" + slist => { + "1.2.3.4", + "127.0.0.1", + "5.9.10.22", + "0.0.0.0", + "255.255.255.255", + "FE80:CD00:0000:0CDE:1257:0000:211E:729C", + "fe80:cd00:0:cde:1257:0:211e:729c", + "2001:db8::1", + "::1", + "::", + "::ffff:192.0.2.128", + }; + + "invalid" + slist => { + "", + "10510.17.10", + "100", + "1.2.3", + "1.2.3.4.5", + "233.444.23.1", + "300.123.123.1", + "1.2.3.4/24", + "1.2.3.4:80", + " 1.2.3.4", + "1.2.3.4 ", + "localhost", + "[::1]", + "[::1]:80", + "1::2::3", + "12345::1", + "g::1", + "1:2:3:4:5:6:7:8:9", + "2001:db8::/32", + }; + + "valid_ipv4" slist => { "1.2.3.4", "255.255.255.255" }; + + "invalid_ipv4" + slist => { + "::1", + "::ffff:192.0.2.128", + "FE80:CD00:0000:0CDE:1257:0000:211E:729C", + "300.123.123.1", + }; + + "valid_ipv6" + slist => { + "::1", "::ffff:192.0.2.128", "FE80:CD00:0000:0CDE:1257:0000:211E:729C", + }; + + "invalid_ipv6" slist => { "1.2.3.4", "255.255.255.255", "12345::1" }; +} + +####################################################### +bundle agent check +{ + classes: + "fail" not => isvalidip("$(test.valid)"); + "fail" expression => isvalidip("$(test.invalid)"); + "fail" not => isvalidip("$(test.valid_ipv4)", "ipv4"); + "fail" expression => isvalidip("$(test.invalid_ipv4)", "ipv4"); + "fail" not => isvalidip("$(test.valid_ipv6)", "ipv6"); + "fail" expression => isvalidip("$(test.invalid_ipv6)", "ipv6"); + + reports: + "Wrongly rejected '$(test.valid)'" unless => isvalidip("$(test.valid)"); + "Wrongly accepted '$(test.invalid)'" if => isvalidip("$(test.invalid)"); + + "Wrongly rejected '$(test.valid_ipv4)' as IPv4" + unless => isvalidip("$(test.valid_ipv4)", "ipv4"); + + "Wrongly accepted '$(test.invalid_ipv4)' as IPv4" + if => isvalidip("$(test.invalid_ipv4)", "ipv4"); + + "Wrongly rejected '$(test.valid_ipv6)' as IPv6" + unless => isvalidip("$(test.valid_ipv6)", "ipv6"); + + "Wrongly accepted '$(test.invalid_ipv6)' as IPv6" + if => isvalidip("$(test.invalid_ipv6)", "ipv6"); + + !fail:: + "$(this.promise_filename) Pass"; + + fail:: + "$(this.promise_filename) FAIL"; +} diff --git a/tests/acceptance/02_classes/02_functions/isvalidip_bad_version.x.cf b/tests/acceptance/02_classes/02_functions/isvalidip_bad_version.x.cf new file mode 100644 index 00000000000..e9f08d09e3a --- /dev/null +++ b/tests/acceptance/02_classes/02_functions/isvalidip_bad_version.x.cf @@ -0,0 +1,29 @@ +####################################################### +# +# Test that isvalidip() rejects an unknown IP version +# +####################################################### +body common control +{ + inputs => { "../../default.sub.cf" }; + bundlesequence => { default("$(this.promise_filename)") }; + version => "1.0"; +} + +####################################################### +bundle agent test +{ + meta: + "description" -> { "CFE-3478" } + string => "Test that isvalidip() fails on an IP version other than ipv4 or ipv6"; + + classes: + "valid" expression => isvalidip("1.2.3.4", "ipv5"); +} + +####################################################### +bundle agent check +{ + reports: + "$(this.promise_filename) Pass"; +} From ab0408f1f8f898e8f22b6a100d7106d46a4a3008 Mon Sep 17 00:00:00 2001 From: Daniel JB Clark Date: Tue, 10 Nov 2026 12:05:11 -0500 Subject: [PATCH 66/70] Fixed simulate diff mode aborting on repeated unversioned package installs DiffPkgOperations() compared the versions of two recorded installations of the same package without checking that both were set, which PkgVersionIsGreater() asserts. The diff report now keeps the record the way the manifest report does: a versioned record over an unversioned one, otherwise the higher version, otherwise the first one recorded. Ticket: none Changelog: Title Signed-off-by: Daniel JB Clark Co-Authored-By: Claude Fable 5.1 Co-Authored-By: Claude Fable 5.2 Co-Authored-By: Claude Opus 5.5 --- cf-agent/simulate_mode.c | 27 +++++++- tests/unit/simulate_mode_test.c | 114 ++++++++++++++++++++++++++++++-- 2 files changed, 135 insertions(+), 6 deletions(-) diff --git a/cf-agent/simulate_mode.c b/cf-agent/simulate_mode.c index 35264e62cc2..2b1d2995ab7 100644 --- a/cf-agent/simulate_mode.c +++ b/cf-agent/simulate_mode.c @@ -793,6 +793,31 @@ static inline char *GetPkgOperationMsg(ChrootPkgOperationCode op, const char *pk return msg; } +static bool PkgRecordShouldBeReplaced(const PkgOperationRecord *prev_record, + const char *new_ver) +{ + if (prev_record == NULL) + { + /* Nothing recorded yet */ + return true; + } + + if (NULL_OR_EMPTY(new_ver)) + { + /* An unversioned record never replaces an existing one */ + return false; + } + + if (NULL_OR_EMPTY(prev_record->pkg_ver)) + { + /* A versioned record is more specific than an unversioned one */ + return true; + } + + /* Both are versioned, keep the higher version */ + return PkgVersionIsGreater(new_ver, prev_record->pkg_ver); +} + bool DiffPkgOperations() { const char *pkgs_ops_csv_file = ToChangesChroot(CHROOT_PKGS_OPS_FILE); @@ -893,7 +918,7 @@ bool DiffPkgOperations() MapRemove(removed, name_arch); PkgOperationRecord *prev_record = MapGet(installed, name_arch); - if ((prev_record == NULL) || PkgVersionIsGreater(pkg_ver, prev_record->pkg_ver)) + if (PkgRecordShouldBeReplaced(prev_record, pkg_ver)) { char *msg = GetPkgOperationMsg(CHROOT_PKG_OPERATION_CODE_INSTALL, pkg_name, pkg_arch, pkg_ver); diff --git a/tests/unit/simulate_mode_test.c b/tests/unit/simulate_mode_test.c index 10b5513121a..9aa8cc01a1e 100644 --- a/tests/unit/simulate_mode_test.c +++ b/tests/unit/simulate_mode_test.c @@ -82,8 +82,8 @@ static void test_diff_install_cancels_removal(void) char output[4096]; assert_true(call_with_captured_stdout(&DiffPkgOperations, output, sizeof(output))); - assert_true(strstr(output, "Package 'foo [1.2.3]' would be installed") != NULL); - assert_true(strstr(output, "would be removed") == NULL); + assert_true(StringContains(output, "Package 'foo [1.2.3]' would be installed")); + assert_false(StringContains(output, "would be removed")); unlink(ToChangesChroot(CHROOT_PKGS_OPS_FILE)); } @@ -98,7 +98,7 @@ static void test_diff_version_and_architecture(void) char output[4096]; assert_true(call_with_captured_stdout(&DiffPkgOperations, output, sizeof(output))); - assert_true(strstr(output, "Package 'foo-x86_64 [1.2.3]' would be installed") != NULL); + assert_true(StringContains(output, "Package 'foo-x86_64 [1.2.3]' would be installed")); unlink(ToChangesChroot(CHROOT_PKGS_OPS_FILE)); } @@ -141,8 +141,106 @@ static void test_manifest_install_cancels_removal(void) char output[4096]; assert_true(call_with_captured_stdout(&ManifestPkgOperations, output, sizeof(output))); - assert_true(strstr(output, "Package 'foo [1.2.3]' would be present") != NULL); - assert_true(strstr(output, "would be absent") == NULL); + assert_true(StringContains(output, "Package 'foo [1.2.3]' would be present")); + assert_false(StringContains(output, "would be absent")); + + unlink(ToChangesChroot(CHROOT_PKGS_OPS_FILE)); +} + +/* Two recorded installations of the same package without a version must be + * reported once, not abort on comparing the empty versions. */ +static void test_diff_repeated_unversioned_install(void) +{ + write_pkgs_ops("i,foo,,\r\n" + "i,foo,,\r\n"); + + char output[4096]; + assert_true(call_with_captured_stdout(&DiffPkgOperations, output, sizeof(output))); + + assert_true(StringContains(output, "Package 'foo' would be installed")); + /* Reported once: the report has no other line. */ + assert_int_equal(StringCountTokens(output, strlen(output), "\n"), 1); + + unlink(ToChangesChroot(CHROOT_PKGS_OPS_FILE)); +} + +/* A versioned installation record is more specific than an unversioned one + * of the same package, so it is the one to report. */ +static void test_diff_unversioned_then_versioned_install(void) +{ + write_pkgs_ops("i,foo,,\r\n" + "i,foo,1.2.3,\r\n"); + + char output[4096]; + assert_true(call_with_captured_stdout(&DiffPkgOperations, output, sizeof(output))); + + assert_true(StringContains(output, "Package 'foo [1.2.3]' would be installed")); + assert_false(StringContains(output, "Package 'foo' would be installed")); + + unlink(ToChangesChroot(CHROOT_PKGS_OPS_FILE)); +} + +/* An unversioned installation record must never replace an existing + * versioned installation record of the same package. */ +static void test_diff_versioned_then_unversioned_install(void) +{ + write_pkgs_ops("i,foo,1.2.3,\r\n" + "i,foo,,\r\n"); + + char output[4096]; + assert_true(call_with_captured_stdout(&DiffPkgOperations, output, sizeof(output))); + + assert_true(StringContains(output, "Package 'foo [1.2.3]' would be installed")); + assert_false(StringContains(output, "Package 'foo' would be installed")); + + unlink(ToChangesChroot(CHROOT_PKGS_OPS_FILE)); +} + +/* When two installations are recorded with different versions and the first + * has the higher version, the first record is kept. */ +static void test_diff_install_higher_version_first_keeps_first(void) +{ + write_pkgs_ops("i,foo,2.0.0,\r\n" + "i,foo,1.0.0,\r\n"); + + char output[4096]; + assert_true(call_with_captured_stdout(&DiffPkgOperations, output, sizeof(output))); + + assert_true(StringContains(output, "Package 'foo [2.0.0]' would be installed")); + assert_false(StringContains(output, "Package 'foo [1.0.0]' would be installed")); + + unlink(ToChangesChroot(CHROOT_PKGS_OPS_FILE)); +} + +/* When two installations are recorded with different versions and the last + * has the higher version, the last record replaces the first. */ +static void test_diff_install_higher_version_last_keeps_last(void) +{ + write_pkgs_ops("i,foo,1.0.0,\r\n" + "i,foo,2.0.0,\r\n"); + + char output[4096]; + assert_true(call_with_captured_stdout(&DiffPkgOperations, output, sizeof(output))); + + assert_true(StringContains(output, "Package 'foo [2.0.0]' would be installed")); + assert_false(StringContains(output, "Package 'foo [1.0.0]' would be installed")); + + unlink(ToChangesChroot(CHROOT_PKGS_OPS_FILE)); +} + +/* Two recorded installations of the same package with the same version + * must be reported once. */ +static void test_diff_repeated_versioned_install(void) +{ + write_pkgs_ops("i,foo,1.2.3,\r\n" + "i,foo,1.2.3,\r\n"); + + char output[4096]; + assert_true(call_with_captured_stdout(&DiffPkgOperations, output, sizeof(output))); + + assert_true(StringContains(output, "Package 'foo [1.2.3]' would be installed")); + /* Reported once: the report has no other line. */ + assert_int_equal(StringCountTokens(output, strlen(output), "\n"), 1); unlink(ToChangesChroot(CHROOT_PKGS_OPS_FILE)); } @@ -161,6 +259,12 @@ int main() unit_test(test_diff_removal_with_version), unit_test(test_diff_removal_with_other_version_keeps_install), unit_test(test_manifest_install_cancels_removal), + unit_test(test_diff_repeated_unversioned_install), + unit_test(test_diff_unversioned_then_versioned_install), + unit_test(test_diff_versioned_then_unversioned_install), + unit_test(test_diff_install_higher_version_first_keeps_first), + unit_test(test_diff_install_higher_version_last_keeps_last), + unit_test(test_diff_repeated_versioned_install), }; int ret = run_tests(tests); From acb4267789dce31d2c4f7539e554101e46142ad2 Mon Sep 17 00:00:00 2001 From: Nick Anderson Date: Wed, 11 Nov 2026 16:41:06 -0600 Subject: [PATCH 67/70] Checked RAND_bytes() result when creating bootstrap_id.dat Changelog: None --- libpromises/bootstrap.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/libpromises/bootstrap.c b/libpromises/bootstrap.c index e79a92294a1..c9b3a6a48b1 100644 --- a/libpromises/bootstrap.c +++ b/libpromises/bootstrap.c @@ -362,8 +362,18 @@ static char *BootstrapIDFilename(const char *workdir) char *CreateBootstrapIDFile(const char *workdir) { assert(workdir != NULL); - char *filename = BootstrapIDFilename(workdir); + CryptoInitialize(); + #define RANDOM_BYTES 240 / 8 // 240 avoids padding (divisible by 6) + #define BASE_64_LENGTH_NO_PADDING (4 * (RANDOM_BYTES / 3)) + unsigned char buf[RANDOM_BYTES]; + if (RAND_bytes(buf, RANDOM_BYTES) != 1) + { + Log(LOG_LEVEL_ERR, "Unable to generate random bootstrap id (RAND_bytes: %s)", + CryptoLastErrorString()); + return NULL; + } + char *filename = BootstrapIDFilename(workdir); FILE *file = safe_fopen_create_perms(filename, "w", CF_PERMS_DEFAULT); if (file == NULL) { @@ -371,11 +381,6 @@ char *CreateBootstrapIDFile(const char *workdir) free(filename); return NULL; } - CryptoInitialize(); - #define RANDOM_BYTES 240 / 8 // 240 avoids padding (divisible by 6) - #define BASE_64_LENGTH_NO_PADDING (4 * (RANDOM_BYTES / 3)) - unsigned char buf[RANDOM_BYTES]; - RAND_bytes(buf, RANDOM_BYTES); char *b64_id = StringEncodeBase64(buf, RANDOM_BYTES); fprintf(file, "%s\n", b64_id); fclose(file); From 345cc37a96541dfbbdc5d2bafcbe4604d935c017 Mon Sep 17 00:00:00 2001 From: Ihor Aleksandrychiev Date: Thu, 12 Nov 2026 14:24:55 +0200 Subject: [PATCH 68/70] Changed backport branch name to backport/- Branch protection patterns like "*" do not match "/", so the old backport-- name was blocked in repos protecting all branches. Changelog: None Signed-off-by: Ihor Aleksandrychiev --- .github/workflows/job-backport.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/job-backport.yml b/.github/workflows/job-backport.yml index e93108a2bc5..5fa40ebfbb4 100644 --- a/.github/workflows/job-backport.yml +++ b/.github/workflows/job-backport.yml @@ -70,7 +70,7 @@ jobs: uses: cfengine/create-pull-request@v7.0.7a with: base: ${{ matrix.branch }} - branch: backport-${{ steps.find_pr.outputs.number }}-${{ matrix.branch }} + branch: backport/${{ steps.find_pr.outputs.number }}-${{ matrix.branch }} delete-branch: true sign-commits: true title: ${{ steps.find_pr.outputs.title }} (${{ matrix.branch }}) From 21aa78d9b44f7b9bdf461c87b6bc66ed7c092cdd Mon Sep 17 00:00:00 2001 From: Ole Herman Schumacher Elgesem Date: Fri, 13 Nov 2026 18:56:20 +0100 Subject: [PATCH 69/70] Fixed typo Signed-off-by: Ole Herman Schumacher Elgesem --- contrib/agentsvg/agentsvg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/agentsvg/agentsvg.py b/contrib/agentsvg/agentsvg.py index bee4c26a5b7..b7053960b09 100644 --- a/contrib/agentsvg/agentsvg.py +++ b/contrib/agentsvg/agentsvg.py @@ -61,7 +61,7 @@ def get_args(): description="Beautiful CFEngine agent logos", formatter_class=argparse.ArgumentDefaultsHelpFormatter) - ap.add_argument("--radius", "-r", help="Circle raidus", type=int, default=16) + ap.add_argument("--radius", "-r", help="Circle radius", type=int, default=16) ap.add_argument("--no-margins", help="No extra space around the agent", action="store_true") ap.add_argument("--body", help="Body color", type=str, default=cfengine_blue) ap.add_argument("--head", help="Head color", type=str, default=cfengine_orange) From 9e309c635a57a8c157af574daf57e61940c24bbd Mon Sep 17 00:00:00 2001 From: Daniel JB Clark Date: Thu, 12 Nov 2026 09:08:35 -0500 Subject: [PATCH 70/70] Fixed crash on JSON null values in host_specific.json Reject null scalar values and keep loading valid entries. Changelog: Title Ticket: none Signed-off-by: Daniel JB Clark --- libpromises/cmdb.c | 23 +++++-- .../06_host_specific_data/13-null-values.cf | 61 +++++++++++++++++++ .../13-null-values.cf.json | 14 +++++ 3 files changed, 92 insertions(+), 6 deletions(-) create mode 100644 tests/acceptance/00_basics/06_host_specific_data/13-null-values.cf create mode 100644 tests/acceptance/00_basics/06_host_specific_data/13-null-values.cf.json diff --git a/libpromises/cmdb.c b/libpromises/cmdb.c index dd25fdc978d..cbe87e1a4ed 100644 --- a/libpromises/cmdb.c +++ b/libpromises/cmdb.c @@ -130,12 +130,23 @@ static bool AddCMDBVariable(EvalContext *ctx, const char *key, const VarRef *ref bool ret; if (JsonGetElementType(data) == JSON_ELEMENT_TYPE_PRIMITIVE) { - char *value = JsonPrimitiveToString(data); - Log(LOG_LEVEL_VERBOSE, "Installing CMDB variable '%s:%s.%s=%s'", - ref->ns, ref->scope, key, value); - ret = EvalContextVariablePutTagsSetWithComment(ctx, ref, value, CF_DATA_TYPE_STRING, - tags, comment); - free(value); + if (JsonGetPrimitiveType(data) == JSON_PRIMITIVE_TYPE_NULL) + { + /* JsonPrimitiveToString() returns NULL for JSON null and there is + * no scalar to install in its place. */ + Log(LOG_LEVEL_ERR, "Invalid value in '%s' variable specification in CMDB data" + " (null is not a supported value)", key); + ret = false; + } + else + { + char *value = JsonPrimitiveToString(data); + Log(LOG_LEVEL_VERBOSE, "Installing CMDB variable '%s:%s.%s=%s'", + ref->ns, ref->scope, key, value); + ret = EvalContextVariablePutTagsSetWithComment(ctx, ref, value, CF_DATA_TYPE_STRING, + tags, comment); + free(value); + } } else if ((JsonGetType(data) == JSON_TYPE_ARRAY) && JsonArrayContainsOnlyPrimitives(data)) diff --git a/tests/acceptance/00_basics/06_host_specific_data/13-null-values.cf b/tests/acceptance/00_basics/06_host_specific_data/13-null-values.cf new file mode 100644 index 00000000000..33dfeba6e06 --- /dev/null +++ b/tests/acceptance/00_basics/06_host_specific_data/13-null-values.cf @@ -0,0 +1,61 @@ +# test of the host_specific.json functionality: JSON null values are rejected +# per entry, the rest of the CMDB data is still installed (used to crash); +# lists containing null keep installing, with the nulls skipped +body common control +{ + inputs => { "../../default.sub.cf" }; + bundlesequence => { default("$(this.promise_filename)") }; + version => "1.0"; +} + +####################################################### +bundle agent init +{ + files: + "$(sys.workdir)$(const.dirsep)data$(const.dirsep)." + create => "true", + perms => mog( + "0700", "$(sys.user_data[username])", "$(sys.user_data[username])" + ); + + methods: + "prepare_host_specific_data" + usebundle => file_copy( + "$(this.promise_filename).json", + "$(sys.workdir)$(const.dirsep)data$(const.dirsep)host_specific.json" + ), + handle => "prepare_host_specific_data"; + + "empty_promises_cf" + usebundle => file_make("$(sys.inputdir)/promises.cf", ''); +} + +####################################################### +bundle agent check +{ + vars: + "command" + string => "$(sys.cf_promises) --show-vars -f $(sys.inputdir)/promises.cf | $(G.grep) -E 'CMDB data|value_from_|null_'"; + + # The offending entries are reported in the order they appear in the CMDB + # data, the remaining variables are installed and shown by --show-vars; + # lists with a null still install with the nulls skipped (RlistFromContainer() + # drops them), exactly as before the null values were rejected. + "expected" + string => concat( + "\s*error: Invalid value in 'null_scalar'.*null is not a supported value.*", + "\s+error: Invalid value in 'null_value'.*null is not a supported value.*", + "\s+error: Invalid value in 'null_bare'.*null is not a supported value.*", + "\s+data:variables\.good_variables\s+value_from_variables\s+source=cmdb", + "\s+data:variables\.good_vars\s+value_from_vars\s+source=cmdb", + "\s+data:variables\.null_container\s+\{\s*\"nested\":\s*null\s*\}\s+source=cmdb", + "\s+data:variables\.null_list\s+\{\"a\"\}\s+source=cmdb", + "\s+data:variables\.null_value_list\s+\{\"a\"\}\s+source=cmdb\s*" + ); + + methods: + "" + usebundle => dcs_passif_output( + $(expected), "", $(command), $(this.promise_filename) + ); +} diff --git a/tests/acceptance/00_basics/06_host_specific_data/13-null-values.cf.json b/tests/acceptance/00_basics/06_host_specific_data/13-null-values.cf.json new file mode 100644 index 00000000000..92ca7ac753a --- /dev/null +++ b/tests/acceptance/00_basics/06_host_specific_data/13-null-values.cf.json @@ -0,0 +1,14 @@ +{ + "vars": { + "null_scalar": null, + "null_list": ["a", null], + "good_vars": "value_from_vars", + "null_container": { "nested": null } + }, + "variables": { + "null_value": { "value": null }, + "null_bare": null, + "null_value_list": { "value": ["a", null] }, + "good_variables": { "value": "value_from_variables" } + } +}