vinix-ports / tests / userland / vpac.sh
110 lines · 103 sloc · 3.91 KB
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)
18package_command=${VPAC_TEST_PACKAGE_COMMAND:-vpac}
19case "$package_command" in
20 vpac) ;;
21 pkg) vpac o /usr/bin/pkg | grep -q vinix-pkg ;;
22 *) echo "unknown test package command $package_command" >&2; exit 2 ;;
23esac
24
25install_netbase() {
26 if [ "$package_command" = pkg ]; then
27 pkg install netbase
28 else
29 vpac i --noconfirm netbase
30 fi
31}
32
33install_test() {
34 test ! -e /etc/services
35 set -- /var/lib/vinix/repository/"$arch"/netbase-[0-9]*.pkg.tar.zst
36 test "$#" -eq 1 && test -s "$1"
37 archive=$1
38
39 phase=reject
40 cp "$archive" /tmp/netbase-original
41 # Change the Zstd magic without changing the signed archive's byte count.
42 printf '\000' | dd of="$archive" bs=1 count=1 conv=notrunc 2>/dev/null
43 test "$(wc -c <"$archive")" = "$(wc -c </tmp/netbase-original)"
44 if cmp -s "$archive" /tmp/netbase-original; then exit 1; fi
45 status=0
46 install_netbase >/tmp/reject.log 2>&1 || status=$?
47 cat /tmp/reject.log
48 test "$status" -ne 0
49 grep -Fiq 'invalid or corrupted package (PGP signature)' /tmp/reject.log
50 test ! -e /etc/services
51 for record in /var/lib/vpac/local/netbase-*; do test ! -d "$record"; done
52 mv /tmp/netbase-original "$archive"
53
54 phase=install
55 install_netbase
56 echo 'VPAC transaction installed authentic netbase'
57 phase=installed-ownership
58 vpac o /etc/services | grep -q netbase
59 phase=installed-record
60 vpac q -F name,validation local/netbase >/tmp/netbase
61 grep -Eq '^name[[:space:]]+netbase$' /tmp/netbase
62 grep -Eq '^validation[[:space:]]+signature$' /tmp/netbase
63 grep -Eq '^ssh[[:space:]]+22/tcp' /etc/services
64
65 echo 'VPAC transaction verified installed owner and signature'
66 phase=remote-record
67 vpac q --noconfirm -F name,version vinix/netbase >/tmp/exact
68 grep -Eq '^name[[:space:]]+netbase$' /tmp/exact
69 echo 'VPAC transaction resolved the exact repository record'
70 phase=local-search
71 vpac s --noconfirm --local --quiet netbase >/tmp/local-names
72 grep -Fxq netbase /tmp/local-names
73 echo 'VPAC transaction searched installed packages'
74 phase=remote-search
75 vpac s --noconfirm --remote --quiet netbase >/tmp/remote-names
76 grep -Fxq netbase /tmp/remote-names
77 vpac s --noconfirm --remote --quiet vinix-fixture-absent-port >/tmp/unknown
78 test ! -s /tmp/unknown
79
80 echo 'VPAC transaction verified package lookup'
81}
82
83mode=${VPAC_TEST_SCENARIO:-all}
84case "$mode" in
85 install) install_test; echo 'VPAC FIXTURE GUEST PASS'; exit 0 ;;
86 all) install_test ;;
87 upgrade) ;;
88 *) echo "unknown test scenario $mode" >&2; exit 2 ;;
89esac
90phase=upgrade
91reference=/var/lib/vinix/test-update
92test ! -e /etc/ssl1.1/cert.pem
93vpac q -F version local/ca-certificates-bundle >/tmp/bundle
94grep -Eq '^version[[:space:]]+20261020-2$' /tmp/bundle
95cp "$reference/"* "/var/lib/vinix/repository/$arch/"
96if [ "$package_command" = pkg ]; then
97 pkg upgrade
98else
99 vpac u --sync --noconfirm
100fi
101phase=upgraded-record
102vpac q -F version,validation local/ca-certificates-bundle >/tmp/upgraded
103grep -Eq '^version[[:space:]]+20261020-3$' /tmp/upgraded
104grep -Eq '^validation[[:space:]]+signature$' /tmp/upgraded
105test ! -d /var/lib/vpac/local/ca-certificates-bundle-20261020-2
106phase=upgraded-files
107test "$(readlink /etc/ssl1.1/cert.pem)" = ../ssl/cert.pem
108cmp /etc/ssl1.1/cert.pem /etc/ssl/certs/ca-certificates.crt
109vpac o /etc/ssl1.1/cert.pem | grep -q ca-certificates-bundle
110echo 'VPAC FIXTURE GUEST PASS'
111