Blame tests/test-pull-summary-sigs.sh

Packit Service 2a3f3d
#!/bin/bash
Packit Service 2a3f3d
#
Packit Service 2a3f3d
# Copyright (C) 2014 Colin Walters <walters@verbum.org>
Packit Service 2a3f3d
#
Packit Service 2a3f3d
# SPDX-License-Identifier: LGPL-2.0+
Packit Service 2a3f3d
#
Packit Service 2a3f3d
# This library is free software; you can redistribute it and/or
Packit Service 2a3f3d
# modify it under the terms of the GNU Lesser General Public
Packit Service 2a3f3d
# License as published by the Free Software Foundation; either
Packit Service 2a3f3d
# version 2 of the License, or (at your option) any later version.
Packit Service 2a3f3d
#
Packit Service 2a3f3d
# This library is distributed in the hope that it will be useful,
Packit Service 2a3f3d
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 2a3f3d
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 2a3f3d
# Lesser General Public License for more details.
Packit Service 2a3f3d
#
Packit Service 2a3f3d
# You should have received a copy of the GNU Lesser General Public
Packit Service 2a3f3d
# License along with this library; if not, write to the
Packit Service 2a3f3d
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Packit Service 2a3f3d
# Boston, MA 02111-1307, USA.
Packit Service 2a3f3d
Packit Service 2a3f3d
set -euo pipefail
Packit Service 2a3f3d
Packit Service 2a3f3d
. $(dirname $0)/libtest.sh
Packit Service 2a3f3d
Packit Service 2a3f3d
COMMIT_SIGN=""
Packit Service 2a3f3d
if has_gpgme; then
Packit Service 2a3f3d
    COMMIT_SIGN="--gpg-homedir=${TEST_GPG_KEYHOME} --gpg-sign=${TEST_GPG_KEYID_1}"
Packit Service 2a3f3d
    echo "1..10"
Packit Service 2a3f3d
else
Packit Service 2a3f3d
    # Only one test don't need GPG support
Packit Service 2a3f3d
    echo "1..1"
Packit Service 2a3f3d
fi
Packit Service 2a3f3d
Packit Service 2a3f3d
setup_fake_remote_repo1 "archive" "${COMMIT_SIGN}"
Packit Service 2a3f3d
Packit Service 2a3f3d
# Now, setup multiple branches
Packit Service 2a3f3d
mkdir ${test_tmpdir}/ostree-srv/other-files
Packit Service 2a3f3d
cd ${test_tmpdir}/ostree-srv/other-files
Packit Service 2a3f3d
echo 'hello world another object' > hello-world
Packit Service 2a3f3d
${CMD_PREFIX} ostree  --repo=${test_tmpdir}/ostree-srv/gnomerepo commit ${COMMIT_SIGN} -b other -s "A commit" -m "Another Commit body"
Packit Service 2a3f3d
Packit Service 2a3f3d
mkdir ${test_tmpdir}/ostree-srv/yet-other-files
Packit Service 2a3f3d
cd ${test_tmpdir}/ostree-srv/yet-other-files
Packit Service 2a3f3d
echo 'hello world yet another object' > yet-another-hello-world
Packit Service 2a3f3d
${CMD_PREFIX} ostree  --repo=${test_tmpdir}/ostree-srv/gnomerepo commit ${COMMIT_SIGN} -b yet-another -s "A commit" -m "Another Commit body"
Packit Service 2a3f3d
Packit Service 2a3f3d
${CMD_PREFIX} ostree --repo=${test_tmpdir}/ostree-srv/gnomerepo summary -u
Packit Service 2a3f3d
Packit Service 2a3f3d
prev_dir=`pwd`
Packit Service 2a3f3d
cd ${test_tmpdir}
Packit Service 2a3f3d
ostree_repo_init repo --mode=archive
Packit Service 2a3f3d
${CMD_PREFIX} ostree --repo=repo remote add --set=gpg-verify=false origin $(cat httpd-address)/ostree/gnomerepo
Packit Service 2a3f3d
${CMD_PREFIX} ostree --repo=repo pull --mirror origin
Packit Service 2a3f3d
assert_has_file repo/summary
Packit Service 2a3f3d
${CMD_PREFIX} ostree --repo=repo checkout -U main main-copy
Packit Service 2a3f3d
assert_file_has_content main-copy/baz/cow "moo"
Packit Service 2a3f3d
${CMD_PREFIX} ostree --repo=repo checkout -U other other-copy
Packit Service 2a3f3d
assert_file_has_content other-copy/hello-world "hello world another object"
Packit Service 2a3f3d
${CMD_PREFIX} ostree --repo=repo checkout -U yet-another yet-another-copy
Packit Service 2a3f3d
assert_file_has_content yet-another-copy/yet-another-hello-world "hello world yet another object"
Packit Service 2a3f3d
${CMD_PREFIX} ostree --repo=repo fsck
Packit Service 2a3f3d
echo "ok pull mirror summary"
Packit Service 2a3f3d
Packit Service 2a3f3d
if ! has_gpgme; then
Packit Service 2a3f3d
    exit 0;
