diff options
30 files changed, 209 insertions, 189 deletions
diff --git a/tests/main/refresh-all-undo/task.yaml b/tests/main/refresh-all-undo/task.yaml index 78a9385e57..497dcdb0ee 100644 --- a/tests/main/refresh-all-undo/task.yaml +++ b/tests/main/refresh-all-undo/task.yaml @@ -13,15 +13,16 @@ prepare: | exit fi - . $TESTSLIB/store.sh + #shellcheck source=tests/lib/store.sh + . "$TESTSLIB"/store.sh echo "Given two snaps are installed" for snap in $GOOD_SNAP $BAD_SNAP; do - snap install $snap + snap install "$snap" done echo "And the daemon is configured to point to the fake store" - setup_fake_store $BLOB_DIR + setup_fake_store "$BLOB_DIR" restore: | if [ "$TRUST_TEST_KEYS" = "false" ]; then @@ -29,9 +30,10 @@ restore: | exit fi - . $TESTSLIB/store.sh - teardown_fake_store $BLOB_DIR - rm -rf $BLOB_DIR + #shellcheck source=tests/lib/store.sh + . "$TESTSLIB"/store.sh + teardown_fake_store "$BLOB_DIR" + rm -rf "$BLOB_DIR" execute: | if [ "$TRUST_TEST_KEYS" = "false" ]; then @@ -43,15 +45,17 @@ execute: | snap refresh 2>&1 | MATCH "All snaps up to date" echo "When the store is configured to make them refreshable" - . $TESTSLIB/files.sh - . $TESTSLIB/store.sh + #shellcheck source=tests/lib/files.sh + . "$TESTSLIB"/files.sh + #shellcheck source=tests/lib/store.sh + . "$TESTSLIB"/store.sh init_fake_refreshes "$BLOB_DIR" "$GOOD_SNAP" - wait_for_file "$BLOB_DIR"/"${GOOD_SNAP}"*fake1*.snap 4 .5 + wait_for_file "$BLOB_DIR/${GOOD_SNAP}"*fake1*.snap 4 .5 init_fake_refreshes "$BLOB_DIR" "$BAD_SNAP" - wait_for_file "$BLOB_DIR"/"${BAD_SNAP}"*fake1*.snap 4 .5 + wait_for_file "$BLOB_DIR/${BAD_SNAP}"*fake1*.snap 4 .5 echo "When a snap is broken" - echo "i-am-broken-now" >> $BLOB_DIR/${BAD_SNAP}*fake1*.snap + echo "i-am-broken-now" >> "$BLOB_DIR/${BAD_SNAP}"*fake1*.snap echo "And a refresh is performed" if snap refresh ; then @@ -65,16 +69,17 @@ execute: | echo "But the bad snap did not get updated" snap list | MATCH -E "${BAD_SNAP}"| MATCH -v "fake" - . $TESTSLIB/changes.sh + #shellcheck source=tests/lib/changes.sh + . "$TESTSLIB"/changes.sh chg_id=$(change_id "Refresh snap" Error) echo "Verify the snap change" - snap change $chg_id | MATCH "Undone.*Download snap \"${BAD_SNAP}\"" - snap change $chg_id | MATCH "Done.*Download snap \"${GOOD_SNAP}\"" - snap change $chg_id | MATCH "ERROR cannot verify snap \"test-snapd-tools\", no matching signatures found" + snap change "$chg_id" | MATCH "Undone.*Download snap \"${BAD_SNAP}\"" + snap change "$chg_id" | MATCH "Done.*Download snap \"${GOOD_SNAP}\"" + snap change "$chg_id" | MATCH "ERROR cannot verify snap \"test-snapd-tools\", no matching signatures found" echo "Verify the 'snap tasks' is the same as 'snap change'" - snap tasks $chg_id | MATCH "Undone.*Download snap \"${BAD_SNAP}\"" + snap tasks "$chg_id" | MATCH "Undone.*Download snap \"${BAD_SNAP}\"" echo "Verify the 'snap tasks --last' shows last refresh change" snap tasks --last=refresh | MATCH "Undone.*Download snap \"${BAD_SNAP}\"" diff --git a/tests/main/refresh-all/task.yaml b/tests/main/refresh-all/task.yaml index 5b61c29be8..5084fad659 100644 --- a/tests/main/refresh-all/task.yaml +++ b/tests/main/refresh-all/task.yaml @@ -16,7 +16,8 @@ prepare: | exit fi - . $TESTSLIB/store.sh + #shellcheck source=tests/lib/store.sh + . "$TESTSLIB"/store.sh echo "Given two snaps are installed" for snap in test-snapd-tools test-snapd-python-webserver; do @@ -24,7 +25,7 @@ prepare: | done echo "And the daemon is configured to point to the fake store" - setup_fake_store $BLOB_DIR + setup_fake_store "$BLOB_DIR" restore: | if [ "$TRUST_TEST_KEYS" = "false" ]; then @@ -32,9 +33,10 @@ restore: | exit fi - . $TESTSLIB/store.sh - teardown_fake_store $BLOB_DIR - rm -rf $BLOB_DIR + #shellcheck source=tests/lib/store.sh + . "$TESTSLIB"/store.sh + teardown_fake_store "$BLOB_DIR" + rm -rf "$BLOB_DIR" execute: | if [ "$TRUST_TEST_KEYS" = "false" ]; then @@ -46,12 +48,14 @@ execute: | snap refresh 2>&1 | MATCH "All snaps up to date." echo "When the store is configured to make them refreshable" - . $TESTSLIB/files.sh - . $TESTSLIB/store.sh - init_fake_refreshes $BLOB_DIR test-snapd-tools - wait_for_file $BLOB_DIR/test-snapd-tools*fake1*.snap 4 .5 - init_fake_refreshes $BLOB_DIR test-snapd-python-webserver - wait_for_file $BLOB_DIR/test-snapd-python-webserver*fake1*.snap 4 .5 + #shellcheck source=tests/lib/files.sh + . "$TESTSLIB"/files.sh + #shellcheck source=tests/lib/store.sh + . "$TESTSLIB"/store.sh + init_fake_refreshes "$BLOB_DIR" test-snapd-tools + wait_for_file "$BLOB_DIR"/test-snapd-tools*fake1*.snap 4 .5 + init_fake_refreshes "$BLOB_DIR" test-snapd-python-webserver + wait_for_file "$BLOB_DIR"/test-snapd-python-webserver*fake1*.snap 4 .5 echo "And a refresh is performed" snap refresh diff --git a/tests/main/refresh-amend/task.yaml b/tests/main/refresh-amend/task.yaml index 0196761efd..cc7b9b8f6e 100644 --- a/tests/main/refresh-amend/task.yaml +++ b/tests/main/refresh-amend/task.yaml @@ -14,7 +14,7 @@ execute: | echo "snap refresh should error but did not" exit 1 fi - cat stderr.out | MATCH 'local snap "test-snapd-only-in-edge" is unknown to the store' + MATCH 'local snap "test-snapd-only-in-edge" is unknown to the store' < stderr.out echo "A refresh with --amend is not enough, the channel needs to be added" if snap refresh --amend test-snapd-only-in-edge 2> stderr.out; then diff --git a/tests/main/refresh-delta-from-core/task.yaml b/tests/main/refresh-delta-from-core/task.yaml index 28f7192bb5..569299c755 100644 --- a/tests/main/refresh-delta-from-core/task.yaml +++ b/tests/main/refresh-delta-from-core/task.yaml @@ -13,7 +13,7 @@ prepare: | fi echo "Given a snap is installed" - snap install --edge $SNAP_NAME + snap install --edge "$SNAP_NAME" restore: | if [ -e /usr/bin/xdelta3.disabled ]; then @@ -25,6 +25,6 @@ execute: | . "$TESTSLIB/journalctl.sh" echo "When the snap is refreshed" - snap refresh --beta $SNAP_NAME + snap refresh --beta "$SNAP_NAME" echo "Then deltas are successfully applied" get_journalctl_log -u snapd | MATCH "Successfully applied delta" diff --git a/tests/main/refresh-delta/task.yaml b/tests/main/refresh-delta/task.yaml index a48c9ab7b4..2d1b9bc838 100644 --- a/tests/main/refresh-delta/task.yaml +++ b/tests/main/refresh-delta/task.yaml @@ -16,14 +16,14 @@ prepare: | # r3 -> r5b # echo "Given a snap is installed" - snap install --edge $SNAP_NAME + snap install --edge "$SNAP_NAME" execute: | # shellcheck source=tests/lib/journalctl.sh . "$TESTSLIB/journalctl.sh" echo "When the snap is refreshed" - snap refresh --beta $SNAP_NAME + snap refresh --beta "$SNAP_NAME" echo "Then deltas are successfully applied" get_journalctl_log -u snapd | MATCH "Successfully applied delta" diff --git a/tests/main/refresh-devmode/task.yaml b/tests/main/refresh-devmode/task.yaml index 770eb7ff68..90d32a09a0 100644 --- a/tests/main/refresh-devmode/task.yaml +++ b/tests/main/refresh-devmode/task.yaml @@ -34,12 +34,14 @@ prepare: | snap install --devmode test-snapd-tools if [ "$STORE_TYPE" = "fake" ]; then - . $TESTSLIB/store.sh - setup_fake_store $BLOB_DIR + #shellcheck source=tests/lib/store.sh + . "$TESTSLIB"/store.sh + setup_fake_store "$BLOB_DIR" echo "And a new version of that snap put in the controlled store" - . $TESTSLIB/store.sh - init_fake_refreshes $BLOB_DIR test-snapd-tools + #shellcheck source=tests/lib/store.sh + . "$TESTSLIB"/store.sh + init_fake_refreshes "$BLOB_DIR" test-snapd-tools fi restore: | @@ -54,8 +56,9 @@ restore: | echo "This test needs test keys to be trusted" exit fi - . $TESTSLIB/store.sh - teardown_fake_store $BLOB_DIR + #shellcheck source=tests/lib/store.sh + . "$TESTSLIB"/store.sh + teardown_fake_store "$BLOB_DIR" fi execute: | @@ -80,7 +83,7 @@ execute: | # echo "=================================" echo "When the snap is refreshed" - snap refresh --devmode --channel=edge $SNAP_NAME + snap refresh --devmode --channel=edge "$SNAP_NAME" echo "Then the new version is listed" expected="$SNAP_NAME +$SNAP_VERSION_PATTERN .*devmode" diff --git a/tests/main/refresh-undo/task.yaml b/tests/main/refresh-undo/task.yaml index af8f156f14..79741dbe3c 100644 --- a/tests/main/refresh-undo/task.yaml +++ b/tests/main/refresh-undo/task.yaml @@ -15,8 +15,8 @@ environment: prepare: | echo "Given a good (v1) and a bad (v2) snap" - snap pack $TESTSLIB/snaps/$SNAP_NAME_GOOD - snap pack $TESTSLIB/snaps/$SNAP_NAME_BAD + snap pack "$TESTSLIB/snaps/$SNAP_NAME_GOOD" + snap pack "$TESTSLIB/snaps/$SNAP_NAME_BAD" debug: | # shellcheck source=tests/lib/journalctl.sh @@ -37,12 +37,12 @@ execute: | done } echo "When we install v1" - snap install --dangerous ${SNAP_FILE_GOOD} + snap install --dangerous "${SNAP_FILE_GOOD}" echo "The v1 service started correctly" wait_for_service_status "service v1" echo "When we refresh to v2" - if snap install --dangerous ${SNAP_FILE_BAD}; then + if snap install --dangerous "${SNAP_FILE_BAD}"; then echo "The ${SNAP_FILE_BAD} snap should not install cleanly, test broken" exit 1 fi diff --git a/tests/main/refresh/task.yaml b/tests/main/refresh/task.yaml index 8bc6bd3991..38151c241f 100644 --- a/tests/main/refresh/task.yaml +++ b/tests/main/refresh/task.yaml @@ -31,7 +31,7 @@ prepare: | fi flags= - if [[ $SNAP_NAME =~ classic ]]; then + if [[ "$SNAP_NAME" =~ classic ]]; then case "$SPREAD_SYSTEM" in ubuntu-core-*|fedora-*|arch-*) exit @@ -41,15 +41,17 @@ prepare: | fi echo "Given a snap is installed" - snap install $flags $SNAP_NAME + snap install "$flags" "$SNAP_NAME" if [ "$STORE_TYPE" = "fake" ]; then - . $TESTSLIB/store.sh - setup_fake_store $BLOB_DIR + #shellcheck source=tests/lib/store.sh + . "$TESTSLIB"/store.sh + setup_fake_store "$BLOB_DIR" echo "And a new version of that snap put in the controlled store" - . $TESTSLIB/store.sh - init_fake_refreshes $BLOB_DIR $SNAP_NAME + #shellcheck source=tests/lib/store.sh + . "$TESTSLIB"/store.sh + init_fake_refreshes "$BLOB_DIR" "$SNAP_NAME" fi restore: | @@ -65,8 +67,9 @@ restore: | echo "This test needs test keys to be trusted" exit fi - . $TESTSLIB/store.sh - teardown_fake_store $BLOB_DIR + #shellcheck source=tests/lib/store.sh + . "$TESTSLIB"/store.sh + teardown_fake_store "$BLOB_DIR" fi execute: | @@ -83,7 +86,7 @@ execute: | fi fi - if [[ $SNAP_NAME =~ classic ]]; then + if [[ "$SNAP_NAME" =~ classic ]]; then case "$SPREAD_SYSTEM" in ubuntu-core-*|fedora-*|arch-*) exit @@ -99,33 +102,34 @@ execute: | # echo "=================================" echo "When the snap is refreshed" - snap refresh --channel=edge $SNAP_NAME + snap refresh --channel=edge "$SNAP_NAME" echo "Then the new version is listed" expected="$SNAP_NAME +$SNAP_VERSION_PATTERN" snap list | grep -Pzq "$expected" echo "When a snap is refreshed and has no update it exit 0" - snap refresh $SNAP_NAME 2>stderr.out - cat stderr.out | MATCH "snap \"$SNAP_NAME\" has no updates available" + snap refresh "$SNAP_NAME" 2>stderr.out + MATCH "snap \"$SNAP_NAME\" has no updates available" < stderr.out echo "classic snaps " echo "When multiple snaps have no update we have a good message" - . $TESTSLIB/snaps.sh + #shellcheck source=tests/lib/snaps.sh + . "$TESTSLIB"/snaps.sh install_local basic - snap refresh $SNAP_NAME basic 2>&1 | MATCH "All snaps up to date." + snap refresh "$SNAP_NAME" basic 2>&1 | MATCH "All snaps up to date." echo "When moving to stable" - snap refresh --stable $SNAP_NAME - snap info $SNAP_NAME | MATCH "tracking: +stable" + snap refresh --stable "$SNAP_NAME" + snap info "$SNAP_NAME" | MATCH "tracking: +stable" - snap refresh --candidate $SNAP_NAME 2>&1 | MATCH "$SNAP_NAME \(candidate\).*" - snap info $SNAP_NAME | MATCH "tracking: +candidate" + snap refresh --candidate "$SNAP_NAME" 2>&1 | MATCH "$SNAP_NAME \\(candidate\\).*" + snap info "$SNAP_NAME" | MATCH "tracking: +candidate" echo "When multiple snaps are refreshed we error if we have unknown names" if snap refresh core invälid-snap-name 2> out.err; then echo "snap refresh invalid-snap-name should fail but it did not?" exit 1 fi - cat out.err | tr '\n' ' ' | tr -s ' ' | MATCH 'cannot refresh .* is not installed' + < out.err tr '\n' ' ' | tr -s ' ' | MATCH 'cannot refresh .* is not installed' diff --git a/tests/main/regression-home-snap-root-owned/task.yaml b/tests/main/regression-home-snap-root-owned/task.yaml index 9da584d15a..d99e0e860e 100644 --- a/tests/main/regression-home-snap-root-owned/task.yaml +++ b/tests/main/regression-home-snap-root-owned/task.yaml @@ -4,22 +4,24 @@ prepare: | # ensure we have no snap user data directory yet rm -rf /home/test/snap rm -rf /root/snap - . $TESTSLIB/snaps.sh + #shellcheck source=tests/lib/snaps.sh + . "$TESTSLIB"/snaps.sh install_local test-snapd-tools execute: | - . $TESTSLIB/dirs.sh + #shellcheck source=tests/lib/dirs.sh + . "$TESTSLIB"/dirs.sh # run a snap command via sudo output=$(su -l -c "sudo $SNAP_MOUNT_DIR/bin/test-snapd-tools.env" test) # ensure SNAP_USER_DATA points to the right place - echo $output | MATCH SNAP_USER_DATA=/root/snap/test-snapd-tools/x[0-9]+ - echo $output | MATCH HOME=/root/snap/test-snapd-tools/x[0-9]+ - echo $output | MATCH SNAP_USER_COMMON=/root/snap/test-snapd-tools/common + echo "$output" | MATCH SNAP_USER_DATA=/root/snap/test-snapd-tools/x[0-9]+ + echo "$output" | MATCH HOME=/root/snap/test-snapd-tools/x[0-9]+ + echo "$output" | MATCH SNAP_USER_COMMON=/root/snap/test-snapd-tools/common echo "Verify that the /root/snap directory created and root owned" - if [ $(stat -c '%U' /root/snap) != "root" ]; then + if [ "$(stat -c '%U' /root/snap)" != "root" ]; then echo "The /root/snap directory is not owned by root" ls -ld $SNAP_MOUNT_DIR/snap exit 1 @@ -27,7 +29,7 @@ execute: | echo "Verify that there is no /home/test/snap appearing" if [ -e /home/test/snap ]; then - user=$(stat -c '%U' /home/test/snap) + user="$(stat -c '%U' /home/test/snap)" echo "An unexpected /home/test/snap directory got created (owner $user)" ls -ld /home/test/snap exit 1 diff --git a/tests/main/remove-errors/task.yaml b/tests/main/remove-errors/task.yaml index a473f750b6..421fb9e6d8 100644 --- a/tests/main/remove-errors/task.yaml +++ b/tests/main/remove-errors/task.yaml @@ -5,13 +5,15 @@ systems: [-ubuntu-core-18-*] execute: | echo "Given a core snap is installed" + #shellcheck source=tests/lib/snaps.sh . "$TESTSLIB/snaps.sh" install_local test-snapd-tools + #shellcheck source=tests/lib/names.sh . "$TESTSLIB/names.sh" echo "Ensure the important snaps can not be removed" for sn in core $kernel_name $gadget_name; do - if snap remove $sn; then + if snap remove "$sn"; then echo "It should not be possible to remove $sn" exit 1 fi diff --git a/tests/main/revert-devmode/task.yaml b/tests/main/revert-devmode/task.yaml index 3977d685b4..9725cd6454 100644 --- a/tests/main/revert-devmode/task.yaml +++ b/tests/main/revert-devmode/task.yaml @@ -23,12 +23,14 @@ prepare: | snap install --devmode test-snapd-tools if [ "$STORE_TYPE" = "fake" ]; then - . $TESTSLIB/store.sh - setup_fake_store $BLOB_DIR + #shellcheck source=tests/lib/store.sh + . "$TESTSLIB"/store.sh + setup_fake_store "$BLOB_DIR" echo "And a new version of that snap put in the controlled store" - . $TESTSLIB/store.sh - init_fake_refreshes $BLOB_DIR test-snapd-tools + #shellcheck source=tests/lib/store.sh + . "$TESTSLIB"/store.sh + init_fake_refreshes "$BLOB_DIR" test-snapd-tools fi restore: | @@ -43,8 +45,9 @@ restore: | echo "This test needs test keys to be trusted" exit fi - . $TESTSLIB/store.sh - teardown_fake_store $BLOB_DIR + #shellcheck source=tests/lib/store.sh + . "$TESTSLIB"/store.sh + teardown_fake_store "$BLOB_DIR" fi execute: | @@ -61,7 +64,8 @@ execute: | fi fi - . $TESTSLIB/dirs.sh + #shellcheck source=tests/lib/dirs.sh + . "$TESTSLIB"/dirs.sh echo "When a refresh is made" snap refresh --devmode --edge test-snapd-tools @@ -80,7 +84,7 @@ execute: | snap list|MATCH 'test-snapd-tools .* devmode' echo "When the latest revision is installed again" - snap remove --revision=$LATEST test-snapd-tools + snap remove --revision="$LATEST" test-snapd-tools snap refresh --edge test-snapd-tools if [ "$(snap debug confinement)" = strict ] ; then diff --git a/tests/main/revert-sideload/task.yaml b/tests/main/revert-sideload/task.yaml index 24a7259965..ef085c86ae 100644 --- a/tests/main/revert-sideload/task.yaml +++ b/tests/main/revert-sideload/task.yaml @@ -1,7 +1,7 @@ summary: Checks for snap sideload reverts prepare: | - snap pack $TESTSLIB/snaps/basic + snap pack "$TESTSLIB"/snaps/basic restore: | rm -f ./basic_1.0_all.snap diff --git a/tests/main/revert/task.yaml b/tests/main/revert/task.yaml index b290595832..d5e28eaa86 100644 --- a/tests/main/revert/task.yaml +++ b/tests/main/revert/task.yaml @@ -23,12 +23,14 @@ prepare: | snap install test-snapd-tools if [ "$STORE_TYPE" = "fake" ]; then - . $TESTSLIB/store.sh - setup_fake_store $BLOB_DIR + #shellcheck source=tests/lib/store.sh + . "$TESTSLIB"/store.sh + setup_fake_store "$BLOB_DIR" echo "And a new version of that snap put in the controlled store" - . $TESTSLIB/store.sh - init_fake_refreshes $BLOB_DIR test-snapd-tools + #shellcheck source=tests/lib/store.sh + . "$TESTSLIB"/store.sh + init_fake_refreshes "$BLOB_DIR" test-snapd-tools fi restore: | @@ -43,8 +45,9 @@ restore: | echo "This test needs test keys to be trusted" exit fi - . $TESTSLIB/store.sh - teardown_fake_store $BLOB_DIR + #shellcheck source=tests/lib/store.sh + . "$TESTSLIB"/store.sh + teardown_fake_store "$BLOB_DIR" fi execute: | @@ -67,13 +70,14 @@ execute: | exit 1 fi - . $TESTSLIB/dirs.sh + #shellcheck source=tests/lib/dirs.sh + . "$TESTSLIB"/dirs.sh echo "When a refresh is made" snap refresh --edge test-snapd-tools echo "Then the new version is installed" - snap list | MATCH "test-snapd-tools +[0-9]+\.[0-9]+\+fake1" + snap list | MATCH -- 'test-snapd-tools +[0-9]+\.[0-9]+\+fake1' echo "And the snap runs" test-snapd-tools.echo hello|MATCH hello @@ -82,11 +86,11 @@ execute: | snap revert test-snapd-tools echo "Then the old version is active" - snap list | MATCH "test-snapd-tools +[0-9]+\.[0-9]+ " + snap list | MATCH -- 'test-snapd-tools +[0-9]+\.[0-9]+ ' echo "And the data directories are present" - ls $SNAP_MOUNT_DIR/test-snapd-tools | MATCH current - ls /var/snap/test-snapd-tools | MATCH current + find $SNAP_MOUNT_DIR/test-snapd-tools -maxdepth 1 | MATCH current + find /var/snap/test-snapd-tools -maxdepth 1 | MATCH current echo "And the snap runs confined" snap list|MATCH 'test-snapd-tools.* -$' @@ -102,8 +106,8 @@ execute: | echo "And a refresh doesn't update the snap" snap refresh - snap list | MATCH "test-snapd-tools +[0-9]+\.[0-9]+ " + snap list | MATCH -- 'test-snapd-tools +[0-9]+\.[0-9]+ ' echo "Unless the snap is asked for explicitly" snap refresh --edge test-snapd-tools - snap list | MATCH "test-snapd-tools +[0-9]+\.[0-9]+\+fake1" + snap list | MATCH -- 'test-snapd-tools +[0-9]+\.[0-9]+\+fake1' diff --git a/tests/main/searching/task.yaml b/tests/main/searching/task.yaml index 713962c378..88ae552f79 100644 --- a/tests/main/searching/task.yaml +++ b/tests/main/searching/task.yaml @@ -12,9 +12,9 @@ restore: | execute: | echo "List all featured snaps" - expected="(?s).*Name +Version +Publisher +Notes +Summary *\n\ - (.*?\n)?\ - .*" + expected='(?s).*Name +Version +Publisher +Notes +Summary *\n + (.*?\n)? + .*' snap find > featured.txt if ! grep -Pzq "$expected" < featured.txt; then echo "expected out put $expected not found in:" @@ -24,12 +24,12 @@ execute: | MATCH "No search term specified. Here are some interesting snaps" < featured.txt MATCH "Provide a search term for more specific results." < featured.txt - if [ $(snap find | wc -l) -gt 50 ]; then + if [ "$(snap find | wc -l)" -gt 50 ]; then echo "Found more than 50 featured apps, this seems bogus:" snap find exit 1 fi - if [ $(snap find | wc -l) -lt 2 ]; then + if [ "$(snap find | wc -l)" -lt 2 ]; then echo "Not found any featured app, this seems bogus:" snap find exit 1 @@ -38,28 +38,28 @@ execute: | echo "Exact matches" for snapName in test-snapd-tools test-snapd-python-webserver do - expected="(?s)Name +Version +Publisher +Notes +Summary *\n\ - (.*?\n)?\ - $snapName +.*? *\n\ + expected="(?s)Name +Version +Publisher +Notes +Summary *\\n\ + (.*?\\n)?\ + $snapName +.*? *\\n\ .*" snap find $snapName | grep -Pzq "$expected" done echo "Partial terms work too" - expected="(?s)Name +Version +Publisher +Notes +Summary *\n\ - (.*?\n)?\ - test-snapd-tools +.*? *\n\ - .*" + expected='(?s)Name +Version +Publisher +Notes +Summary *\n + (.*?\n)? + test-snapd-tools +.*? *\n + .*' snap find test-snapd- | grep -Pzq "$expected" echo "List of snaps in a section works" # NOTE: this shows featured snaps which change all the time, do not # make any assumptions about the contents - test $(snap find --section=featured | wc -l) -gt 1 + test "$(snap find --section=featured | wc -l)" -gt 1 # TODO: discuss with the store how we can make this test stable, i.e. # that section/snap changes do not break us - if [ $(uname -m) = "x86_64" ]; then + if [ "$(uname -m)" = "x86_64" ]; then snap find --section=video vlc | MATCH vlc else snap find --section=video vlc 2>&1 | MATCH 'No matching snaps' @@ -69,4 +69,4 @@ execute: | if snap find " " | grep "status code 403"; then echo 'snap find " " returns non user friendly error with whitespace query' exit 1 - fi \ No newline at end of file + fi diff --git a/tests/main/security-apparmor/task.yaml b/tests/main/security-apparmor/task.yaml index b2082aa138..fdee9fdee5 100644 --- a/tests/main/security-apparmor/task.yaml +++ b/tests/main/security-apparmor/task.yaml @@ -2,7 +2,8 @@ summary: Check basic apparmor confinement rules. prepare: | echo "Given a basic snap is installed" - . $TESTSLIB/snaps.sh + #shellcheck source=tests/lib/snaps.sh + . "$TESTSLIB"/snaps.sh install_local test-snapd-tools execute: | if [ "$(snap debug confinement)" = partial ] ; then diff --git a/tests/main/security-device-cgroups-classic/task.yaml b/tests/main/security-device-cgroups-classic/task.yaml index 7191cfc2eb..872fafc781 100644 --- a/tests/main/security-device-cgroups-classic/task.yaml +++ b/tests/main/security-device-cgroups-classic/task.yaml @@ -18,7 +18,8 @@ prepare: | fi echo "Given a snap declaring a plug on framebuffer is installed in classic" - . $TESTSLIB/snaps.sh + #shellcheck source=tests/lib/snaps.sh + . "$TESTSLIB"/snaps.sh install_local_classic test-classic-cgroup restore: | @@ -27,11 +28,12 @@ restore: | fi execute: | - . $TESTSLIB/dirs.sh + #shellcheck source=tests/lib/dirs.sh + . "$TESTSLIB"/dirs.sh # classic snaps don't use 'plugs', so just test the accesses after install echo "the classic snap can access the framebuffer" "$SNAP_MOUNT_DIR"/bin/test-classic-cgroup.read-fb 2>&1 | MATCH -v '(Permission denied|Operation not permitted)' echo "the classic snap can access other devices" - test "`$SNAP_MOUNT_DIR/bin/test-classic-cgroup.read-kmsg`" + test "$($SNAP_MOUNT_DIR/bin/test-classic-cgroup.read-kmsg)" diff --git a/tests/main/security-device-cgroups-devmode/task.yaml b/tests/main/security-device-cgroups-devmode/task.yaml index 0259c4ee37..c4bdb1833f 100644 --- a/tests/main/security-device-cgroups-devmode/task.yaml +++ b/tests/main/security-device-cgroups-devmode/task.yaml @@ -14,7 +14,8 @@ prepare: | fi echo "Given a snap declaring a plug on framebuffer is installed in devmode" - . $TESTSLIB/snaps.sh + #shellcheck source=tests/lib/snaps.sh + . "$TESTSLIB"/snaps.sh install_local_devmode test-devmode-cgroup restore: | @@ -23,7 +24,8 @@ restore: | fi execute: | - . $TESTSLIB/dirs.sh + #shellcheck source=tests/lib/dirs.sh + . "$TESTSLIB"/dirs.sh echo "And the framebuffer plug is connected" snap connect test-devmode-cgroup:framebuffer @@ -31,7 +33,7 @@ execute: | "$SNAP_MOUNT_DIR"/bin/test-devmode-cgroup.read-fb 2>&1 | MATCH -v '(Permission denied|Operation not permitted)' echo "the devmode snap can access other devices" - test "`$SNAP_MOUNT_DIR/bin/test-devmode-cgroup.read-kmsg`" + test "$($SNAP_MOUNT_DIR/bin/test-devmode-cgroup.read-kmsg)" echo "And the framebuffer plug is disconnected" snap disconnect test-devmode-cgroup:framebuffer @@ -39,4 +41,4 @@ execute: | "$SNAP_MOUNT_DIR"/bin/test-devmode-cgroup.read-fb 2>&1 | MATCH -v '(Permission denied|Operation not permitted)' echo "the devmode snap can access other devices" - test "`$SNAP_MOUNT_DIR/bin/test-devmode-cgroup.read-kmsg`" + test "$($SNAP_MOUNT_DIR/bin/test-devmode-cgroup.read-kmsg)" diff --git a/tests/main/security-device-cgroups-jailmode/task.yaml b/tests/main/security-device-cgroups-jailmode/task.yaml index e2ed362a7c..9604f46715 100644 --- a/tests/main/security-device-cgroups-jailmode/task.yaml +++ b/tests/main/security-device-cgroups-jailmode/task.yaml @@ -17,7 +17,8 @@ prepare: | fi echo "Given a snap declaring a plug on framebuffer is installed in jailmode" - . $TESTSLIB/snaps.sh + #shellcheck source=tests/lib/snaps.sh + . "$TESTSLIB"/snaps.sh install_local_jailmode test-devmode-cgroup restore: | @@ -26,7 +27,8 @@ restore: | fi execute: | - . $TESTSLIB/dirs.sh + #shellcheck source=tests/lib/dirs.sh + . "$TESTSLIB"/dirs.sh echo "And the framebuffer plug is connected" snap connect test-devmode-cgroup:framebuffer diff --git a/tests/main/security-device-cgroups-serial-port/task.yaml b/tests/main/security-device-cgroups-serial-port/task.yaml index fca36bc891..e3c5a5acb0 100644 --- a/tests/main/security-device-cgroups-serial-port/task.yaml +++ b/tests/main/security-device-cgroups-serial-port/task.yaml @@ -22,7 +22,8 @@ restore: | execute: | echo "Given a snap is installed" - . $TESTSLIB/snaps.sh + #shellcheck source=tests/lib/snaps.sh + . "$TESTSLIB"/snaps.sh install_local test-snapd-tools echo "Then the device is not assigned to that snap" diff --git a/tests/main/security-device-cgroups-strict/task.yaml b/tests/main/security-device-cgroups-strict/task.yaml index c3937cd9d7..912413ec0c 100644 --- a/tests/main/security-device-cgroups-strict/task.yaml +++ b/tests/main/security-device-cgroups-strict/task.yaml @@ -16,7 +16,8 @@ prepare: | fi echo "Given a snap declaring a plug on framebuffer is installed in strict" - . $TESTSLIB/snaps.sh + #shellcheck source=tests/lib/snaps.sh + . "$TESTSLIB"/snaps.sh install_local test-strict-cgroup restore: | @@ -25,7 +26,8 @@ restore: | fi execute: | - . $TESTSLIB/dirs.sh + #shellcheck source=tests/lib/dirs.sh + . "$TESTSLIB"/dirs.sh echo "And the framebuffer plug is connected" snap connect test-strict-cgroup:framebuffer diff --git a/tests/main/security-device-cgroups/task.yaml b/tests/main/security-device-cgroups/task.yaml index f4d4936a93..914a6ce68e 100644 --- a/tests/main/security-device-cgroups/task.yaml +++ b/tests/main/security-device-cgroups/task.yaml @@ -77,11 +77,12 @@ execute: | fi echo "Given a snap is installed" - . $TESTSLIB/snaps.sh + #shellcheck source=tests/lib/snaps.sh + . "$TESTSLIB"/snaps.sh install_local test-snapd-tools echo "Then the device is not assigned to that snap" - ! udevadm info $UDEVADM_PATH | MATCH "E: TAGS=.*snap_test-snapd-tools_env" + ! udevadm info "$UDEVADM_PATH" | MATCH "E: TAGS=.*snap_test-snapd-tools_env" echo "And the device is not shown in the snap device list" # FIXME: this is, apparently, a layered can of worms. Zyga says he needs to fix it. @@ -100,10 +101,10 @@ execute: | udevadm settle echo "Then the device is shown as assigned to the snap" - udevadm info $UDEVADM_PATH | MATCH "E: TAGS=.*snap_test-snapd-tools_env" + udevadm info "$UDEVADM_PATH" | MATCH "E: TAGS=.*snap_test-snapd-tools_env" echo "And other devices are not shown as assigned to the snap" - udevadm info $OTHER_UDEVADM_PATH | MATCH -v "E: TAGS=.*snap_test-snapd-tools_env" + udevadm info "$OTHER_UDEVADM_PATH" | MATCH -v "E: TAGS=.*snap_test-snapd-tools_env" echo "=================================================" diff --git a/tests/main/security-devpts/task.yaml b/tests/main/security-devpts/task.yaml index 6d633b07b7..95083dea41 100644 --- a/tests/main/security-devpts/task.yaml +++ b/tests/main/security-devpts/task.yaml @@ -6,7 +6,8 @@ execute: | fi echo "Given a basic snap is installed" - . $TESTSLIB/snaps.sh + #shellcheck source=tests/lib/snaps.sh + . "$TESTSLIB"/snaps.sh install_local test-snapd-devpts echo "When no plugs are not connected" diff --git a/tests/main/security-private-tmp/task.yaml b/tests/main/security-private-tmp/task.yaml index 7b20a18cc8..d705327002 100644 --- a/tests/main/security-private-tmp/task.yaml +++ b/tests/main/security-private-tmp/task.yaml @@ -8,21 +8,23 @@ environment: prepare: | echo "Given a basic snap is installed" - . $TESTSLIB/snaps.sh + #shellcheck source=tests/lib/snaps.sh + . "$TESTSLIB"/snaps.sh install_local test-snapd-tools echo "And another basic snap is installed" - mkdir -p $SNAP_INSTALL_DIR - cp -ra $TESTSLIB/snaps/test-snapd-tools/* $SNAP_INSTALL_DIR - sed -i 's/test-snapd-tools/not-test-snapd-tools/g' $SNAP_INSTALL_DIR/meta/snap.yaml - snap pack $SNAP_INSTALL_DIR + mkdir -p "$SNAP_INSTALL_DIR" + cp -ra "$TESTSLIB"/snaps/test-snapd-tools/* "$SNAP_INSTALL_DIR" + sed -i 's/test-snapd-tools/not-test-snapd-tools/g' "$SNAP_INSTALL_DIR/meta/snap.yaml" + snap pack "$SNAP_INSTALL_DIR" snap install --dangerous not-test-snapd-tools_1.0_all.snap restore: | - rm -rf not-test-snapd-tools_1.0_all.snap "$SNAP_INSTALL_DIR" /tmp/foo *stat.error + rm -rf not-test-snapd-tools_1.0_all.snap "$SNAP_INSTALL_DIR" /tmp/foo ./*stat.error execute: | - . $TESTSLIB/dirs.sh + #shellcheck source=tests/lib/dirs.sh + . "$TESTSLIB"/dirs.sh echo "When a temporary file is created by one snap" expect -d -f tmp-create.exp diff --git a/tests/main/security-profiles/task.yaml b/tests/main/security-profiles/task.yaml index 654b06c236..5b9380db6e 100644 --- a/tests/main/security-profiles/task.yaml +++ b/tests/main/security-profiles/task.yaml @@ -1,7 +1,7 @@ summary: Check security profile generation for apps and hooks. prepare: | - snap pack $TESTSLIB/snaps/basic-hooks + snap pack "$TESTSLIB"/snaps/basic-hooks restore: | rm -f basic-hooks_1.0_all.snap @@ -13,13 +13,14 @@ execute: | seccomp_profile_directory="/var/lib/snapd/seccomp/bpf" echo "Security profiles are generated and loaded for apps" - . $TESTSLIB/snaps.sh + #shellcheck source=tests/lib/snaps.sh + . "$TESTSLIB"/snaps.sh install_local test-snapd-tools loaded_profiles=$(cat /sys/kernel/security/apparmor/profiles) for profile in snap.test-snapd-tools.block snap.test-snapd-tools.cat snap.test-snapd-tools.echo snap.test-snapd-tools.fail snap.test-snapd-tools.success do - MATCH "^${profile} \(enforce\)$" <<<"$loaded_profiles" + MATCH "^${profile} \\(enforce\\)$" <<<"$loaded_profiles" [ -f "$seccomp_profile_directory/${profile}.bin" ] done @@ -27,5 +28,5 @@ execute: | snap install --dangerous basic-hooks_1.0_all.snap loaded_profiles=$(cat /sys/kernel/security/apparmor/profiles) - echo "$loaded_profiles" | MATCH "^snap.basic-hooks.hook.configure \(enforce\)$" + echo "$loaded_profiles" | MATCH '^snap.basic-hooks.hook.configure \(enforce\)$' [ -f "$seccomp_profile_directory/snap.basic-hooks.hook.configure.bin" ] diff --git a/tests/main/security-setuid-root/task.yaml b/tests/main/security-setuid-root/task.yaml index 486106cb17..1c963acb02 100644 --- a/tests/main/security-setuid-root/task.yaml +++ b/tests/main/security-setuid-root/task.yaml @@ -14,7 +14,8 @@ details: | the usual location (/usr/lib/snapd/snap-confine). As a security precaution it should detect and refuse to run if invoked from the core snap. prepare: | - . $TESTSLIB/snaps.sh + #shellcheck source=tests/lib/snaps.sh + . "$TESTSLIB"/snaps.sh install_local test-snapd-tools echo "Ensure the snap-confine profiles on core are not loaded" for p in /var/lib/snapd/apparmor/profiles/snap-confine.*; do @@ -23,10 +24,11 @@ prepare: | restore: | echo "Ensure the snap-confine profiles are restored" for p in /var/lib/snapd/apparmor/profiles/snap-confine.*; do - apparmor_parser -r $p + apparmor_parser -r "$p" done execute: | - . $TESTSLIB/dirs.sh + #shellcheck source=tests/lib/dirs.sh + . "$TESTSLIB"/dirs.sh # NOTE: This has to run as the test user because the protection is only # active if user gains elevated permissions as a result of using setuid @@ -37,7 +39,7 @@ execute: | fi su test -c "sh -c \"SNAP_NAME=test-snapd-tools $SNAP_MOUNT_DIR/core/current/usr/lib/snapd/snap-confine snap.test-snapd-tools.cmd /bin/true 2>&1\"" | MATCH "Refusing to continue to avoid permission escalation attacks" debug: | - ls -ld $SNAP_MOUNT_DIR/core/current/usr/lib/snapd/snap-confine || true - ls -ld $SNAP_MOUNT_DIR/ubuntu-core/current/usr/lib/snapd/snap-confine || true + ls -ld "$SNAP_MOUNT_DIR/core/current/usr/lib/snapd/snap-confine" || true + ls -ld "$SNAP_MOUNT_DIR/ubuntu-core/current/usr/lib/snapd/snap-confine" || true ls -ld /usr/lib/snapd/snap-confine || true snap list diff --git a/tests/main/security-udev-input-subsystem/task.yaml b/tests/main/security-udev-input-subsystem/task.yaml index 00e653e1d9..0a84536fdf 100644 --- a/tests/main/security-udev-input-subsystem/task.yaml +++ b/tests/main/security-udev-input-subsystem/task.yaml @@ -50,7 +50,7 @@ execute: | echo "When the mir plug is disconnected" snap disconnect test-snapd-udev-input-subsystem:mir-plug test-snapd-udev-input-subsystem:mir-slot - snap interfaces -i mir | MATCH "\- +test-snapd-udev-input-subsystem:mir-plug" + snap interfaces -i mir | MATCH '- +test-snapd-udev-input-subsystem:mir-plug' echo "The snap's plug still cannot access an evdev keyboard" if test-snapd-udev-input-subsystem.plug 2>"${PWD}"/call.error; then @@ -61,7 +61,7 @@ execute: | MATCH "Permission denied" < call.error echo "When the time-control plug is disconnected" - snap interfaces -i time-control | MATCH ":time-control +\-" + snap interfaces -i time-control | MATCH ':time-control +-' echo "The snap's time-control plug cannot access an evdev keyboard when disconnected" if test-snapd-udev-input-subsystem.plug-with-time-control 2>"${PWD}"/call.error; then diff --git a/tests/main/server-snap/task.yaml b/tests/main/server-snap/task.yaml index 2078982797..c85e58ac1c 100644 --- a/tests/main/server-snap/task.yaml +++ b/tests/main/server-snap/task.yaml @@ -18,14 +18,14 @@ environment: warn-timeout: 3m prepare: | - snap install $SNAP_NAME + snap install "$SNAP_NAME" cat > request.txt <<EOF GET / HTTP/1.0 EOF echo "Wait for the service to be listening, limited to the task kill-timeout" # shellcheck source=tests/lib/network.sh - . $TESTSLIB/network.sh + . "$TESTSLIB"/network.sh wait_listen_port "$PORT" restore: | @@ -34,6 +34,6 @@ restore: | execute: | response=$(nc -w 5 -"$IP_VERSION" "$LOCALHOST" "$PORT" < request.txt) - statusPattern="(?s)HTTP\/1\.0 200 OK\n*" + statusPattern='(?s)HTTP\/1\.0 200 OK\n*' echo "$response" | grep -Pzq "$statusPattern" echo "$response" | grep -Pzq "$TEXT" diff --git a/tests/main/set-proxy-store/task.yaml b/tests/main/set-proxy-store/task.yaml index e74c23edda..60b4055670 100644 --- a/tests/main/set-proxy-store/task.yaml +++ b/tests/main/set-proxy-store/task.yaml @@ -12,10 +12,11 @@ prepare: | fi echo "Given a snap is installed" - snap install $SNAP_NAME + snap install "$SNAP_NAME" - . $TESTSLIB/store.sh - setup_fake_store $BLOB_DIR + #shellcheck source=tests/lib/store.sh + . "$TESTSLIB"/store.sh + setup_fake_store "$BLOB_DIR" # undo the setup through envvars systemctl stop snapd.service snapd.socket rm /etc/systemd/system/snapd.service.d/store.conf @@ -23,16 +24,18 @@ prepare: | systemctl start snapd.socket # prepare bundle - cat $TESTSLIB/assertions/testrootorg-store.account-key >fake.store + cat "$TESTSLIB"/assertions/testrootorg-store.account-key >fake.store + #shellcheck disable=SC2129 echo >>fake.store - cat $TESTSLIB/assertions/developer1.account >>fake.store + cat "$TESTSLIB"/assertions/developer1.account >>fake.store + #shellcheck disable=SC2129 echo >>fake.store - cat $TESTSLIB/assertions/fake.store >>fake.store + cat "$TESTSLIB"/assertions/fake.store >>fake.store echo "Ack fake store assertion" snap ack fake.store echo "And a new version of that snap put in the controlled store" - init_fake_refreshes $BLOB_DIR $SNAP_NAME + init_fake_refreshes "$BLOB_DIR" "$SNAP_NAME" restore: | rm -f fake.store @@ -44,8 +47,9 @@ restore: | snap set core proxy.store= - . $TESTSLIB/store.sh - teardown_fake_store $BLOB_DIR + #shellcheck source=tests/lib/store.sh + . "$TESTSLIB"/store.sh + teardown_fake_store "$BLOB_DIR" execute: | if [ "$TRUST_TEST_KEYS" = "false" ]; then @@ -68,7 +72,7 @@ execute: | snap set core proxy.store=fake echo "Now we can proceed with the refresh from the fakestore" - snap refresh $SNAP_NAME + snap refresh "$SNAP_NAME" echo "Then the new version is listed" snap list | grep -Pzq "$expected" diff --git a/tests/main/snap-advise-command/task.yaml b/tests/main/snap-advise-command/task.yaml index 1a68a9b5c4..e07b7faa86 100644 --- a/tests/main/snap-advise-command/task.yaml +++ b/tests/main/snap-advise-command/task.yaml @@ -15,7 +15,7 @@ restore: | execute: | echo "wait for snapd to pull in the commands data" echo "(it will do that on startup)" - for i in $(seq 120); do + for _ in $(seq 120); do if stat /var/cache/snapd/commands.db; then break fi @@ -23,17 +23,17 @@ execute: | done stat /var/cache/snapd/commands.db echo "Ensure the database is readable by a regular user" - if [ $(stat -c "%a" /var/cache/snapd/commands.db) != "644" ]; then + if [ "$(stat -c '%a' /var/cache/snapd/commands.db)" != "644" ]; then echo "incorrect permissions for /var/cache/snapd/commands.db" echo "expected 0644 got:" stat /var/cache/snapd/commands.db exit 1 fi - echo "Ensure `snap advise-snap --command` lookup works" + echo "Ensure 'snap advise-snap --command' lookup works" snap advise-snap --command test-snapd-tools.echo | MATCH test-snapd-tools - echo "Ensure `advise-snap --command` works as command-not-found symlink" + echo "Ensure 'advise-snap --command' works as command-not-found symlink" ln -s /usr/bin/snap /usr/lib/command-not-found /usr/lib/command-not-found test-snapd-tools.echo | MATCH test-snapd-tools diff --git a/tests/unit/spread-shellcheck/can-fail b/tests/unit/spread-shellcheck/can-fail index 944298b91f..dd7bf5ef9e 100644 --- a/tests/unit/spread-shellcheck/can-fail +++ b/tests/unit/spread-shellcheck/can-fail @@ -1,32 +1,3 @@ -tests/main/refresh-all-undo/task.yaml -tests/main/refresh-all/task.yaml -tests/main/refresh-amend/task.yaml -tests/main/refresh-delta-from-core/task.yaml -tests/main/refresh-delta/task.yaml -tests/main/refresh-devmode/task.yaml -tests/main/refresh-undo/task.yaml -tests/main/refresh/task.yaml -tests/main/regression-home-snap-root-owned/task.yaml -tests/main/remove-errors/task.yaml -tests/main/revert-devmode/task.yaml -tests/main/revert-sideload/task.yaml -tests/main/revert/task.yaml -tests/main/searching/task.yaml -tests/main/security-apparmor/task.yaml -tests/main/security-device-cgroups-classic/task.yaml -tests/main/security-device-cgroups-devmode/task.yaml -tests/main/security-device-cgroups-jailmode/task.yaml -tests/main/security-device-cgroups-serial-port/task.yaml -tests/main/security-device-cgroups-strict/task.yaml -tests/main/security-device-cgroups/task.yaml -tests/main/security-devpts/task.yaml -tests/main/security-private-tmp/task.yaml -tests/main/security-profiles/task.yaml -tests/main/security-setuid-root/task.yaml -tests/main/security-udev-input-subsystem/task.yaml -tests/main/server-snap/task.yaml -tests/main/set-proxy-store/task.yaml -tests/main/snap-advise-command/task.yaml tests/main/snap-auto-import-asserts-spools/task.yaml tests/main/snap-auto-import-asserts/task.yaml tests/main/snap-auto-mount/task.yaml |
