diff --git a/tests/integration/userns.bats b/tests/integration/userns.bats new file mode 100644 index 00000000000..a6a336ab211 --- /dev/null +++ b/tests/integration/userns.bats @@ -0,0 +1,45 @@ +#!/usr/bin/env bats + +load helpers + +function setup() { + teardown_busybox + setup_busybox + mkdir -p "$BUSYBOX_BUNDLE"/source-{accessible,inaccessible}/dir + chmod 750 "$BUSYBOX_BUNDLE"/source-inaccessible + mkdir -p "$BUSYBOX_BUNDLE"/rootfs/{proc,sys,tmp} + mkdir -p "$BUSYBOX_BUNDLE"/rootfs/tmp/{accessible,inaccessible} + update_config ' .process.args += ["-c", "echo HelloWorld"] ' + update_config ' .linux.namespaces += [{"type": "user"}] + | .linux.uidMappings += [{"hostID": 100000, "containerID": 0, "size": 65534}] + | .linux.gidMappings += [{"hostID": 100000, "containerID": 0, "size": 65534}] ' +} + +function teardown() { + teardown_busybox +} + +@test "userns without mount" { + runc run test_userns_without_mount + [ "$status" -eq 0 ] + + [[ "${output}" == *"HelloWorld"* ]] +} + +@test "userns with simple mount" { + update_config ' .mounts += [{"source": "source-accessible/dir", "destination": "/tmp/accessible", "options": ["bind"]}] ' + + runc run test_userns_with_simple_mount + [ "$status" -eq 0 ] + + [[ "${output}" == *"HelloWorld"* ]] +} + +@test "userns with inaccessible mount" { + update_config ' .mounts += [{"source": "source-inaccessible/dir", "destination": "/tmp/inaccessible", "options": ["bind"]}] ' + + runc run test_userns_with_difficult_mount + [ "$status" -eq 0 ] + + [[ "${output}" == *"HelloWorld"* ]] +}