Packit Service 2a3f3d
fi
Packit Service 2a3f3d
Packit Service 2a3f3d
cd $prev_dir
Packit Service 2a3f3d
Packit Service 2a3f3d
${OSTREE} --repo=${test_tmpdir}/ostree-srv/gnomerepo summary -u ${COMMIT_SIGN}
Packit Service 2a3f3d
Packit Service 2a3f3d
repo_reinit () {
Packit Service 2a3f3d
  cd ${test_tmpdir}
Packit Service 2a3f3d
  rm -rf repo
Packit Service 2a3f3d
  mkdir repo
Packit Service 2a3f3d
  ostree_repo_init repo --mode=archive
Packit Service 2a3f3d
  ${OSTREE} --repo=repo remote add --set=gpg-verify-summary=true origin $(cat httpd-address)/ostree/gnomerepo
Packit Service 2a3f3d
}
Packit Service 2a3f3d
Packit Service 2a3f3d
cd ${test_tmpdir}
Packit Service 2a3f3d
repo_reinit
Packit Service 2a3f3d
${OSTREE} --repo=repo pull origin main
Packit Service 2a3f3d
assert_has_file repo/tmp/cache/summaries/origin
Packit Service 2a3f3d
assert_has_file repo/tmp/cache/summaries/origin.sig
Packit Service 2a3f3d
Packit Service 2a3f3d
rm repo/tmp/cache/summaries/origin
Packit Service 2a3f3d
${OSTREE} --repo=repo pull origin main
Packit Service 2a3f3d
assert_has_file repo/tmp/cache/summaries/origin
Packit Service 2a3f3d
Packit Service 2a3f3d
echo "ok pull with signed summary"
Packit Service 2a3f3d
Packit Service 2a3f3d
touch repo/tmp/cache/summaries/foo
Packit Service 2a3f3d
touch repo/tmp/cache/summaries/foo.sig
Packit Service 2a3f3d
${OSTREE} --repo=repo prune
Packit Service 2a3f3d
assert_not_has_file repo/tmp/cache/summaries/foo
Packit Service 2a3f3d
assert_not_has_file repo/tmp/cache/summaries/foo.sig
Packit Service 2a3f3d
assert_has_file repo/tmp/cache/summaries/origin
Packit Service 2a3f3d
assert_has_file repo/tmp/cache/summaries/origin.sig
Packit Service 2a3f3d
echo "ok prune summary cache"
Packit Service 2a3f3d
Packit Service 2a3f3d
cd ${test_tmpdir}
Packit Service 2a3f3d
repo_reinit
Packit Service 2a3f3d
mkdir cachedir
Packit Service 2a3f3d
${OSTREE} --repo=repo pull --cache-dir=cachedir origin main
Packit Service 2a3f3d
assert_not_has_file repo/tmp/cache/summaries/origin
Packit Service 2a3f3d
assert_not_has_file repo/tmp/cache/summaries/origin.sig
Packit Service 2a3f3d
assert_has_file cachedir/summaries/origin
Packit Service 2a3f3d
assert_has_file cachedir/summaries/origin.sig
Packit Service 2a3f3d
Packit Service 2a3f3d
rm cachedir/summaries/origin
Packit Service 2a3f3d
${OSTREE} --repo=repo pull --cache-dir=cachedir origin main
Packit Service 2a3f3d
assert_not_has_file repo/tmp/cache/summaries/origin
Packit Service 2a3f3d
assert_has_file cachedir/summaries/origin
Packit Service 2a3f3d
Packit Service 2a3f3d
echo "ok pull with signed summary and cachedir"
Packit Service 2a3f3d
Packit Service 2a3f3d
cd ${test_tmpdir}
Packit Service 2a3f3d
repo_reinit
Packit Service 2a3f3d
mv ${test_tmpdir}/ostree-srv/gnomerepo/summary.sig{,.good}
Packit Service 2a3f3d
echo invalid > ${test_tmpdir}/ostree-srv/gnomerepo/summary.sig
Packit Service 2a3f3d
if ${OSTREE} --repo=repo pull origin main 2>err.txt; then
Packit Service 2a3f3d
    assert_not_reached "Successful pull with invalid GPG sig"
