Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/pkg
Path: blob/main/tests/frontend/http.sh
2065 views
1
#! /usr/bin/env atf-sh
2
3
. $(atf_get_srcdir)/test_environment.sh
4
5
CLEANUP="simple_fetch simple_repo simple_audit"
6
7
tests_init \
8
simple_fetch \
9
simple_repo \
10
simple_audit
11
12
13
httpd_startup() {
14
pidfile=${TMPDIR}/http.pid
15
statusfile=${TMPDIR}/http.status
16
: > ${pidfile}
17
: > ${statusfile}
18
19
DIR=$1
20
python3 -u -m http.server -d "${DIR}" --bind 127.0.0.1 0 > ${statusfile} &
21
jobs -p %1 > ${pidfile}
22
# a crude way to wait for its startup, I can't think of anything better
23
while kill -s 0 %1 && ! [ -s ${statusfile} ]; do
24
sleep .1
25
done
26
url=$(sed -n 's#.*(\(http://.*\)/).*#\1#p' ${statusfile})
27
atf_check test -n "${url}"
28
}
29
30
httpd_cleanup() {
31
pid=$(cat ${TMPDIR}/http.pid)
32
if [ -z "${pid}" ]; then
33
return 1
34
fi
35
if kill -s 0 ${pid}; then
36
kill -s INT ${pid}
37
for i in 0 1 2 3 4 5 6 7 8 9; do
38
if ! kill -s 0 ${pid}; then
39
break
40
fi
41
done
42
fi
43
}
44
45
simple_repo_body()
46
{
47
atf_require python3 "Requires python3 to run this test"
48
atf_check sh ${RESOURCEDIR}/test_subr.sh new_pkg test test 1
49
atf_check pkg create -M test.ucl
50
mkdir repo
51
mv test-1.txz test-1.pkg repo/
52
atf_check -o ignore pkg repo repo
53
54
httpd_startup ${TMPDIR}/repo
55
56
cat > pkg.conf << EOF
57
PKG_DBDIR=${TMPDIR}
58
PKG_CACHEDIR=${TMPDIR}/cache
59
REPOS_DIR=[]
60
repositories: {
61
local: { url: ${url} }
62
}
63
EOF
64
atf_check -o ignore \
65
pkg -C ./pkg.conf update
66
atf_check -o match:"Installing test-1" \
67
pkg -C ./pkg.conf install -y test
68
}
69
70
simple_repo_cleanup()
71
{
72
httpd_cleanup
73
}
74
75
simple_fetch_body()
76
{
77
atf_require python3 "Requires python3 to run this test"
78
atf_check sh ${RESOURCEDIR}/test_subr.sh new_pkg test test 1
79
atf_check pkg create -M test.ucl
80
mkdir repo
81
mv test-1.txz test-1.pkg repo/
82
atf_check -o ignore pkg repo repo
83
84
httpd_startup ${TMPDIR}/repo
85
86
cat > pkg.conf << EOF
87
PKG_DBDIR=${TMPDIR}
88
PKG_CACHEDIR=${TMPDIR}/cache
89
REPOS_DIR=[]
90
repositories: {
91
local: { url: ${url} }
92
}
93
EOF
94
atf_check -o ignore \
95
pkg -C ./pkg.conf update
96
atf_check -o match:"test-1" \
97
pkg -C ./pkg.conf fetch -y test
98
}
99
100
simple_fetch_cleanup()
101
{
102
httpd_cleanup
103
}
104
105
simple_audit_body()
106
{
107
atf_require python3 "Requires python3 to run this test"
108
109
mkdir rootdir
110
cat > ${TMPDIR}/rootdir/meh <<EOF
111
<?xml version="1.0" encoding="utf-8"?>
112
<vuxml xmlns="http://www.vuxml.org/apps/vuxml-1">
113
</vuxml>
114
EOF
115
bzip2 ${TMPDIR}/rootdir/meh
116
117
httpd_startup ${TMPDIR}/rootdir
118
119
cat > pkg.conf << EOF
120
PKG_DBDIR=${TMPDIR}
121
VULNXML_SITE = "${url}/meh.bz2"
122
EOF
123
124
atf_check -o ignore pkg -C ./pkg.conf audit -F
125
126
}
127
simple_audit_cleanup()
128
{
129
httpd_cleanup
130
}
131
132