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
|
summary: Ensure that the removable-media interface works.
details: |
The removable-media interface allows to access to removable storage filesystems.
prepare: |
"$TESTSTOOLS"/snaps-state install-local test-snapd-sh
if ! [ -d /media ]; then
mkdir -p /media
touch /media/fake
fi
mkdir -p /media/testdir
touch /media/testdir/testfile
if ! [ -d /run/media ]; then
mkdir -p /run/media
touch /run/media/fake
fi
mkdir -p /run/media/testdir
touch /run/media/testdir/testfile
echo "Mount a filesystem in /tmp/testing and put some data there"
mkdir -p /mnt/testing/
mount -t tmpfs none /mnt/testing
echo canary > /mnt/testing/data
restore: |
rm -rf /media/testdir
if [ -f /media/fake ]; then
#shellcheck disable=SC2114
rm -rf /media
fi
rm -rf /run/media/testdir
if [ -f /run/media/fake ]; then
rm -rf /run/media/
fi
umount /mnt/testing
rmdir /mnt/testing || true # in case the user had /mnt/testing
execute: |
echo "The interface is not connected by default"
snap interfaces -i removable-media | MATCH -- '- +test-snapd-sh:removable-media'
echo "When the interface is connected"
snap connect test-snapd-sh:removable-media
echo "Then the snap is able to read inside /run"
test-snapd-sh.with-removable-media-plug -c "ls /run"
echo "And the snap is able to access to read/write removable storage filesystems"
test-snapd-sh.with-removable-media-plug -c "ls /media"
test-snapd-sh.with-removable-media-plug -c "ls /media/testdir"
test-snapd-sh.with-removable-media-plug -c "echo test >> /media/testdir/testfile"
test-snapd-sh.with-removable-media-plug -c "ls /run/media"
test-snapd-sh.with-removable-media-plug -c "ls /run/media/testdir"
test-snapd-sh.with-removable-media-plug -c "echo test >> /run/media/testdir/testfile"
echo "And the snap has read-write access to /mnt/testing/data"
test-snapd-sh.with-removable-media-plug -c 'cat /mnt/testing/data' | MATCH canary
test-snapd-sh.with-removable-media-plug -c 'echo modified > /mnt/testing/data'
MATCH modified < /mnt/testing/data
if [ "$(snap debug confinement)" = partial ]; then
exit 0
fi
echo "When the plug is disconnected"
snap disconnect test-snapd-sh:removable-media
echo "Then the snap is not able to access read the test media file"
if test-snapd-sh.with-removable-media-plug -c "ls /run" 2> call.error; then
echo "Expected permission error accessing to removable storage filesystems"
exit 1
fi
MATCH "Permission denied" < call.error
echo "Then /mnt/testing/data is no longer readable"
if test-snapd-sh.with-removable-media-plug -c 'cat /mnt/testing/data'; then
echo "/mnt/testing/data should no longer be readable" && exit 1
fi
|