Packit Service 2a3f3d
fi
Packit Service 2a3f3d
assert_file_has_content err.txt "no signatures found"
Packit Service 2a3f3d
mv ${test_tmpdir}/ostree-srv/gnomerepo/summary.sig{.good,}
Packit Service 2a3f3d
echo "ok pull with invalid summary gpg signature fails"
Packit Service 2a3f3d
Packit Service 2a3f3d
cd ${test_tmpdir}
Packit Service 2a3f3d
repo_reinit
Packit Service 2a3f3d
cp ${test_tmpdir}/ostree-srv/gnomerepo/summary{,.good}
Packit Service 2a3f3d
# Some leading garbage
Packit Service 2a3f3d
(echo invalid && cat ${test_tmpdir}/ostree-srv/gnomerepo/summary) > summary.bad.tmp && mv summary.bad.tmp ${test_tmpdir}/ostree-srv/gnomerepo/summary
Packit Service 2a3f3d
if ${OSTREE} --repo=repo pull origin main; then
Packit Service 2a3f3d
    assert_not_reached "Successful pull with invalid summary"
Packit Service 2a3f3d
fi
Packit Service 2a3f3d
mv ${test_tmpdir}/ostree-srv/gnomerepo/summary{.good,}
Packit Service 2a3f3d
echo "ok pull with invalid summary (leading garbage) fails"
Packit Service 2a3f3d
Packit Service 2a3f3d
# Generate a delta
Packit Service 2a3f3d
${OSTREE} --repo=${test_tmpdir}/ostree-srv/gnomerepo static-delta generate --empty main
Packit Service 2a3f3d
${OSTREE} --repo=${test_tmpdir}/ostree-srv/gnomerepo summary -u ${COMMIT_SIGN}
Packit Service 2a3f3d
Packit Service 2a3f3d
cd ${test_tmpdir}
Packit Service 2a3f3d
repo_reinit
Packit Service 2a3f3d
${OSTREE} --repo=repo pull origin main
Packit Service 2a3f3d
echo "ok pull delta with signed summary"
Packit Service 2a3f3d
Packit Service 2a3f3d
# Verify 'ostree remote summary' output.
Packit Service 2a3f3d
${OSTREE} --repo=repo remote summary origin > summary.txt
Packit Service 2a3f3d
assert_file_has_content summary.txt "* main"
Packit Service 2a3f3d
assert_file_has_content summary.txt "* other"
Packit Service 2a3f3d
assert_file_has_content summary.txt "* yet-another"
Packit Service 2a3f3d
assert_file_has_content summary.txt "found 1 signature"
Packit Service 2a3f3d
assert_file_has_content summary.txt "Good signature from \"Ostree Tester <test@test\.com>\""
Packit Service 2a3f3d
grep static-deltas summary.txt > static-deltas.txt
Packit Service 2a3f3d
assert_file_has_content static-deltas.txt \
Packit Service 2a3f3d
  $(${OSTREE} --repo=repo rev-parse origin:main)
