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
|
summary: Ensure that the hostname-control interface works
details: |
The hostname-control interface allows to configure the system hostname
prepare: |
echo "Install test hostname-control snap"
"$TESTSTOOLS"/snaps-state install-local test-snapd-sh
execute: |
hostname="$(hostname)"
echo "The plug is disconnected by default"
snap interfaces -i hostname-control | MATCH -- '- +test-snapd-sh:hostname-control'
echo "When the plug is connected"
snap connect test-snapd-sh:hostname-control
echo "The hostname command can be used"
snap_hostname="$(test-snapd-sh.with-hostname-control-plug -c "/bin/hostname")"
[ "$hostname" = "$snap_hostname" ]
# On core systems /etc/hostname is not writable
if os.query is-classic; then
echo "And the /etc/hostname file can be written"
test-snapd-sh.with-hostname-control-plug -c "echo $hostname > /etc/hostname"
fi
echo "And hostname can be get/set through dbus"
test-snapd-sh.with-hostname-control-plug -c "hostnamectl" | MATCH "$hostname"
test-snapd-sh.with-hostname-control-plug -c "hostnamectl set-hostname $hostname"
if [ "$(snap debug confinement)" = partial ]; then
exit 0
fi
echo "When the plug is disconnected"
snap disconnect test-snapd-sh:hostname-control
echo "Then the hostname method cannot be accessed through dbus"
if test-snapd-sh.with-hostname-control-plug -c "hostnamectl set-hostname $hostname" 2> access.error; then
echo "Expected permission error trying to set hostname with disconnected plug"
exit 1
fi
MATCH "Permission denied" < access.error
echo "And the /etc/hostname file cannot be written"
if test-snapd-sh.with-hostname-control-plug -c "echo $hostname > /etc/hostname" 2> hostname.error; then
echo "Expected permission error trying to acess to /etc/hostname with disconnected plug"
exit 1
fi
MATCH "Permission denied" < hostname.error
echo "And the /etc/hostname file and the hostname command are still available even without the connection."
test-snapd-sh.with-hostname-control-plug -c "test -f /etc/hostname"
test-snapd-sh.with-hostname-control-plug -c "test -x /bin/hostname"
|