#!/bin/bash # Test script to verify CORS functionality for Gajim compatibility echo "๐Ÿงช Testing CORS Functionality for Gajim Compatibility" echo "========================================================" SERVER_URL="http://localhost:8080" echo "" echo "1. Testing OPTIONS preflight request (Gajim issue):" echo "---------------------------------------------------" CORS_RESULT=$(curl -s -X OPTIONS "$SERVER_URL/" -w "HTTP_CODE:%{http_code}" -H "Origin: https://example.com") HTTP_CODE=$(echo "$CORS_RESULT" | grep -o "HTTP_CODE:[0-9]*" | cut -d: -f2) if [ "$HTTP_CODE" = "200" ]; then echo "โœ… OPTIONS request successful (HTTP 200)" echo " This fixes Gajim's 'bad gateway' error!" else echo "โŒ OPTIONS request failed (HTTP $HTTP_CODE)" exit 1 fi echo "" echo "2. Checking CORS headers in response:" echo "------------------------------------" HEADERS=$(curl -s -X OPTIONS "$SERVER_URL/" -D -) echo "$HEADERS" | grep -i "access-control" | while read line; do echo "โœ… $line" done echo "" echo "3. Testing regular GET request with CORS:" echo "-----------------------------------------" GET_RESULT=$(curl -s "$SERVER_URL/health" -w "HTTP_CODE:%{http_code}" -H "Origin: https://gajim.org") GET_CODE=$(echo "$GET_RESULT" | grep -o "HTTP_CODE:[0-9]*" | cut -d: -f2) if [ "$GET_CODE" = "200" ]; then echo "โœ… GET request with CORS successful (HTTP 200)" else echo "โŒ GET request failed (HTTP $GET_CODE)" fi echo "" echo "4. Simulating XMPP client preflight sequence:" echo "---------------------------------------------" # This simulates what Gajim does before file upload echo "Step 1: OPTIONS preflight..." OPTIONS_TEST=$(curl -s -X OPTIONS "$SERVER_URL/upload" \ -H "Origin: https://gajim.org" \ -H "Access-Control-Request-Method: PUT" \ -H "Access-Control-Request-Headers: Authorization,Content-Type" \ -w "HTTP_CODE:%{http_code}") OPTIONS_CODE=$(echo "$OPTIONS_TEST" | grep -o "HTTP_CODE:[0-9]*" | cut -d: -f2) if [ "$OPTIONS_CODE" = "200" ]; then echo "โœ… XMPP client preflight successful" else echo "โŒ XMPP client preflight failed (HTTP $OPTIONS_CODE)" fi echo "" echo "๐ŸŽฏ SUMMARY:" echo "===========" if [ "$HTTP_CODE" = "200" ] && [ "$GET_CODE" = "200" ] && [ "$OPTIONS_CODE" = "200" ]; then echo "โœ… ALL TESTS PASSED" echo "โœ… Gajim's 'bad gateway' error should be FIXED!" echo "โœ… XMPP clients can now perform CORS preflight requests" echo "" echo "๐Ÿ“‹ What this fixes:" echo " - Gajim intermittent 'bad gateway' errors" echo " - Web-based XMPP clients CORS issues" echo " - Any client that sends OPTIONS requests" else echo "โŒ SOME TESTS FAILED" echo "โŒ Gajim may still experience issues" exit 1 fi