Packit Service 2a3f3d
Packit Service 2a3f3d
## Tests for handling of cached summaries while racing with remote summary updates
Packit Service 2a3f3d
Packit Service 2a3f3d
# Make 2 different but valid summary/signature pairs to test races with
Packit Service 2a3f3d
${OSTREE} --repo=${test_tmpdir}/ostree-srv/gnomerepo summary -u ${COMMIT_SIGN}
Packit Service 2a3f3d
cp ${test_tmpdir}/ostree-srv/gnomerepo/summary{,.1}
Packit Service 2a3f3d
cp ${test_tmpdir}/ostree-srv/gnomerepo/summary.sig{,.1}
Packit Service 2a3f3d
mkdir ${test_tmpdir}/ostree-srv/even-another-files
Packit Service 2a3f3d
cd ${test_tmpdir}/ostree-srv/even-another-files
Packit Service 2a3f3d
echo 'hello world even another object' > even-another-hello-world
Packit Service 2a3f3d
${OSTREE} --repo=${test_tmpdir}/ostree-srv/gnomerepo commit ${COMMIT_SIGN} -b even-another -s "A commit" -m "Another Commit body"
Packit Service 2a3f3d
${OSTREE} --repo=${test_tmpdir}/ostree-srv/gnomerepo summary -u ${COMMIT_SIGN}
Packit Service 2a3f3d
cp ${test_tmpdir}/ostree-srv/gnomerepo/summary{,.2}
Packit Service 2a3f3d
cp ${test_tmpdir}/ostree-srv/gnomerepo/summary.sig{,.2}
Packit Service 2a3f3d
cd ${test_tmpdir}
Packit Service 2a3f3d
Packit Service 2a3f3d
# Reset to the old valid summary and pull to cache it
Packit Service 2a3f3d
cp ${test_tmpdir}/ostree-srv/gnomerepo/summary{.1,}
Packit Service 2a3f3d
cp ${test_tmpdir}/ostree-srv/gnomerepo/summary.sig{.1,}
Packit Service 2a3f3d
repo_reinit
Packit Service 2a3f3d
${OSTREE} --repo=repo pull origin main
Packit Service 2a3f3d
assert_has_file repo/tmp/cache/summaries/origin
Packit Service 2a3f3d
assert_has_file repo/tmp/cache/summaries/origin.sig
Packit Service 2a3f3d
cmp repo/tmp/cache/summaries/origin ${test_tmpdir}/ostree-srv/gnomerepo/summary.1 >&2
Packit Service 2a3f3d
cmp repo/tmp/cache/summaries/origin.sig ${test_tmpdir}/ostree-srv/gnomerepo/summary.sig.1 >&2
Packit Service 2a3f3d
Packit Service 2a3f3d
# Simulate a pull race where the client gets the old summary and the new
Packit Service 2a3f3d
# summary signature since it was generated on the server between the
Packit Service 2a3f3d
# requests
Packit Service 2a3f3d
cp ${test_tmpdir}/ostree-srv/gnomerepo/summary.sig{.2,}
Packit Service 2a3f3d
if ${OSTREE} --repo=repo pull origin main 2>err.txt; then
Packit Service 2a3f3d
    assert_not_reached "Successful pull with old summary"
