Skip to content

Commit e242e90

Browse files
committed
Fixed findlocalusers_unsafe test
Changelog: Fixed the unsafe test for findlocalusers unsafe. Replaced the users in the test with custom ones, to make it depend less on the individual quirks of the OS. Changed the username of the custom users, because on AIX and HP-UX, it is limited by 8 characters. Ticket: ENT-13533 Signed-off-by: Victor Moene <victor.moene@northern.tech>
1 parent ff09a71 commit e242e90

File tree

2 files changed

+42
-92
lines changed

2 files changed

+42
-92
lines changed

tests/acceptance/01_vars/02_functions/unsafe/findlocalusers_unsafe.cf

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,55 +14,53 @@ bundle agent init
1414
create => "true";
1515

1616
users:
17-
"test_user1"
17+
"testu1"
1818
policy => "present",
1919
home_dir => "/tmp/test_folder1",
2020
description => "TestUser 1",
21-
group_primary => "users",
21+
group_primary => "root", # we need a group which we know for sure the gid
2222
shell => "/bin/sh",
2323
uid => "12345";
2424

25-
"test_user2"
25+
"testu2"
2626
policy => "present",
2727
home_dir => "/tmp/test_folder2",
2828
description => "TestUser 2",
29-
group_primary => "users",
29+
group_primary => "root",
3030
shell => "/bin/sh",
3131
uid => "54321";
3232
vars:
33+
"no" int => getfields("root:.*", "/etc/group", ":", "groupdata");
34+
"root_gid" string => "$(groupdata[3])";
35+
3336
# simple filters
34-
"simple_filter" slist => { "name=root" };
35-
"number_filter" slist => { "uid=0" };
37+
"simple_filter" slist => { "name=testu1" };
38+
"number_filter" slist => { "uid=12345" };
3639

3740
# longer filters
38-
"slist_filter" slist => { "gid=0", "name=root" };
41+
"slist_filter" slist => { "gid=$(root_gid)", "name=testu1" };
3942

4043
# using data
41-
"data_filter" data => '[ "gid=0", "name=root" ]';
44+
"data_filter" data => '[ "gid=$(root_gid)", "name=testu1" ]';
4245

4346
# using regex
44-
"simple_regex" slist => { "name=test_user.*" };
47+
"simple_regex" slist => { "name=testu.*" };
4548
"number_regex" slist => { "uid=1234.*" };
46-
"longer_regex" slist => { "name=test_user.*", "uid=1.*" };
49+
"longer_regex" slist => { "name=testu.*", "uid=1.*" };
4750

4851
# non-existent user
4952
"unknown" slist => { "name=thisuserdoesntexist" };
5053
}
5154
bundle agent test
5255
{
53-
meta:
54-
"test_soft_fail" string => "windows|aix|solaris|hpux|redhat_10",
55-
comment => "RedHat 10 root user is named 'Super User' not 'root'",
56-
meta => { "CFE-2318" };
57-
5856
vars:
59-
"ulist1" data => findlocalusers("@(init.simple_filter)");
60-
"ulist2" data => findlocalusers("init.number_filter");
61-
"ulist4" data => findlocalusers("@(init.slist_filter)");
62-
"ulist3" data => findlocalusers("@(init.data_filter)");
63-
"ulist5" data => findlocalusers("@(init.simple_regex)");
64-
"ulist6" data => findlocalusers("@(init.number_regex)");
65-
"ulist7" data => findlocalusers("@(init.longer_regex)");
57+
"ulist1" data => mapdata(json, '"$(this.k)"', findlocalusers("@(init.simple_filter)"));
58+
"ulist2" data => mapdata(json, '"$(this.k)"', findlocalusers("init.number_filter"));
59+
"ulist3" data => mapdata(json, '"$(this.k)"', findlocalusers("@(init.data_filter)"));
60+
"ulist4" data => mapdata(json, '"$(this.k)"', findlocalusers("@(init.slist_filter)"));
61+
"ulist5" data => mapdata(json, '"$(this.k)"', findlocalusers("@(init.simple_regex)"));
62+
"ulist6" data => mapdata(json, '"$(this.k)"', findlocalusers("@(init.number_regex)"));
63+
"ulist7" data => mapdata(json, '"$(this.k)"', findlocalusers("@(init.longer_regex)"));
6664
"ulist8" data => findlocalusers("@(init.unknown)");
6765

6866
}
Lines changed: 22 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,26 @@
11
{
2-
"ulist1": {
3-
"root": {
4-
"dir": "/root",
5-
"gecos": "root",
6-
"gid": 0,
7-
"shell": "/bin/bash",
8-
"uid": 0
9-
}
10-
},
11-
"ulist2": {
12-
"root": {
13-
"dir": "/root",
14-
"gecos": "root",
15-
"gid": 0,
16-
"shell": "/bin/bash",
17-
"uid": 0
18-
}
19-
},
20-
"ulist3": {
21-
"root": {
22-
"dir": "/root",
23-
"gecos": "root",
24-
"gid": 0,
25-
"shell": "/bin/bash",
26-
"uid": 0
27-
}
28-
},
29-
"ulist4": {
30-
"root": {
31-
"dir": "/root",
32-
"gecos": "root",
33-
"gid": 0,
34-
"shell": "/bin/bash",
35-
"uid": 0
36-
}
37-
},
38-
"ulist5": {
39-
"test_user1": {
40-
"dir": "/tmp/test_folder1",
41-
"gecos": "TestUser 1",
42-
"gid": 100,
43-
"shell": "/bin/sh",
44-
"uid": 12345
45-
},
46-
"test_user2": {
47-
"dir": "/tmp/test_folder2",
48-
"gecos": "TestUser 2",
49-
"gid": 100,
50-
"shell": "/bin/sh",
51-
"uid": 54321
52-
}
53-
},
54-
"ulist6": {
55-
"test_user1": {
56-
"dir": "/tmp/test_folder1",
57-
"gecos": "TestUser 1",
58-
"gid": 100,
59-
"shell": "/bin/sh",
60-
"uid": 12345
61-
}
62-
},
63-
"ulist7": {
64-
"test_user1": {
65-
"dir": "/tmp/test_folder1",
66-
"gecos": "TestUser 1",
67-
"gid": 100,
68-
"shell": "/bin/sh",
69-
"uid": 12345
70-
}
71-
},
2+
"ulist1": [
3+
"testu1"
4+
],
5+
"ulist2": [
6+
"testu1"
7+
],
8+
"ulist3": [
9+
"testu1"
10+
],
11+
"ulist4": [
12+
"testu1"
13+
],
14+
"ulist5": [
15+
"testu1",
16+
"testu2"
17+
],
18+
"ulist6": [
19+
"testu1"
20+
],
21+
"ulist7": [
22+
"testu1"
23+
],
7224
"ulist8": {
7325
}
7426
}

0 commit comments

Comments
 (0)