@@ -42,3 +42,42 @@ function teardown() {
42
42
[[ " $output " == * " error running $hook hook #1:" * ]]
43
43
done
44
44
}
45
+
46
+ @test " runc run [hook with env property]" {
47
+ update_config ' .process.args = ["/bin/true"]'
48
+ update_config ' .process.env = ["TEST_VAR=val"]'
49
+ # All hooks except Poststop.
50
+ for hook in prestart createRuntime createContainer startContainer poststart; do
51
+ echo " testing hook $hook "
52
+ # shellcheck disable=SC2016
53
+ update_config ' .hooks = {
54
+ "' $hook ' ": [{
55
+ "path": "/bin/sh",
56
+ "args": ["/bin/sh", "-c", "[ \"$TEST_VAR\"==\"val\" ] && echo yes, we got val from the env TEST_VAR && exit 1 || exit 0"],
57
+ "env": ["TEST_VAR=val"]
58
+ }]
59
+ }'
60
+ TEST_VAR=val runc run " test_hook-$hook "
61
+ [ " $status " -ne 0 ]
62
+ [[ " $output " == * " yes, we got val from the env TEST_VAR" * ]]
63
+ done
64
+ }
65
+
66
+ # https://github.com/opencontainers/runtime-spec/blob/v1.0.1/config.md#posix-platform-hooks
67
+ @test " runc run [hook without env property should not inherit host env]" {
68
+ update_config ' .process.args = ["/bin/true"]'
69
+ update_config ' .process.env = ["TEST_VAR=val"]'
70
+ # All hooks except Poststop.
71
+ for hook in prestart createRuntime createContainer startContainer poststart; do
72
+ echo " testing hook $hook "
73
+ # shellcheck disable=SC2016
74
+ update_config ' .hooks = {
75
+ "' $hook ' ": [{
76
+ "path": "/bin/sh",
77
+ "args": ["/bin/sh", "-c", "[[ \"$TEST_VAR\" == \"val\" ]] && echo \"$TEST_VAR\" && exit 1 || exit 0"]
78
+ }]
79
+ }'
80
+ TEST_VAR=val runc run " test_hook-$hook "
81
+ [ " $status " -eq 0 ]
82
+ done
83
+ }
0 commit comments