Packit Service 2a3f3d
fi
Packit Service 2a3f3d
assert_file_has_content err.txt "BAD signature"
Packit Service 2a3f3d
assert_has_file repo/tmp/cache/summaries/origin
Packit Service 2a3f3d
assert_has_file repo/tmp/cache/summaries/origin.sig
Packit Service 2a3f3d
cmp repo/tmp/cache/summaries/origin ${test_tmpdir}/ostree-srv/gnomerepo/summary.1 >&2
Packit Service 2a3f3d
cmp repo/tmp/cache/summaries/origin.sig ${test_tmpdir}/ostree-srv/gnomerepo/summary.sig.1 >&2
Packit Service 2a3f3d
Packit Service 2a3f3d
# Publish correct summary and check that subsequent pull succeeds
Packit Service 2a3f3d
cp ${test_tmpdir}/ostree-srv/gnomerepo/summary{.2,}
Packit Service 2a3f3d
${OSTREE} --repo=repo pull origin main
Packit Service 2a3f3d
assert_has_file repo/tmp/cache/summaries/origin
Packit Service 2a3f3d
assert_has_file repo/tmp/cache/summaries/origin.sig
Packit Service 2a3f3d
cmp repo/tmp/cache/summaries/origin ${test_tmpdir}/ostree-srv/gnomerepo/summary.2 >&2
Packit Service 2a3f3d
cmp repo/tmp/cache/summaries/origin.sig ${test_tmpdir}/ostree-srv/gnomerepo/summary.sig.2 >&2
Packit Service 2a3f3d
Packit Service 2a3f3d
echo "ok pull with signed summary remote old summary"
Packit Service 2a3f3d
Packit Service 2a3f3d
# Reset to the old valid summary and pull to cache it
Packit Service 2a3f3d
cp ${test_tmpdir}/ostree-srv/gnomerepo/summary{.1,}
Packit Service 2a3f3d
cp ${test_tmpdir}/ostree-srv/gnomerepo/summary.sig{.1,}
Packit Service 2a3f3d
repo_reinit
Packit Service 2a3f3d
${OSTREE} --repo=repo pull origin main
Packit Service 2a3f3d
assert_has_file repo/tmp/cache/summaries/origin
Packit Service 2a3f3d
assert_has_file repo/tmp/cache/summaries/origin.sig
Packit Service 2a3f3d
cmp repo/tmp/cache/summaries/origin ${test_tmpdir}/ostree-srv/gnomerepo/summary.1 >&2
Packit Service 2a3f3d
cmp repo/tmp/cache/summaries/origin.sig ${test_tmpdir}/ostree-srv/gnomerepo/summary.sig.1 >&2
Packit Service 2a3f3d
Packit Service 2a3f3d
# Simulate a pull race where the client gets the new summary and the old
Packit Service 2a3f3d
# summary signature. This is unlikely to happen except if the web server
Packit Service 2a3f3d
# is caching the old signature. This should succeed because the cached
Packit Service 2a3f3d
# old summary is used.
Packit Service 2a3f3d
cp ${test_tmpdir}/ostree-srv/gnomerepo/summary{.2,}
Packit Service 2a3f3d
${OSTREE} --repo=repo pull origin main
Packit Service 2a3f3d
assert_has_file repo/tmp/cache/summaries/origin
Packit Service 2a3f3d
assert_has_file repo/tmp/cache/summaries/origin.sig
Packit Service 2a3f3d
cmp repo/tmp/cache/summaries/origin ${test_tmpdir}/ostree-srv/gnomerepo/summary.1 >&2
Packit Service 2a3f3d
cmp repo/tmp/cache/summaries/origin.sig ${test_tmpdir}/ostree-srv/gnomerepo/summary.sig.1 >&2
Packit Service 2a3f3d
Packit Service 2a3f3d
# Publish correct signature and check that subsequent pull succeeds
Packit Service 2a3f3d
cp ${test_tmpdir}/ostree-srv/gnomerepo/summary.sig{.2,}
Packit Service 2a3f3d
${OSTREE} --repo=repo pull origin main
Packit Service 2a3f3d
assert_has_file repo/tmp/cache/summaries/origin
Packit Service 2a3f3d
assert_has_file repo/tmp/cache/summaries/origin.sig
Packit Service 2a3f3d
cmp repo/tmp/cache/summaries/origin ${test_tmpdir}/ostree-srv/gnomerepo/summary.2 >&2
Packit Service 2a3f3d
cmp repo/tmp/cache/summaries/origin.sig ${test_tmpdir}/ostree-srv/gnomerepo/summary.sig.2 >&2
Packit Service 2a3f3d
Packit Service 2a3f3d
echo "ok pull with signed summary remote old summary signature"
Packit Service 2a3f3d
Packit Service 2a3f3d
# Reset to the old valid summary and pull to cache it
Packit Service 2a3f3d
cp ${test_tmpdir}/ostree-srv/gnomerepo/summary{.1,}
Packit Service 2a3f3d
cp ${test_tmpdir}/ostree-srv/gnomerepo/summary.sig{.1,}
Packit Service 2a3f3d
repo_reinit
Packit Service 2a3f3d
${OSTREE} --repo=repo pull origin main
Packit Service 2a3f3d
assert_has_file repo/tmp/cache/summaries/origin
Packit Service 2a3f3d
assert_has_file repo/tmp/cache/summaries/origin.sig
Packit Service 2a3f3d
cmp repo/tmp/cache/summaries/origin ${test_tmpdir}/ostree-srv/gnomerepo/summary.1 >&2
Packit Service 2a3f3d
cmp repo/tmp/cache/summaries/origin.sig ${test_tmpdir}/ostree-srv/gnomerepo/summary.sig.1 >&2
Packit Service 2a3f3d
Packit Service 2a3f3d
# Simulate a broken summary cache to see if it can be recovered from.
Packit Service 2a3f3d
# Prior to commit c4c2b5eb the client would save the summary to the
Packit Service 2a3f3d
# cache before validating the signature. That would mean the cache would
Packit Service 2a3f3d
# have mismatched summary and signature and ostree would remain
Packit Service 2a3f3d
# deadlocked there until the remote published a new signature.
Packit Service 2a3f3d
#
Packit Service 2a3f3d
# First pull with OSTREE_REPO_TEST_ERROR=invalid-cache to see the
Packit Service 2a3f3d
# invalid cache is detected. Then pull again to check if it can be
Packit Service 2a3f3d
# recovered from.
Packit Service 2a3f3d
cp ${test_tmpdir}/ostree-srv/gnomerepo/summary.2 repo/tmp/cache/summaries/origin
Packit Service 2a3f3d
if OSTREE_REPO_TEST_ERROR=invalid-cache ${OSTREE} --repo=repo pull origin main 2>err.txt; then
Packit Service 2a3f3d
    assert_not_reached "Should have hit OSTREE_REPO_TEST_ERROR_INVALID_CACHE"
