Skip to content

Commit 37fee76

Browse files
committed
Fixed findlocaluser test
Ticket: ENT-13532 Signed-off-by: Victor Moene <victor.moene@northern.tech>
1 parent ff09a71 commit 37fee76

File tree

2 files changed

+40
-86
lines changed

2 files changed

+40
-86
lines changed

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

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,23 @@ 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
1119
"simple_filter" slist => { "name=root" };
1220
"number_filter" slist => { "uid=0" };
1321

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

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

2028
# using regex
2129
"simple_regex" slist => { "name=roo.*" };
@@ -27,26 +35,39 @@ bundle agent init
2735
}
2836
bundle agent test
2937
{
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-
3538
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)");
39+
"ulist1" string => storejson(findlocalusers("@(init.simple_filter)"));
40+
"ulist2" string => storejson(findlocalusers("init.number_filter"));
41+
"ulist4" string => storejson(findlocalusers("@(init.slist_filter)"));
42+
"ulist3" string => storejson(findlocalusers("@(init.data_filter)"));
43+
"ulist5" string => storejson(findlocalusers("@(init.simple_regex)"));
44+
"ulist6" string => storejson(findlocalusers("@(init.number_regex)"));
45+
"ulist7" string => storejson(findlocalusers("@(init.longer_regex)"));
46+
"ulist8" string => storejson(findlocalusers("@(init.unknown)"));
4447

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