1 Bash/linedump-ratelimit-test
Caffeine Fueled edited this page 2025-10-01 19:37:45 +00:00
#!/bin/bash

# Test script for linedump rate limiting
# This script will attempt to upload files rapidly to test the rate limit

SERVER_URL=${1:-"http://localhost:8000"}
TEST_UPLOADS=${2:-55}  # Test more than the default 50/hour limit

echo "Testing rate limit on $SERVER_URL"
echo "Attempting $TEST_UPLOADS uploads..."
echo "Expected: First ~50 should succeed, then rate limit should kick in"
echo

success_count=0
rate_limited_count=0

for i in $(seq 1 $TEST_UPLOADS); do
    # Create unique test content for each upload
    test_content="Test upload #$i - $(date '+%H:%M:%S')"

    # Make the upload request and capture HTTP status
    response=$(curl -s -w "%{http_code}" -X POST -d "$test_content" "$SERVER_URL/")
    http_code="${response: -3}"  # Last 3 characters are the HTTP code
    response_body="${response%???}"  # Everything except last 3 characters

    if [ "$http_code" = "200" ]; then
        success_count=$((success_count + 1))
        echo "✓ Upload $i: SUCCESS (HTTP $http_code) - $response_body"
    elif [ "$http_code" = "429" ]; then
        rate_limited_count=$((rate_limited_count + 1))
        echo "✗ Upload $i: RATE LIMITED (HTTP $http_code)"
    else
        echo "! Upload $i: UNEXPECTED (HTTP $http_code) - $response_body"
    fi

    # Small delay to avoid overwhelming the server
    sleep 0.1
done

echo
echo "=== RESULTS ==="
echo "Successful uploads: $success_count"
echo "Rate limited: $rate_limited_count"
echo "Total attempts: $TEST_UPLOADS"

if [ $rate_limited_count -gt 0 ]; then
    echo "✓ Rate limiting is working!"
else
    echo "⚠ No rate limiting detected - check server configuration"
fi