vinix-ports / tests / userland / vpac.sh
91 lines · 86 sloc · 3.51 KB · f98dcf28a458c2e1c6e7a36657c62fe25a86cd41
Raw
1#!/bin/sh
2# Boot a root with target vpac installed and netbase available only in the embedded feed.
3set -eu
4export PATH=/bin:/usr/bin:/sbin:/usr/sbin LC_ALL=C HOME=/root
5phase=identity
6finish() {
7 status=$?
8 if [ "$status" -ne 0 ]; then echo "VPAC TRANSACTION FAIL at $phase with status $status"; fi
9 /sbin/poweroff -f
10}
11trap finish EXIT
12test "$(uname -o)" = Vinix
13mkdir -p /tmp
14vpac q -F name,validation local/musl >/tmp/musl
15grep -Eq '^validation[[:space:]]+signature$' /tmp/musl
16vpac o /bin/busybox | grep -q busybox
17arch=$(uname -m)
18install_test() {
19 test ! -e /etc/services
20 set -- /var/lib/vinix/repository/"$arch"/netbase-[0-9]*.pkg.tar.zst
21 test "$#" -eq 1 && test -s "$1"
22 archive=$1
23
24 phase=reject
25 cp "$archive" /tmp/netbase-original
26 # Change the Zstd magic without changing the signed archive's byte count.
27 printf '\000' | dd of="$archive" bs=1 count=1 conv=notrunc 2>/dev/null
28 test "$(wc -c <"$archive")" = "$(wc -c </tmp/netbase-original)"
29 if cmp -s "$archive" /tmp/netbase-original; then exit 1; fi
30 status=0
31 vpac i --noconfirm netbase >/tmp/reject.log 2>&1 || status=$?
32 cat /tmp/reject.log
33 test "$status" -ne 0
34 grep -Fiq 'invalid or corrupted package (PGP signature)' /tmp/reject.log
35 test ! -e /etc/services
36 for record in /var/lib/vpac/local/netbase-*; do test ! -d "$record"; done
37 mv /tmp/netbase-original "$archive"
38
39 phase=install
40 vpac i --noconfirm netbase
41 echo 'VPAC transaction installed authentic netbase'
42 phase=installed-ownership
43 vpac o /etc/services | grep -q netbase
44 phase=installed-record
45 vpac q -F name,validation local/netbase >/tmp/netbase
46 grep -Eq '^name[[:space:]]+netbase$' /tmp/netbase
47 grep -Eq '^validation[[:space:]]+signature$' /tmp/netbase
48 grep -Eq '^ssh[[:space:]]+22/tcp' /etc/services
49
50 echo 'VPAC transaction verified installed owner and signature'
51 phase=remote-record
52 vpac q --noconfirm -F name,version vinix/netbase >/tmp/exact
53 grep -Eq '^name[[:space:]]+netbase$' /tmp/exact
54 echo 'VPAC transaction resolved the exact repository record'
55 phase=local-search
56 vpac s --noconfirm --local --quiet netbase >/tmp/local-names
57 grep -Fxq netbase /tmp/local-names
58 echo 'VPAC transaction searched installed packages'
59 phase=remote-search
60 vpac s --noconfirm --remote --quiet netbase >/tmp/remote-names
61 grep -Fxq netbase /tmp/remote-names
62 vpac s --noconfirm --remote --quiet vinix-fixture-absent-port >/tmp/unknown
63 test ! -s /tmp/unknown
64
65 echo 'VPAC transaction verified package lookup'
66}
67
68mode=${VPAC_TEST_SCENARIO:-all}
69case "$mode" in
70 install) install_test; echo 'VPAC FIXTURE GUEST PASS'; exit 0 ;;
71 all) install_test ;;
72 upgrade) ;;
73 *) echo "unknown test scenario $mode" >&2; exit 2 ;;
74esac
75phase=upgrade
76reference=/var/lib/vinix/test-update
77test ! -e /etc/ssl1.1/cert.pem
78vpac q -F version local/ca-certificates-bundle >/tmp/bundle
79grep -Eq '^version[[:space:]]+20261020-2$' /tmp/bundle
80cp "$reference/"* "/var/lib/vinix/repository/$arch/"
81vpac u --sync --noconfirm
82phase=upgraded-record
83vpac q -F version,validation local/ca-certificates-bundle >/tmp/upgraded
84grep -Eq '^version[[:space:]]+20261020-3$' /tmp/upgraded
85grep -Eq '^validation[[:space:]]+signature$' /tmp/upgraded
86test ! -d /var/lib/vpac/local/ca-certificates-bundle-20261020-2
87phase=upgraded-files
88test "$(readlink /etc/ssl1.1/cert.pem)" = ../ssl/cert.pem
89cmp /etc/ssl1.1/cert.pem /etc/ssl/certs/ca-certificates.crt
90vpac o /etc/ssl1.1/cert.pem | grep -q ca-certificates-bundle
91echo 'VPAC FIXTURE GUEST PASS'
92