Skip to content

Commit 1c5d206

Browse files
authored
Merge pull request #5960 from victormlg/findlocalusers_tests_fix
ENT-13532: Fixed findlocaluser test
2 parents c3d386a + 251986a commit 1c5d206

File tree

2 files changed

+44
-90
lines changed

2 files changed

+44
-90
lines changed

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

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,46 +7,67 @@ body common control
77
bundle agent init
88
{
99
vars:
10+
# parsing /etc/passwd for 'root' user
11+
"root_idx" int => getfields("root.*", "/etc/passwd", ":", "userdata");
12+
"root_string" string => ifelse(isvariable("userdata[1]"),
13+
storejson(parsejson('{$(userdata[1]) : { "uid" : $(userdata[3]) , "gid" : $(userdata[4]) , "gecos" : "$(userdata[5])", "dir" : "$(userdata[6])", "shell" : "$(userdata[7])"}}')),
14+
storejson(parsejson('{}'))
15+
);
16+
"empty_string" string => storejson(parsejson('{}'));
17+
1018
# simple filters
11-
"simple_filter" slist => { "name=root" };
12-
"number_filter" slist => { "uid=0" };
19+
"simple_filter" slist => { "name=$(userdata[1])" };
1320

1421
# longer filters
15-
"slist_filter" slist => { "gid=0", "name=root" };
22+
"slist_filter" slist => { "gid=$(userdata[4])", "name=root" };
1623

1724
# using data
18-
"data_filter" data => '[ "gid=0", "name=root" ]';
25+
"data_filter" data => '[ "gid=$(userdata[4])", "name=root" ]';
1926

2027
# using regex
2128
"simple_regex" slist => { "name=roo.*" };
22-
"number_regex" slist => { "uid=0.*" };
23-
"longer_regex" slist => { "name=ro.*", "uid=0.*" };
29+
"longer_regex" slist => { "name=roo.*", "uid=0.*" };
2430

2531
# non-existent user
2632
"unknown" slist => { "name=thisuserdoesntexist" };
2733
}
2834
bundle agent test
2935
{
30-
meta:
31-
"test_soft_fail" string => "windows|aix|solaris|hpux|redhat_10",
32-
comment => "redhat_10 user name is 'Super User' not 'root'",
33-
meta => { "CFE-2318" };
34-
3536
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)");
37+
"ulist1" string => storejson(findlocalusers("@(init.simple_filter)"));
38+
"ulist2" string => storejson(findlocalusers("@(init.data_filter)"));
39+
"ulist3" string => storejson(findlocalusers("@(init.slist_filter)"));
40+
"ulist4" string => storejson(findlocalusers("@(init.simple_regex)"));
41+
"ulist5" string => storejson(findlocalusers("@(init.longer_regex)"));
42+
"ulist6" string => storejson(findlocalusers("@(init.unknown)"));
4443

4544
}
4645
bundle agent check
4746
{
48-
methods:
49-
"check" usebundle => dcs_check_state(test,
50-
"$(this.promise_filename).expected.json",
51-
$(this.promise_filename));
47+
meta:
48+
"test_soft_fail" string => "windows",
49+
meta => { "CFE-2318" };
50+
classes:
51+
"ok" expression => and(
52+
strcmp("$(test.ulist1)", "$(init.root_string)"),
53+
strcmp("$(test.ulist2)", "$(init.root_string)"),
54+
strcmp("$(test.ulist3)", "$(init.root_string)"),
55+
strcmp("$(test.ulist4)", "$(init.root_string)"),
56+
strcmp("$(test.ulist5)", "$(init.root_string)"),
57+
strcmp("$(test.ulist6)", "$(init.empty_string)")
58+
);
59+
reports:
60+
ok::
61+
"$(this.promise_filename) Pass";
62+
!ok::
63+
"$(this.promise_filename) FAIL";
64+
DEBUG::
65+
"$(init.root_string)";
66+
67+
"$(test.ulist1)";
68+
"$(test.ulist2)";
69+
"$(test.ulist3)";
70+
"$(test.ulist4)";
71+
"$(test.ulist5)";
72+
"$(test.ulist6)";
5273
}

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)