#!/bin/bash # E2E Test: Authentication Flow # Tests Nostr authentication, session management, and protected endpoints set -e BASE_URL="http://localhost:9876" echo "=== Authentication Flow E2E Test ===" # Test 1: Get authentication challenge echo "Getting authentication challenge..." CHALLENGE_RESPONSE=$(curl -s "$BASE_URL/api/auth/challenge") echo "Challenge response: $CHALLENGE_RESPONSE" CHALLENGE=$(echo "$CHALLENGE_RESPONSE" | grep -o '"challenge":"[^"]*"' | cut -d'"' -f4) if [ -z "$CHALLENGE" ]; then echo "❌ Failed to get challenge" exit 1 fi echo "✅ Authentication challenge received: ${CHALLENGE:0:20}..." # Test 2: Test protected endpoint without auth echo "Testing protected endpoint without authentication..." UNAUTH_RESPONSE=$(curl -s -w "%{http_code}" "$BASE_URL/api/users/me/files") HTTP_CODE="${UNAUTH_RESPONSE: -3}" if [ "$HTTP_CODE" != "401" ]; then echo "❌ Expected 401 Unauthorized but got $HTTP_CODE" exit 1 fi echo "✅ Protected endpoint correctly returns 401 without auth" # Test 3: Test invalid authentication echo "Testing invalid authentication..." INVALID_AUTH=$(cat <