Skip to content
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
18 changes: 18 additions & 0 deletions tests/main/system-usernames-hooks/task.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
summary: exercise snap hooks using system-usernames

details: |
Exercise a scenario in which a snap that uses system-usernames carries
hooks. Make sure that hooks are able to exercise functionality provided by
system-usernames.

prepare: |
tests.cleanup defer "$TESTSTOOLS"/user-state remove-with-group snap_daemon

execute: |
"$TESTSTOOLS"/snaps-state install-local test-snapd-sh

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

maybe add some assertions for files (e.g. "$SNAP_COMMON"/hook.log and $SNAP_COMMON/data/foo) after install and refresh?

test-snapd-sh.sh -c 'setpriv --clear-groups \
--reuid snap_daemon \
--regid snap_daemon -- \
id'

"$TESTSTOOLS"/snaps-state install-local test-snapd-sh
3 changes: 3 additions & 0 deletions tests/main/system-usernames-hooks/test-snapd-sh/bin/sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
PS1='$ '
exec /bin/sh "$@"
11 changes: 11 additions & 0 deletions tests/main/system-usernames-hooks/test-snapd-sh/meta/hooks/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

exec 2>&1

echo "running install hook" >> "$SNAP_COMMON"/hook.log

mkdir "$SNAP_COMMON"/data
touch "$SNAP_COMMON"/data/foo

chown -R snap_daemon "$SNAP_COMMON"/data
chgrp -R root "$SNAP_COMMON"/data
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

exec 2>&1

echo "running post-refresh hook" >> "$SNAP_COMMON"/hook.log

setpriv \
--clear-groups \
--reuid snap_daemon \
--regid snap_daemon -- \
/bin/sh -c "echo 'post refresh' >> $SNAP_COMMON/data/foo"
11 changes: 11 additions & 0 deletions tests/main/system-usernames-hooks/test-snapd-sh/meta/snap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: test-snapd-sh
summary: Minimal snap for testing
version: 1.0
base: core24

apps:
sh:
command: bin/sh

system-usernames:
snap_daemon: shared
Loading