mirror of
https://github.com/token2/snapd.git
synced 2026-03-13 11:15:47 -07:00
* tests: adding details to tests in core suite - part 1 * Update tests/core/compat/task.yaml Co-authored-by: Zygmunt Bazyli Krynicki <me@zygoon.pl> * Update tests/core/basic18/task.yaml Co-authored-by: Zygmunt Bazyli Krynicki <me@zygoon.pl> * Update tests/core/compat/task.yaml Co-authored-by: Zygmunt Bazyli Krynicki <me@zygoon.pl> * Update tests/core/config-defaults-once/task.yaml Co-authored-by: Zygmunt Bazyli Krynicki <me@zygoon.pl> * Update tests/core/core-dump/task.yaml Co-authored-by: Zygmunt Bazyli Krynicki <me@zygoon.pl> * Update tests/core/create-user-2/task.yaml Co-authored-by: Zygmunt Bazyli Krynicki <me@zygoon.pl> * Update tests/core/create-user-2/task.yaml Co-authored-by: Zygmunt Bazyli Krynicki <me@zygoon.pl> * Update tests/core/create-user/task.yaml Co-authored-by: Zygmunt Bazyli Krynicki <me@zygoon.pl> * Update tests/core/create-user/task.yaml Co-authored-by: Zygmunt Bazyli Krynicki <me@zygoon.pl> * Update tests/core/fan/task.yaml Co-authored-by: Zygmunt Bazyli Krynicki <me@zygoon.pl> * Update tests/core/grub-no-unpacked-assets/task.yaml Co-authored-by: Zygmunt Bazyli Krynicki <me@zygoon.pl> * Update tests/core/core-to-snapd-failover16/task.yaml Co-authored-by: Zygmunt Bazyli Krynicki <me@zygoon.pl> --------- Co-authored-by: Zygmunt Bazyli Krynicki <me@zygoon.pl>
67 lines
2.3 KiB
YAML
67 lines
2.3 KiB
YAML
summary: Ensure create-user functionality
|
|
|
|
details: |
|
|
Check the command `snap create-user` succeeds when run as non-root user with sudo.
|
|
Ensure the ssh keys are imported for the user and that it can be created as a sudoer.
|
|
|
|
environment:
|
|
USER_EMAIL: mvo@ubuntu.com
|
|
USER_NAME: mvo
|
|
|
|
restore: |
|
|
if [ -e managed.device ]; then
|
|
exit 0
|
|
fi
|
|
# Check if the user exists before remove it
|
|
if id "$USER_NAME" >/dev/null 2>&1; then
|
|
snap remove-user "$USER_NAME"
|
|
fi
|
|
|
|
debug: |
|
|
if [ -e managed.device ]; then
|
|
ls -al /home/"$USER_NAME" || true
|
|
cat /var/lib/extrausers/passwd || true
|
|
fi
|
|
|
|
execute: |
|
|
echo "snap create-user -- ensure failure when run as non-root user without sudo"
|
|
expected="error: while creating user: access denied"
|
|
if obtained=$(su - test /bin/sh -c "snap create-user $USER_EMAIL 2>&1"); then
|
|
echo "create-user command should have failed"
|
|
fi
|
|
[[ "$obtained" =~ $expected ]]
|
|
|
|
if [ "$(snap managed)" = "true" ]; then
|
|
# Leave a file indicating the device was initially managed
|
|
touch managed.device
|
|
|
|
echo "snap create-user -- not success when run as non-root user with sudo on managed device"
|
|
if su - test /bin/sh -c "sudo snap create-user --sudoer $USER_EMAIL" 2>create.error; then
|
|
echo "Did not get expected error creating user in managed device"
|
|
exit 1
|
|
fi
|
|
MATCH "cannot create user: device already managed" < create.error
|
|
|
|
exit 0
|
|
fi
|
|
|
|
echo "snap create-user -- ensure success when run as non-root user with sudo"
|
|
expected="created user \"$USER_NAME\""
|
|
obtained=$(su - test /bin/sh -c "sudo snap create-user --sudoer $USER_EMAIL 2>&1")
|
|
[[ "$obtained" =~ $expected ]]
|
|
|
|
echo "ensure user exists in /etc/passwd"
|
|
MATCH "^$USER_NAME:x:[0-9]+:[0-9]+:$USER_EMAIL" < /var/lib/extrausers/passwd
|
|
|
|
echo "ensure proper sudoers.d file"
|
|
MATCH "$USER_NAME ALL=\\(ALL\\) NOPASSWD:ALL" < "/etc/sudoers.d/create-user-$USER_NAME"
|
|
|
|
echo "ensure the user's home directory exists"
|
|
test -d "/home/$USER_NAME"
|
|
|
|
echo "ensure ~/.snap/auth.json was created"
|
|
test -f "/home/$USER_NAME/.snap/auth.json"
|
|
|
|
echo "ensure user's email was stored in ~/.snap/auth.json"
|
|
MATCH "\"email\":\"$USER_EMAIL\"" < "/home/$USER_NAME/.snap/auth.json"
|