Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: show that snap from snapd deb can be bundled #14551

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions tests/main/bin-snap-in-snap/task.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
summary: snaps bundling /bin/snap from snapd.deb can do so
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: Summary should start with capital, and preferable end with '.'


details: |
The snap binary may be embedded in a snap for as long as the bases match.
The snap binary may be called with LD_PRELOAD=, or other dynamic linker
environment variables without ill effects.

Note that this contract does *not* extend to the snap binary from the snapd
snap. That version cannot be embedded in snap applications.

systems:
# This test runs only on systems that are ABI-matching the core24 snap. This
# test could be extended to include more bases later. This test cannot run
# on ubuntu core, because /usr/bin/snap is the "snapd snap" version which is
# linked differently.
- ubuntu-24.04-64

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra space


prepare: |
cp "$(command -v snap)" test-snapd-sh-core24/bin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cp "$(command -v snap)" test-snapd-sh-core24/bin
cp -v "$(command -v snap)" test-snapd-sh-core24/bin

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could also copy the snap command the snapd snap and show that it fails to run

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but then the test name would need to be different. I also don't know what that specific test would show. On some systems (without apparmor) it would actually work because it would load the dynamic linker from /snap/snapd/current

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is running only on ubuntu-24.04, which means that if you copy a snap binary from the snap it will fail (or at least should), which is the exact scenario folks should not be doing. i.e. copying stuff from the snapd snap into their snaps.

snap pack test-snapd-sh-core24
snap install --dangerous ./test-snapd-sh-core24_1.0_all.snap

execute: |
# We are pre-loading libz simply because it's small and easy to get. The
# point is to show, that the copied snap executable does not crash in this
# configuration.
#
# shellcheck disable=SC2016
test-snapd-sh-core24.sh -c 'LD_PRELOAD=/lib/x86_64-linux-gnu/libz.so "$SNAP"/bin/snap' | MATCH 'Usage: snap <command> \[<options>...\]'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure LD_PRELOAD is making any difference here if it's loading a library from base which matches the running system.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the whole point. It's supposed to show you can do it in a very specific way.
We're not testing for properties of the snap binary from the snapd snap.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's nothing specific about it. We almost guarantee that taking a binary from 24.04 it keeps working when executed in a snap that uses core24, preload or not.

3 changes: 3 additions & 0 deletions tests/main/bin-snap-in-snap/test-snapd-sh-core24/bin/sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
PS1='$ '
exec /bin/sh "$@"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: test-snapd-sh-core24
version: 1.0
architectures: ["all"]
base: core24
apps:
sh:
command: bin/sh
Loading