test-sprocket-manual.sh raw

   1  #!/bin/bash
   2  
   3  # Manual Sprocket Test Script
   4  # This script demonstrates sprocket functionality by sending test events
   5  
   6  set -e
   7  
   8  echo "๐Ÿงช Manual Sprocket Test"
   9  echo "======================"
  10  
  11  # Configuration
  12  RELAY_HOST="127.0.0.1"
  13  RELAY_PORT="3334"
  14  RELAY_URL="ws://$RELAY_HOST:$RELAY_PORT"
  15  
  16  # Check if websocat is available
  17  if ! command -v websocat &> /dev/null; then
  18      echo "โŒ websocat is required for this test"
  19      echo "Install it with: cargo install websocat"
  20      exit 1
  21  fi
  22  
  23  # Function to send an event and get response
  24  send_event() {
  25      local event_json="$1"
  26      local description="$2"
  27      
  28      echo "๐Ÿ“ค Testing: $description"
  29      echo "Event: $event_json"
  30      
  31      # Send EVENT message
  32      local message="[\"EVENT\",$event_json]"
  33      echo "Sending: $message"
  34      
  35      # Send and receive response
  36      local response=$(echo "$message" | websocat "$RELAY_URL" --text)
  37      echo "Response: $response"
  38      echo "---"
  39  }
  40  
  41  # Test events
  42  echo "๐Ÿš€ Starting manual sprocket test..."
  43  echo "Make sure the relay is running with sprocket enabled!"
  44  echo ""
  45  
  46  # Test 1: Normal event (should be accepted)
  47  send_event '{
  48      "id": "test_normal_123",
  49      "pubkey": "1234567890abcdef1234567890abcdef12345678",
  50      "created_at": '$(date +%s)',
  51      "kind": 1,
  52      "content": "Hello, world! This is a normal message.",
  53      "sig": "test_sig_normal"
  54  }' "Normal event (should be accepted)"
  55  
  56  # Test 2: Spam content (should be rejected)
  57  send_event '{
  58      "id": "test_spam_456",
  59      "pubkey": "1234567890abcdef1234567890abcdef12345678",
  60      "created_at": '$(date +%s)',
  61      "kind": 1,
  62      "content": "This message contains spam content",
  63      "sig": "test_sig_spam"
  64  }' "Spam content (should be rejected)"
  65  
  66  # Test 3: Test kind 9999 (should be shadow rejected)
  67  send_event '{
  68      "id": "test_kind_789",
  69      "pubkey": "1234567890abcdef1234567890abcdef12345678",
  70      "created_at": '$(date +%s)',
  71      "kind": 9999,
  72      "content": "Test message with special kind",
  73      "sig": "test_sig_kind"
  74  }' "Test kind 9999 (should be shadow rejected)"
  75  
  76  # Test 4: Blocked hashtag (should be rejected)
  77  send_event '{
  78      "id": "test_hashtag_101",
  79      "pubkey": "1234567890abcdef1234567890abcdef12345678",
  80      "created_at": '$(date +%s)',
  81      "kind": 1,
  82      "content": "Message with blocked hashtag",
  83      "tags": [["t", "blocked"]],
  84      "sig": "test_sig_hashtag"
  85  }' "Blocked hashtag (should be rejected)"
  86  
  87  # Test 5: Too long content (should be rejected)
  88  send_event '{
  89      "id": "test_long_202",
  90      "pubkey": "1234567890abcdef1234567890abcdef12345678",
  91      "created_at": '$(date +%s)',
  92      "kind": 1,
  93      "content": "'$(printf 'a%.0s' {1..1001})'",
  94      "sig": "test_sig_long"
  95  }' "Too long content (should be rejected)"
  96  
  97  # Test 6: Old timestamp (should be rejected)
  98  send_event '{
  99      "id": "test_old_303",
 100      "pubkey": "1234567890abcdef1234567890abcdef12345678",
 101      "created_at": '$(($(date +%s) - 7200))',
 102      "kind": 1,
 103      "content": "Message with old timestamp",
 104      "sig": "test_sig_old"
 105  }' "Old timestamp (should be rejected)"
 106  
 107  echo "โœ… Manual sprocket test completed!"
 108  echo ""
 109  echo "Expected results:"
 110  echo "- Normal event: OK, true"
 111  echo "- Spam content: OK, false, 'Content contains spam'"
 112  echo "- Test kind 9999: OK, true (but shadow rejected)"
 113  echo "- Blocked hashtag: OK, false, 'Hashtag blocked is not allowed'"
 114  echo "- Too long content: OK, false, 'Content too long'"
 115  echo "- Old timestamp: OK, false, 'Event timestamp too old'"
 116