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
|
summary: Check the confdb and views feature
details: |
Verify the basic features of experimental configuration feature based on
confdb and views.
# the test snaps have a core24 base
systems: [ -ubuntu-16.04 ]
prepare: |
snap set system experimental.confdb=true
snap set system experimental.parallel-instances=true
restore: |
snap unset system experimental.confdb
snap unset system experimental.parallel-instances
execute: |
if [ "$TRUST_TEST_KEYS" = "false" ]; then
echo "This test needs test keys to be trusted"
exit
fi
snap ack "$TESTSLIB/assertions/developer1-network.confdb"
"$TESTSTOOLS"/snaps-state install-local test-custodian-snap
snap connect test-custodian-snap:manage-wifi
# check basic read, write and unset
snap set developer1/network/wifi-setup ssid=canonical
snap get developer1/network/wifi-setup ssid | MATCH "canonical"
# hook was called
MATCH "canonical" < /var/snap/test-custodian-snap/common/observe-view-manage-wifi-ran
snap set developer1/network/wifi-setup ssid!
snap get developer1/network/wifi-setup ssid 2>&1 | tr -d '\n' | tr -s ' ' ' ' | MATCH $'cannot get "ssid" through developer1/network/wifi-setup: no data'
# check writing, reading and unsetting using placeholders
snap set -t developer1/network/wifi-setup private.my-company=\"my-config\" private.your-company=\"your-config\"
snap get developer1/network/wifi-setup private.my-company | MATCH "my-config"
snap get developer1/network/wifi-setup private.your-company | MATCH "your-config"
snap set developer1/network/wifi-setup private.my-company!
snap get developer1/network/wifi-setup private.my-company 2>&1 | tr -d '\n' | tr -s ' ' ' ' | MATCH $'cannot get "private.my-company" through developer1/network/wifi-setup: no data'
snap get developer1/network/wifi-setup private.your-company | MATCH "your-config"
snap set developer1/network/wifi-setup private.your-company!
# check setting lists with different types
snap set -t developer1/network/wifi-setup ssids='["one", 2]'
snap set developer1/network/wifi-setup ssids[0]=two
# read specific index
snap get developer1/network/wifi-setup ssids[0] | MATCH 'two'
# append to the list
snap set developer1/network/wifi-setup ssids[2]=true
snap get -d developer1/network/wifi-setup ssids | gojq -c .ssids | MATCH "\[\"two\",2,true\]"
# remove at the middle and at the end (both with unset and set!)
snap unset developer1/network/wifi-setup ssids[1]
snap get -d developer1/network/wifi-setup ssids | gojq -c .ssids | MATCH "\[\"two\",true\]"
snap set developer1/network/wifi-setup ssids[1]!
snap get -d developer1/network/wifi-setup ssids | gojq -c .ssids | MATCH "\[\"two\"\]"
# check access control
snap set developer1/network/wifi-setup status=foo 2>&1 | tr -d '\n' | tr -s ' ' ' ' | MATCH 'cannot set "status" through developer1/network/wifi-setup: no matching rule'
snap set developer1/network/wifi-setup password=foo
snap get developer1/network/wifi-setup password 2>&1 | tr -d '\n' | tr -s ' ' ' ' | MATCH 'cannot get "password" through developer1/network/wifi-setup: no matching rule'
# check that snaps can't access confdb through snapctl without a connected plug
snap disconnect test-custodian-snap:manage-wifi
# install another snap to serve as the custodian
"$TESTSTOOLS"/snaps-state install-local-as test-custodian-snap test-custodian-snap_other
snap connect test-custodian-snap_other:manage-wifi
# the new custodian can still access confdb
snap run --shell test-custodian-snap_other.sh -c 'snapctl set --view :manage-wifi ssid=foo'
snap run --shell test-custodian-snap_other.sh -c 'snapctl get --view :manage-wifi ssid' | MATCH "foo"
# but the disconnected snap cannot
snap run --shell test-custodian-snap.sh -c 'snapctl get --view :manage-wifi ssid' 2>&1 | MATCH "error: snapctl: cannot access confdb through unconnected plug :manage-wifi"
snap run --shell test-custodian-snap.sh -c 'snapctl set --view :manage-wifi ssid=foo' 2>&1 | MATCH "error: snapctl: cannot access confdb through unconnected plug :manage-wifi"
snap run --shell test-custodian-snap.sh -c 'snapctl unset --view :manage-wifi ssid' 2>&1 | MATCH "error: snapctl: cannot access confdb through unconnected plug :manage-wifi"
|