70 lines
1.6 KiB
Bash
Executable File
70 lines
1.6 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# exit immediately if any command returns non-zero exit code
|
|
set -e
|
|
|
|
# print commands as they are executed by the shell interpreter
|
|
set -x
|
|
|
|
# global constants
|
|
HOST="localhost"
|
|
PORT="1234"
|
|
PKEY="./pkey.pem"
|
|
CERT="./cert.pem"
|
|
CURL_OUT="./curl.out"
|
|
CURL_ERR="./curl.err"
|
|
NGHTTP_OUT="./nghttp.out"
|
|
NGHTTP_ERR="./nghttp.err"
|
|
SELF="./runtest.sh"
|
|
URL="https://${HOST}:${PORT}/${SELF}"
|
|
|
|
# print versions of related pkgs
|
|
PKGS="$(set +x; eval echo {lib,}curl {lib,}nghttp2 openssl{,-libs})"
|
|
rpm -q $PKGS | sort -V
|
|
rpm -V $PKGS
|
|
|
|
# print full path of used commands
|
|
(set +x
|
|
for i in curl nghttp{,d} openssl; do
|
|
(set -x; command -v $i)
|
|
done
|
|
)
|
|
|
|
# make sure that $SELF exists
|
|
pwd
|
|
file -E $SELF
|
|
|
|
# create a self-signed certificate
|
|
openssl req -x509 -newkey rsa:4096 -sha256 -days 3650 \
|
|
-subj /CN=${HOST} -addext subjectAltName=DNS:${HOST} \
|
|
-nodes -keyout $PKEY -out $CERT
|
|
|
|
# run nghttpd in the background
|
|
nghttpd -d "$PWD" $PORT $PKEY $CERT &
|
|
NGHTTPD_PID=$!
|
|
|
|
# FIXME: wait for open port instead
|
|
sleep 2
|
|
|
|
# transfer the contents of this script over HTTP/2 using curl
|
|
curl --cacert $CERT --fail --silent --verbose $URL \
|
|
> $CURL_OUT 2> $CURL_ERR
|
|
|
|
# check whether the received data matches the original contents
|
|
diff $SELF $CURL_OUT
|
|
|
|
# check that we made a successful HTTP/2 request with curl
|
|
grep '^< HTTP/2 200' $CURL_ERR
|
|
|
|
# transfer the contents of this script over HTTP/2 using nghttp
|
|
nghttp $URL > $NGHTTP_OUT
|
|
|
|
# check whether the received data matches the original contents
|
|
diff $SELF $NGHTTP_OUT
|
|
|
|
# kill nghttpd running in the background
|
|
kill $NGHTTPD_PID
|
|
|
|
# wait till the background process finishes
|
|
wait
|