tests: Generalize has_gpgme, has_sign_ed25519 into has_ostree_feature
authorSimon McVittie <smcv@collabora.com>
Mon, 19 Feb 2024 15:57:51 +0000 (15:57 +0000)
committerSimon McVittie <smcv@collabora.com>
Mon, 19 Feb 2024 21:01:05 +0000 (21:01 +0000)
Signed-off-by: Simon McVittie <smcv@collabora.com>
21 files changed:
tests/libtest.sh
tests/pull-test.sh
tests/test-commit-sign.sh
tests/test-create-usb.sh
tests/test-delta-ed25519.sh
tests/test-find-remotes.sh
tests/test-gpg-signed-commit.sh
tests/test-local-pull.sh
tests/test-parent.sh
tests/test-pre-signed-pull.sh
tests/test-pull-collections.sh
tests/test-pull-contenturl.sh
tests/test-pull-mirror-summary.sh
tests/test-pull-repeated.sh
tests/test-pull-summary-caching.sh
tests/test-pull-summary-sigs.sh
tests/test-signed-commit.sh
tests/test-signed-pull-summary.sh
tests/test-signed-pull.sh
tests/test-summary-update.sh
tests/test-summary-view.sh

index d1c99eab8fc8e0e7ae65e630b63404e603fbf488..2c2a33f0d947d1d918884c14cf0fa86cc7242f81 100755 (executable)
@@ -696,18 +696,20 @@ skip_without_fuse () {
     [ -e /etc/mtab ] || skip "no /etc/mtab"
 }
 
