63 lines
1.9 KiB
Bash
Executable File
63 lines
1.9 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Simple test script to verify subscription limit enforcement and rate limiting
|
|
# This script tests that subscription limits are enforced early
|
|
|
|
set -e
|
|
|
|
RELAY_URL="ws://127.0.0.1:8888"
|
|
|
|
echo "=== Subscription Limit Test ==="
|
|
echo "[INFO] Testing relay at: $RELAY_URL"
|
|
echo "[INFO] Note: This test assumes default subscription limits (max 25 per client)"
|
|
echo ""
|
|
|
|
# Test basic connectivity first
|
|
echo "=== Test 1: Basic Connectivity ==="
|
|
echo "[INFO] Testing basic WebSocket connection..."
|
|
|
|
# Send a simple REQ message
|
|
response=$(echo '["REQ","basic_test",{}]' | timeout 5 websocat -n1 "$RELAY_URL" 2>/dev/null || echo "TIMEOUT")
|
|
|
|
if echo "$response" | grep -q "EOSE\|EVENT\|NOTICE"; then
|
|
echo "[PASS] Basic connectivity works"
|
|
else
|
|
echo "[FAIL] Basic connectivity failed. Response: $response"
|
|
exit 1
|
|
fi
|
|
echo ""
|
|
|
|
# Test subscription limits
|
|
echo "=== Test 2: Subscription Limit Enforcement ==="
|
|
echo "[INFO] Testing subscription limits by creating multiple subscriptions..."
|
|
|
|
success_count=0
|
|
limit_hit=false
|
|
|
|
# Create multiple subscriptions in sequence (each in its own connection)
|
|
for i in {1..30}; do
|
|
echo "[INFO] Creating subscription $i..."
|
|
sub_id="limit_test_$i_$(date +%s%N)"
|
|
response=$(echo "[\"REQ\",\"$sub_id\",{}]" | timeout 5 websocat -n1 "$RELAY_URL" 2>/dev/null || echo "TIMEOUT")
|
|
|
|
if echo "$response" | grep -q "CLOSED.*$sub_id.*exceeded"; then
|
|
echo "[INFO] Hit subscription limit at subscription $i"
|
|
limit_hit=true
|
|
break
|
|
elif echo "$response" | grep -q "EOSE\|EVENT"; then
|
|
((success_count++))
|
|
else
|
|
echo "[WARN] Unexpected response for subscription $i: $response"
|
|
fi
|
|
|
|
sleep 0.1
|
|
done
|
|
|
|
if [ "$limit_hit" = true ]; then
|
|
echo "[PASS] Subscription limit enforcement working (limit hit after $success_count subscriptions)"
|
|
else
|
|
echo "[WARN] Subscription limit not hit after 30 attempts"
|
|
fi
|
|
echo ""
|
|
|
|
echo "=== Test Complete ===" |