interplane-forge
INTERPLANE Forge
Brought by drakestapleton
interplane-forge / social / tests / lockout.sh
| 1 | #!/bin/bash |
| 2 | # ForgeSocial sign-in lockout test (security review P2-4), HOST_TESTED on spark. |
| 3 | # 61 failed sign-ins for one DID (a wrong key signs for D1) from 6 X-Real-IP values inside one minute, |
| 4 | # then a legitimate sign-in for D1 from a 7th IP must still succeed (303). |
| 5 | # Negative control: SOCIAL_SRC=<dir with the old social/*.om> social/tests/lockout.sh must FAIL |
| 6 | # (the old 60-per-minute site-wide verify cap answers the legitimate sign-in 429). |
| 7 | # Usage: social/tests/lockout.sh (from ~/work/forge/web; cores 2) |
| 8 | . "$(dirname "$0")/lib.sh" |
| 9 | start |
| 10 | # the limiters count per wall-clock minute: start early in a minute so all 62 POSTs share it |
| 11 | s=$((10#$(date +%S))); [ "$s" -le 20 ] || sleep $((61 - s)) |
| 12 | M0=$(( $(date +%s) / 60 )) |
| 13 | declare -A TALLY |
| 14 | for i in $(seq 0 60); do |
| 15 | ip=10.9.0.$((i % 6 + 1)) |
| 16 | login_get -H "X-Real-IP: $ip" > /dev/null |
| 17 | sign "$T/k2" |
| 18 | c=$(login_post "$D1" -H "X-Real-IP: $ip") |
| 19 | TALLY[$c]=$(( ${TALLY[$c]:-0} + 1 )) |
| 20 | done |
| 21 | echo "61 failed attempts from 6 IPs: $(for k in "${!TALLY[@]}"; do printf '%s x%s ' "$k" "${TALLY[$k]}"; done)" |
| 22 | check "$(( ${TALLY[403]:-0} + ${TALLY[429]:-0} ))" 61 "all 61 wrong-key attempts refused (403 or 429)" |
| 23 | login_get -H "X-Real-IP: 10.9.0.7" > /dev/null; sign "$T/k1" |
| 24 | c=$(login_post "$D1" -H "X-Real-IP: 10.9.0.7"); check "$c" 303 "legitimate sign-in from a 7th IP after the flood" |
| 25 | M1=$(( $(date +%s) / 60 )) |
| 26 | check "$M1" "$M0" "flood and sign-in inside one minute (else the run is void: rerun)" |
| 27 | echo "---- $PASS passed, $FAIL failed" |
| 28 | [ "$FAIL" = 0 ] |