| 1 | #!/bin/sh |
| 2 | # Boot a root with target vpac installed and netbase available only in the embedded feed. |
| 3 | set -eu |
| 4 | export PATH=/bin:/usr/bin:/sbin:/usr/sbin LC_ALL=C HOME=/root |
| 5 | phase=identity |
| 6 | tls_server= |
| 7 | finish() { |
| 8 | status=$? |
| 9 | if [ -n "$tls_server" ]; then kill "$tls_server" 2>/dev/null || true; fi |
| 10 | if [ "$status" -ne 0 ]; then echo "VPAC TRANSACTION FAIL at $phase with status $status"; fi |
| 11 | /sbin/poweroff -f |
| 12 | } |
| 13 | trap finish EXIT |
| 14 | test "$(uname -o)" = Vinix |
| 15 | mkdir -p /tmp |
| 16 | vpac q -F name,validation local/musl >/tmp/musl |
| 17 | grep -Eq '^validation[[:space:]]+signature$' /tmp/musl |
| 18 | vpac o /bin/busybox | grep -q busybox |
| 19 | arch=$(uname -m) |
| 20 | package_command=${VPAC_TEST_PACKAGE_COMMAND:-vpac} |
| 21 | case "$package_command" in |
| 22 | vpac) ;; |
| 23 | pkg) vpac o /usr/bin/pkg | grep -q vinix-pkg ;; |
| 24 | *) echo "unknown test package command $package_command" >&2; exit 2 ;; |
| 25 | esac |
| 26 | |
| 27 | install_netbase() { |
| 28 | if [ "$package_command" = pkg ]; then |
| 29 | pkg install netbase |
| 30 | else |
| 31 | vpac i --noconfirm netbase |
| 32 | fi |
| 33 | } |
| 34 | |
| 35 | install_test() { |
| 36 | test ! -e /etc/services |
| 37 | set -- /var/lib/vinix/repository/"$arch"/netbase-[0-9]*.pkg.tar.zst |
| 38 | test "$#" -eq 1 && test -s "$1" |
| 39 | archive=$1 |
| 40 | |
| 41 | phase=reject |
| 42 | cp "$archive" /tmp/netbase-original |
| 43 | # Change the Zstd magic without changing the signed archive's byte count. |
| 44 | printf '\000' | dd of="$archive" bs=1 count=1 conv=notrunc 2>/dev/null |
| 45 | test "$(wc -c <"$archive")" = "$(wc -c </tmp/netbase-original)" |
| 46 | if cmp -s "$archive" /tmp/netbase-original; then exit 1; fi |
| 47 | status=0 |
| 48 | install_netbase >/tmp/reject.log 2>&1 || status=$? |
| 49 | cat /tmp/reject.log |
| 50 | test "$status" -ne 0 |
| 51 | grep -Fiq 'invalid or corrupted package (PGP signature)' /tmp/reject.log |
| 52 | test ! -e /etc/services |
| 53 | for record in /var/lib/vpac/local/netbase-*; do test ! -d "$record"; done |
| 54 | mv /tmp/netbase-original "$archive" |
| 55 | |
| 56 | phase=install |
| 57 | install_netbase |
| 58 | echo 'VPAC transaction installed authentic netbase' |
| 59 | phase=installed-ownership |
| 60 | vpac o /etc/services | grep -q netbase |
| 61 | phase=installed-record |
| 62 | vpac q -F name,validation local/netbase >/tmp/netbase |
| 63 | grep -Eq '^name[[:space:]]+netbase$' /tmp/netbase |
| 64 | grep -Eq '^validation[[:space:]]+signature$' /tmp/netbase |
| 65 | grep -Eq '^ssh[[:space:]]+22/tcp' /etc/services |
| 66 | |
| 67 | echo 'VPAC transaction verified installed owner and signature' |
| 68 | phase=remote-record |
| 69 | vpac q --noconfirm -F name,version vinix/netbase >/tmp/exact |
| 70 | grep -Eq '^name[[:space:]]+netbase$' /tmp/exact |
| 71 | echo 'VPAC transaction resolved the exact repository record' |
| 72 | phase=local-search |
| 73 | vpac s --noconfirm --local --quiet netbase >/tmp/local-names |
| 74 | grep -Fxq netbase /tmp/local-names |
| 75 | echo 'VPAC transaction searched installed packages' |
| 76 | phase=remote-search |
| 77 | vpac s --noconfirm --remote --quiet netbase >/tmp/remote-names |
| 78 | grep -Fxq netbase /tmp/remote-names |
| 79 | vpac s --noconfirm --remote --quiet vinix-fixture-absent-port >/tmp/unknown |
| 80 | test ! -s /tmp/unknown |
| 81 | |
| 82 | echo 'VPAC transaction verified package lookup' |
| 83 | } |
| 84 | |
| 85 | mode=${VPAC_TEST_SCENARIO:-all} |
| 86 | case "$mode" in |
| 87 | install) install_test; echo 'VPAC FIXTURE GUEST PASS'; exit 0 ;; |
| 88 | all) install_test ;; |
| 89 | upgrade) ;; |
| 90 | *) echo "unknown test scenario $mode" >&2; exit 2 ;; |
| 91 | esac |
| 92 | phase=upgrade |
| 93 | reference=/var/lib/vinix/test-update |
| 94 | test ! -e /etc/ssl1.1/cert.pem |
| 95 | vpac q -F version local/ca-certificates-bundle >/tmp/bundle |
| 96 | grep -Eq '^version[[:space:]]+20261020-2$' /tmp/bundle |
| 97 | if [ "${VPAC_TEST_UPGRADE_HTTPS:-0}" = 1 ]; then |
| 98 | phase=upgrade-https-setup |
| 99 | unset http_proxy https_proxy HTTP_PROXY HTTPS_PROXY ALL_PROXY SSL_CERT_FILE SSL_CERT_DIR |
| 100 | tls=$(mktemp -d /tmp/vpac-fixture-tls.XXXXXX) |
| 101 | openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:P-256 -nodes -days 1 \ |
| 102 | -subj /CN=127.0.0.1 -addext subjectAltName=IP:127.0.0.1 \ |
| 103 | -keyout "$tls/key.pem" -out "$tls/cert.pem" |
| 104 | ( |
| 105 | cd "$reference" |
| 106 | exec openssl s_server -accept 127.0.0.1:28443 -cert "$tls/cert.pem" -key "$tls/key.pem" -WWW |
| 107 | ) >"$tls/server.log" 2>&1 & |
| 108 | tls_server=$! |
| 109 | url=https://127.0.0.1:28443 |
| 110 | tries=0 |
| 111 | until curl --disable --noproxy '*' --fail --silent --show-error --max-time 5 \ |
| 112 | --cacert "$tls/cert.pem" "$url/vinix.db" -o "$tls/remote.db" >"$tls/client.log" 2>&1; do |
| 113 | tries=$((tries + 1)) |
| 114 | if [ "$tries" -ge 5 ]; then cat "$tls/client.log" "$tls/server.log"; exit 1; fi |
| 115 | sleep 1 |
| 116 | done |
| 117 | cmp "$reference/vinix.db" "$tls/remote.db" |
| 118 | trust_hash=$(openssl x509 -in "$tls/cert.pem" -noout -subject_hash) |
| 119 | cp "$tls/cert.pem" "/etc/ssl/certs/$trust_hash.0" |
| 120 | sed -i "s|file:///var/lib/vinix/repository/$arch|$url|" /etc/vpac.d/config.vile |
| 121 | grep -Fq "$url" /etc/vpac.d/config.vile |
| 122 | else |
| 123 | cp "$reference/"* "/var/lib/vinix/repository/$arch/" |
| 124 | fi |
| 125 | phase=upgrade |
| 126 | if [ "$package_command" = pkg ]; then |
| 127 | pkg upgrade |
| 128 | else |
| 129 | vpac u --sync --noconfirm |
| 130 | fi |
| 131 | phase=upgraded-record |
| 132 | vpac q -F version,validation local/ca-certificates-bundle >/tmp/upgraded |
| 133 | grep -Eq '^version[[:space:]]+20261020-3$' /tmp/upgraded |
| 134 | grep -Eq '^validation[[:space:]]+signature$' /tmp/upgraded |
| 135 | test ! -d /var/lib/vpac/local/ca-certificates-bundle-20261020-2 |
| 136 | phase=upgraded-files |
| 137 | test "$(readlink /etc/ssl1.1/cert.pem)" = ../ssl/cert.pem |
| 138 | cmp /etc/ssl1.1/cert.pem /etc/ssl/certs/ca-certificates.crt |
| 139 | vpac o /etc/ssl1.1/cert.pem | grep -q ca-certificates-bundle |
| 140 | if [ "${VPAC_TEST_UPGRADE_HTTPS:-0}" = 1 ]; then |
| 141 | echo 'VPAC upgraded a signed package over HTTPS' |
| 142 | fi |
| 143 | echo 'VPAC FIXTURE GUEST PASS' |
| 144 | |