Skip to content

Commit 5da8b11

Browse files
committed
Added acceptance tests for immutable bit
Ticket: ENT-10961, CFE-1840 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
1 parent 93b5bb7 commit 5da8b11

File tree

6 files changed

+268
-0
lines changed

6 files changed

+268
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
##############################################################################
2+
#
3+
# Test that immutable file CANNOT be edited by agent without specifying
4+
# fsattrs immutable constraint.
5+
#
6+
##############################################################################
7+
8+
body common control
9+
{
10+
inputs => { "../../default.cf.sub" };
11+
bundlesequence => { default("$(this.promise_filename)") };
12+
version => "1.0";
13+
}
14+
15+
body fsattrs set_immutable
16+
{
17+
immutable => "true";
18+
}
19+
20+
body fsattrs set_mutable
21+
{
22+
immutable => "false";
23+
}
24+
25+
bundle agent init
26+
{
27+
files:
28+
"/tmp/00_immutable.txt"
29+
content => "I'm immutable",
30+
fsattrs => set_immutable;
31+
}
32+
33+
bundle agent test
34+
{
35+
meta:
36+
"description" -> { "CFE-1840", "ENT-10961" }
37+
string => "Test that immutable file cannot be edited by agent without specifying fsattrs immutable constraint";
38+
39+
"test_soft_fail"
40+
string => "hpux|aix|windows",
41+
meta => { "CFE-1840", "ENT-10961" };
42+
43+
commands:
44+
"$(sys.cf_agent) -Kf $(this.promise_filename).sub";
45+
}
46+
47+
bundle agent check
48+
{
49+
vars:
50+
"expected"
51+
string => "I'm immutable";
52+
"actual"
53+
string => readfile("/tmp/00_immutable.txt");
54+
55+
classes:
56+
"ok"
57+
expression => strcmp("$(actual)", "$(expected)");
58+
59+
methods:
60+
"any"
61+
usebundle => dcs_passif("ok", "$(this.promise_filename)"),
62+
inherit => "true";
63+
64+
reports:
65+
"Expected: '$(expected)', actual: '$(actual)'";
66+
}
67+
68+
bundle agent destroy
69+
{
70+
files:
71+
# Make sure immutable bit is not set
72+
"/tmp/00_immutable.txt"
73+
fsattrs => set_mutable,
74+
delete => tidy;
75+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
body fsattrs set_immutable
2+
{
3+
# Nothing here
4+
}
5+
6+
bundle agent main
7+
{
8+
files:
9+
"/tmp/00_immutable.txt"
10+
content => "I'm mutable",
11+
fsattrs => set_immutable;
12+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
##############################################################################
2+
#
3+
# Test that immutable file CAN be edited by agent with fsattrs immutable
4+
# constraint set to true.
5+
#
6+
##############################################################################
7+
8+
body common control
9+
{
10+
inputs => { "../../default.cf.sub" };
11+
bundlesequence => { default("$(this.promise_filename)") };
12+
version => "1.0";
13+
}
14+
15+
body fsattrs set_immutable
16+
{
17+
immutable => "true";
18+
}
19+
20+
body fsattrs set_mutable
21+
{
22+
immutable => "false";
23+
}
24+
25+
bundle agent init
26+
{
27+
files:
28+
"/tmp/01_immutable.txt"
29+
content => "I'm immutable",
30+
fsattrs => set_immutable;
31+
}
32+
33+
bundle agent test
34+
{
35+
meta:
36+
"description" -> { "CFE-1840", "ENT-10961" }
37+
string => "Test that immutable file CAN be edited by agent with fsattrs immutable constraint set to true";
38+
39+
# "test_soft_fail" will not work here, because init will not be able to set
40+
# the immutable bit, hence the agent will be able to mutate it
41+
"test_skip_unsupported"
42+
string => "hpux|aix|windows",
43+
meta => { "CFE-1840", "ENT-10961" };
44+
45+
commands:
46+
"$(sys.cf_agent) -Kf $(this.promise_filename).sub";
47+
}
48+
49+
bundle agent check
50+
{
51+
vars:
52+
"expected"
53+
string => "I'm mutable";
54+
"actual"
55+
string => readfile("/tmp/01_immutable.txt");
56+
57+
classes:
58+
"ok"
59+
expression => strcmp("$(actual)", "$(expected)");
60+
61+
methods:
62+
"any"
63+
usebundle => dcs_passif("ok", "$(this.promise_filename)"),
64+
inherit => "true";
65+
66+
reports:
67+
any::
68+
"Expected: '$(expected)', actual: '$(actual)'";
69+
}
70+
71+
bundle agent destroy
72+
{
73+
files:
74+
# Make sure immutable bit is not set
75+
"/tmp/01_immutable.txt"
76+
fsattrs => set_mutable,
77+
delete => tidy;
78+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
body fsattrs set_immutable
2+
{
3+
immutable => "true";
4+
}
5+
6+
bundle agent main
7+
{
8+
files:
9+
"/tmp/01_immutable.txt"
10+
content => "I'm mutable",
11+
fsattrs => set_immutable;
12+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
##############################################################################
2+
#
3+
# Test that immutable bit can be cleared by agent with fsattrs immutable
4+
# constraint set to false.
5+
#
6+
##############################################################################
7+
8+
body common control
9+
{
10+
inputs => { "../../default.cf.sub" };
11+
bundlesequence => { default("$(this.promise_filename)") };
12+
version => "1.0";
13+
}
14+
15+
body fsattrs set_immutable
16+
{
17+
immutable => "true";
18+
}
19+
20+
body fsattrs set_mutable
21+
{
22+
immutable => "false";
23+
}
24+
25+
bundle agent init
26+
{
27+
files:
28+
"/tmp/02_immutable.txt"
29+
content => "I'm immutable",
30+
fsattrs => set_immutable;
31+
}
32+
33+
bundle agent test
34+
{
35+
meta:
36+
"description" -> { "CFE-1840", "ENT-10961" }
37+
string => "Test that immutable bit can be cleared by agent with fsattrs immutable constraint set to false";
38+
39+
# "test_soft_fail" will not work here, because init will not be able to set
40+
# the immutable bit, hence the agent will be able to mutate it, even without
41+
# actually clearing it.
42+
"test_skip_unsupported"
43+
string => "hpux|aix|windows",
44+
meta => { "CFE-1840", "ENT-10961" };
45+
46+
commands:
47+
"$(sys.cf_agent) -Kf $(this.promise_filename).sub";
48+
}
49+
50+
bundle agent check
51+
{
52+
vars:
53+
"expected"
54+
string => "I'm mutable";
55+
"actual"
56+
string => readfile("/tmp/02_immutable.txt");
57+
58+
classes:
59+
"ok"
60+
expression => strcmp("$(actual)", "$(expected)");
61+
62+
methods:
63+
"any"
64+
usebundle => dcs_passif("ok", "$(this.promise_filename)"),
65+
inherit => "true";
66+
67+
reports:
68+
any::
69+
"Expected: '$(expected)', actual: '$(actual)'";
70+
}
71+
72+
bundle agent destroy
73+
{
74+
files:
75+
# Make sure immutable bit is not set
76+
"/tmp/02_immutable.txt"
77+
fsattrs => set_mutable,
78+
delete => tidy;
79+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
body fsattrs set_immutable
2+
{
3+
immutable => "false";
4+
}
5+
6+
bundle agent main
7+
{
8+
files:
9+
"/tmp/02_immutable.txt"
10+
content => "I'm mutable",
11+
fsattrs => set_immutable;
12+
}

0 commit comments

Comments
 (0)