File: task.yaml

package info (click to toggle)
snapd 2.72-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 80,412 kB
  • sloc: sh: 16,506; ansic: 16,211; python: 11,213; makefile: 1,919; exp: 190; awk: 58; xml: 22
file content (109 lines) | stat: -rw-r--r-- 3,906 bytes parent folder | download | duplicates (3)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
summary: Check that auto-refresh works with private snaps.

details: |
    These tests rely on the existence of a snap in the remote store set to private.

    In order to do the full checks, it also needs the credentials of the owner of that
    snap set in the environment variables SPREAD_STORE_USER and SPREAD_STORE_PASSWORD, if
    they are not present then only the negative check is performed.

# we don't have expect available on ubuntu-core, so the authenticated check need to be skipped on those systems
systems: [-ubuntu-core-*]

restore: |
    snap logout || true

execute: |
    echo "Given account store credentials are available"
    if [ -z "$SPREAD_STORE_USER" ] || [  -z "$SPREAD_STORE_PASSWORD" ]; then
        exit 0
    fi

    echo "And the user has logged in"
    expect -f "$TESTSLIB"/successful_login.exp

    echo "Install a private snap together with a public snap"
    snap install test-snapd-private test-snapd-public

    echo "Switch both to edge"
    snap switch --edge test-snapd-private
    snap switch --edge test-snapd-public
    snap list|MATCH 'test-snapd-private +1\.0.*private'
    snap list|MATCH 'test-snapd-public +1\.0'

    echo "Force auto-refresh to happen"
    snap set core refresh.schedule="0:00-23:59"

    systemctl stop snapd.{service,socket}
    "$TESTSTOOLS"/snapd-state force-autorefresh
    systemctl start snapd.{service,socket}

    echo "Wait for auto-refresh to happen"
    for _ in $(seq 120); do
        if snap changes|grep -q "Done.*Auto-refresh.*test-snapd-public.*"; then
           break
        fi
        echo "Ensure refresh"
        snap debug ensure-state-soon
        sleep 5
    done

    echo "Check they were both refreshed"
    snap list|MATCH 'test-snapd-public +2\.0'
    snap list|MATCH 'test-snapd-private +2\.0.*private'

    if [ -z "$SPREAD_STORE_EXPIRED_MACAROON" ] || [  -z "$SPREAD_STORE_EXPIRED_DISCHARGE" ]; then
        if [[ "$SPREAD_STORE_USER" =~ .*dummydev.* ]] ; then
            # we should have hard-coded ones for this user
            #shellcheck source=tests/main/auto-refresh-private/expired_macaroons.sh
            . expired_macaroons.sh
        else
            exit 0
        fi
    fi

    #shellcheck source=tests/lib/changes.sh
    . "$TESTSLIB/changes.sh"
    AUTO_REFRESH_ID=$(change_id "Auto-refresh.*test-snapd-public.*" Done)

    echo "Try the same with expired creds"
    snap remove --purge test-snapd-private test-snapd-public
    snap install test-snapd-private test-snapd-public

    echo "Clear the snap cache"
    rm -f /var/lib/snapd/cache/*

    echo "Switch both to edge"
    snap switch --edge test-snapd-private
    snap switch --edge test-snapd-public
    snap list|MATCH 'test-snapd-private +1\.0.*private'
    snap list|MATCH 'test-snapd-public +1\.0'

    echo "Force auto-refresh to happen with expired creds"
    M="$SPREAD_STORE_EXPIRED_MACAROON"
    D="$SPREAD_STORE_EXPIRED_DISCHARGE"

    systemctl stop snapd.{service,socket}

    gojq ".data.auth.users[0][\"store-macaroon\"] = \"$M\"|.data.auth.users[0][\"store-discharges\"][0] = \"$D\"" \
        /var/lib/snapd/state.json > /var/lib/snapd/state.json.new
    mv /var/lib/snapd/state.json.new /var/lib/snapd/state.json
    "$TESTSTOOLS"/snapd-state force-autorefresh
    systemctl start snapd.{service,socket}

    echo "Wait for auto-refresh to happen"
    for _ in $(seq 120); do
        if snap changes|grep -vE "^$AUTO_REFRESH_ID +Done"|grep -q "Done.*Auto-refresh.*test-snapd-public.*"; then
           break
        fi
        echo "Ensure refresh"
        snap debug ensure-state-soon
        sleep 5
    done

    echo "Check exactly test-snapd-public was refreshed"
    snap list|MATCH 'test-snapd-public +2\.0'
    snap list|MATCH 'test-snapd-private +1\.0.*private'

    # sanity check there is no access
    snap find --private test-snapd-private 2>&1|MATCH 'No matching snaps for "test-snapd-private"'