2014-08-01 02:50:19 +04:00
#!/bin/bash
#
# Copyright (C) 2014 Colin Walters <walters@verbum.org>
#
2018-01-30 22:26:26 +03:00
# SPDX-License-Identifier: LGPL-2.0+
#
2014-08-01 02:50:19 +04:00
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
2021-12-07 04:20:55 +03:00
# License along with this library. If not, see <https://www.gnu.org/licenses/>.
2014-08-01 02:50:19 +04:00
2016-01-27 19:44:10 +03:00
set -euo pipefail
2014-08-01 02:50:19 +04:00
. $( dirname $0 ) /libtest.sh
2023-09-19 22:25:36 +03:00
if test -z " ${ OSTREE_HTTPD } " ; then
echo "1..0 #SKIP no ostree-trivial-httpd"
exit 0
fi
2017-09-01 23:15:33 +03:00
setup_fake_remote_repo1 "archive"
2014-08-01 02:50:19 +04:00
2016-03-02 18:28:04 +03:00
echo '1..9'
2014-08-01 02:50:19 +04:00
# And another web server acting as the metalink server
cd ${ test_tmpdir }
mkdir metalink-data
cd metalink-data
2016-12-30 22:18:34 +03:00
${ OSTREE_HTTPD } --autoexit --daemonize -p ${ test_tmpdir } /metalink-httpd-port
2014-08-01 02:50:19 +04:00
metalink_port = $( cat ${ test_tmpdir } /metalink-httpd-port)
echo " http://127.0.0.1: ${ metalink_port } " > ${ test_tmpdir } /metalink-httpd-address
2015-11-09 15:03:35 +03:00
${ CMD_PREFIX } ostree --repo= ${ test_tmpdir } /ostree-srv/gnomerepo summary -u
2014-08-01 02:50:19 +04:00
summary_path = ${ test_tmpdir } /ostree-srv/gnomerepo/summary
echo -n broken > ${ summary_path } .bad
cd ${ test_tmpdir }
2015-06-16 04:09:37 +03:00
cat > metalink-valid-summary.xml <<EOF
2014-08-01 02:50:19 +04:00
<file name = "summary" >
<size>$( stat -c '%s' ${ summary_path } ) </size>
<verification>
<hash type = "md5" >$( md5sum ${ summary_path } | cut -f 1 -d ' ' ) </hash>
<hash type = "sha256" >$( sha256sum ${ summary_path } | cut -f 1 -d ' ' ) </hash>
<hash type = "sha512" >$( sha512sum ${ summary_path } | cut -f 1 -d ' ' ) </hash>
</verification>
<resources maxconnections = "1" >
<url protocol = "http" type = "http" location = "US" preference = "100" >$( cat httpd-address) /ostree/gnomerepo/summary.bad</url>
<url protocol = "http" type = "http" location = "US" preference = "99" >$( cat httpd-address) /ostree/gnomerepo/nosuchfile</url>
<url protocol = "http" type = "http" location = "US" preference = "98" >$( cat httpd-address) /ostree/gnomerepo/summary</url>
</resources>
</file>
2015-06-16 04:09:37 +03:00
EOF
cat > ${ test_tmpdir } /metalink-data/metalink.xml <<EOF
<?xml version = "1.0" encoding = "utf-8" ?>
<metalink version = "3.0" xmlns = "http://www.metalinker.org/" >
<files>
$( cat metalink-valid-summary.xml)
2014-08-01 02:50:19 +04:00
</files>
</metalink>
EOF
cd ${ test_tmpdir }
mkdir repo
2017-03-24 17:35:59 +03:00
ostree_repo_init repo
2014-08-01 02:50:19 +04:00
${ CMD_PREFIX } ostree --repo= repo remote add --set= gpg-verify= false origin metalink = $( cat metalink-httpd-address) /metalink.xml
${ CMD_PREFIX } ostree --repo= repo pull origin:main
${ CMD_PREFIX } ostree --repo= repo rev-parse origin:main
${ CMD_PREFIX } ostree --repo= repo fsck
echo "ok pull via metalink"
2015-06-07 22:20:14 +03:00
# Test fetching the summary through ostree_repo_remote_fetch_summary()
${ CMD_PREFIX } ostree --repo= repo remote refs origin > origin_refs
assert_file_has_content origin_refs "main"
echo "ok remote refs via metalink"
2014-08-01 02:50:19 +04:00
cp metalink-data/metalink.xml{ ,.orig}
cp ostree-srv/gnomerepo/summary{ ,.orig}
test_metalink_pull_error( ) {
msg = $1
rm repo -rf
mkdir repo
2017-03-24 17:35:59 +03:00
ostree_repo_init repo
2014-08-01 02:50:19 +04:00
${ CMD_PREFIX } ostree --repo= repo remote add --set= gpg-verify= false origin metalink = $( cat metalink-httpd-address) /metalink.xml
if ${ CMD_PREFIX } ostree --repo= repo pull origin:main 2>err.txt; then
assert_not_reached "pull unexpectedly succeeded"
fi
assert_file_has_content err.txt " ${ msg } "
}
cd ${ test_tmpdir }
sed -e 's,<hash type="sha512">.*</hash>,<hash type="sha512">bacon</hash>,' < metalink-data/metalink.xml.orig > metalink-data/metalink.xml
test_metalink_pull_error "Invalid hash digest for sha512"
echo "ok metalink err hash format"
cd ${ test_tmpdir }
sed -e 's,<hash type="sha512">.*</hash>,<hash type="sha512">' $( ( echo -n dummy; cat ${ summary_path } ) | sha512sum | cut -f 1 -d ' ' ) '</hash>,' < metalink-data/metalink.xml.orig > metalink-data/metalink.xml
test_metalink_pull_error "Expected checksum is .* but actual is"
echo "ok metalink err hash sha512"
cd ${ test_tmpdir }
cp metalink-data/metalink.xml.orig metalink-data/metalink.xml
echo -n moo > ostree-srv/gnomerepo/summary
test_metalink_pull_error "Expected size is .* bytes but content is 3 bytes"
echo "ok metalink err size"
cp ostree-srv/gnomerepo/summary{ .orig,}
cd ${ test_tmpdir }
grep -v sha256 < metalink-data/metalink.xml.orig | grep -v sha512 > metalink-data/metalink.xml
test_metalink_pull_error "No.*verification.*with known.*hash"
echo "ok metalink err no verify"
cd ${ test_tmpdir }
grep -v '<url protocol' < metalink-data/metalink.xml.orig > metalink-data/metalink.xml
test_metalink_pull_error "No.*url.*method.*elements"
echo "ok metalink err no url"
cd ${ test_tmpdir }
echo bacon > metalink-data/metalink.xml
test_metalink_pull_error "Document must begin with an element"
echo "ok metalink err malformed"
2015-06-16 04:09:37 +03:00
cat > ${ test_tmpdir } /metalink-data/metalink.xml <<EOF
<?xml version = "1.0" encoding = "utf-8" ?>
<metalink version = "3.0" xmlns = "http://www.metalinker.org/" >
<deeply>
<nested>
<unknown>
<data>
hello world
</data>
</unknown>
</nested>
</deeply>
<files>
$( cat metalink-valid-summary.xml)
</files>
<deeply>
<nested>
<unknown>
<data>
hello world
</data>
</unknown>
</nested>
</deeply>
</metalink>
EOF
cd ${ test_tmpdir }
rm repo -rf
mkdir repo
2017-03-24 17:35:59 +03:00
ostree_repo_init repo
2015-06-16 04:09:37 +03:00
${ CMD_PREFIX } ostree --repo= repo remote add --set= gpg-verify= false origin metalink = $( cat metalink-httpd-address) /metalink.xml
${ CMD_PREFIX } ostree --repo= repo pull origin:main
${ CMD_PREFIX } ostree --repo= repo rev-parse origin:main
${ CMD_PREFIX } ostree --repo= repo fsck
echo "ok pull via metalink with nested data"