From 37fee76736b72da94dad12ebb531518aa60e3758 Mon Sep 17 00:00:00 2001 From: Victor Moene Date: Fri, 28 Nov 2025 13:55:35 +0100 Subject: [PATCH] Fixed findlocaluser test Ticket: ENT-13532 Signed-off-by: Victor Moene --- .../01_vars/02_functions/findlocalusers.cf | 59 ++++++++++------ .../findlocalusers.cf.expected.json | 67 ------------------- 2 files changed, 40 insertions(+), 86 deletions(-) delete mode 100644 tests/acceptance/01_vars/02_functions/findlocalusers.cf.expected.json diff --git a/tests/acceptance/01_vars/02_functions/findlocalusers.cf b/tests/acceptance/01_vars/02_functions/findlocalusers.cf index 095a44ddef..a078a6b729 100644 --- a/tests/acceptance/01_vars/02_functions/findlocalusers.cf +++ b/tests/acceptance/01_vars/02_functions/findlocalusers.cf @@ -7,15 +7,23 @@ body common control bundle agent init { vars: + # parsing /etc/passwd for 'root' user + "root_idx" int => getfields("root.*", "/etc/passwd", ":", "userdata"); + "root_string" string => ifelse(isvariable("userdata[1]"), + storejson(parsejson('{$(userdata[1]) : { "uid" : $(userdata[3]) , "gid" : $(userdata[4]) , "gecos" : "$(userdata[5])", "dir" : "$(userdata[6])", "shell" : "$(userdata[7])"}}')), + storejson(parsejson('{}')) + ); + "empty_string" string => storejson(parsejson('{}')); + # simple filters "simple_filter" slist => { "name=root" }; "number_filter" slist => { "uid=0" }; # longer filters - "slist_filter" slist => { "gid=0", "name=root" }; + "slist_filter" slist => { "gid=$(userdata[4])", "name=root" }; # using data - "data_filter" data => '[ "gid=0", "name=root" ]'; + "data_filter" data => '[ "gid=$(userdata[4])", "name=root" ]'; # using regex "simple_regex" slist => { "name=roo.*" }; @@ -27,26 +35,39 @@ bundle agent init } bundle agent test { - meta: - "test_soft_fail" string => "windows|aix|solaris|hpux|redhat_10", - comment => "redhat_10 user name is 'Super User' not 'root'", - meta => { "CFE-2318" }; - vars: - "ulist1" data => findlocalusers("@(init.simple_filter)"); - "ulist2" data => findlocalusers("init.number_filter"); - "ulist4" data => findlocalusers("@(init.slist_filter)"); - "ulist3" data => findlocalusers("@(init.data_filter)"); - "ulist5" data => findlocalusers("@(init.simple_regex)"); - "ulist6" data => findlocalusers("@(init.number_regex)"); - "ulist7" data => findlocalusers("@(init.longer_regex)"); - "ulist8" data => findlocalusers("@(init.unknown)"); + "ulist1" string => storejson(findlocalusers("@(init.simple_filter)")); + "ulist2" string => storejson(findlocalusers("init.number_filter")); + "ulist4" string => storejson(findlocalusers("@(init.slist_filter)")); + "ulist3" string => storejson(findlocalusers("@(init.data_filter)")); + "ulist5" string => storejson(findlocalusers("@(init.simple_regex)")); + "ulist6" string => storejson(findlocalusers("@(init.number_regex)")); + "ulist7" string => storejson(findlocalusers("@(init.longer_regex)")); + "ulist8" string => storejson(findlocalusers("@(init.unknown)")); } bundle agent check { - methods: - "check" usebundle => dcs_check_state(test, - "$(this.promise_filename).expected.json", - $(this.promise_filename)); + meta: + "test_soft_fail" string => "windows", + meta => { "CFE-2318" }; + classes: + "ok" expression => and( + strcmp("$(test.ulist1)", "$(init.root_string)"), + strcmp("$(test.ulist2)", "$(init.root_string)"), + strcmp("$(test.ulist3)", "$(init.root_string)"), + strcmp("$(test.ulist4)", "$(init.root_string)"), + strcmp("$(test.ulist5)", "$(init.root_string)"), + strcmp("$(test.ulist6)", "$(init.root_string)"), + strcmp("$(test.ulist7)", "$(init.root_string)"), + strcmp("$(test.ulist8)", "$(init.empty_string)") + ); + reports: + ok:: + "$(this.promise_filename) Pass"; + !ok:: + "$(this.promise_filename) FAIL"; + DEBUG:: + "$(init.root_string)"; + "$(test.ulist1)"; } diff --git a/tests/acceptance/01_vars/02_functions/findlocalusers.cf.expected.json b/tests/acceptance/01_vars/02_functions/findlocalusers.cf.expected.json deleted file mode 100644 index 1e05153cea..0000000000 --- a/tests/acceptance/01_vars/02_functions/findlocalusers.cf.expected.json +++ /dev/null @@ -1,67 +0,0 @@ -{ - "ulist1": { - "root": { - "dir": "/root", - "gecos": "root", - "gid": 0, - "shell": "/bin/bash", - "uid": 0 - } - }, - "ulist2": { - "root": { - "dir": "/root", - "gecos": "root", - "gid": 0, - "shell": "/bin/bash", - "uid": 0 - } - }, - "ulist3": { - "root": { - "dir": "/root", - "gecos": "root", - "gid": 0, - "shell": "/bin/bash", - "uid": 0 - } - }, - "ulist4": { - "root": { - "dir": "/root", - "gecos": "root", - "gid": 0, - "shell": "/bin/bash", - "uid": 0 - } - }, - "ulist5": { - "root": { - "dir": "/root", - "gecos": "root", - "gid": 0, - "shell": "/bin/bash", - "uid": 0 - } - }, - "ulist6": { - "root": { - "dir": "/root", - "gecos": "root", - "gid": 0, - "shell": "/bin/bash", - "uid": 0 - } - }, - "ulist7": { - "root": { - "dir": "/root", - "gecos": "root", - "gid": 0, - "shell": "/bin/bash", - "uid": 0 - } - }, - "ulist8": { - } -}