|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -e |
| 4 | + |
| 5 | +cd "${BASH_SOURCE%/*}/.." |
| 6 | + |
| 7 | +fail() { |
| 8 | + echo "$1" >&2 |
| 9 | + exit 1 |
| 10 | +} |
| 11 | + |
| 12 | +write_meta() { |
| 13 | + cat > binaries/3.14.0-ubuntu-24.04-x86_64.meta <<EOF |
| 14 | +# pyenv-binary metadata |
| 15 | +version=3.14.0 |
| 16 | +os=Linux |
| 17 | +arch=x86_64 |
| 18 | +platform=linux-x86_64 |
| 19 | +distro=ubuntu 24.04 |
| 20 | +libc=glibc 2.39 |
| 21 | +build_prefix=/tmp/pyenv/versions/3.14.0-ubuntu-24.04-x86_64 |
| 22 | +archive=$1 |
| 23 | +EOF |
| 24 | +} |
| 25 | + |
| 26 | +tmpdir="$(mktemp -d)" |
| 27 | +trap 'rm -rf "$tmpdir"' EXIT |
| 28 | + |
| 29 | +cp update.sh index.html "$tmpdir" |
| 30 | +mkdir "$tmpdir/binaries" |
| 31 | +printf archive-data > "$tmpdir/binaries/3.14.0-ubuntu-24.04-x86_64.tar.gz" |
| 32 | +printf definition > "$tmpdir/binaries/3.14.0-ubuntu-24.04-x86_64" |
| 33 | + |
| 34 | +cd "$tmpdir" |
| 35 | +write_meta 3.14.0-ubuntu-24.04-x86_64.tar.gz |
| 36 | +bash ./update.sh >/dev/null 2>&1 || fail "update failed" |
| 37 | + |
| 38 | +sha=8a6111c3ca752ed6d5f8e8a6daa3ba4b8c3b0bf55f00a87ac2b285024ef87e5f |
| 39 | +[ "binaries/3.14.0-ubuntu-24.04-x86_64.tar.gz" -ef "$sha" ] || |
| 40 | + fail "checksum path is not a hardlink to the archive" |
| 41 | + |
| 42 | +entry='<li><a href="binaries/3.14.0-ubuntu-24.04-x86_64.tar.gz">3.14.0-ubuntu-24.04-x86_64.tar.gz</a> (<a href="binaries/3.14.0-ubuntu-24.04-x86_64">definition</a>)</li>' |
| 43 | +grep -Fqx "$entry" index.html || fail "prebuilt archive is missing from index.html" |
| 44 | + |
| 45 | +cp index.html index.before |
| 46 | +bash ./update.sh >/dev/null 2>&1 || fail "second update failed" |
| 47 | +cmp -s index.before index.html || fail "second update changed index.html" |
| 48 | +[ "$(grep -Fxc "$entry" index.html)" -eq 1 ] || fail "prebuilt archive is listed more than once" |
| 49 | + |
| 50 | +bad_name=$'bad\nname' |
| 51 | +printf 'archive=bad\narchive=name.tar.gz\n' > "binaries/$bad_name.meta" |
| 52 | +printf archive-data > "binaries/$bad_name.tar.gz" |
| 53 | +printf definition > "binaries/$bad_name" |
| 54 | +rm "$sha" |
| 55 | +if output="$(bash ./update.sh 2>&1)"; then |
| 56 | + fail "update accepted a control character in an archive name" |
| 57 | +fi |
| 58 | +case "$output" in |
| 59 | +*"Invalid archive name in binaries/"*) ;; |
| 60 | +*) fail "update did not reject the invalid archive name during validation" ;; |
| 61 | +esac |
| 62 | +[ ! -e "$sha" ] || fail "update created a checksum link before name validation completed" |
| 63 | +rm "binaries/$bad_name.meta" "binaries/$bad_name.tar.gz" "binaries/$bad_name" |
| 64 | + |
| 65 | +mkdir source |
| 66 | +printf source-data > source/example.tar.gz |
| 67 | +printf '<li><a href="">example.tar.gz</a></li>\n' >> index.html |
| 68 | +cp index.html index.before |
| 69 | +cp binaries/3.14.0-ubuntu-24.04-x86_64.meta binaries/z-invalid.meta |
| 70 | +sed -i 's/^archive=.*/archive=invalid.tar.gz/' binaries/z-invalid.meta |
| 71 | +if bash ./update.sh >/dev/null 2>&1; then |
| 72 | + fail "update accepted invalid metadata" |
| 73 | +fi |
| 74 | +[ ! -e "$sha" ] || fail "update created a binary checksum link before validation completed" |
| 75 | +source_sha=6bb69d845f4a714ca982e2903d2c03fabeb2448b67185bca413d3efddea9397c |
| 76 | +[ ! -e "$source_sha" ] || fail "update created a source checksum link before validation completed" |
| 77 | +cmp -s index.before index.html || fail "update changed index.html before validation completed" |
| 78 | +rm -rf source binaries/z-invalid.meta |
| 79 | + |
| 80 | +write_meta ../outside.tar.gz |
| 81 | +printf outside > outside.tar.gz |
| 82 | +if bash ./update.sh >/dev/null 2>&1; then |
| 83 | + fail "update accepted an archive outside binaries" |
| 84 | +fi |
| 85 | + |
| 86 | +write_meta 3.14.0-ubuntu-24.04-x86_64.tar.gz |
| 87 | +rm binaries/3.14.0-ubuntu-24.04-x86_64 |
| 88 | +if bash ./update.sh >/dev/null 2>&1; then |
| 89 | + fail "update accepted a missing definition" |
| 90 | +fi |
| 91 | + |
| 92 | +printf definition > binaries/3.14.0-ubuntu-24.04-x86_64 |
| 93 | +rm binaries/3.14.0-ubuntu-24.04-x86_64.tar.gz |
| 94 | +if bash ./update.sh >/dev/null 2>&1; then |
| 95 | + fail "update accepted a missing archive" |
| 96 | +fi |
| 97 | + |
| 98 | +echo "ok" |
0 commit comments