1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
summary: current working directory is preserved (if possible)
details: |
snap-confine will preserve the current working directory as long as that
directory is the same inside the execution environment. If the directory
exists but is not the same (e.g. /tmp) it will be re-interpreted according
to the view inside the mount namespace. If the directory does not exist the
special fallback /var/lib/snapd/void is used.
# ubuntu-14.04: the test sets up a user session, which requires more recent systemd
systems: [-ubuntu-14.04-*]
prepare: |
"$TESTSTOOLS"/snaps-state install-local test-snapd-sh
tests.session -u test prepare
restore: |
rmdir /tmp/test || true
tests.session -u test restore
debug: |
# Much of what we do depends on permissions. If the permissions on those
# two essential (for this test) directories are wrong the test will
# misbehave.
ls -ld /root /var/lib/snapd/void
execute: |
# The current working directory that exists in the snap mount namespace and
# represents the same inode is is preserved.
test "$(cd "$HOME" && test-snapd-sh.sh -c pwd)" = "$HOME"
test "$(cd "$HOME" && test-snapd-sh.sh -c 'stat -c %i .')" = "$(cd "$HOME" && stat -c %i .)"
# The current working directory that is visible in the snap mount namespace
# but represents a different inode is re-interpreted to give the view on
# the inside.
test "$(cd /tmp && test-snapd-sh.sh -c pwd)" = "/tmp"
test "$(cd /tmp && test-snapd-sh.sh -c 'stat -c %i .')" != "$(cd /tmp && stat -c %i .)"
# The current working directory that does not exist in the snap mount
# namespace is re-mapped to a special directory.
test "$(mkdir -p /tmp/test && cd /tmp/test && test-snapd-sh.sh -c pwd)" = "/var/lib/snapd/void"
# The current working directory that does exist in the snap mount
# namespace but has permissions preventing the user to enter it (e.g.
# via a symlink attack in /tmp) is remapped to a special directory.
# FIXME: su doesn't have /snap/bin in PATH.
case "$SPREAD_SYSTEM" in
fedora-*|opensuse-tumbleweed-*|arch-linux-*)
# nothiing, we have to go through tests.session which always starts in
# the $HOME directory
;;
*)
test "$(cd /root && runuser -u test -- sh -c "snap run test-snapd-sh.sh -c pwd" )" = "/var/lib/snapd/void"
;;
esac
# Since the void directory is used when there are insufficient permissions
# to enter the regular directory we must be able to go there in the first
# place. The directory is sometimes created on demand so check for the
# actual permissions at the end of the test.
test "$(stat -c %a /var/lib/snapd/void)" = 111
|