File: task.yaml

package info (click to toggle)
snapd 2.71-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 79,536 kB
  • sloc: ansic: 16,114; sh: 16,105; python: 9,941; makefile: 1,890; exp: 190; awk: 40; xml: 22
file content (69 lines) | stat: -rw-r--r-- 2,180 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
summary: Ensure that snap create-user works in ubuntu-core
# FIXME: combine this test with tests/core/create-user-2?

details: |
    Check that the command `snap create-user` works in ubuntu core.
    Ensure that the keys are imported for the user and 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: |
    if [ "$(snap managed)" = "true" ]; then
        # Leave a file indicating the device was initially managed
        touch managed.device

        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

        exit 0
    fi

    echo "Adding invalid user"
    expected='error: while creating user: cannot create user "nosuchuser@example.com"'
    if output=$(snap create-user nosuchuser@example.com 2>&1); then
        echo "snap create-user should fail for unknown users but it did not"
        exit 1
    fi
    MATCH "$expected" <<<"$output"

    echo "Adding valid user"
    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/"$USER_NAME"/.ssh/authorized_keys

    echo "Ensure the user is a sudo user"
    sudo -u "$USER_NAME" sudo true

    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