Skip to content

Commit 89868cb

Browse files
committed
tests: add test to check StartContainer hook env
This is to ensure that changes in Process.Env handling won't affect StartContainer hook. Reported-by: lfbzhm <[email protected]> Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent c9f8ee0 commit 89868cb

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tests/integration/hooks.bats

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,24 @@ function teardown() {
4242
[[ "$output" == *"error running $hook hook #1:"* ]]
4343
done
4444
}
45+
46+
# While runtime-spec does not say what environment variables hooks should have,
47+
# if not explicitly specified, historically the StartContainer hook inherited
48+
# the process environment specified for init.
49+
#
50+
# Check this behavior is preserved.
51+
@test "runc run [startContainer hook should inherit process environment]" {
52+
cat >"rootfs/check-env.sh" <<-'EOF'
53+
#!/bin/sh -ue
54+
test $ONE = two
55+
test $FOO = bar
56+
echo $HOME # Test HOME is set w/o checking the value.
57+
EOF
58+
chmod +x "rootfs/check-env.sh"
59+
60+
update_config ' .process.args = ["/bin/true"]
61+
| .process.env = ["ONE=two", "FOO=bar"]
62+
| .hooks |= {"startContainer": [{"path": "/check-env.sh"}]}'
63+
runc run ct1
64+
[ "$status" -eq 0 ]
65+
}

0 commit comments

Comments
 (0)