#!/bin/bash # list_test.sh - Test script for GET /list/ endpoint # This script tests the blob listing functionality BASE_URL="http://localhost:9001" NOSTR_PRIVKEY="0000000000000000000000000000000000000000000000000000000000000001" NOSTR_PUBKEY="79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798" # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color echo "=== Ginxsom List Blobs Tests ===" echo # Function to generate a Nostr event for list authorization generate_list_auth() { local content="$1" local created_at=$(date +%s) local expiration=$((created_at + 3600)) # 1 hour from now # Note: This is a placeholder - in real implementation, you'd use nostr tools # to generate properly signed events. For now, we'll create the structure. cat << EOF { "id": "placeholder_id", "pubkey": "$NOSTR_PUBKEY", "kind": 24242, "content": "$content", "created_at": $created_at, "tags": [ ["t", "list"], ["expiration", "$expiration"] ], "sig": "placeholder_signature" } EOF } # Test 1: List blobs without authorization (should work if optional auth) echo -e "${YELLOW}Test 1: GET /list/ without authorization${NC}" RESPONSE=$(curl -s -w "\nHTTP_STATUS:%{http_code}" "$BASE_URL/list/$NOSTR_PUBKEY") HTTP_STATUS=$(echo "$RESPONSE" | grep "HTTP_STATUS" | cut -d: -f2) BODY=$(echo "$RESPONSE" | sed '/HTTP_STATUS/d') echo "HTTP Status: $HTTP_STATUS" echo "Response: $BODY" echo # # Test 2: List blobs with authorization # echo -e "${YELLOW}Test 2: GET /list/ with authorization${NC}" # LIST_AUTH=$(generate_list_auth "List Blobs") # AUTH_B64=$(echo "$LIST_AUTH" | base64 -w 0) # RESPONSE=$(curl -s -w "\nHTTP_STATUS:%{http_code}" \ # -H "Authorization: Nostr $AUTH_B64" \ # "$BASE_URL/list/$NOSTR_PUBKEY") # HTTP_STATUS=$(echo "$RESPONSE" | grep "HTTP_STATUS" | cut -d: -f2) # BODY=$(echo "$RESPONSE" | sed '/HTTP_STATUS/d') # echo "HTTP Status: $HTTP_STATUS" # echo "Response: $BODY" # echo # # Test 3: List blobs with since parameter # echo -e "${YELLOW}Test 3: GET /list/ with since parameter${NC}" # SINCE_TIMESTAMP=$(($(date +%s) - 86400)) # 24 hours ago # RESPONSE=$(curl -s -w "\nHTTP_STATUS:%{http_code}" \ # "$BASE_URL/list/$NOSTR_PUBKEY?since=$SINCE_TIMESTAMP") # HTTP_STATUS=$(echo "$RESPONSE" | grep "HTTP_STATUS" | cut -d: -f2) # BODY=$(echo "$RESPONSE" | sed '/HTTP_STATUS/d') # echo "HTTP Status: $HTTP_STATUS" # echo "Response: $BODY" # echo # # Test 4: List blobs with until parameter # echo -e "${YELLOW}Test 4: GET /list/ with until parameter${NC}" # UNTIL_TIMESTAMP=$(date +%s) # now # RESPONSE=$(curl -s -w "\nHTTP_STATUS:%{http_code}" \ # "$BASE_URL/list/$NOSTR_PUBKEY?until=$UNTIL_TIMESTAMP") # HTTP_STATUS=$(echo "$RESPONSE" | grep "HTTP_STATUS" | cut -d: -f2) # BODY=$(echo "$RESPONSE" | sed '/HTTP_STATUS/d') # echo "HTTP Status: $HTTP_STATUS" # echo "Response: $BODY" # echo # # Test 5: List blobs with both since and until parameters # echo -e "${YELLOW}Test 5: GET /list/ with since and until parameters${NC}" # SINCE_TIMESTAMP=$(($(date +%s) - 86400)) # 24 hours ago # UNTIL_TIMESTAMP=$(date +%s) # now # RESPONSE=$(curl -s -w "\nHTTP_STATUS:%{http_code}" \ # "$BASE_URL/list/$NOSTR_PUBKEY?since=$SINCE_TIMESTAMP&until=$UNTIL_TIMESTAMP") # HTTP_STATUS=$(echo "$RESPONSE" | grep "HTTP_STATUS" | cut -d: -f2) # BODY=$(echo "$RESPONSE" | sed '/HTTP_STATUS/d') # echo "HTTP Status: $HTTP_STATUS" # echo "Response: $BODY" # echo # # Test 6: List blobs for non-existent pubkey # echo -e "${YELLOW}Test 6: GET /list/${NC}" # FAKE_PUBKEY="1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef" # RESPONSE=$(curl -s -w "\nHTTP_STATUS:%{http_code}" "$BASE_URL/list/$FAKE_PUBKEY") # HTTP_STATUS=$(echo "$RESPONSE" | grep "HTTP_STATUS" | cut -d: -f2) # BODY=$(echo "$RESPONSE" | sed '/HTTP_STATUS/d') # if [ "$HTTP_STATUS" = "200" ]; then # echo -e "${GREEN}✓ Correctly returned 200 with empty array${NC}" # else # echo "HTTP Status: $HTTP_STATUS" # fi # echo "Response: $BODY" # echo # # Test 7: List blobs with invalid pubkey format # echo -e "${YELLOW}Test 7: GET /list/${NC}" # INVALID_PUBKEY="invalid_pubkey" # RESPONSE=$(curl -s -w "\nHTTP_STATUS:%{http_code}" "$BASE_URL/list/$INVALID_PUBKEY") # HTTP_STATUS=$(echo "$RESPONSE" | grep "HTTP_STATUS" | cut -d: -f2) # BODY=$(echo "$RESPONSE" | sed '/HTTP_STATUS/d') # if [ "$HTTP_STATUS" = "400" ]; then # echo -e "${GREEN}✓ Correctly returned 400 for invalid pubkey format${NC}" # else # echo "HTTP Status: $HTTP_STATUS" # fi # echo "Response: $BODY" # echo # # Test 8: List blobs with invalid since/until parameters # echo -e "${YELLOW}Test 8: GET /list/ with invalid timestamp parameters${NC}" # RESPONSE=$(curl -s -w "\nHTTP_STATUS:%{http_code}" \ # "$BASE_URL/list/$NOSTR_PUBKEY?since=invalid&until=invalid") # HTTP_STATUS=$(echo "$RESPONSE" | grep "HTTP_STATUS" | cut -d: -f2) # BODY=$(echo "$RESPONSE" | sed '/HTTP_STATUS/d') # echo "HTTP Status: $HTTP_STATUS" # echo "Response: $BODY" # echo # echo "=== List Tests Complete ===" # echo # echo "Expected blob descriptor format:" # echo '{' # echo ' "url": "https://server.com/.",' # echo ' "sha256": "",' # echo ' "size": ,' # echo ' "type": "",' # echo ' "uploaded": ' # echo '}' # echo # echo "Note: These tests use placeholder Nostr events." # echo "For real testing, use proper Nostr signing tools to generate valid events."