#!/bin/bash # test-integration.sh - Integration tests for inou services # Run: make test or ./scripts/test-integration.sh set -e RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' ERRORS=0 TESTS=0 # Test dossier ID (Johan) TEST_LOGIN="4f1ffbc65c0a44d9" # Test dossier with imaging (Sophia) TEST_IMAGING_DOSSIER="3b38234f2b0f7ee6" TEST_STUDY="39961ec388576df2" TEST_SERIES="77ce1a32aa297f29" pass() { echo -e "${GREEN}✓${NC} $1" TESTS=$((TESTS + 1)) } fail() { echo -e "${RED}✗${NC} $1" ERRORS=$((ERRORS + 1)) TESTS=$((TESTS + 1)) } echo "=== Inou Integration Tests ===" echo "" # ============================================================================= # Service Health Checks # ============================================================================= echo "--- Service Health ---" # Portal HTTP=$(curl -s -o /dev/null -w "%{http_code}" "https://inou.com/" 2>/dev/null || echo "000") if [ "$HTTP" = "200" ]; then pass "Portal HTTPS (200)"; else fail "Portal HTTPS ($HTTP)"; fi # API HTTP=$(curl -s -o /dev/null -w "%{http_code}" "https://inou.com/api/version" 2>/dev/null || echo "000") if [ "$HTTP" = "200" ]; then pass "API HTTPS (200)"; else fail "API HTTPS ($HTTP)"; fi # Internal ports HTTP=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:1080/" 2>/dev/null || echo "000") if [ "$HTTP" = "200" ]; then pass "Portal internal :1080 (200)"; else fail "Portal internal :1080 ($HTTP)"; fi HTTP=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:8082/api/version" 2>/dev/null || echo "000") if [ "$HTTP" = "200" ]; then pass "API internal :8082 (200)"; else fail "API internal :8082 ($HTTP)"; fi echo "" # ============================================================================= # Login Flow # ============================================================================= echo "--- Login Flow ---" # Start page RESP=$(curl -s "http://localhost:1080/start") if echo "$RESP" | grep -q "Sign in"; then pass "Login page renders"; else fail "Login page missing"; fi # Send code (with nonce for bot protection) RESP=$(curl -s -X POST "http://localhost:1080/send-code" -d "email=test@example.com&nonce=3000") if echo "$RESP" | grep -q "Check your email"; then pass "Send code works"; else fail "Send code failed"; fi echo "" # ============================================================================= # Authenticated Routes # ============================================================================= echo "--- Authenticated Routes ---" # Dashboard RESP=$(curl -s -b "login=$TEST_LOGIN" "http://localhost:1080/dashboard") if echo "$RESP" | grep -q "Dossiers"; then pass "Dashboard renders"; else fail "Dashboard failed"; fi # Add dossier page RESP=$(curl -s -b "login=$TEST_LOGIN" "http://localhost:1080/dossier/add") if echo "$RESP" | grep -q "Add dossier"; then pass "Add dossier page renders"; else fail "Add dossier page failed"; fi # View dossier RESP=$(curl -s -b "login=$TEST_LOGIN" "http://localhost:1080/dossier/$TEST_IMAGING_DOSSIER") if echo "$RESP" | grep -q "Sophia"; then pass "View dossier renders"; else fail "View dossier failed"; fi # Edit dossier RESP=$(curl -s -b "login=$TEST_LOGIN" "http://localhost:1080/dossier/$TEST_IMAGING_DOSSIER/edit") if echo "$RESP" | grep -q 'value="Sophia'; then pass "Edit dossier renders"; else fail "Edit dossier failed"; fi echo "" # ============================================================================= # Dossier CRUD # ============================================================================= echo "--- Dossier CRUD ---" # Create test dossier RESP=$(curl -s -b "login=$TEST_LOGIN" -X POST "http://localhost:1080/dossier/add" \ -d "name=Integration Test&dob=1985-03-20&sex=F&relation=8&nonce=3000" \ -w "\n%{redirect_url}") NEW_ID=$(echo "$RESP" | grep -oE '[a-f0-9]{16}' | tail -1) if [ -n "$NEW_ID" ]; then pass "Create dossier (ID: $NEW_ID)" # Verify via API RESP=$(curl -s "http://localhost:8082/api/dossiers?token=$TEST_LOGIN") if echo "$RESP" | grep -q "Integration Test"; then pass "Dossier visible in API" else fail "Dossier not in API" fi # Clean up sqlite3 /tank/inou/data/inou.db "DELETE FROM dossier_access WHERE target_dossier_id = '$NEW_ID' OR accessor_dossier_id = '$NEW_ID'" 2>/dev/null sqlite3 /tank/inou/data/inou.db "DELETE FROM dossiers WHERE dossier_id = '$NEW_ID'" 2>/dev/null pass "Cleanup test dossier" else fail "Create dossier failed" fi echo "" # ============================================================================= # API Data Access (uses token= query param for auth) # ============================================================================= echo "--- API Data Access ---" # List dossiers RESP=$(curl -s "http://localhost:8082/api/dossiers?token=$TEST_LOGIN") if echo "$RESP" | grep -q "Sophia"; then pass "API list dossiers"; else fail "API list dossiers"; fi # List studies RESP=$(curl -s "http://localhost:8082/api/studies?dossier=$TEST_IMAGING_DOSSIER&token=$TEST_LOGIN") if echo "$RESP" | grep -q "MRI BRAIN"; then pass "API list studies"; else fail "API list studies"; fi # List series RESP=$(curl -s "http://localhost:8082/api/series?dossier=$TEST_IMAGING_DOSSIER&study=$TEST_STUDY&token=$TEST_LOGIN") if echo "$RESP" | grep -q "SAG T1"; then pass "API list series"; else fail "API list series"; fi # List slices RESP=$(curl -s "http://localhost:8082/api/slices?dossier=$TEST_IMAGING_DOSSIER&series=$TEST_SERIES&token=$TEST_LOGIN") if echo "$RESP" | grep -q "slice_location"; then pass "API list slices"; else fail "API list slices"; fi echo "" # ============================================================================= # Image Fetch # ============================================================================= echo "--- Image Fetch ---" # Get first slice ID SLICE_ID=$(curl -s "http://localhost:8082/api/slices?dossier=$TEST_IMAGING_DOSSIER&series=$TEST_SERIES&token=$TEST_LOGIN" \ | grep -oE '"id":"[a-f0-9]{16}"' | head -1 | cut -d'"' -f4) if [ -n "$SLICE_ID" ]; then # Fetch image SIZE=$(curl -s "http://localhost:8082/image/$SLICE_ID?dossier=$TEST_IMAGING_DOSSIER&token=$TEST_LOGIN" \ -o /tmp/test_slice.png -w "%{size_download}") if [ "$SIZE" -gt 10000 ]; then pass "Fetch image ($SIZE bytes)" else fail "Image too small ($SIZE bytes)" fi rm -f /tmp/test_slice.png else fail "Could not get slice ID" fi echo "" # ============================================================================= # Summary # ============================================================================= echo "=== Summary ===" PASSED=$((TESTS - ERRORS)) echo -e "Passed: ${GREEN}$PASSED${NC} / $TESTS" if [ $ERRORS -eq 0 ]; then echo -e "${GREEN}All tests passed!${NC}" exit 0 else echo -e "${RED}$ERRORS test(s) failed${NC}" exit 1 fi