forked from canonical/snapd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request canonical#8205 from sergiocazzolato/tests-fix-crea…
…te-user-2 tests: just remove user when the system is not managed on create-user-2 test
- Loading branch information
Showing
3 changed files
with
43 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,21 +4,27 @@ summary: Ensure that snap create-user works in ubuntu-core | |
# TODO:UC20: enable for UC20 | ||
systems: [ubuntu-core-1*] | ||
|
||
environment: | ||
USER_EMAIL: [email protected] | ||
USER_NAME: mvo | ||
|
||
restore: | | ||
# FIXME: use deluser here now that it supports --extrausers | ||
sed -i '/^mvo/d' /var/lib/extrausers/passwd | ||
sed -i '/^mvo/d' /var/lib/extrausers/shadow | ||
sed -i '/^mvo/d' /var/lib/extrausers/group | ||
rm -rf /home/mvo | ||
rm -f create.error | ||
if [ -e managed.device ]; then | ||
exit 0 | ||
fi | ||
snap remove-user "$USER_NAME" | ||
execute: | | ||
if [ "$MANAGED_DEVICE" = "true" ]; then | ||
if snap create-user --sudoer [email protected] 2>create.error; then | ||
if 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 | ||
# Leave a file indicating the device was initially managed | ||
touch managed.device | ||
exit 0 | ||
fi | ||
echo "Adding invalid user" | ||
|
@@ -30,23 +36,23 @@ execute: | | |
MATCH "$expected" <<<"$output" | ||
echo "Adding valid user" | ||
expected='created user "mvo"' | ||
output=$(snap create-user --sudoer [email protected]) | ||
expected="created user \"$USER_NAME\"" | ||
output=$(snap create-user --sudoer "$USER_EMAIL") | ||
if [ "$output" != "$expected" ]; then | ||
echo "Unexpected output $output" | ||
exit 1 | ||
fi | ||
echo "Ensure there are ssh keys imported" | ||
MATCH ssh-rsa < /home/mvo/.ssh/authorized_keys | ||
MATCH ssh-rsa < /home/"$USER_NAME"/.ssh/authorized_keys | ||
echo "Ensure the user is a sudo user" | ||
sudo -u mvo sudo true | ||
sudo -u "$USER_NAME" sudo true | ||
echo "ensure the user's home directory exists" | ||
test -d /home/mvo | ||
test -d /home/"$USER_NAME" | ||
echo "ensure ~/.snap/auth.json was created" | ||
test -f /home/mvo/.snap/auth.json | ||
test -f /home/"$USER_NAME"/.snap/auth.json | ||
echo "ensure user's email was stored in ~/.snap/auth.json" | ||
MATCH '"email":"[email protected]"' < /home/mvo/.snap/auth.json | ||
MATCH "\"email\":\"$USER_EMAIL\"" < /home/"$USER_NAME"/.snap/auth.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters