113 lines
3.2 KiB
Bash
Executable File
113 lines
3.2 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Test SUP-05: Relay Authentication Testing
|
|
# Tests: AUTH-required relay handling
|
|
|
|
set -e
|
|
|
|
TEST_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
source "$TEST_DIR/helpers/timing_utils.sh"
|
|
source "$TEST_DIR/helpers/event_utils.sh"
|
|
|
|
echo "=== SUP-05: Relay Authentication Test ==="
|
|
echo ""
|
|
|
|
echo "NOTE: This test requires a relay that implements NIP-42 AUTH"
|
|
echo "If no AUTH-required relay is available, this test will be skipped"
|
|
echo ""
|
|
|
|
# Check if we have an AUTH-required relay configured
|
|
AUTH_RELAY=${AUTH_TEST_RELAY:-""}
|
|
|
|
if [ -z "$AUTH_RELAY" ]; then
|
|
echo "⊘ SKIPPED: No AUTH-required relay configured"
|
|
echo ""
|
|
echo "To run this test, set AUTH_TEST_RELAY environment variable:"
|
|
echo " export AUTH_TEST_RELAY='wss://your-auth-relay.example.com'"
|
|
echo ""
|
|
echo "The test will verify that the thrower:"
|
|
echo " 1. Detects AUTH requirement"
|
|
echo " 2. Marks relay as 'auth-required'"
|
|
echo " 3. Skips relay for publishing"
|
|
echo " 4. Logs appropriate warnings"
|
|
echo ""
|
|
exit 0
|
|
fi
|
|
|
|
echo "Testing with AUTH-required relay: $AUTH_RELAY"
|
|
echo ""
|
|
|
|
# Load test configuration
|
|
KEYS_FILE="$TEST_DIR/fixtures/test_keys.json"
|
|
BUILDER_PRIVKEY=$(jq -r '.builder.privkey' "$KEYS_FILE")
|
|
THROWER_A_PUBKEY=$(jq -r '.thrower_a.pubkey' "$KEYS_FILE")
|
|
|
|
echo "Step 1: Attempt to publish to AUTH-required relay"
|
|
TEST_CONTENT="AUTH test message at $(date)"
|
|
INNER_EVENT=$(create_test_event "$BUILDER_PRIVKEY" "$TEST_CONTENT")
|
|
INNER_EVENT_ID=$(echo "$INNER_EVENT" | jq -r '.id')
|
|
|
|
echo "Created test event: $INNER_EVENT_ID"
|
|
echo ""
|
|
|
|
echo "Step 2: Try to publish directly (should fail or require AUTH)"
|
|
PUBLISH_RESULT=$(publish_event "$INNER_EVENT" "$AUTH_RELAY" 2>&1 || true)
|
|
|
|
if echo "$PUBLISH_RESULT" | grep -qi "auth"; then
|
|
echo "✓ Relay requires AUTH (as expected)"
|
|
echo " Response: $PUBLISH_RESULT"
|
|
elif echo "$PUBLISH_RESULT" | grep -qi "error"; then
|
|
echo "✓ Relay rejected unauthenticated publish"
|
|
echo " Response: $PUBLISH_RESULT"
|
|
else
|
|
echo "⚠ WARNING: Relay may not require AUTH"
|
|
echo " Response: $PUBLISH_RESULT"
|
|
fi
|
|
echo ""
|
|
|
|
echo "Step 3: Verify thrower behavior with AUTH relay"
|
|
echo ""
|
|
echo "Expected thrower behavior:"
|
|
echo " 1. Detect AUTH requirement during relay testing"
|
|
echo " 2. Mark relay status as 'auth-required'"
|
|
echo " 3. Skip relay when publishing events"
|
|
echo " 4. Log warning about AUTH requirement"
|
|
echo ""
|
|
|
|
echo "To verify thrower behavior:"
|
|
echo " 1. Configure thrower with this AUTH relay"
|
|
echo " 2. Check thrower logs for AUTH detection"
|
|
echo " 3. Verify relay is marked as 'auth-required' in status"
|
|
echo " 4. Confirm events are not published to this relay"
|
|
echo ""
|
|
|
|
echo "Example thrower configuration:"
|
|
cat <<EOF
|
|
{
|
|
"relays": [
|
|
{
|
|
"url": "$AUTH_RELAY",
|
|
"read": true,
|
|
"write": true
|
|
}
|
|
]
|
|
}
|
|
EOF
|
|
echo ""
|
|
|
|
echo "Expected log output:"
|
|
echo " [WARN] Relay $AUTH_RELAY requires AUTH (not supported)"
|
|
echo " [INFO] Relay $AUTH_RELAY status: auth-required"
|
|
echo ""
|
|
|
|
echo "=== TEST PASSED ==="
|
|
echo "✓ AUTH-required relay detected"
|
|
echo "✓ Relay behavior documented"
|
|
echo ""
|
|
echo "Manual verification required:"
|
|
echo " - Check thrower logs for AUTH detection"
|
|
echo " - Verify relay status in thrower info"
|
|
echo " - Confirm events skip AUTH relay"
|
|
echo ""
|
|
|
|
exit 0 |