#!/bin/bash # Comprehensive E2E Test Script for LittleShop and SilverPAY # This script tests all features and functions of the integrated system echo "==========================================" echo "COMPREHENSIVE E2E TEST SUITE" echo "LittleShop + SilverPAY Integration" echo "Date: $(date)" echo "==========================================" # Configuration LITTLESHOP_URL="http://localhost:8080" SILVERPAY_URL="http://31.97.57.205:8001" ADMIN_USER="admin" ADMIN_PASS="admin" TEST_RESULTS_FILE="test_results_$(date +%Y%m%d_%H%M%S).json" # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color # Test counters TESTS_PASSED=0 TESTS_FAILED=0 TESTS_SKIPPED=0 # Function to print test result print_result() { local test_name=$1 local result=$2 local message=$3 if [ "$result" = "PASS" ]; then echo -e "${GREEN}✓${NC} $test_name: PASSED" ((TESTS_PASSED++)) elif [ "$result" = "FAIL" ]; then echo -e "${RED}✗${NC} $test_name: FAILED - $message" ((TESTS_FAILED++)) else echo -e "${YELLOW}⊘${NC} $test_name: SKIPPED - $message" ((TESTS_SKIPPED++)) fi } # Function to make authenticated request auth_request() { local method=$1 local endpoint=$2 local data=$3 if [ -z "$AUTH_TOKEN" ]; then # Get auth token first AUTH_RESPONSE=$(curl -s -X POST "$LITTLESHOP_URL/api/auth/login" \ -H "Content-Type: application/json" \ -d "{\"username\":\"$ADMIN_USER\",\"password\":\"$ADMIN_PASS\"}") AUTH_TOKEN=$(echo $AUTH_RESPONSE | grep -o '"token":"[^"]*' | sed 's/"token":"//') fi if [ -z "$data" ]; then curl -s -X $method "$LITTLESHOP_URL$endpoint" \ -H "Authorization: Bearer $AUTH_TOKEN" else curl -s -X $method "$LITTLESHOP_URL$endpoint" \ -H "Authorization: Bearer $AUTH_TOKEN" \ -H "Content-Type: application/json" \ -d "$data" fi } echo "" echo "=== 1. INFRASTRUCTURE TESTS ===" echo "--------------------------------" # Test 1.1: LittleShop Health echo -n "Testing LittleShop availability... " RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" "$LITTLESHOP_URL/") if [ "$RESPONSE" = "200" ]; then print_result "LittleShop Health" "PASS" "" else print_result "LittleShop Health" "FAIL" "HTTP $RESPONSE" fi # Test 1.2: SilverPAY Health echo -n "Testing SilverPAY health endpoint... " RESPONSE=$(curl -s "$SILVERPAY_URL/health") if echo "$RESPONSE" | grep -q "healthy"; then print_result "SilverPAY Health" "PASS" "" else print_result "SilverPAY Health" "FAIL" "Not healthy" fi # Test 1.3: Database Connectivity echo -n "Testing database connectivity... " RESPONSE=$(curl -s "$LITTLESHOP_URL/api/test/database") if [ "$?" -eq 0 ]; then print_result "Database Connectivity" "PASS" "" else print_result "Database Connectivity" "FAIL" "Connection failed" fi echo "" echo "=== 2. AUTHENTICATION TESTS ===" echo "--------------------------------" # Test 2.1: Admin Login echo -n "Testing admin login... " LOGIN_RESPONSE=$(curl -s -X POST "$LITTLESHOP_URL/api/auth/login" \ -H "Content-Type: application/json" \ -d '{"username":"admin","password":"admin"}') if echo "$LOGIN_RESPONSE" | grep -q "token"; then AUTH_TOKEN=$(echo $LOGIN_RESPONSE | grep -o '"token":"[^"]*' | sed 's/"token":"//') print_result "Admin Login" "PASS" "" else print_result "Admin Login" "FAIL" "Invalid credentials" fi # Test 2.2: Token Validation echo -n "Testing token validation... " RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" -X GET "$LITTLESHOP_URL/api/users" \ -H "Authorization: Bearer $AUTH_TOKEN") if [ "$RESPONSE" = "200" ]; then print_result "Token Validation" "PASS" "" else print_result "Token Validation" "FAIL" "HTTP $RESPONSE" fi echo "" echo "=== 3. CATALOG API TESTS ===" echo "-----------------------------" # Test 3.1: Get Categories echo -n "Testing categories endpoint... " RESPONSE=$(curl -s "$LITTLESHOP_URL/api/catalog/categories") if echo "$RESPONSE" | grep -q '\['; then print_result "Get Categories" "PASS" "" else print_result "Get Categories" "FAIL" "Invalid response" fi # Test 3.2: Get Products echo -n "Testing products endpoint... " RESPONSE=$(curl -s "$LITTLESHOP_URL/api/catalog/products") if echo "$RESPONSE" | grep -q '\['; then PRODUCT_COUNT=$(echo "$RESPONSE" | grep -o '"id"' | wc -l) print_result "Get Products" "PASS" "Found $PRODUCT_COUNT products" else print_result "Get Products" "FAIL" "Invalid response" fi # Test 3.3: Product Variations echo -n "Testing product variations... " RESPONSE=$(curl -s "$LITTLESHOP_URL/api/catalog/products") if echo "$RESPONSE" | grep -q "variations"; then print_result "Product Variations" "PASS" "" else print_result "Product Variations" "SKIP" "No variations found" fi echo "" echo "=== 4. ORDER MANAGEMENT TESTS ===" echo "---------------------------------" # Test 4.1: Create Order echo -n "Testing order creation... " ORDER_DATA='{ "customerIdentity": "TEST-CUSTOMER-001", "items": [ { "productId": "00000000-0000-0000-0000-000000000001", "quantity": 1, "price": 10.00 } ], "shippingAddress": { "name": "Test Customer", "address1": "123 Test Street", "city": "London", "postCode": "SW1A 1AA", "country": "UK" } }' ORDER_RESPONSE=$(auth_request "POST" "/api/orders" "$ORDER_DATA") if echo "$ORDER_RESPONSE" | grep -q "id"; then ORDER_ID=$(echo $ORDER_RESPONSE | grep -o '"id":"[^"]*' | sed 's/"id":"//') print_result "Create Order" "PASS" "Order ID: ${ORDER_ID:0:8}..." else print_result "Create Order" "FAIL" "Could not create order" fi # Test 4.2: Get Order Status if [ ! -z "$ORDER_ID" ]; then echo -n "Testing order retrieval... " RESPONSE=$(auth_request "GET" "/api/orders/$ORDER_ID") if echo "$RESPONSE" | grep -q "$ORDER_ID"; then print_result "Get Order" "PASS" "" else print_result "Get Order" "FAIL" "Order not found" fi fi echo "" echo "=== 5. PAYMENT INTEGRATION TESTS ===" echo "------------------------------------" # Test 5.1: SilverPAY Order Creation echo -n "Testing SilverPAY order creation... " PAYMENT_DATA='{ "external_id": "TEST-'$(date +%s)'", "amount": 10.00, "currency": "BTC", "description": "Test payment", "webhook_url": "https://littleshop.silverlabs.uk/api/silverpay/webhook" }' SILVERPAY_RESPONSE=$(curl -s -X POST "$SILVERPAY_URL/api/v1/orders" \ -H "Content-Type: application/json" \ -H "X-API-Key: test-api-key" \ -d "$PAYMENT_DATA") if echo "$SILVERPAY_RESPONSE" | grep -q "id"; then SILVERPAY_ORDER_ID=$(echo $SILVERPAY_RESPONSE | grep -o '"id":"[^"]*' | sed 's/"id":"//') print_result "SilverPAY Order" "PASS" "ID: ${SILVERPAY_ORDER_ID:0:8}..." else print_result "SilverPAY Order" "FAIL" "$(echo $SILVERPAY_RESPONSE | head -c 50)" fi # Test 5.2: Payment Creation via LittleShop (using SilverPAY) echo -n "Testing payment creation via LittleShop... " if [ ! -z "$ORDER_ID" ]; then PAYMENT_RESPONSE=$(auth_request "POST" "/api/orders/$ORDER_ID/payments" '{"currency":"BTC"}') if echo "$PAYMENT_RESPONSE" | grep -q "walletAddress\|paymentAddress\|address"; then print_result "Payment Creation" "PASS" "SilverPAY integration working" else print_result "Payment Creation" "FAIL" "No payment address returned" fi else print_result "Payment Creation" "SKIP" "No order created" fi echo "" echo "=== 6. ADMIN PANEL TESTS ===" echo "----------------------------" # Test 6.1: Admin Dashboard echo -n "Testing admin dashboard... " RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" "$LITTLESHOP_URL/Admin/Dashboard") if [ "$RESPONSE" = "200" ] || [ "$RESPONSE" = "302" ]; then print_result "Admin Dashboard" "PASS" "" else print_result "Admin Dashboard" "FAIL" "HTTP $RESPONSE" fi # Test 6.2: Category Management echo -n "Testing category management... " RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" "$LITTLESHOP_URL/Admin/Categories") if [ "$RESPONSE" = "200" ] || [ "$RESPONSE" = "302" ]; then print_result "Category Management" "PASS" "" else print_result "Category Management" "FAIL" "HTTP $RESPONSE" fi # Test 6.3: Product Management echo -n "Testing product management... " RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" "$LITTLESHOP_URL/Admin/Products") if [ "$RESPONSE" = "200" ] || [ "$RESPONSE" = "302" ]; then print_result "Product Management" "PASS" "" else print_result "Product Management" "FAIL" "HTTP $RESPONSE" fi echo "" echo "=== 7. PUSH NOTIFICATION TESTS ===" echo "----------------------------------" # Test 7.1: VAPID Key Generation echo -n "Testing VAPID key endpoint... " RESPONSE=$(curl -s "$LITTLESHOP_URL/api/push/vapid-key") if echo "$RESPONSE" | grep -q "publicKey"; then print_result "VAPID Key" "PASS" "" else print_result "VAPID Key" "FAIL" "No public key" fi # Test 7.2: Subscription Endpoint echo -n "Testing subscription endpoint... " SUB_DATA='{ "endpoint": "https://test.endpoint.com", "keys": { "p256dh": "test-key", "auth": "test-auth" } }' RESPONSE=$(auth_request "POST" "/api/push/subscribe" "$SUB_DATA") if [ "$?" -eq 0 ]; then print_result "Push Subscription" "PASS" "" else print_result "Push Subscription" "FAIL" "Subscription failed" fi echo "" echo "=== 8. WEBHOOK TESTS ===" echo "------------------------" # Test 8.1: SilverPAY Webhook echo -n "Testing SilverPAY webhook... " WEBHOOK_DATA='{ "order_id": "test-order-123", "status": "paid", "amount": 10.00, "tx_hash": "test-tx-hash", "confirmations": 3 }' RESPONSE=$(curl -s -X POST "$LITTLESHOP_URL/api/silverpay/webhook" \ -H "Content-Type: application/json" \ -d "$WEBHOOK_DATA") if [ "$?" -eq 0 ]; then print_result "SilverPAY Webhook" "PASS" "" else print_result "SilverPAY Webhook" "FAIL" "Webhook failed" fi # Test 8.2: SilverPAY Status Check (replacing BTCPay webhook test) echo -n "Testing SilverPAY order status check... " # Test if we can check order status via SilverPAY if [ ! -z "$SILVERPAY_ORDER_ID" ]; then STATUS_RESPONSE=$(curl -s -X GET "$SILVERPAY_URL/api/v1/orders/$SILVERPAY_ORDER_ID" \ -H "X-API-Key: test-api-key") if echo "$STATUS_RESPONSE" | grep -q "id"; then print_result "SilverPAY Status Check" "PASS" "" else print_result "SilverPAY Status Check" "FAIL" "Could not get order status" fi else print_result "SilverPAY Status Check" "SKIP" "No SilverPAY order created" fi echo "" echo "=== 9. DATABASE OPERATIONS ===" echo "------------------------------" # Test 9.1: User Operations echo -n "Testing user CRUD operations... " USER_DATA='{"username":"testuser'$(date +%s)'","email":"test@test.com","password":"Test123!","role":"Staff"}' RESPONSE=$(auth_request "POST" "/api/users" "$USER_DATA") if echo "$RESPONSE" | grep -q "id"; then USER_ID=$(echo $RESPONSE | grep -o '"id":"[^"]*' | sed 's/"id":"//') print_result "User Creation" "PASS" "" # Test user deletion DELETE_RESPONSE=$(auth_request "DELETE" "/api/users/$USER_ID") if [ "$?" -eq 0 ]; then print_result "User Deletion" "PASS" "" else print_result "User Deletion" "FAIL" "" fi else print_result "User Creation" "FAIL" "Could not create user" fi echo "" echo "=== 10. SECURITY TESTS ===" echo "--------------------------" # Test 10.1: Unauthorized Access echo -n "Testing unauthorized access prevention... " RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" "$LITTLESHOP_URL/api/users") if [ "$RESPONSE" = "401" ]; then print_result "Unauthorized Access" "PASS" "Properly blocked" else print_result "Unauthorized Access" "FAIL" "HTTP $RESPONSE (expected 401)" fi # Test 10.2: Invalid Token echo -n "Testing invalid token rejection... " RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" "$LITTLESHOP_URL/api/users" \ -H "Authorization: Bearer invalid-token-12345") if [ "$RESPONSE" = "401" ]; then print_result "Invalid Token" "PASS" "Properly rejected" else print_result "Invalid Token" "FAIL" "HTTP $RESPONSE (expected 401)" fi # Test 10.3: SQL Injection Prevention echo -n "Testing SQL injection prevention... " RESPONSE=$(curl -s "$LITTLESHOP_URL/api/catalog/products?category=';DROP TABLE users;--") if echo "$RESPONSE" | grep -q "DROP" || echo "$RESPONSE" | grep -q "error"; then print_result "SQL Injection" "FAIL" "Vulnerable to SQL injection" else print_result "SQL Injection" "PASS" "Protected" fi echo "" echo "==========================================" echo "TEST SUMMARY" echo "==========================================" echo -e "${GREEN}Passed:${NC} $TESTS_PASSED" echo -e "${RED}Failed:${NC} $TESTS_FAILED" echo -e "${YELLOW}Skipped:${NC} $TESTS_SKIPPED" echo "Total: $((TESTS_PASSED + TESTS_FAILED + TESTS_SKIPPED))" echo "" # Calculate success rate if [ $((TESTS_PASSED + TESTS_FAILED)) -gt 0 ]; then SUCCESS_RATE=$((TESTS_PASSED * 100 / (TESTS_PASSED + TESTS_FAILED))) echo "Success Rate: $SUCCESS_RATE%" if [ $SUCCESS_RATE -ge 90 ]; then echo -e "${GREEN}✓ EXCELLENT - System is production ready!${NC}" elif [ $SUCCESS_RATE -ge 75 ]; then echo -e "${YELLOW}⚠ GOOD - Minor issues need attention${NC}" else echo -e "${RED}✗ NEEDS WORK - Critical issues found${NC}" fi fi # Save results to JSON cat > "$TEST_RESULTS_FILE" << EOF { "timestamp": "$(date -Iseconds)", "results": { "passed": $TESTS_PASSED, "failed": $TESTS_FAILED, "skipped": $TESTS_SKIPPED, "total": $((TESTS_PASSED + TESTS_FAILED + TESTS_SKIPPED)), "success_rate": ${SUCCESS_RATE:-0} }, "environment": { "littleshop_url": "$LITTLESHOP_URL", "silverpay_url": "$SILVERPAY_URL" } } EOF echo "" echo "Results saved to: $TEST_RESULTS_FILE" echo "=========================================="