2026-05-07 14:07:21 +08:00

59 lines
1.6 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
# Verifies that the public production entrypoint allows large intake uploads
# to reach the app instead of being blocked by the outer proxy/nginx layer.
#
# Usage:
# bash scripts/check-prod-upload-limit.sh
# bash scripts/check-prod-upload-limit.sh https://cp.jiansun.vip 200
#
# Expected result for an unauthenticated request is usually 401 from the app.
# A 413 response means the public proxy/body-size limit is still too low.
BASE_URL="${1:-https://cp.jiansun.vip}"
TEST_SIZE_MB="${2:-200}"
TEST_PRODUCT_ID="upload-limit-check"
UPLOAD_URL="${BASE_URL%/}/api/intake/non-integrated/${TEST_PRODUCT_ID}/upload"
if ! [[ "$TEST_SIZE_MB" =~ ^[0-9]+$ ]]; then
echo "TEST_SIZE_MB must be an integer." >&2
exit 2
fi
tmp_file="$(mktemp)"
body_file="$(mktemp)"
trap 'rm -f "$tmp_file" "$body_file"' EXIT
dd if=/dev/zero of="$tmp_file" bs=1M count="$TEST_SIZE_MB" status=none
status="$(
curl -sS \
-o "$body_file" \
-w "%{http_code}" \
-X POST \
--data-binary "@$tmp_file" \
--max-time 60 \
"$UPLOAD_URL"
)"
echo "POST $UPLOAD_URL"
echo "Payload: ${TEST_SIZE_MB}MB"
echo "HTTP status: $status"
case "$status" in
413)
echo "FAILED: public proxy still blocks ${TEST_SIZE_MB}MB uploads."
echo "Set client_max_body_size 500m; or higher on the cp.jiansun.vip proxy/nginx entry, then reload it."
exit 1
;;
401|403|400|404|405|422|200|201)
echo "OK: request reached the app layer. Public nginx did not block this payload."
;;
*)
echo "CHECK: unexpected status. Inspect the response body below."
sed -n '1,80p' "$body_file"
exit 1
;;
esac