Packit Service 2a3f3d
fi
Packit Service 2a3f3d
assert_file_has_content err.txt "OSTREE_REPO_TEST_ERROR_INVALID_CACHE"
Packit Service 2a3f3d
assert_has_file repo/tmp/cache/summaries/origin
Packit Service 2a3f3d
assert_has_file repo/tmp/cache/summaries/origin.sig
Packit Service 2a3f3d
cmp repo/tmp/cache/summaries/origin ${test_tmpdir}/ostree-srv/gnomerepo/summary.2 >&2
Packit Service 2a3f3d
cmp repo/tmp/cache/summaries/origin.sig ${test_tmpdir}/ostree-srv/gnomerepo/summary.sig.1 >&2
Packit Service 2a3f3d
${OSTREE} --repo=repo pull origin main
Packit Service 2a3f3d
assert_has_file repo/tmp/cache/summaries/origin
Packit Service 2a3f3d
assert_has_file repo/tmp/cache/summaries/origin.sig
Packit Service 2a3f3d
cmp repo/tmp/cache/summaries/origin ${test_tmpdir}/ostree-srv/gnomerepo/summary.1 >&2
Packit Service 2a3f3d
cmp repo/tmp/cache/summaries/origin.sig ${test_tmpdir}/ostree-srv/gnomerepo/summary.sig.1 >&2
Packit Service 2a3f3d
Packit Service 2a3f3d
# Publish new signature and check that subsequent pull succeeds
Packit Service 2a3f3d
cp ${test_tmpdir}/ostree-srv/gnomerepo/summary{.2,}
Packit Service 2a3f3d
cp ${test_tmpdir}/ostree-srv/gnomerepo/summary.sig{.2,}
Packit Service 2a3f3d
${OSTREE} --repo=repo pull origin main
Packit Service 2a3f3d
assert_has_file repo/tmp/cache/summaries/origin
Packit Service 2a3f3d
assert_has_file repo/tmp/cache/summaries/origin.sig
Packit Service 2a3f3d
cmp repo/tmp/cache/summaries/origin ${test_tmpdir}/ostree-srv/gnomerepo/summary.2 >&2
Packit Service 2a3f3d
cmp repo/tmp/cache/summaries/origin.sig ${test_tmpdir}/ostree-srv/gnomerepo/summary.sig.2 >&2
Packit Service 2a3f3d
Packit Service 2a3f3d
echo "ok pull with signed summary broken cache"