tests/gpg: fix GPG-dependent shell tests if no GPG support

Skip tests or run them without GPG-related functionality if GPGME
wasn't enabled in a build time.

Signed-off-by: Denis Pynkin <denis.pynkin@collabora.com>

Closes: #1889
Approved by: cgwalters
This commit is contained in:
Denis Pynkin 2019-07-30 02:39:12 +03:00 committed by Atomic Bot
parent 453ce83379
commit 3767d87107
11 changed files with 113 additions and 52 deletions

View File

@ -54,7 +54,12 @@ function verify_initial_contents() {
assert_file_has_content baz/cow '^moo$'
}
echo "1..34"
if has_gpgme; then
echo "1..34"
else
# 3 tests needs GPG support
echo "1..31"
fi
# Try both syntaxes
repo_init --no-gpg-verify
@ -543,13 +548,15 @@ fi
assert_file_has_content err.txt "404"
echo "ok pull repo 404"
cd ${test_tmpdir}
repo_init --set=gpg-verify=true
if ${CMD_PREFIX} ostree --repo=repo --depth=0 pull origin main 2>err.txt; then
assert_not_reached "pull repo 404 succeeded?"
if has_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
assert_not_reached "pull repo 404 succeeded?"
fi
assert_file_has_content err.txt "GPG verification enabled, but no signatures found"
echo "ok pull repo 404 (gpg)"
fi
assert_file_has_content err.txt "GPG verification enabled, but no signatures found"
echo "ok pull repo 404 (gpg)"
cd ${test_tmpdir}
find ostree-srv/gnomerepo/objects -name '*.dirtree' | while read f; do mv ${f}{,.orig}; done
@ -561,29 +568,31 @@ 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"
cd ${test_tmpdir}
repo_init --set=gpg-verify=true
${CMD_PREFIX} ostree --repo=ostree-srv/gnomerepo commit ${COMMIT_ARGS} \
--gpg-homedir=${TEST_GPG_KEYHOME} --gpg-sign=${TEST_GPG_KEYID_1} -b main \
-s "A signed commit" --tree=ref=main
${CMD_PREFIX} ostree --repo=ostree-srv/gnomerepo summary -u
# make sure gpg verification is correctly on
csum=$(${CMD_PREFIX} ostree --repo=ostree-srv/gnomerepo rev-parse main)
objpath=objects/${csum::2}/${csum:2}.commitmeta
remotesig=ostree-srv/gnomerepo/$objpath
localsig=repo/$objpath
mv $remotesig $remotesig.bak
if ${CMD_PREFIX} ostree --repo=repo --depth=0 pull origin main; then
assert_not_reached "pull with gpg-verify unexpectedly succeeded?"
if has_gpgme; then
cd ${test_tmpdir}
repo_init --set=gpg-verify=true
${CMD_PREFIX} ostree --repo=ostree-srv/gnomerepo commit ${COMMIT_ARGS} \
--gpg-homedir=${TEST_GPG_KEYHOME} --gpg-sign=${TEST_GPG_KEYID_1} -b main \
-s "A signed commit" --tree=ref=main
${CMD_PREFIX} ostree --repo=ostree-srv/gnomerepo summary -u
# make sure gpg verification is correctly on
csum=$(${CMD_PREFIX} ostree --repo=ostree-srv/gnomerepo rev-parse main)
objpath=objects/${csum::2}/${csum:2}.commitmeta
remotesig=ostree-srv/gnomerepo/$objpath
localsig=repo/$objpath
mv $remotesig $remotesig.bak
if ${CMD_PREFIX} ostree --repo=repo --depth=0 pull origin main; then
assert_not_reached "pull with gpg-verify unexpectedly succeeded?"
fi
# ok now check that we can pull correctly
mv $remotesig.bak $remotesig
${CMD_PREFIX} ostree --repo=repo pull origin main
echo "ok pull signed commit"
rm $localsig
${CMD_PREFIX} ostree --repo=repo pull origin main
test -f $localsig
echo "ok re-pull signature for stored commit"
fi
# ok now check that we can pull correctly
mv $remotesig.bak $remotesig
${CMD_PREFIX} ostree --repo=repo pull origin main
echo "ok pull signed commit"
rm $localsig
${CMD_PREFIX} ostree --repo=repo pull origin main
test -f $localsig
echo "ok re-pull signature for stored commit"
cd ${test_tmpdir}
repo_init --no-gpg-verify

