vinix-ports / tests / userland / network.sh
66 lines · 61 sloc · 2.49 KB · f26bf8bdfbef57feec518b71ceecad6f71289275
Raw
1#!/bin/sh
2# BusyBox starts this script as the signed network packages' guest smoke test.
3set -eu
4export PATH=/bin:/usr/bin:/sbin:/usr/sbin HOME=/tmp TERM=dumb LC_ALL=C
5phase=identity
6server=
7finish() {
8 status=$?
9 if [ -n "$server" ]; then kill "$server" 2>/dev/null || true; fi
10 if [ "$status" -ne 0 ]; then echo "VPAC NETWORK FAIL at $phase with status $status"; fi
11 /sbin/poweroff -f
12}
13trap finish EXIT
14test "$(uname -o)" = Vinix
15mkdir -p /tmp/network
16cd /tmp/network
17
18phase=trust
19openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:P-256 -nodes -days 1 \
20 -subj /CN=vinix.test -addext subjectAltName=DNS:vinix.test -keyout key.pem -out cert.pem
21mkdir -p /usr/local/share/ca-certificates
22cp cert.pem /usr/local/share/ca-certificates/vinix-fixture.crt
23update-ca-certificates
24openssl verify -CAfile /etc/ssl/cert.pem cert.pem
25openssl verify -no-CAfile -no-CAstore -CApath /etc/ssl/certs cert.pem
26
27phase=https
28openssl s_server -accept 127.0.0.1:2443 -cert cert.pem -key key.pem -www >tls.log 2>&1 &
29server=$!
30curl --disable --noproxy '*' --retry 5 --retry-connrefused --max-time 8 --silent --show-error \
31 --resolve vinix.test:2443:127.0.0.1 https://vinix.test:2443/ -o page
32grep -qi '<html>' page
33status=0
34curl --disable --noproxy '*' --max-time 5 --silent --show-error --resolve wrong.test:2443:127.0.0.1 \
35 https://wrong.test:2443/ -o wrong || status=$?
36test "$status" -eq 60
37kill "$server"
38wait "$server" || true
39server=
40
41phase=git
42git init -q repo
43printf '%s\n' 'Vinix source ports' >repo/note
44git -C repo add note
45git -C repo -c user.name=Vinix -c user.email=ports@example.invalid commit -qm fixture
46test "$(git -C repo show HEAD:note)" = 'Vinix source ports'
47git -C repo grep -q -P '(?=source)source'
48
49phase=ssh
50ssh-keygen -q -t ed25519 -N '' -f ssh-key
51ssh-keygen -Y sign -f ssh-key -n vinix repo/note
52printf 'builder %s\n' "$(cat ssh-key.pub)" >signers
53ssh-keygen -Y verify -f signers -I builder -n vinix -s repo/note.sig <repo/note
54
55phase=xbps
56arch=$(xbps-uhelper arch)
57test "$arch" = "$(uname -m)-musl"
58mkdir payload client conf
59cp repo/note payload/note
60xbps-create -A "$arch" -n vinix-test-1.0_1 -s 'Vinix fixture' payload
61xbps-rindex -a "vinix-test-1.0_1.$arch.xbps"
62test "$(xbps-query -r "$PWD/client" -C "$PWD/conf" --repository="$PWD" -R -p pkgver vinix-test)" = vinix-test-1.0_1
63xbps-install -y -r "$PWD/client" -C "$PWD/conf" --repository="$PWD" vinix-test
64cmp payload/note client/note
65test "$(xbps-query -r "$PWD/client" -C "$PWD/conf" -p pkgver vinix-test)" = vinix-test-1.0_1
66echo 'VPAC FIXTURE GUEST PASS'
67