#!/bin/bash # Test SNS Bounce Webhook # This script simulates an SNS bounce notification (without signature verification for testing) API_URL="http://localhost:8000" echo "Testing SNS Bounce Webhook..." echo # Test 1: Health check echo "1. Testing API health..." curl -s "$API_URL/health" | jq . echo # Test 2: Create a test subscription confirmation (the webhook will auto-confirm) echo "2. Testing subscription confirmation handling..." curl -s -X POST "$API_URL/webhooks/sns" \ -H "Content-Type: application/json" \ -d '{ "Type": "SubscriptionConfirmation", "MessageId": "test-message-id", "Token": "test-token", "TopicArn": "arn:aws:sns:eu-west-2:123456789:test-topic", "Message": "You have chosen to subscribe to the topic", "SubscribeURL": "https://example.com/subscribe", "Timestamp": "2025-01-01T12:00:00.000Z" }' || echo "Note: Signature verification will fail for test messages (expected)" echo echo # Test 3: Simulated bounce notification (will fail signature verification) echo "3. Testing bounce notification structure..." echo "Note: In production, AWS SNS will send properly signed messages." echo "This test demonstrates the expected structure." echo cat << 'EOF' > /tmp/test_bounce.json { "Type": "Notification", "MessageId": "test-notification-id", "TopicArn": "arn:aws:sns:eu-west-2:123456789:test-topic", "Subject": "Amazon SES Email Event Notification", "Message": "{\"notificationType\":\"Bounce\",\"bounce\":{\"bounceType\":\"Permanent\",\"bounceSubType\":\"General\",\"bouncedRecipients\":[{\"emailAddress\":\"bounce@simulator.amazonses.com\",\"diagnosticCode\":\"smtp; 550 5.1.1 user unknown\"}],\"timestamp\":\"2025-01-01T12:00:00.000Z\",\"feedbackId\":\"test-feedback-id\"}}", "Timestamp": "2025-01-01T12:00:00.000Z", "SignatureVersion": "1", "Signature": "test-signature", "SigningCertURL": "https://sns.eu-west-2.amazonaws.com/test.pem" } EOF cat /tmp/test_bounce.json | jq . echo echo "Expected behavior: Signature verification will fail without real AWS credentials" echo "In production, AWS SNS will send properly signed messages that will be verified" echo # Test 4: Check if database schema has bounce tables echo "4. Checking database schema for bounce tables..." sudo docker-compose exec -T mysql mysql -u maillist -pmaillist maillist -e "SHOW TABLES LIKE '%bounce%';" 2>/dev/null echo # Test 5: Check members table for bounce columns echo "5. Checking members table for bounce columns..." sudo docker-compose exec -T mysql mysql -u maillist -pmaillist maillist -e "DESCRIBE members;" 2>/dev/null | grep -i bounce echo echo "✓ Setup complete!" echo echo "To test with real AWS SNS:" echo "1. Set up SNS topic in AWS Console" echo "2. Subscribe webhook: https://your-domain.com:8000/webhooks/sns" echo "3. Configure SES to send bounce notifications to the SNS topic" echo "4. Send test email to bounce@simulator.amazonses.com" echo echo "See BOUNCE_HANDLING_SETUP.md for detailed setup instructions"