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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
summary: Ensure that the home interface works.
details: |
The home interface allows a snap to access non-hidden files in $HOME
A snap which defines the home plug must be shown in the interfaces list. The
plug must be auto-connected on install for classic systems and disconnected
on all-snaps and, as usual, must be able to be reconnected. When connected
it must grant access to non hidden home files.
environment:
SNAP_FILE: "home-consumer_1.0_all.snap"
CREATABLE_FILE: "$HOME/creatable"
READABLE_FILE: "$HOME/readable"
WRITABLE_FILE: "$HOME/writable"
HIDDEN_CREATABLE_FILE: "$HOME/.creatable"
HIDDEN_READABLE_FILE: "$HOME/.readable"
prepare: |
echo "Given a snap declaring the home plug is installed"
"$TESTSTOOLS"/snaps-state install-local home-consumer
echo "And there is a readable file in HOME"
echo ok > "$READABLE_FILE"
echo "And there is a writable file in HOME"
echo ok > "$WRITABLE_FILE"
echo "And there is a hidden readable file in HOME"
echo ok > "$HIDDEN_READABLE_FILE"
restore: |
rm -f "$READABLE_FILE" "$WRITABLE_FILE" "$CREATABLE_FILE" "$HIDDEN_READABLE_FILE"
execute: |
if os.query is-core; then
echo "The interface is not connected by default"
snap interfaces -i home | MATCH '^- +home-consumer:home'
echo "And the plug can be connected"
snap connect home-consumer:home
else
echo "The interface is connected by default"
snap interfaces -i home | MATCH ":home .*home-consumer"
echo "When the plug is disconnected"
snap disconnect home-consumer:home
echo "Then the plug can be connected again"
snap connect home-consumer:home
fi
echo "When the plug is connected"
snap connect home-consumer:home
echo "Then the snap is able to read home files"
home-consumer.reader "$READABLE_FILE" | grep -Pqz ok
if [ "$(snap debug confinement)" = strict ] ; then
echo "When the plug is disconnected"
snap disconnect home-consumer:home
echo "Then snap can't read home files"
if home-consumer.reader "$READABLE_FILE"; then
echo "Home files shouldn't be readable" && exit 1
fi
fi
echo "When the plug is connected"
snap connect home-consumer:home
echo "Then the snap is able to append to home files"
home-consumer.writer "$WRITABLE_FILE"
grep -Pqz 'ok\nok' < "$WRITABLE_FILE"
if [ "$(snap debug confinement)" = strict ] ; then
echo "When the plug is disconnected"
snap disconnect home-consumer:home
echo "Then snap can't append to home files"
if home-consumer.writer "$WRITABLE_FILE"; then
echo "Home files shouldn't be writable" && exit 1
fi
fi
echo "When the plug is connected"
snap connect home-consumer:home
echo "Then the snap is able to create home files"
home-consumer.writer "$CREATABLE_FILE"
grep -Pqz "ok" < "$CREATABLE_FILE"
if [ "$(snap debug confinement)" = partial ] ; then
exit 0
fi
echo "When the plug is disconnected"
snap disconnect home-consumer:home
echo "Then snap can't create home files"
if home-consumer.writer "$CREATABLE_FILE"; then
echo "It should be impossible to create home files" && exit 1
fi
echo "When the plug is connected"
snap connect home-consumer:home
echo "Then the snap is not able to read hidden home files"
if home-consumer.reader "$HIDDEN_READABLE_FILE"; then
echo "Hidden home files shouldn't be readable" && exit 1
fi
echo "When the plug is connected"
snap connect home-consumer:home
echo "Then the snap is not able to write hidden home files"
if home-consumer.writer "$HIDDEN_CREATABLE_FILE"; then
echo "It should be impossible to create hidden home files" && exit 1
fi
|