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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
summary: Ensure that snap layouts are applied
details: |
This test installs a test snap that uses layout declarations.
The layout changes which directories and files exist in the filesystem
in the area beyond the $SNAP directory. In addition all applications and
hooks get permissions to access those areas.
prepare: |
"$TESTSTOOLS"/snaps-state install-local test-snapd-layout
debug: |
ls -ld /etc || :
ls -ld /etc/demo || :
ls -ld /etc/demo.conf || :
ls -ld /etc/demo.cfg || :
execute: |
for i in $(seq 2); do
if [ "$i" -eq 2 ]; then
echo "The snap works across refreshes"
"$TESTSTOOLS"/snaps-state install-local test-snapd-layout
fi
echo "snap declaring layouts doesn't explode on startup"
test-snapd-layout.sh -c "true"
echo "layout declarations are honored"
test-snapd-layout.sh -c "test -d /etc/demo"
test-snapd-layout.sh -c "test -f /etc/demo.conf"
test-snapd-layout.sh -c "test -h /etc/demo.cfg"
#shellcheck disable=SC2016
test "$(test-snapd-layout.sh -c "readlink /etc/demo.cfg")" = "$(test-snapd-layout.sh -c 'echo $SNAP_COMMON/etc/demo.conf')"
test-snapd-layout.sh -c "test -d /usr/share/demo"
test-snapd-layout.sh -c "test -d /var/lib/demo"
test-snapd-layout.sh -c "test -d /var/cache/demo"
test-snapd-layout.sh -c "test -d /opt/demo"
test-snapd-layout.sh -c "test -d /bin/very/weird/place"
# Ideally we'd perform this test but the rsyslog directory has mode 700 and user mode 108:4
# test-snapd-layout.sh -c "test -d /var/spool/rsyslog/demo"
echo "layout constructed a mimic using tmpfs as aid (/opt)"
[ "$(test-snapd-layout.sh -c "stat -f /opt -c '%T'")" = "tmpfs" ]
echo "and the tmpfs was mounted with 0755 and root/root user/group to mimic /opt in core"
[ "$(test-snapd-layout.sh -c "stat /opt -c '%a'")" = "755" ]
[ "$(test-snapd-layout.sh -c "stat /opt -c '%u'")" = "0" ]
[ "$(test-snapd-layout.sh -c "stat /opt -c '%g'")" = "0" ]
echo "layout constructed a mimic using tmpfs as aid (/var/spool/rsyslog)"
[ "$(test-snapd-layout.sh -c "stat -f /var/spool/rsyslog -c '%T'")" = "tmpfs" ]
echo "and the tmpfs was mounted with 0700 and syslog/adm user/group to mimic /var/spool/rsyslog in core"
[ "$(test-snapd-layout.sh -c "stat /var/spool/rsyslog -c '%a'")" = "700" ]
[ "$(test-snapd-layout.sh -c "stat /var/spool/rsyslog -c '%u'")" = "108" ]
[ "$(test-snapd-layout.sh -c "stat /var/spool/rsyslog -c '%g'")" = "4" ]
echo "layout declarations didn't leak to the host"
test ! -e /etc/demo
test ! -e /etc/demo.conf
test ! -e /etc/demo.cfg
test ! -e /usr/share/demo
test ! -e /var/lib/demo
test ! -e /var/cache/demo
test ! -e /opt/demo
echo "layout locations pointing to SNAP_DATA and SNAP_COMMON are writable"
echo "and the writes go to the right place in the backing store"
test-snapd-layout.sh -c "echo foo-1 > /etc/demo/writable"
#shellcheck disable=SC2016
test "$(test-snapd-layout.sh -c 'cat $SNAP_COMMON/etc/demo/writable')" = "foo-1"
test-snapd-layout.sh -c "echo foo-2 > /etc/demo.conf"
#shellcheck disable=SC2016
test "$(test-snapd-layout.sh -c 'cat $SNAP_COMMON/etc/demo.conf')" = "foo-2"
# NOTE: this is a symlink to demo.conf, effectively
test-snapd-layout.sh -c "echo foo-3 > /etc/demo.cfg"
#shellcheck disable=SC2016
test "$(test-snapd-layout.sh -c 'cat $SNAP_COMMON/etc/demo.conf')" = "foo-3"
test-snapd-layout.sh -c "echo foo-4 > /var/lib/demo/writable"
#shellcheck disable=SC2016
test "$(test-snapd-layout.sh -c 'cat $SNAP_DATA/var/lib/demo/writable')" = "foo-4"
test-snapd-layout.sh -c "echo foo-5 > /var/cache/demo/writable"
#shellcheck disable=SC2016
test "$(test-snapd-layout.sh -c 'cat $SNAP_DATA/var/cache/demo/writable')" = "foo-5"
echo "layout locations pointing to SNAP are readable"
test-snapd-layout.sh -c "test -r /usr/share/demo/file"
test-snapd-layout.sh -c "test -r /opt/demo/file"
echo "layout locations in dynamically created SNAP directories are writable"
# shellcheck disable=SC2016
test-snapd-layout.sh -c 'test -w $SNAP/bin/very/weird/place'
test-snapd-layout.sh -c 'test -w /bin/very/weird/place'
done
|