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

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