-has_gpgme () {
-    local ret
+has_ostree_feature () {
+    local ret=0
+    # Note that this needs to write to a file and then grep the file, to
+    # avoid ostree --version being killed with SIGPIPE and exiting with a
+    # nonzero status under `set -o pipefail`.
     ${CMD_PREFIX} ostree --version > version.txt
-    grep -q -e '- gpgme' version.txt
-    ret=$?
+    grep -q -e "- $1\$" version.txt || ret=$?
     rm -f version.txt
     return ${ret}
 }
 
-skip_without_gpgme() {
-    if ! has_gpgme; then
-        skip "no gpg support compiled in"
+skip_without_ostree_feature () {
+    if ! has_ostree_feature "$1"; then
+        skip "no $1 support compiled in"
     fi
 }
 
@@ -750,21 +752,6 @@ libtest_cleanup_gpg () {
 }
 libtest_exit_cmds+=(libtest_cleanup_gpg)
 
-has_sign_ed25519 () {
-    local ret
-    ${CMD_PREFIX} ostree --version > version.txt
-    grep -q -e '- sign-ed25519' version.txt
-    ret=$?
-    rm -f version.txt
-    return ${ret}
-}
-
-skip_without_sign_ed25519() {
-    if ! has_sign_ed25519; then
-        skip "no ed25519 support compiled in"
-    fi
-}
-
 # Keys for ed25519 signing tests
 ED25519PUBLIC=
 ED25519SEED=
index f40842907728cae14cc6c9503049125fde48fb70..d61735a0e93d687bf5bbb314b0fe426471185d82 100644 (file)
@@ -54,7 +54,7 @@ function verify_initial_contents() {
 
 n_base_tests=35
 gpg_tests=3
-if has_gpgme; then
+if has_ostree_feature gpgme; then
     echo "1..$(($n_base_tests+$gpg_tests))"
 else
     echo "1..$((n_base_tests))"
@@ -633,7 +633,7 @@ fi
 assert_file_has_content err.txt "404"
 echo "ok pull repo 404"
 
-if has_gpgme; then
+if has_ostree_feature gpgme; then
     cd ${test_tmpdir}
     repo_init --set=gpg-verify=true
     if ${CMD_PREFIX} ostree --repo=repo --depth=0 pull origin main 2>err.txt; then
@@ -653,7 +653,7 @@ assert_file_has_content err.txt "404"
 find ostree-srv/gnomerepo/objects -name '*.dirtree.orig' | while read f; do mv ${f} $(dirname $f)/$(basename ${f} .orig); done
 echo "ok pull repo 404 on dirtree object"
 
-if has_gpgme; then
+if has_ostree_feature gpgme; then
     cd ${test_tmpdir}
     repo_init --set=gpg-verify=true
     ${CMD_PREFIX} ostree --repo=ostree-srv/gnomerepo commit ${COMMIT_ARGS} \
index 345c22289ef587bc246ba81bc6e9d25f0e6ed5ec..8e1ba615063263a439ba8529e0fe06d9dc9d4a23 100755 (executable)
@@ -21,10 +21,7 @@ set -euo pipefail
 
 . $(dirname $0)/libtest.sh
 
-if ! has_gpgme; then
-    echo "1..0 #SKIP no gpg support compiled in"
-    exit 0
-fi
+skip_without_ostree_feature gpgme
 
 if test -z "${OSTREE_HTTPD}"; then
     echo "1..0 #SKIP no ostree-trivial-httpd"
index 016d32c7fd92e61ae5e1cb8c8ca66ff0548104db..064501fef76b4c2d7278e7ac9a91156a5c117d73 100755 (executable)
@@ -24,7 +24,7 @@ set -euo pipefail
 
 . $(dirname $0)/libtest.sh
 
-skip_without_gpgme
+skip_without_ostree_feature gpgme
 
 echo "1..5"
 
index 9e00fdb45acd48980e912078e6c386420b9afea3..9cd22286f72fcf9fd2a221f30233274dcd1f7f4a 100755 (executable)
@@ -23,7 +23,7 @@ set -euo pipefail
 
 skip_without_user_xattrs
 
-skip_without_sign_ed25519
+skip_without_ostree_feature sign-ed25519
 
 bindatafiles="bash true ostree"
 
index abcc41dcac62734c4d4606755a719ce41ec7b8f3..3ec81f91c5b9c90b2b4a95010736a6594104c103 100755 (executable)
@@ -21,7 +21,7 @@ set -euo pipefail
 
 . $(dirname $0)/libtest.sh
 
-skip_without_gpgme
+skip_without_ostree_feature gpgme
 
 echo '1..1'
 
index 7b00f9e9e5086efae785fdf7136b9add793ac264..d3b543327231353aba52097355325e7d6b6cd687 100755 (executable)
@@ -22,10 +22,7 @@ set -euo pipefail
 
 . $(dirname $0)/libtest.sh
 
-if ! has_gpgme; then
-    echo "1..0 #SKIP no gpgme support compiled in"
-    exit 0
-fi
+skip_without_ostree_feature gpgme
 
 num_tests=1
 
index 79b86abc9616d15fc8e079419f5444c3cff0494e..e1b916c4ecf2b95f429b0ea51a3f898033bfe274 100755 (executable)
@@ -61,7 +61,7 @@ cmp checkout1.files checkout2.files
 cmp checkout1.files checkout3.files
 echo "ok checkouts same"
 
-if has_gpgme; then
+if has_ostree_feature gpgme; then
     # These tests are needed GPG support
     mkdir repo4
     ostree_repo_init repo4 --mode="archive"
index 4b5806c59d9c113d0c7b65e193b866bbbd940ba2..5a8809f8650a511e801a40470c00c6708103444e 100755 (executable)
@@ -23,7 +23,7 @@ set -euo pipefail
 
 skip_without_user_xattrs
 
-skip_without_gpgme
+skip_without_ostree_feature gpgme
 
 echo '1..2'
 
index 2a1a1d239efb9ee2dc484041a9bae2c434f31ddc..0ac8e0aa1fa80329b7efc77cc37e92c3a1377ea5 100755 (executable)
@@ -23,7 +23,7 @@ set -euo pipefail
 
 echo "1..1"
 
-if ! has_sign_ed25519; then
+if ! has_ostree_feature sign-ed25519; then
     echo "ok pre-signed pull # SKIP due ed25519 unavailability"
     exit 0
 fi
index 1d14e5db988de274f3ba3e84ad5b9f70c15d11ed..518545d75d6a68b98bd1bd3ef13ffee88d23c4c2 100755 (executable)
@@ -33,7 +33,7 @@ do_commit() {
     mkdir -p files
     pushd files
     local GPG_ARGS=""
-    if has_gpgme; then
+    if has_ostree_feature gpgme; then
         GPG_ARGS="--gpg-homedir=${TEST_GPG_KEYHOME} --gpg-sign=${TEST_GPG_KEYID_1}"
     fi
     ${CMD_PREFIX} ostree --repo="../${repo}" commit -s "Test ${repo} commit for branch ${branch}" -b "${branch}" ${GPG_ARGS} "$@" > "../${branch}-checksum"
@@ -45,7 +45,7 @@ do_summary() {
     shift 1
 
     local GPG_ARGS=""
-    if has_gpgme; then
+    if has_ostree_feature gpgme; then
         GPG_ARGS="--gpg-homedir=${TEST_GPG_KEYHOME} --gpg-sign=${TEST_GPG_KEYID_1}"
     fi
     ${CMD_PREFIX} ostree "--repo=${repo}" summary --update ${GPG_ARGS}
@@ -103,7 +103,7 @@ do_remote_add() {
     shift 2
 
     local GPG_ARGS=""
-    if has_gpgme; then
+    if has_ostree_feature gpgme; then
         GPG_ARGS="--gpg-import=${test_tmpdir}/gpghome/key1.asc"
     fi
     ${CMD_PREFIX} ostree "--repo=${repo}" remote add "${remote_repo}-remote" "file://$(pwd)/${remote_repo}" "$@" ${GPG_ARGS}
index d47fdfe11059bf774304fe16c72e3ca24d53440b..63eecf720930bbf90983b4693b030384db97b7f8 100755 (executable)
@@ -29,7 +29,7 @@ fi
 echo "1..2"
 
 COMMIT_SIGN=""
-if has_gpgme; then
+if has_ostree_feature gpgme; then
   COMMIT_SIGN="--gpg-homedir=${TEST_GPG_KEYHOME} --gpg-sign=${TEST_GPG_KEYID_1}"
 fi
 
@@ -47,7 +47,7 @@ cp -a ${test_tmpdir}/ostree-srv ostree
 
 # delete all the meta stuff from here
 rm ostree/gnomerepo/summary
-if has_gpgme; then
+if has_ostree_feature gpgme; then
   rm ostree/gnomerepo/summary.sig
   find ostree/gnomerepo/objects -name '*.commitmeta' | xargs rm
 fi
@@ -63,7 +63,7 @@ echo "http://127.0.0.1:${content_port}" > ${test_tmpdir}/httpd-content-address
 cd ${test_tmpdir}
 mkdir repo
 ostree_repo_init repo
-if has_gpgme; then VERIFY=true; else VERIFY=false; fi
+if has_ostree_feature gpgme; then VERIFY=true; else VERIFY=false; fi
 ${CMD_PREFIX} ostree --repo=repo remote add origin \
   --set=gpg-verify=$VERIFY --set=gpg-verify-summary=$VERIFY \
   --contenturl=$(cat httpd-content-address)/ostree/gnomerepo \
@@ -72,7 +72,7 @@ ${CMD_PREFIX} ostree --repo=repo pull origin:main
 
 echo "ok pull objects from contenturl"
 
-if ! has_gpgme; then
+if ! has_ostree_feature gpgme; then
   echo "ok don't pull sigs from contenturl # SKIP not compiled with gpgme"
 else
   echo "ok don't pull sigs from contenturl"
index 94a8c02013eef1be1c03371a2ebf68d4e5b1fbc5..88a37b8a79180fae1ccd46a6da3c9ead7146a251 100755 (executable)
@@ -22,7 +22,7 @@ set -euo pipefail
 . $(dirname $0)/libtest.sh
 
 COMMIT_SIGN=""
-if has_gpgme; then
+if has_ostree_feature gpgme; then
     COMMIT_SIGN="--gpg-homedir=${TEST_GPG_KEYHOME} --gpg-sign=${TEST_GPG_KEYID_1}"
     echo "1..5"
 else
@@ -67,7 +67,7 @@ find repo/objects -name '*.filez' | while read name; do
 done
 echo "ok pull mirror summary"
 
-if ! has_gpgme; then
+if ! has_ostree_feature gpgme; then
     exit 0;
 fi
 
index 7f724c9539d0330cce113d101f5e340a5132ae91..b3e0074207e56482f785e41dfb17eff380dcf954 100755 (executable)
@@ -22,7 +22,7 @@ set -euo pipefail
 . $(dirname $0)/libtest.sh
 
 COMMIT_SIGN=""
-if has_gpgme; then
+if has_ostree_feature gpgme; then
     COMMIT_SIGN="--gpg-homedir=${TEST_GPG_KEYHOME} --gpg-sign=${TEST_GPG_KEYID_1}"
 fi
 
index 8c6727d05e7ff6c7e916254574b5401ccb11c1db..180f671cdd9c1c9d4e48d01336f047917e31fbe5 100755 (executable)
@@ -24,10 +24,7 @@ set -euo pipefail
 
 . $(dirname $0)/libtest.sh
 
-if ! has_gpgme; then
-    echo "1..0 #SKIP no gpg support compiled in"
-    exit 0
-fi
+skip_without_ostree_feature gpgme
 
 # Ensure repo caching is in use.
 unset OSTREE_SKIP_CACHE
index e1b0412e68741e0a5b41a66ae9d108f2b6924706..8a5cc4fbffbc7c9f5fe32fc9cc41ebce2f443dae 100755 (executable)
@@ -25,7 +25,7 @@ set -euo pipefail
 unset OSTREE_SKIP_CACHE
 
 COMMIT_SIGN=""
-if has_gpgme; then
+if has_ostree_feature gpgme; then
     COMMIT_SIGN="--gpg-homedir=${TEST_GPG_KEYHOME} --gpg-sign=${TEST_GPG_KEYID_1}"
     echo "1..10"
 else
@@ -63,7 +63,7 @@ assert_file_has_content yet-another-copy/yet-another-hello-world "hello world ye
 ${CMD_PREFIX} ostree --repo=repo fsck
 echo "ok pull mirror summary"
 
-if ! has_gpgme; then
+if ! has_ostree_feature gpgme; then
     exit 0;
 fi
 
index 432687d8d8555c0ad26bf55b4c179864597fa9d5..cf1cd1c8527bbe2c823a8f6b4df4fa59d89d6dc9 100755 (executable)
@@ -61,7 +61,7 @@ assert_file_has_content_literal err.txt ' No valid signatures found'
 echo "ok dummy sig requires env"
 
 # tests below require libsodium support
-if ! has_sign_ed25519; then
+if ! has_ostree_feature sign-ed25519; then
     echo "ok Detached ed25519 signature # SKIP due libsodium unavailability"
     echo "ok ed25519 signature verified # SKIP due libsodium unavailability"
     echo "ok multiple signing # SKIP due libsodium unavailability"
index d28738947e637739f8ba98184170c5cc1491c1e2..e5339078d72272845f90a268d82b3c15413a6f37 100755 (executable)
@@ -52,7 +52,7 @@ do
             PUBLIC_KEY="dummysign"
             ;;
         ed25519)
-            if ! has_sign_ed25519; then
+            if ! has_ostree_feature sign-ed25519; then
                 echo "ok ${engine} pull mirror summary # SKIP due libsodium unavailability"
                 echo "ok ${engine} pull with signed summary # SKIP due libsodium unavailability"
                 echo "ok ${engine} prune summary cache # SKIP due libsodium unavailability"
@@ -174,7 +174,7 @@ do
 
 done
 
-if ! has_sign_ed25519; then
+if ! has_ostree_feature sign-ed25519; then
     echo "ok ${engine} pull with signed summary remote old summary # SKIP due libsodium unavailability"
     echo "ok ${engine} pull with signed summary broken cache # SKIP due libsodium unavailability"
     exit 0
index 5754914fce5d8e3195c96f5797b47f7180606d12..a08d3fbf77a92e02b13d63cd48a11b10e4e516f7 100755 (executable)
@@ -140,7 +140,7 @@ fi
 assert_file_has_content err.txt 'Invalid key reference'
 echo "ok remote add errs"
 
-if ! has_sign_ed25519; then
+if ! has_ostree_feature sign-ed25519; then
     echo "ok ed25519-key pull signed commit # SKIP due libsodium unavailability"
     echo "ok ed25519-key re-pull signature for stored commit # SKIP due libsodium unavailability"
     echo "ok ed25519-key+file pull signed commit # SKIP due libsodium unavailability"
index d85e9c4b3926f92e78634b21a8ef94ac73da1c84..6cf5fccbc845501ec35ca13f3b70d4a77d05c5a1 100755 (executable)
@@ -27,7 +27,7 @@ set -euo pipefail
 echo "1..2"
 
 COMMIT_SIGN=""
-if has_gpgme; then
+if has_ostree_feature gpgme; then
     COMMIT_SIGN="--gpg-homedir=${TEST_GPG_KEYHOME} --gpg-sign=${TEST_GPG_KEYID_1}"
 fi
 
index 9dfc74f44689b8b23d9121627a3564a2acbe400c..473c6db54ef80c08dc7cdf9fcb889749eef1ffa3 100755 (executable)
@@ -27,7 +27,7 @@ set -euo pipefail
 echo "1..2"
 
 COMMIT_SIGN=""
-if has_gpgme; then
+if has_ostree_feature gpgme; then
     COMMIT_SIGN="--gpg-homedir=${TEST_GPG_KEYHOME} --gpg-sign=${TEST_GPG_KEYID_1}"
 fi