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
|
summary: Check that `snap auto-import` works as expected
details: |
The auto-import command searches available mounted devices looking for
assertions that are signed by trusted authorities, and potentially
performs system changes based on them.
If one or more device paths are provided via --mount, these are temporarily
mounted to be inspected as well
Assertions to be imported must be made available in the auto-import.assert file
in the root of the filesystem.
This test creates new block device to trigger auto-import mount and then
verifies the auto-mount magic has given us the assertion.
systems:
- ubuntu-core-16-64
- ubuntu-core-18-64
- ubuntu-core-20-64
- ubuntu-core-22-64
# On core24 the udev rules will not trigger because the dm device
# that is set up is not marked 'removable', the udev rules has been
# changed in core24 to require this for auto-import - this test should be
# rewritten to be a nested test and tested with a fake usb-device in
# qemu instead of trying to fake it with a dm device.
# - ubuntu-core-24-64
prepare: |
if [ "$TRUST_TEST_KEYS" = "false" ]; then
echo "This test needs test keys to be trusted"
exit
fi
echo "Install dmsetup"
snap install --devmode --edge dmsetup
echo "Ensure the testrootorg-store.account-key is not already added"
output=$(snap known account-key | grep -c "name: test-store" || true)
if [ "$output" != "0" ]; then
echo " testrootorg-store.account-key is already added"
exit 1
fi
echo "Create a ramdisk with the testrootorg-store.account-key assertion"
#shellcheck source=tests/lib/ramdisk.sh
. "$TESTSLIB/ramdisk.sh"
setup_ramdisk
# We use different filesystems to cover both: fat and ext. fat is the most
# common fs used and we also use ext3 because fat is not available on ubuntu core 18
if os.query is-core18; then
mkfs.ext3 /dev/ram0
else
mkfs.vfat /dev/ram0
fi
mount /dev/ram0 /mnt
cp "$TESTSLIB"/assertions/testrootorg-store.account-key /mnt/auto-import.assert
sync
umount /mnt
echo "Create new block device to trigger auto-import mount"
# wait for all udev events to be handled, sometimes we are getting an error:
#
# $ dmsetup -v --noudevsync --noudevrules create dm-ram0 --table '0 131072 linear /dev/ram0 0'
# device-mapper: reload ioctl on dm-ram0 failed: Device or resource busy
#
# and in syslog:
#
# Jun 28 09:18:34 localhost kernel: [ 36.434220] device-mapper: table: 252:0: linear: Device lookup failed
# Jun 28 09:18:34 localhost kernel: [ 36.434686] device-mapper: ioctl: error adding target to table
udevadm settle
dmsetup -v --noudevsync --noudevrules create dm-ram0 --table "0 $(blockdev --getsize /dev/ram0) linear /dev/ram0 0"
udevadm settle
restore: |
if [ "$TRUST_TEST_KEYS" = "false" ]; then
echo "This test needs test keys to be trusted"
exit
fi
dmsetup -v --noudevsync --noudevrules remove dm-ram0
debug: |
"$TESTSTOOLS"/journal-state get-log -b | tail -100
execute: |
if [ "$TRUST_TEST_KEYS" = "false" ]; then
echo "This test needs test keys to be trusted"
exit
fi
echo "The auto-mount magic has given us the assertion"
retry -n 5 sh -c 'snap known account-key | MATCH "name: test-store"'
|