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
|
summary: |
Ensure `snap validate --enforce --refresh` resolves validation set enforcement errors automatically.
details: |
Check that snapd enforces validation sets, preventing snaps from being
installed or removed if it would violate a constraint. Check that the
`snap validate --refresh --enforce` command automatically resolves unmet
validation set constraints except when it would require removing snaps.
environment:
ACCOUNT_ID: test-snapd
restore: |
snap validate --forget "$ACCOUNT_ID"/refresh-enforce-set-pinned-test || true
snap validate --forget "$ACCOUNT_ID"/refresh-enforce-set-test || true
execute: |
# pin a validation set, this should remained pinned once the other validation
# set is enforced
snap validate --refresh --enforce "$ACCOUNT_ID"/refresh-enforce-set-pinned-test=1
echo "Check that --enforce --refresh installs required snaps"
# TODO: test the auto-resolution for wrong revisions by installing revision 2
# and checking it's moved to revision 1
snap install --channel=latest/stable test-snapd-public | MATCH "test-snapd-public 1\.0.+"
snap validate --refresh --enforce "$ACCOUNT_ID"/refresh-enforce-set-test
# enforcing the new set should not have unpinned the previous set
snap validate | MATCH "${ACCOUNT_ID}/refresh-enforce-set-pinned-test=1"
# we can remove it now, as it is no longer needed
snap validate --forget "$ACCOUNT_ID"/refresh-enforce-set-pinned-test
snap list | MATCH "test-snapd-tools +1\.0 +[0-9]+ +latest/stable"
snap list | MATCH "test-snapd-public +1\.0 +1 +latest/stable"
echo "Check that an invalid snap cannot be installed"
if snap install hello-world > log.txt 2>&1; then
echo "Expected snap install to fail"
exit 1
fi
"$TESTSTOOLS"/to-one-line "$(cat log.txt)" | MATCH "error: cannot install \"hello-world\": cannot install snap \"hello-world\" due to enforcing rules of validation set 16/$ACCOUNT_ID/refresh-enforce-set-test/1"
echo "Check that a required snap or revision cannot be removed"
if snap remove --purge test-snapd-tools > log.txt 2>&1; then
echo "Expected snap remove to fail"
exit 1
fi
"$TESTSTOOLS"/to-one-line "$(cat log.txt)" | MATCH "error: cannot remove \"test-snapd-tools\": snap \"test-snapd-tools\" is not removable: snap \"test-snapd-tools\" is required by validation sets: 16/$ACCOUNT_ID/refresh-enforce-set-test/1"
echo "Check that --enforce --refresh can't auto-resolve if it requires removing snaps"
snap validate --forget "$ACCOUNT_ID"/refresh-enforce-set-test
snap install hello-world
if snap validate --refresh --enforce "$ACCOUNT_ID"/refresh-enforce-set-test > log.txt 2>&1; then
echo "Expected snap validate --refresh --enforce to fail"
exit 1
fi
"$TESTSTOOLS"/to-one-line "$(cat log.txt)" | MATCH "error: cannot refresh: cannot auto-resolve validation set constraints that require removing snaps: \"hello-world\""
|