Skip to content

Commit

Permalink
tests/main: account for expected failures when running with SNAP_REEX…
Browse files Browse the repository at this point in the history
…EC=1

Account for expected failures when running with SNAP_REEXEC on unsupported
distros.

Signed-off-by: Maciej Borzecki <[email protected]>
  • Loading branch information
bboozzoo committed Jun 27, 2024
1 parent b520f23 commit 7e09dd8
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/main/command-chain/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ details: |
that the command-chain is executed when running a snap with `snap run
--shell`.
systems:
# uubuntu 32bit: test uses snap with base core20 which there is no 32bit
# variant of
- -ubuntu-*-32

environment:
# Ensure that running purely from the deb (without re-exec) works
# correctly
Expand All @@ -19,13 +24,36 @@ prepare: |
echo "Build command chain snap"
snap pack command-chain
snap install --dangerous command-chain_1.0_all.snap
SNAP_MOUNT_DIR="$(os.paths snap-mount-dir)"
if [ "$SNAP_REEXEC" = "1" ] && [ "$SNAP_MOUNT_DIR" != "/snap" ] && [ ! -L /snap ]; then
# reexec expects to find the snapd snap under /snap, enable it to do so
# on distros using /var/lib/snapd/snap
ln -sf "$SNAP_MOUNT_DIR" /snap
tests.cleanup defer rm -f /snap
fi
execute: |
echo "Test that command-chain runs for hooks"
[ "$(cat "$BREADCRUMB")" = "chain1 chain2 configure" ]
MATCH '^CHAIN_1_RAN=1$' < "$ENVDUMP"
MATCH '^CHAIN_2_RAN=1$' < "$ENVDUMP"
SNAP_MOUNT_DIR="$(os.paths snap-mount-dir)"
if [ "$SNAP_REEXEC" = "1" ] && [ "$SNAP_MOUNT_DIR" != "/snap" ]; then
# with snap mount dir different than /snap, internal s-c checks will fail
if command-chain.hello > err.out 2>&1 ; then
echo "unexpected success"
cat err.out || true
exit 1
fi
# with no AA support, we fail on a simple check for s-c being executed
# from /snap/snapd/<rev>/, with AA we fail on an earlier check for AA
# confinement
MATCH "(running from unexpected location:|snap-confine has elevated permissions)" < err.out
exit 0
fi
echo "Test that command-chain runs for apps"
[ "$(command-chain.hello)" = "chain1 chain2 hello" ]
Expand Down
24 changes: 24 additions & 0 deletions tests/main/install-sideload/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ prepare: |
for snap in basic test-snapd-tools basic-desktop test-snapd-devmode snap-hooks-bad-install; do
snap pack "$TESTSLIB"/snaps/$snap
done
SNAP_MOUNT_DIR="$(os.paths snap-mount-dir)"
if [ "$SNAP_REEXEC" = "1" ] && [ "$SNAP_MOUNT_DIR" != "/snap" ] && [ ! -L /snap ]; then
# reexec expects to find the snapd snap under /snap, enable it to do so
# on distros using /var/lib/snapd/snap
ln -sf "$SNAP_MOUNT_DIR" /snap
tests.cleanup defer rm -f /snap
fi
execute: |
echo "Sideloaded snap shows status"
Expand All @@ -29,6 +36,23 @@ execute: |
echo "Sideloaded snap executes commands"
snap install --dangerous ./test-snapd-tools_1.0_all.snap
SNAP_MOUNT_DIR="$(os.paths snap-mount-dir)"
if [ "$SNAP_REEXEC" = "1" ] && [ "$SNAP_MOUNT_DIR" != "/snap" ]; then
# with snap mount dir different than /snap, internal s-c checks will fail
if test-snapd-tools.success > err.out 2>&1 ; then
echo "unexpected success"
cat err.out || true
exit 1
fi
# with no AA support, we fail on a simple check for s-c being executed
# from /snap/snapd/<rev>/, with AA we fail on an earlier check for AA
# confinement
MATCH "(running from unexpected location:|snap-confine has elevated permissions)" < err.out
exit 0
fi
test-snapd-tools.success
[ "$(test-snapd-tools.echo Hello World)" = "Hello World" ]
Expand Down
23 changes: 23 additions & 0 deletions tests/main/snap-run-hook/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,36 @@ environment:

prepare: |
"$TESTSTOOLS"/snaps-state install-local basic-hooks
SNAP_MOUNT_DIR="$(os.paths snap-mount-dir)"
if [ "$SNAP_REEXEC" = "1" ] && [ "$SNAP_MOUNT_DIR" != "/snap" ] && [ ! -L /snap ]; then
# reexec expects to find the snapd snap under /snap, enable it to do so
# on distros using /var/lib/snapd/snap
ln -sf "$SNAP_MOUNT_DIR" /snap
tests.cleanup defer rm -f /snap
fi
execute: |
# Note that `snap run` doesn't exit non-zero if the hook is missing, so we
# check the output instead.
echo "Test that snap run can call valid hooks"
SNAP_MOUNT_DIR="$(os.paths snap-mount-dir)"
if [ "$SNAP_REEXEC" = "1" ] && [ "$SNAP_MOUNT_DIR" != "/snap" ]; then
# with snap mount dir different than /snap, internal s-c checks will fail
if snap run --hook=configure basic-hooks > err.out 2>&1 ; then
echo "unexpected success"
cat err.out || true
exit 1
fi
# with no AA support, we fail on a simple check for s-c being executed
# from /snap/snapd/<rev>/, with AA we fail on an earlier check for AA
# confinement
MATCH "(running from unexpected location:|snap-confine has elevated permissions)" < err.out
exit 0
fi
if ! output="$(snap run --hook=configure basic-hooks)"; then
echo "Failed to run configure hook"
exit 1
Expand Down
24 changes: 24 additions & 0 deletions tests/main/writable-areas/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,35 @@ environment:

prepare: |
snap pack data-writer
SNAP_MOUNT_DIR="$(os.paths snap-mount-dir)"
if [ "$SNAP_REEXEC" = "1" ] && [ "$SNAP_MOUNT_DIR" != "/snap" ] && [ ! -L /snap ]; then
# reexec expects to find the snapd snap under /snap, enable it to do so
# on distros using /var/lib/snapd/snap
ln -sf "$SNAP_MOUNT_DIR" /snap
tests.cleanup defer rm -f /snap
fi
execute: |
snap install --dangerous data-writer_1.0_all.snap
echo "Apps can write to writable areas"
SNAP_MOUNT_DIR="$(os.paths snap-mount-dir)"
if [ "$SNAP_REEXEC" = "1" ] && [ "$SNAP_MOUNT_DIR" != "/snap" ]; then
# with snap mount dir different than /snap, internal s-c checks will fail
if data-writer.app > err.out 2>&1 ; then
echo "unexpected success"
cat err.out || true
exit 1
fi
# with no AA support, we fail on a simple check for s-c being executed
# from /snap/snapd/<rev>/, with AA we fail on an earlier check for AA
# confinement
MATCH "(running from unexpected location:|snap-confine has elevated permissions)" < err.out
exit 0
fi
data-writer.app
[ -f /var/snap/data-writer/x1/from-app ]
[ -f /var/snap/data-writer/common/from-app ]
Expand Down

0 comments on commit 7e09dd8

Please sign in to comment.