Skip to content

Commit 7ec1e4e

Browse files
committed
tests/int: refactor to use runc status checks
Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent 2f2f910 commit 7ec1e4e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+581
-1170
lines changed

tests/integration/capabilities.bats

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ function teardown() {
1212
}
1313

1414
@test "runc run no capability" {
15-
runc run test_no_caps
16-
[ "$status" -eq 0 ]
15+
runc -0 run test_no_caps
1716

1817
[[ "${output}" == *"CapInh: 0000000000000000"* ]]
1918
[[ "${output}" == *"CapAmb: 0000000000000000"* ]]
@@ -22,8 +21,7 @@ function teardown() {
2221

2322
@test "runc run with unknown capability" {
2423
update_config '.process.capabilities.bounding = ["CAP_UNKNOWN", "UNKNOWN_CAP"]'
25-
runc run test_unknown_caps
26-
[ "$status" -eq 0 ]
24+
runc -0 run test_unknown_caps
2725

2826
[[ "${output}" == *"CapInh: 0000000000000000"* ]]
2927
[[ "${output}" == *"CapAmb: 0000000000000000"* ]]
@@ -32,8 +30,7 @@ function teardown() {
3230

3331
@test "runc run with new privileges" {
3432
update_config '.process.noNewPrivileges = false'
35-
runc run test_new_privileges
36-
[ "$status" -eq 0 ]
33+
runc -0 run test_new_privileges
3734

3835
[[ "${output}" == *"CapInh: 0000000000000000"* ]]
3936
[[ "${output}" == *"CapAmb: 0000000000000000"* ]]
@@ -44,8 +41,7 @@ function teardown() {
4441
update_config '.process.user = {"uid":0}'
4542
update_config '.process.capabilities.bounding = ["CAP_SYS_ADMIN"]'
4643
update_config '.process.capabilities.permitted = ["CAP_SYS_ADMIN", "CAP_AUDIT_WRITE", "CAP_KILL", "CAP_NET_BIND_SERVICE"]'
47-
runc run test_some_caps
48-
[ "$status" -eq 0 ]
44+
runc -0 run test_some_caps
4945

5046
[[ "${output}" == *"CapInh: 0000000000000000"* ]]
5147
[[ "${output}" == *"CapBnd: 0000000000200000"* ]]
@@ -57,20 +53,17 @@ function teardown() {
5753
@test "runc exec --cap" {
5854
update_config ' .process.args = ["/bin/sh"]
5955
| .process.capabilities = {}'
60-
runc run -d --console-socket "$CONSOLE_SOCKET" test_exec_cap
61-
[ "$status" -eq 0 ]
56+
runc -0 run -d --console-socket "$CONSOLE_SOCKET" test_exec_cap
6257

63-
runc exec test_exec_cap cat /proc/self/status
64-
[ "$status" -eq 0 ]
58+
runc -0 exec test_exec_cap cat /proc/self/status
6559
# Check no capabilities are set.
6660
[[ "${output}" == *"CapInh: 0000000000000000"* ]]
6761
[[ "${output}" == *"CapPrm: 0000000000000000"* ]]
6862
[[ "${output}" == *"CapEff: 0000000000000000"* ]]
6963
[[ "${output}" == *"CapBnd: 0000000000000000"* ]]
7064
[[ "${output}" == *"CapAmb: 0000000000000000"* ]]
7165

72-
runc exec --cap CAP_KILL --cap CAP_AUDIT_WRITE test_exec_cap cat /proc/self/status
73-
[ "$status" -eq 0 ]
66+
runc -0 exec --cap CAP_KILL --cap CAP_AUDIT_WRITE test_exec_cap cat /proc/self/status
7467
# Check capabilities are added into bounding/effective/permitted only,
7568
# but not to inheritable or ambient.
7669
#
@@ -90,11 +83,9 @@ function teardown() {
9083
| .process.capabilities.effective = ["CAP_KILL"]
9184
| .process.capabilities.bounding = ["CAP_KILL", "CAP_CHOWN", "CAP_SYSLOG"]
9285
| .process.capabilities.ambient = ["CAP_CHOWN"]'
93-
runc run -d --console-socket "$CONSOLE_SOCKET" test_some_caps
94-
[ "$status" -eq 0 ]
86+
runc -0 run -d --console-socket "$CONSOLE_SOCKET" test_some_caps
9587

96-
runc exec test_some_caps cat /proc/self/status
97-
[ "$status" -eq 0 ]
88+
runc -0 exec test_some_caps cat /proc/self/status
9889
# Check that capabilities are as set in spec.
9990
#
10091
# CAP_CHOWN is 0, the bit mask is 0x1 (1 << 0)
@@ -108,8 +99,7 @@ function teardown() {
10899

109100
# Check that if config.json has an inheritable capability set,
110101
# runc exec --cap adds ambient capabilities.
111-
runc exec --cap CAP_SYSLOG test_some_caps cat /proc/self/status
112-
[ "$status" -eq 0 ]
102+
runc -0 exec --cap CAP_SYSLOG test_some_caps cat /proc/self/status
113103
[[ "${output}" == *"CapInh: 0000000400000001"* ]]
114104
[[ "${output}" == *"CapPrm: 0000000400000021"* ]]
115105
[[ "${output}" == *"CapEff: 0000000400000021"* ]]
@@ -120,8 +110,7 @@ function teardown() {
120110
@test "runc run [ambient caps not set in inheritable result in a warning]" {
121111
update_config ' .process.capabilities.inheritable = ["CAP_KILL"]
122112
| .process.capabilities.ambient = ["CAP_KILL", "CAP_CHOWN"]'
123-
runc run test_amb
124-
[ "$status" -eq 0 ]
113+
runc -0 run test_amb
125114
# This should result in CAP_KILL set in ambient,
126115
# and a warning about inability to set CAP_CHOWN.
127116
#

tests/integration/cgroup_delegation.bats

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,9 @@ function setup() {
2727
}
2828

2929
@test "runc exec (cgroup v2, ro cgroupfs, new cgroupns) does not chown cgroup" {
30-
runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroup_chown
31-
[ "$status" -eq 0 ]
30+
runc -0 run -d --console-socket "$CONSOLE_SOCKET" test_cgroup_chown
3231

33-
runc exec test_cgroup_chown sh -c "stat -c %U /sys/fs/cgroup"
34-
[ "$status" -eq 0 ]
32+
runc -0 exec test_cgroup_chown sh -c "stat -c %U /sys/fs/cgroup"
3533
[ "$output" = "nobody" ] # /sys/fs/cgroup owned by unmapped user
3634
}
3735

@@ -41,21 +39,17 @@ function setup() {
4139
# inherit cgroup namespace (remove cgroup from namespaces list)
4240
update_config '.linux.namespaces |= map(select(.type != "cgroup"))'
4341

44-
runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroup_chown
45-
[ "$status" -eq 0 ]
42+
runc -0 run -d --console-socket "$CONSOLE_SOCKET" test_cgroup_chown
4643

47-
runc exec test_cgroup_chown sh -c "stat -c %U /sys/fs/cgroup"
48-
[ "$status" -eq 0 ]
44+
runc -0 exec test_cgroup_chown sh -c "stat -c %U /sys/fs/cgroup"
4945
[ "$output" = "nobody" ] # /sys/fs/cgroup owned by unmapped user
5046
}
5147

5248
@test "runc exec (cgroup v2, rw cgroupfs, new cgroupns) does chown cgroup" {
5349
set_cgroup_mount_writable
5450

55-
runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroup_chown
56-
[ "$status" -eq 0 ]
51+
runc -0 run -d --console-socket "$CONSOLE_SOCKET" test_cgroup_chown
5752

58-
runc exec test_cgroup_chown sh -c "stat -c %U /sys/fs/cgroup"
59-
[ "$status" -eq 0 ]
53+
runc -0 exec test_cgroup_chown sh -c "stat -c %U /sys/fs/cgroup"
6054
[ "$output" = "root" ] # /sys/fs/cgroup owned by root (of user namespace)
6155
}

0 commit comments

Comments
 (0)