View File

@ -26,6 +26,8 @@ set -euo pipefail
. $(dirname $0)/libtest.sh
skip_without_gpgme
echo "1..5"
cd ${test_tmpdir}

View File

@ -23,6 +23,8 @@ set -euo pipefail
. $(dirname $0)/libtest.sh
skip_without_gpgme
echo '1..1'
# Create two upstream collection repositories with some example commits

View File

@ -28,7 +28,12 @@ unset OSTREE_GPG_HOME
skip_without_user_xattrs
echo "1..8"
if has_gpgme; then
echo "1..8"
else
# Only some tests doesn't need GPG support
echo "1..5"
fi
setup_test_repository "archive"
echo "ok setup"
@ -63,6 +68,20 @@ cmp checkout1.files checkout2.files
cmp checkout1.files checkout3.files
echo "ok checkouts same"
mkdir repo7
ostree_repo_init repo7 --mode="archive"
${CMD_PREFIX} ostree --repo=repo7 pull-local repo
${CMD_PREFIX} ostree --repo=repo7 fsck
for src_object in `find repo/objects -name '*.filez'`; do
dst_object=${src_object/repo/repo7}
assert_files_hardlinked "$src_object" "$dst_object"
done
echo "ok pull-local z2 to z2 default hardlink"
if ! has_gpgme; then
exit 0
fi
mkdir repo4
ostree_repo_init repo4 --mode="archive"
${CMD_PREFIX} ostree --repo=repo4 remote add --gpg-import ${test_tmpdir}/gpghome/key1.asc origin repo
@ -97,13 +116,3 @@ ${OSTREE} summary --update --gpg-sign=${TEST_GPG_KEYID_1} --gpg-homedir=${TEST_G
${CMD_PREFIX} ostree --repo=repo6 pull-local --remote=origin --gpg-verify-summary repo test2 2>&1
echo "ok --gpg-verify-summary"
mkdir repo7
ostree_repo_init repo7 --mode="archive"
${CMD_PREFIX} ostree --repo=repo7 pull-local repo
${CMD_PREFIX} ostree --repo=repo7 fsck
for src_object in `find repo/objects -name '*.filez'`; do
dst_object=${src_object/repo/repo7}
assert_files_hardlinked "$src_object" "$dst_object"
done
echo "ok pull-local z2 to z2 default hardlink"

View File

@ -25,6 +25,8 @@ set -euo pipefail
skip_without_user_xattrs
skip_without_gpgme
echo '1..2'
setup_test_repository "archive"

View File

@ -34,7 +34,11 @@ do_commit() {
mkdir -p files
pushd files
${CMD_PREFIX} ostree --repo="../${repo}" commit -s "Test ${repo} commit for branch ${branch}" -b "${branch}" --gpg-homedir="${TEST_GPG_KEYHOME}" --gpg-sign="${TEST_GPG_KEYID_1}" "$@" > "../${branch}-checksum"
local GPG_ARGS=""
if has_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"
popd
}
@ -42,7 +46,11 @@ do_summary() {
local repo=$1
shift 1
${CMD_PREFIX} ostree "--repo=${repo}" summary --update --gpg-homedir="${TEST_GPG_KEYHOME}" --gpg-sign="${TEST_GPG_KEYID_1}"
local GPG_ARGS=""
if has_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}
}
do_collection_ref_show() {
@ -96,7 +104,11 @@ do_remote_add() {
local remote_repo=$2
shift 2
${CMD_PREFIX} ostree "--repo=${repo}" remote add "${remote_repo}-remote" "file://$(pwd)/${remote_repo}" "$@" --gpg-import="${test_tmpdir}/gpghome/key1.asc"
local GPG_ARGS=""
if has_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}
}
do_pull() {

View File

@ -23,9 +23,15 @@ set -euo pipefail
. $(dirname $0)/libtest.sh
echo "1..5"
COMMIT_SIGN=""
if has_gpgme; then
COMMIT_SIGN="--gpg-homedir=${TEST_GPG_KEYHOME} --gpg-sign=${TEST_GPG_KEYID_1}"
echo "1..5"
else
# Only one test don't need GPG support
echo "1..1"
fi
COMMIT_SIGN="--gpg-homedir=${TEST_GPG_KEYHOME} --gpg-sign=${TEST_GPG_KEYID_1}"
setup_fake_remote_repo1 "archive" "${COMMIT_SIGN}"
# Now, setup multiple branches

View File

@ -23,9 +23,12 @@ set -euo pipefail
. $(dirname $0)/libtest.sh
echo "1..4"
COMMIT_SIGN=""
if has_gpgme; then
COMMIT_SIGN="--gpg-homedir=${TEST_GPG_KEYHOME} --gpg-sign=${TEST_GPG_KEYID_1}"
fi
COMMIT_SIGN="--gpg-homedir=${TEST_GPG_KEYHOME} --gpg-sign=${TEST_GPG_KEYID_1}"
echo "1..4"
# Test pulling from a repo which gives error 500 (internal server error) a lot of the time.
setup_fake_remote_repo1 "archive" "${COMMIT_SIGN}" --random-500s=50

View File

@ -23,9 +23,15 @@ set -euo pipefail
. $(dirname $0)/libtest.sh
echo "1..10"
COMMIT_SIGN=""
if has_gpgme; then
COMMIT_SIGN="--gpg-homedir=${TEST_GPG_KEYHOME} --gpg-sign=${TEST_GPG_KEYID_1}"
echo "1..10"
else
# Only one test don't need GPG support
echo "1..1"
fi
COMMIT_SIGN="--gpg-homedir=${TEST_GPG_KEYHOME} --gpg-sign=${TEST_GPG_KEYID_1}"
setup_fake_remote_repo1 "archive" "${COMMIT_SIGN}"
# Now, setup multiple branches

View File

@ -28,6 +28,12 @@ set -euo pipefail
echo "1..2"
COMMIT_SIGN=""
if has_gpgme; then
COMMIT_SIGN="--gpg-homedir=${TEST_GPG_KEYHOME} --gpg-sign=${TEST_GPG_KEYID_1}"
fi
cd ${test_tmpdir}
mkdir repo
ostree_repo_init repo
@ -45,7 +51,7 @@ done
${CMD_PREFIX} ostree --repo=repo summary --update
# Generate a signed summary file.
${CMD_PREFIX} ostree --repo=repo summary --update --gpg-homedir=${TEST_GPG_KEYHOME} --gpg-sign=${TEST_GPG_KEYID_1}
${CMD_PREFIX} ostree --repo=repo summary --update ${COMMIT_SIGN}
# Try various ways of adding additional data.
${CMD_PREFIX} ostree --repo=repo summary --update --add-metadata key="'value'" --add-metadata=key2=true
@ -77,7 +83,7 @@ done
${CMD_PREFIX} ostree --repo=repo summary --update
# Generate a signed summary file.
${CMD_PREFIX} ostree --repo=repo summary --update --gpg-homedir=${TEST_GPG_KEYHOME} --gpg-sign=${TEST_GPG_KEYID_1}
${CMD_PREFIX} ostree --repo=repo summary --update ${COMMIT_SIGN}
# Try various ways of adding additional data.
${CMD_PREFIX} ostree --repo=repo summary --update --add-metadata key="'value'" --add-metadata=key2=true

View File

@ -28,7 +28,11 @@ set -euo pipefail
echo "1..2"
COMMIT_SIGN="--gpg-homedir=${TEST_GPG_KEYHOME} --gpg-sign=${TEST_GPG_KEYID_1}"
COMMIT_SIGN=""
if has_gpgme; then
COMMIT_SIGN="--gpg-homedir=${TEST_GPG_KEYHOME} --gpg-sign=${TEST_GPG_KEYID_1}"
fi
setup_fake_remote_repo1 "archive" "${COMMIT_SIGN}"
# Set up a second branch.