Skip to content

Commit b8b991c

Browse files
committed
Fixed findlocaluser test
Ticket: ENT-13532 Signed-off-by: Victor Moene <[email protected]>
1 parent 4fbdccf commit b8b991c

File tree

2 files changed

+46
-105
lines changed

2 files changed

+46
-105
lines changed

tests/acceptance/01_vars/02_functions/findlocalusers.cf

Lines changed: 46 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,49 +4,57 @@ body common control
44
bundlesequence => { default("$(this.promise_filename)") };
55
version => "1.0";
66
}
7-
bundle agent init
8-
{
9-
vars:
10-
# simple filters
11-
"simple_filter" slist => { "name=root" };
12-
"number_filter" slist => { "uid=0" };
13-
14-
# longer filters
15-
"slist_filter" slist => { "gid=0", "name=root" };
16-
17-
# using data
18-
"data_filter" data => '[ "gid=0", "name=root" ]';
19-
20-
# using regex
21-
"simple_regex" slist => { "name=roo.*" };
22-
"number_regex" slist => { "uid=0.*" };
23-
"longer_regex" slist => { "name=ro.*", "uid=0.*" };
24-
25-
# non-existent user
26-
"unknown" slist => { "name=thisuserdoesntexist" };
27-
}
28-
bundle agent test
7+
bundle agent check
298
{
309
meta:
3110
"test_soft_fail" string => "windows|aix|solaris|hpux|redhat_10",
3211
comment => "redhat_10 user name is 'Super User' not 'root'",
3312
meta => { "CFE-2318" };
3413

3514
vars:
36-
"ulist1" data => findlocalusers("@(init.simple_filter)");
37-
"ulist2" data => findlocalusers("init.number_filter");
38-
"ulist4" data => findlocalusers("@(init.slist_filter)");
39-
"ulist3" data => findlocalusers("@(init.data_filter)");
40-
"ulist5" data => findlocalusers("@(init.simple_regex)");
41-
"ulist6" data => findlocalusers("@(init.number_regex)");
42-
"ulist7" data => findlocalusers("@(init.longer_regex)");
43-
"ulist8" data => findlocalusers("@(init.unknown)");
15+
"user_entries"
16+
slist => splitstring(string_trim(readfile("/etc/passwd")), "\n", 999);
4417

45-
}
46-
bundle agent check
47-
{
48-
methods:
49-
"check" usebundle => dcs_check_state(test,
50-
"$(this.promise_filename).expected.json",
51-
$(this.promise_filename));
52-
}
18+
"user"
19+
string => nth("@(user_entries)", 0);
20+
21+
"user_name"
22+
string => nth(splitstring("$(user)", ":", 8), 0);
23+
"user_uid"
24+
string => nth(splitstring("$(user)", ":", 8), 2);
25+
26+
# simple filters
27+
"simple_filter" slist => { "name=$(user_name)" };
28+
"number_filter" slist => { "uid=$(user_uid)" };
29+
30+
# longer filters
31+
"slist_filter" slist => { "gid=$(user_uid)", "name=$(user_name)" };
32+
33+
# using data
34+
"data_filter" data => '[ "gid=$(user_uid)", "name=$(user_name)" ]';
35+
36+
# non-existent user
37+
"unknown" slist => { "name=thisuserdoesntexist" };
38+
39+
"ulist1" string => nth(getindices(findlocalusers("@(simple_filter)")), 0);
40+
"ulist2" string => nth(getindices(findlocalusers("@(number_filter)")), 0);
41+
"ulist3" string => nth(getindices(findlocalusers("@(data_filter)")), 0);
42+
"ulist4" string => nth(getindices(findlocalusers("@(slist_filter)")), 0);
43+
"ulist8" string => nth(getindices(findlocalusers("@(unknown)")), 0);
44+
45+
classes:
46+
"ok"
47+
expression => and(
48+
strcmp("$(user_name)", "$(ulist1)"),
49+
strcmp("$(user_name)", "$(ulist2)"),
50+
strcmp("$(user_name)", "$(ulist3)"),
51+
strcmp("$(user_name)", "$(ulist4)")
52+
);
53+
54+
reports:
55+
ok::
56+
"$(this.promise_filename) Pass";
57+
!ok::
58+
"$(this.promise_filename) FAIL";
59+
60+
}

tests/acceptance/01_vars/02_functions/findlocalusers.cf.expected.json

Lines changed: 0 additions & 67 deletions
This file was deleted.

0 commit comments

Comments
 (0)