131 lines
3.3 KiB
Bash
131 lines
3.3 KiB
Bash
# Copyright 2026 The Forgejo Authors
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
PROXYPROTO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
proxyproto_test_basic() {
|
|
local home="$(curl -s "http://localhost:3001")"
|
|
if ! grep -q "Forgejo" <<< "$home"; then
|
|
echo "[PROXY v1] Forgejo homepage not found"
|
|
exit 1
|
|
fi
|
|
|
|
local home="$(curl -s "http://localhost:3002")"
|
|
if ! grep -q "Forgejo" <<< "$home"; then
|
|
echo "[PROXY v2] Forgejo homepage not found"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
check_bombardier_output() {
|
|
[[ -z "$1" || -z "$2" ]] && exit 1
|
|
|
|
if [[ "$(jq '.result.req5xx' <<< "$2")" > 10 ]]; then
|
|
echo "[$1] more than 10 requests failed"
|
|
exit 1
|
|
fi
|
|
|
|
# The 5000 is kind of chose arbitrarily to make sure some requests pass
|
|
if [[ "$(jq '.result.req2xx' <<< "$2")" -lt 5000 ]]; then
|
|
echo "[$1] les than 5000 requests were made in 10 seconds"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
proxyproto_test_bombardier() {
|
|
local res="$(bombardier -p r -o j http://localhost:3001)"
|
|
check_bombardier_output "PROXY v1" "$res" || exit 1
|
|
|
|
local res="$(bombardier -p r -o j http://localhost:3002)"
|
|
check_bombardier_output "PROXY v2" "$res" || exit 1
|
|
}
|
|
|
|
check_repo_readme() {
|
|
[[ -z "$1" || -z "$2" ]] && exit 1
|
|
|
|
out="$(curl -s "$1")"
|
|
grep -q "$2" <<< "$out" || exit 1
|
|
}
|
|
|
|
proxyproto_push_http() {
|
|
forgejo_tmp="$(mktemp -d)"
|
|
"$CURL" api_json \
|
|
--data '{"name":"repo","auto_init":true}' \
|
|
"http://$V1_HOST_PORT/api/v1/user/repos" > "$forgejo_tmp/one-repo.json"
|
|
|
|
rm -rf "$DIR/repo"
|
|
mkdir -p "$DIR/repo"
|
|
|
|
(
|
|
cd "$DIR/repo"
|
|
|
|
git init
|
|
git checkout -b main
|
|
|
|
git config user.email "$FORGEJO_USER@example.com"
|
|
git config user.name "$FORGEJO_USER"
|
|
|
|
echo "frog!" > README
|
|
git add README
|
|
git commit -m 'PROXY v1'
|
|
|
|
git push -f "http://$FORGEJO_USER:$FORGEJO_PASSWORD@localhost:3001/$FORGEJO_USER/repo" main
|
|
check_repo_readme "http://localhost:3001/$FORGEJO_USER/repo" "frog!"
|
|
|
|
echo "frog2!" > README
|
|
git add README
|
|
git commit -m 'PROXY v2'
|
|
|
|
git push -f "http://$FORGEJO_USER:$FORGEJO_PASSWORD@localhost:3002/$FORGEJO_USER/repo" main
|
|
check_repo_readme "http://localhost:3001/$FORGEJO_USER/repo" "frog2!"
|
|
)
|
|
}
|
|
|
|
proxyproto_run_test() {
|
|
[[ -z "$1" ]] && exit 1
|
|
|
|
local version="$1"
|
|
local config="$PROXYPROTO_DIR/default-app.ini"
|
|
|
|
reset_forgejo "$config"
|
|
start_forgejo "$version" "$config"
|
|
|
|
export CURL="$DIR/$(work_path_base "$config")/forgejo-curl.sh"
|
|
export V1_HOST_PORT="$(get_host_port "$config")"
|
|
|
|
run proxyproto_test_basic
|
|
run proxyproto_test_bombardier
|
|
run proxyproto_push_http
|
|
|
|
stop_forgejo $config
|
|
}
|
|
|
|
proxyproto_setup_haproxy() {
|
|
daemon \
|
|
--chdir="$DIR" \
|
|
--unsafe \
|
|
--pidfile="$DIR/haproxy-pid" \
|
|
--errlog="$DIR/haproxy-err.log" \
|
|
--output="$DIR/haproxy-out.log" \
|
|
-- \
|
|
haproxy \
|
|
-f "$PROXYPROTO_DIR/haproxy.cfg"
|
|
}
|
|
|
|
test_proxyproto() {
|
|
local versions="${1:-$RELEASE_NUMBERS}"
|
|
|
|
mkdir -p "$DIR"
|
|
proxyproto_setup_haproxy
|
|
|
|
for v in $versions; do
|
|
if dpkg --compare-versions "$v" lt "15.0"; then
|
|
continue
|
|
fi
|
|
|
|
proxyproto_run_test "$v"
|
|
done
|
|
|
|
stop_daemon "haproxy"
|
|
}
|
|
|