mirror of
https://github.com/opencontainers/runc.git
synced 2026-11-06 05:17:05 +00:00
The point of the assert helpers is that a failed test says what it wanted and what it got, so leaving most comparisons as bare [[ ]] defeats it. Convert the rest of the checks on $output and $lines. Those using a glob to look for a substring become --partial, the rest become --regexp (the patterns are translated to extended regular expressions, and anchored where the glob was). The few remaining [[ ]] are not assertions: one is an if condition, and another one is the left hand side of ||, offering an alternative to the assert that follows it. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
119 lines
4.2 KiB
Bash
119 lines
4.2 KiB
Bash
#!/usr/bin/env bats
|
|
|
|
load helpers
|
|
|
|
TESTVOLUME="${BATS_RUN_TMPDIR}/mounts_recursive"
|
|
|
|
function setup_volume() {
|
|
# requires root (in the current user namespace) to mount tmpfs outside runc
|
|
requires root
|
|
|
|
mkdir -p "${TESTVOLUME}"
|
|
mount -t tmpfs none "${TESTVOLUME}"
|
|
echo "foo" >"${TESTVOLUME}/foo"
|
|
|
|
mkdir "${TESTVOLUME}/subvol"
|
|
mount -t tmpfs none "${TESTVOLUME}/subvol"
|
|
echo "bar" >"${TESTVOLUME}/subvol/bar"
|
|
}
|
|
|
|
function teardown_volume() {
|
|
umount -R "${TESTVOLUME}"
|
|
}
|
|
|
|
function setup() {
|
|
setup_volume
|
|
setup_debian
|
|
}
|
|
|
|
function teardown() {
|
|
teardown_volume
|
|
teardown_bundle
|
|
}
|
|
|
|
@test "runc run [rbind,ro mount is read-only but not recursively]" {
|
|
update_config ".mounts += [{source: \"${TESTVOLUME}\" , destination: \"/mnt\", options: [\"rbind\",\"ro\"]}]"
|
|
|
|
run -0 runc run -d --console-socket "$CONSOLE_SOCKET" test_rbind_ro
|
|
|
|
run -1 runc exec test_rbind_ro touch /mnt/foo
|
|
assert_output --partial "Read-only file system"
|
|
|
|
run -0 runc exec test_rbind_ro touch /mnt/subvol/bar
|
|
}
|
|
|
|
@test "runc run [rbind,rro mount is recursively read-only]" {
|
|
requires_kernel 5.12
|
|
update_config ".mounts += [{source: \"${TESTVOLUME}\" , destination: \"/mnt\", options: [\"rbind\",\"rro\"]}]"
|
|
|
|
run -0 runc run -d --console-socket "$CONSOLE_SOCKET" test_rbind_rro
|
|
|
|
run -1 runc exec test_rbind_rro touch /mnt/foo
|
|
assert_output --partial "Read-only file system"
|
|
|
|
run -1 runc exec test_rbind_rro touch /mnt/subvol/bar
|
|
assert_output --partial "Read-only file system"
|
|
}
|
|
|
|
@test "runc run [rbind,ro,rro mount is recursively read-only too]" {
|
|
requires_kernel 5.12
|
|
update_config ".mounts += [{source: \"${TESTVOLUME}\" , destination: \"/mnt\", options: [\"rbind\",\"ro\",\"rro\"]}]"
|
|
|
|
run -0 runc run -d --console-socket "$CONSOLE_SOCKET" test_rbind_ro_rro
|
|
|
|
run -1 runc exec test_rbind_ro_rro touch /mnt/foo
|
|
assert_output --partial "Read-only file system"
|
|
|
|
run -1 runc exec test_rbind_ro_rro touch /mnt/subvol/bar
|
|
assert_output --partial "Read-only file system"
|
|
}
|
|
|
|
# https://github.com/opencontainers/runc/issues/5095
|
|
@test "runc run [ check rbind,r*atime mounts]" {
|
|
requires_kernel 5.12
|
|
update_config ".mounts += [{source: \"${TESTVOLUME}\" , destination: \"/mnt1\", options: [\"rbind\",\"ratime\"]}]"
|
|
update_config ".mounts += [{source: \"${TESTVOLUME}\" , destination: \"/mnt2\", options: [\"rbind\",\"rnoatime\"]}]"
|
|
update_config ".mounts += [{source: \"${TESTVOLUME}\" , destination: \"/mnt3\", options: [\"rbind\",\"rstrictatime\"]}]"
|
|
update_config ".mounts += [{source: \"${TESTVOLUME}\" , destination: \"/mnt4\", options: [\"rbind\",\"rnostrictatime\"]}]"
|
|
update_config ".mounts += [{source: \"${TESTVOLUME}\" , destination: \"/mnt5\", options: [\"rbind\",\"rrelatime\"]}]"
|
|
update_config ".mounts += [{source: \"${TESTVOLUME}\" , destination: \"/mnt6\", options: [\"rbind\",\"rnorelatime\"]}]"
|
|
|
|
run -0 runc run -d --console-socket "$CONSOLE_SOCKET" test_rbind_ratime
|
|
|
|
run -0 runc exec test_rbind_ratime findmnt --noheadings -o options /mnt1
|
|
assert_output --regexp '^rw,relatime,'
|
|
|
|
run -0 runc exec test_rbind_ratime findmnt --noheadings -o options /mnt1/subvol
|
|
assert_output --regexp '^rw,relatime,'
|
|
|
|
run -0 runc exec test_rbind_ratime findmnt --noheadings -o options /mnt2
|
|
assert_output --regexp '^rw,noatime,'
|
|
|
|
run -0 runc exec test_rbind_ratime findmnt --noheadings -o options /mnt2/subvol
|
|
assert_output --regexp '^rw,noatime,'
|
|
|
|
run -0 runc exec test_rbind_ratime findmnt --noheadings -o options /mnt3
|
|
assert_output --regexp '^rw,'
|
|
|
|
run -0 runc exec test_rbind_ratime findmnt --noheadings -o options /mnt3/subvol
|
|
assert_output --regexp '^rw,'
|
|
|
|
run -0 runc exec test_rbind_ratime findmnt --noheadings -o options /mnt4
|
|
assert_output --regexp '^rw,relatime,'
|
|
|
|
run -0 runc exec test_rbind_ratime findmnt --noheadings -o options /mnt4/subvol
|
|
assert_output --regexp '^rw,relatime,'
|
|
|
|
run -0 runc exec test_rbind_ratime findmnt --noheadings -o options /mnt5
|
|
assert_output --regexp '^rw,relatime,'
|
|
|
|
run -0 runc exec test_rbind_ratime findmnt --noheadings -o options /mnt5/subvol
|
|
assert_output --regexp '^rw,relatime,'
|
|
|
|
run -0 runc exec test_rbind_ratime findmnt --noheadings -o options /mnt6
|
|
assert_output --regexp '^rw,relatime,'
|
|
|
|
run -0 runc exec test_rbind_ratime findmnt --noheadings -o options /mnt6/subvol
|
|
assert_output --regexp '^rw,relatime,'
|
|
}
|