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
|
summary: Ensure that the hardware-random-control interface works.
details: |
The hardware-control interface allows a snap to access hardware-random
information.
A snap which access to the hardware-random information must be shown in the
interfaces list. The plug must not be connected on install and, as usual,
must be able to be reconnected.
A snap declaring a plug on this interface must be able to read files in
/sys/class/misc/hw_random/{rng_available,rng_current} and /dev/hwrng
# Execution skipped on debian, arch and amazon due to device /dev/hwrng not
# created by default
systems: [-debian-*, -arch-*, -amazon-*, -centos-*]
prepare: |
echo "Given a snap declaring a plug on the hardware-random-control interface is installed"
"$TESTSTOOLS"/snaps-state install-local test-snapd-hardware-random-control
execute: |
echo "The interface is not connected by default"
snap interfaces -i hardware-random-control | MATCH '^- +test-snapd-hardware-random-control:hardware-random-control'
echo "When the plug is connected"
snap connect test-snapd-hardware-random-control:hardware-random-control
echo "Then the snap is able to read hardware random information"
# note that /dev/hwrng isn't normally written to, only read from
test-snapd-hardware-random-control.check /dev/hwrng
test-snapd-hardware-random-control.check /sys/class/misc/hw_random/rng_available
test-snapd-hardware-random-control.check /sys/class/misc/hw_random/rng_current
if [ "$(snap debug confinement)" = partial ] ; then
exit 0
fi
echo "When the plug is disconnected"
snap disconnect test-snapd-hardware-random-control:hardware-random-control
echo "Then the snap is not able to read the hardware random information"
not test-snapd-hardware-random-control.check /dev/hwrng 2>hw.error
# blocked by cgroups
MATCH "dd: .*: Operation not permitted" < hw.error
not test-snapd-hardware-random-control.check /sys/class/misc/hw_random/rng_current 2>hw.error
MATCH "cat: .*: Permission denied" < hw.error
echo "And the snap is able to reconnect"
snap connect test-snapd-hardware-random-control:hardware-random-control
|