chore: import upstream snapshot with attribution
Check engine pin consistency / Dockerfile / CI pin consistency (push) Successful in 8s
Sirius CI/CD Pipeline / Detect Changes (push) Successful in 23s
Validate Docker Configuration / Validate Docker Compose Configuration (push) Successful in 47s
Sirius CI/CD Pipeline / Build API (${{ matrix.platform }}) (push) Has been cancelled
Sirius CI/CD Pipeline / Build UI (${{ matrix.platform }}) (push) Has been cancelled
Sirius CI/CD Pipeline / Merge Engine Manifest (push) Has been cancelled
Sirius CI/CD Pipeline / Merge API Manifest (push) Has been cancelled
Sirius CI/CD Pipeline / Merge UI Manifest (push) Has been cancelled
Sirius CI/CD Pipeline / Build Engine (${{ matrix.platform }}) (push) Has been cancelled
Sirius CI/CD Pipeline / Build Infra (${{ matrix.service }}, ${{ matrix.platform }}) (push) Has been cancelled
Sirius CI/CD Pipeline / Merge Infra Manifest (sirius-postgres) (push) Has been cancelled
Sirius CI/CD Pipeline / Merge Infra Manifest (sirius-rabbitmq) (push) Has been cancelled
Sirius CI/CD Pipeline / Merge Infra Manifest (sirius-valkey) (push) Has been cancelled
Sirius CI/CD Pipeline / Integration Test (push) Has been cancelled
Sirius CI/CD Pipeline / Public Stack Contract (push) Has been cancelled
Sirius CI/CD Pipeline / Dispatch Demo Deployment (sirius-demo branch) (push) Has been cancelled
Sirius CI/CD Pipeline / Dispatch Demo Canary (main branch) (push) Has been cancelled
Sirius CI/CD Pipeline / Guard Registry Namespace (push) Has been cancelled
Check engine pin consistency / Dockerfile / CI pin consistency (push) Successful in 8s
Sirius CI/CD Pipeline / Detect Changes (push) Successful in 23s
Validate Docker Configuration / Validate Docker Compose Configuration (push) Successful in 47s
Sirius CI/CD Pipeline / Build API (${{ matrix.platform }}) (push) Has been cancelled
Sirius CI/CD Pipeline / Build UI (${{ matrix.platform }}) (push) Has been cancelled
Sirius CI/CD Pipeline / Merge Engine Manifest (push) Has been cancelled
Sirius CI/CD Pipeline / Merge API Manifest (push) Has been cancelled
Sirius CI/CD Pipeline / Merge UI Manifest (push) Has been cancelled
Sirius CI/CD Pipeline / Build Engine (${{ matrix.platform }}) (push) Has been cancelled
Sirius CI/CD Pipeline / Build Infra (${{ matrix.service }}, ${{ matrix.platform }}) (push) Has been cancelled
Sirius CI/CD Pipeline / Merge Infra Manifest (sirius-postgres) (push) Has been cancelled
Sirius CI/CD Pipeline / Merge Infra Manifest (sirius-rabbitmq) (push) Has been cancelled
Sirius CI/CD Pipeline / Merge Infra Manifest (sirius-valkey) (push) Has been cancelled
Sirius CI/CD Pipeline / Integration Test (push) Has been cancelled
Sirius CI/CD Pipeline / Public Stack Contract (push) Has been cancelled
Sirius CI/CD Pipeline / Dispatch Demo Deployment (sirius-demo branch) (push) Has been cancelled
Sirius CI/CD Pipeline / Dispatch Demo Canary (main branch) (push) Has been cancelled
Sirius CI/CD Pipeline / Guard Registry Namespace (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,215 @@
|
||||
# SiriusScan Docker Testing Makefile
|
||||
# Provides easy commands for testing and development
|
||||
|
||||
.PHONY: help build test test-build test-health test-integration test-runtime-contract test-public-ghcr test-release-gates test-all test-security validate-ci-overhaul clean logs lint-docs lint-docs-quick lint-agents lint-agents-quick lint-agent-index regenerate-agents regenerate-agent check-agent-sync
|
||||
|
||||
# Default target
|
||||
help:
|
||||
@echo "SiriusScan Docker Testing Commands"
|
||||
@echo "=================================="
|
||||
@echo ""
|
||||
@echo "Build Commands:"
|
||||
@echo " build-base Build base configuration"
|
||||
@echo " build-dev Build development configuration"
|
||||
@echo " build-prod Build production configuration"
|
||||
@echo " build-all Build all configurations"
|
||||
@echo ""
|
||||
@echo "Test Commands:"
|
||||
@echo " test-build Test individual container builds"
|
||||
@echo " test-health Test service health checks"
|
||||
@echo " test-integration Test service integration"
|
||||
@echo " test-runtime-contract Verify runtime auth/binary contracts"
|
||||
@echo " test-public-ghcr Verify anonymous GHCR access for compose images"
|
||||
@echo " test-release-gates Run release-blocking validation checks"
|
||||
@echo " test-security Run security/auth penetration tests"
|
||||
@echo " test-all Run all tests (build, health, integration, runtime auth contract)"
|
||||
@echo " validate-ci-overhaul Validate base images and CI pipeline changes"
|
||||
@echo ""
|
||||
@echo "Development Commands:"
|
||||
@echo " dev Start development environment"
|
||||
@echo " prod Start production environment"
|
||||
@echo " stop Stop all services"
|
||||
@echo " restart Restart all services"
|
||||
@echo ""
|
||||
@echo "Utility Commands:"
|
||||
@echo " clean Clean up containers and images"
|
||||
@echo " logs Show logs for all services"
|
||||
@echo " status Show status of all services"
|
||||
@echo ""
|
||||
@echo "Documentation Commands:"
|
||||
@echo " lint-docs Run full documentation linting"
|
||||
@echo " lint-docs-quick Run quick documentation checks"
|
||||
@echo " lint-index Check documentation index completeness"
|
||||
@echo ""
|
||||
@echo "Agent Identity Commands:"
|
||||
@echo " regenerate-agents Regenerate all agent identities"
|
||||
@echo " regenerate-agent Regenerate specific agent (PRODUCT=name)"
|
||||
@echo " check-agent-sync Check if agent identities need regeneration"
|
||||
@echo " lint-agents Run full agent identity linting"
|
||||
@echo " lint-agents-quick Run quick agent checks"
|
||||
@echo " lint-agent-index Check agent identity index completeness"
|
||||
|
||||
# Build commands
|
||||
build-base:
|
||||
@echo "🔨 Building base configuration..."
|
||||
docker compose config --quiet
|
||||
@echo "✅ Base configuration is valid"
|
||||
|
||||
build-dev:
|
||||
@echo "🔨 Building development configuration..."
|
||||
docker compose -f docker-compose.yaml -f docker-compose.dev.yaml config --quiet
|
||||
@echo "✅ Development configuration is valid"
|
||||
|
||||
build-prod:
|
||||
@echo "🔨 Building production configuration..."
|
||||
docker compose config --quiet
|
||||
@echo "✅ Production configuration is valid (base docker-compose.yaml)"
|
||||
|
||||
build-all: build-base build-dev build-prod
|
||||
@echo "🎉 All configurations are valid!"
|
||||
|
||||
# Test commands
|
||||
test-build:
|
||||
@echo "🧪 Running build tests..."
|
||||
./test-build.sh
|
||||
|
||||
test-health:
|
||||
@echo "🏥 Running health tests..."
|
||||
./test-health.sh
|
||||
|
||||
test-integration:
|
||||
@echo "🔗 Running integration tests..."
|
||||
./test-integration.sh
|
||||
|
||||
test-runtime-contract:
|
||||
@echo "🧷 Verifying runtime auth/binary contracts..."
|
||||
@cd ../.. && \
|
||||
POSTGRES_PASSWORD=$${POSTGRES_PASSWORD:-test-postgres-password} \
|
||||
NEXTAUTH_SECRET=$${NEXTAUTH_SECRET:-test-nextauth-secret} \
|
||||
INITIAL_ADMIN_PASSWORD=$${INITIAL_ADMIN_PASSWORD:-test-admin-password} \
|
||||
DATABASE_URL=$${DATABASE_URL:-postgresql://postgres:test-postgres-password@sirius-postgres:5432/sirius} \
|
||||
mkdir -p secrets && \
|
||||
printf '%s\n' "$${SIRIUS_INTERNAL_API_KEY_TEST_VALUE:-test-api-key}" > secrets/sirius_api_key.txt && \
|
||||
docker compose up -d && \
|
||||
bash scripts/verify-runtime-auth-contract.sh && \
|
||||
docker compose down
|
||||
|
||||
test-public-ghcr:
|
||||
@echo "🌍 Verifying anonymous GHCR access for compose-rendered images..."
|
||||
@cd ../.. && bash scripts/verify-ghcr-public-access.sh "$${IMAGE_TAG:-latest}"
|
||||
|
||||
test-release-gates: test-build test-integration test-runtime-contract
|
||||
@echo "✅ Release-gating contract checks passed!"
|
||||
|
||||
test-security:
|
||||
@echo "🔒 Running security penetration tests..."
|
||||
cd ../security && go run .
|
||||
@echo "✅ Security tests completed!"
|
||||
|
||||
test-all: test-build test-health test-integration test-runtime-contract
|
||||
@echo "🎉 All tests completed (including runtime auth contract)!"
|
||||
|
||||
# Development commands
|
||||
dev:
|
||||
@echo "🚀 Starting development environment..."
|
||||
docker compose -f docker-compose.yaml -f docker-compose.dev.yaml up -d
|
||||
@echo "✅ Development environment started"
|
||||
@echo "🌐 UI: http://localhost:3000"
|
||||
@echo "🔌 API: http://localhost:9001"
|
||||
@echo "⚙️ Engine: http://localhost:5174"
|
||||
|
||||
prod:
|
||||
@echo "🚀 Starting production environment..."
|
||||
docker compose up -d
|
||||
@echo "✅ Production environment started (base docker-compose.yaml is production-ready)"
|
||||
@echo "🌐 UI: http://localhost:3000"
|
||||
@echo "🔌 API: http://localhost:9001"
|
||||
@echo "⚙️ Engine: http://localhost:5174"
|
||||
|
||||
stop:
|
||||
@echo "🛑 Stopping all services..."
|
||||
docker compose down
|
||||
@echo "✅ All services stopped"
|
||||
|
||||
restart: stop dev
|
||||
@echo "🔄 Services restarted"
|
||||
|
||||
# Utility commands
|
||||
clean:
|
||||
@echo "🧹 Cleaning up containers and images..."
|
||||
docker compose down --volumes --remove-orphans
|
||||
docker system prune -f
|
||||
@echo "✅ Cleanup completed"
|
||||
|
||||
logs:
|
||||
@echo "📋 Showing logs for all services..."
|
||||
docker compose logs -f
|
||||
|
||||
status:
|
||||
@echo "📊 Service Status:"
|
||||
docker compose ps
|
||||
|
||||
# Quick test for CI/CD
|
||||
ci-test: build-all test-build
|
||||
@echo "✅ CI/CD tests passed!"
|
||||
|
||||
# Validate CI/CD overhaul (base images + all app containers)
|
||||
validate-ci-overhaul:
|
||||
@echo "🔬 Validating CI/CD overhaul (base images, app builds, compose config)..."
|
||||
../../scripts/validate-ci-overhaul.sh
|
||||
@echo "✅ CI/CD overhaul validation passed!"
|
||||
|
||||
# Full validation
|
||||
validate: build-all test-all
|
||||
@echo "🎉 Full validation completed successfully!"
|
||||
|
||||
# Documentation linting commands
|
||||
lint-docs:
|
||||
@echo "📚 Running full documentation linting..."
|
||||
../../scripts/documentation/lint-docs.sh
|
||||
@echo "✅ Documentation linting completed!"
|
||||
|
||||
lint-docs-quick:
|
||||
@echo "📚 Running quick documentation checks..."
|
||||
../../scripts/documentation/lint-quick.sh
|
||||
@echo "✅ Quick documentation checks completed!"
|
||||
|
||||
lint-index:
|
||||
@echo "📚 Running index completeness linting..."
|
||||
../../scripts/documentation/lint-index.sh
|
||||
@echo "✅ Index linting completed!"
|
||||
|
||||
# Agent identity linting commands
|
||||
lint-agents:
|
||||
@echo "🤖 Running full agent identity linting..."
|
||||
cd ../../scripts/agent-identities && npm run validate
|
||||
@echo "✅ Agent identity linting completed!"
|
||||
|
||||
lint-agents-quick:
|
||||
@echo "🤖 Running quick agent checks..."
|
||||
cd ../../scripts/agent-identities && npm run validate
|
||||
@echo "✅ Quick agent checks completed!"
|
||||
|
||||
lint-agent-index:
|
||||
@echo "🤖 Checking agent identity index..."
|
||||
cd ../../scripts/agent-identities && npm run check-sync
|
||||
@echo "✅ Agent index linting completed!"
|
||||
|
||||
# Agent identity generation commands
|
||||
regenerate-agents:
|
||||
@echo "🔄 Regenerating agent identities..."
|
||||
cd ../../scripts/agent-identities && npm run generate -- --all
|
||||
@echo "✅ Agent identities regenerated!"
|
||||
|
||||
regenerate-agent:
|
||||
@echo "🔄 Regenerating $(PRODUCT) agent identity..."
|
||||
cd ../../scripts/agent-identities && npm run generate -- --product=$(PRODUCT)
|
||||
@echo "✅ $(PRODUCT) agent identity regenerated!"
|
||||
|
||||
check-agent-sync:
|
||||
@echo "🔍 Checking agent identity sync status..."
|
||||
cd ../../scripts/agent-identities && npm run check-sync
|
||||
|
||||
# Full validation including documentation and agents
|
||||
validate-all: build-all test-all lint-docs lint-agents
|
||||
@echo "🎉 Complete validation including documentation and agent identities completed successfully!"
|
||||
Executable
+160
@@ -0,0 +1,160 @@
|
||||
#!/bin/bash
|
||||
|
||||
# SiriusScan Container Build Test Script
|
||||
# Tests individual container builds and reports results
|
||||
|
||||
set -e
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Configuration
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
# Check if we're in container-testing directory or testing directory
|
||||
if [[ "$SCRIPT_DIR" == *"/container-testing" ]]; then
|
||||
PROJECT_ROOT="$(dirname "$(dirname "$SCRIPT_DIR")")"
|
||||
else
|
||||
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
|
||||
fi
|
||||
LOG_DIR="$PROJECT_ROOT/testing/logs"
|
||||
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
|
||||
LOG_FILE="$LOG_DIR/build_test_$TIMESTAMP.log"
|
||||
|
||||
# Required compose variables for strict startup contract.
|
||||
export POSTGRES_PASSWORD="${POSTGRES_PASSWORD:-test-postgres-password}"
|
||||
export NEXTAUTH_SECRET="${NEXTAUTH_SECRET:-test-nextauth-secret}"
|
||||
export INITIAL_ADMIN_PASSWORD="${INITIAL_ADMIN_PASSWORD:-test-admin-password}"
|
||||
export DATABASE_URL="${DATABASE_URL:-postgresql://postgres:${POSTGRES_PASSWORD:-test-postgres-password}@sirius-postgres:5432/sirius}"
|
||||
INTERNAL_API_KEY_TEST_VALUE="${SIRIUS_INTERNAL_API_KEY_TEST_VALUE:-test-api-key}"
|
||||
|
||||
# Base compose mounts ./secrets/sirius_api_key.txt — ensure a placeholder exists for `docker compose config` in CI/local runs.
|
||||
if [ ! -f "$PROJECT_ROOT/secrets/sirius_api_key.txt" ]; then
|
||||
mkdir -p "$PROJECT_ROOT/secrets"
|
||||
printf '%s\n' "$INTERNAL_API_KEY_TEST_VALUE" > "$PROJECT_ROOT/secrets/sirius_api_key.txt"
|
||||
fi
|
||||
|
||||
# Create logs directory
|
||||
mkdir -p "$LOG_DIR"
|
||||
|
||||
# Logging function
|
||||
log() {
|
||||
echo -e "$1" | tee -a "$LOG_FILE"
|
||||
}
|
||||
|
||||
# Test result tracking
|
||||
TOTAL_TESTS=0
|
||||
PASSED_TESTS=0
|
||||
FAILED_TESTS=0
|
||||
|
||||
# Test function
|
||||
run_test() {
|
||||
local test_name="$1"
|
||||
local test_command="$2"
|
||||
local expected_exit_code="${3:-0}"
|
||||
|
||||
TOTAL_TESTS=$((TOTAL_TESTS + 1))
|
||||
|
||||
log "${BLUE}🧪 Testing: $test_name${NC}"
|
||||
log "Command: $test_command"
|
||||
|
||||
if eval "$test_command" >> "$LOG_FILE" 2>&1; then
|
||||
if [ $? -eq $expected_exit_code ]; then
|
||||
log "${GREEN}✅ PASSED: $test_name${NC}"
|
||||
PASSED_TESTS=$((PASSED_TESTS + 1))
|
||||
return 0
|
||||
else
|
||||
log "${RED}❌ FAILED: $test_name (unexpected exit code: $?)${NC}"
|
||||
FAILED_TESTS=$((FAILED_TESTS + 1))
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
log "${RED}❌ FAILED: $test_name (command failed)${NC}"
|
||||
FAILED_TESTS=$((FAILED_TESTS + 1))
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Main test execution
|
||||
main() {
|
||||
log "${BLUE}🚀 Starting SiriusScan Container Build Tests${NC}"
|
||||
log "Timestamp: $(date)"
|
||||
log "Project Root: $PROJECT_ROOT"
|
||||
log "Log File: $LOG_FILE"
|
||||
log ""
|
||||
|
||||
cd "$PROJECT_ROOT"
|
||||
|
||||
# Test 1: Base Docker Compose Configuration
|
||||
run_test "Base Docker Compose Config" "docker compose config --quiet"
|
||||
|
||||
# Test 2: Development Docker Compose Configuration
|
||||
run_test "Development Docker Compose Config" "docker compose -f docker-compose.yaml -f docker-compose.dev.yaml config --quiet"
|
||||
|
||||
# Test 3: Source Build Docker Compose Configuration
|
||||
run_test "Source Build Docker Compose Config" "docker compose -f docker-compose.yaml -f docker-compose.build.yaml config --quiet"
|
||||
|
||||
# Test 4: sirius-postgres entrypoint contract
|
||||
run_test "sirius-postgres Entrypoint Contract" "docker build -t sirius-postgres:test ./sirius-postgres/ && docker run --rm --entrypoint /bin/sh sirius-postgres:test -lc 'test -x /usr/local/bin/start-with-monitor.sh && /bin/sh -n /usr/local/bin/start-with-monitor.sh'"
|
||||
|
||||
# Test 5: sirius-ui Production Build (base docker-compose.yaml is production-ready)
|
||||
run_test "sirius-ui Production Build" "docker build -t sirius-ui:test ./sirius-ui/ --target production"
|
||||
|
||||
# Test 6: sirius-api Runner Build
|
||||
run_test "sirius-api Runner Build" "docker build -t sirius-api:test ./sirius-api/ --target runner"
|
||||
|
||||
# Test 7: logging clients include API key auth on protected logs routes (file/env loader + engine patch)
|
||||
run_test "Logging API Key Contract" "python3 -c \"from pathlib import Path; api_handler = Path('sirius-api/handlers/log_handler.go').read_text(); engine_dockerfile = Path('sirius-engine/Dockerfile').read_text(); assert 'infraauth.LoadSiriusAPIKey' in api_handler; assert 'GO_API_COMMIT_SHA=v0.0.18' in engine_dockerfile; assert 'git apply' not in engine_dockerfile\""
|
||||
|
||||
# Test 7b: internal API key _FILE + env loader (Go)
|
||||
run_test "Internal API Key Loader Unit Tests" "( cd sirius-api && go test ./internal/infraauth/... -count=1 )"
|
||||
|
||||
# Test 8: sirius-engine Development Build
|
||||
run_test "sirius-engine Development Build" "docker build -t sirius-engine:dev ./sirius-engine/ --target development"
|
||||
|
||||
# Test 9: sirius-engine Runtime Build
|
||||
run_test "sirius-engine Runtime Build" "docker build -t sirius-engine:runtime ./sirius-engine/ --target runtime"
|
||||
|
||||
# Test 10: sirius-engine runtime startup contract binaries
|
||||
run_test "sirius-engine Runtime Binary Contract" "docker run --rm --entrypoint /bin/bash sirius-engine:runtime -lc 'command -v bash >/dev/null && command -v curl >/dev/null && command -v psql >/dev/null && command -v pkill >/dev/null && command -v nmap >/dev/null && command -v rustscan >/dev/null && command -v pwsh >/dev/null'"
|
||||
|
||||
# Test 11: sirius-engine entrypoint syntax contract
|
||||
run_test "sirius-engine Entrypoint Syntax Contract" "docker run --rm --entrypoint /bin/bash sirius-engine:runtime -lc '/bin/bash -n /start-enhanced.sh && grep -q \"validate_required_binary \\\"psql\\\"\" /start-enhanced.sh'"
|
||||
|
||||
# Test 11b: sirius-engine internal API key contract is file-backed only
|
||||
run_test "sirius-engine Internal API Key File Contract" "python3 -c \"from pathlib import Path; data = Path('sirius-engine/start-enhanced.sh').read_text(); assert 'SIRIUS_API_KEY_FILE is required' in data; assert 'SIRIUS_API_KEY differs from mounted sirius_api_key secret' not in data\""
|
||||
|
||||
# Test 12: sirius-ui Development Build
|
||||
run_test "sirius-ui Development Build" "docker build -t sirius-ui:dev ./sirius-ui/ --target development"
|
||||
|
||||
# Test 12b: sirius-ui startup scripts require readable secret files
|
||||
run_test "sirius-ui Internal API Key File Contract" "python3 -c \"from pathlib import Path; prod = Path('sirius-ui/start-prod.sh').read_text(); dev = Path('sirius-ui/start-dev.sh').read_text(); assert 'require_readable_file \\\"SIRIUS_API_KEY_FILE\\\"' in prod; assert 'require_readable_file \\\"SIRIUS_API_KEY_FILE\\\"' in dev; assert 'require_env \\\"SIRIUS_API_KEY\\\"' not in prod + dev\""
|
||||
|
||||
# Test 13: sirius-api Development Build
|
||||
run_test "sirius-api Development Build" "docker build -t sirius-api:dev ./sirius-api/ --target development"
|
||||
|
||||
# Cleanup test images
|
||||
log "${YELLOW}🧹 Cleaning up test images...${NC}"
|
||||
docker rmi sirius-postgres:test sirius-ui:test sirius-api:test sirius-engine:dev sirius-engine:runtime sirius-ui:dev sirius-api:dev 2>/dev/null || true
|
||||
|
||||
# Summary
|
||||
log ""
|
||||
log "${BLUE}📊 Test Summary${NC}"
|
||||
log "Total Tests: $TOTAL_TESTS"
|
||||
log "Passed: ${GREEN}$PASSED_TESTS${NC}"
|
||||
log "Failed: ${RED}$FAILED_TESTS${NC}"
|
||||
|
||||
if [ $FAILED_TESTS -eq 0 ]; then
|
||||
log "${GREEN}🎉 All tests passed!${NC}"
|
||||
exit 0
|
||||
else
|
||||
log "${RED}💥 Some tests failed. Check the log file: $LOG_FILE${NC}"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Run main function
|
||||
main "$@"
|
||||
Executable
+228
@@ -0,0 +1,228 @@
|
||||
#!/bin/bash
|
||||
|
||||
# SiriusScan Container Health Test Script
|
||||
# Tests service health checks and basic functionality
|
||||
|
||||
set -e
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Configuration
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
# Check if we're in container-testing directory or testing directory
|
||||
if [[ "$SCRIPT_DIR" == *"/container-testing" ]]; then
|
||||
PROJECT_ROOT="$(dirname "$(dirname "$SCRIPT_DIR")")"
|
||||
else
|
||||
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
|
||||
fi
|
||||
LOG_DIR="$PROJECT_ROOT/testing/logs"
|
||||
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
|
||||
LOG_FILE="$LOG_DIR/health_test_$TIMESTAMP.log"
|
||||
|
||||
# Required compose variables for strict startup contract.
|
||||
export SIRIUS_API_KEY="${SIRIUS_API_KEY:-test-api-key}"
|
||||
export POSTGRES_PASSWORD="${POSTGRES_PASSWORD:-test-postgres-password}"
|
||||
export NEXTAUTH_SECRET="${NEXTAUTH_SECRET:-test-nextauth-secret}"
|
||||
export INITIAL_ADMIN_PASSWORD="${INITIAL_ADMIN_PASSWORD:-test-admin-password}"
|
||||
|
||||
# Environment variables for configuration
|
||||
TEST_TIMEOUT="${TEST_TIMEOUT:-60}" # Default 60 seconds
|
||||
TEST_RETRIES="${TEST_RETRIES:-60}" # Default 60 retries (2 seconds each = 120 seconds total)
|
||||
LOG_LEVEL="${LOG_LEVEL:-info}" # Default info level
|
||||
|
||||
# Create logs directory
|
||||
mkdir -p "$LOG_DIR"
|
||||
|
||||
# Logging function
|
||||
log() {
|
||||
echo -e "$1" | tee -a "$LOG_FILE"
|
||||
}
|
||||
|
||||
# Test result tracking
|
||||
TOTAL_TESTS=0
|
||||
PASSED_TESTS=0
|
||||
FAILED_TESTS=0
|
||||
|
||||
# Wait for service to be ready
|
||||
wait_for_service() {
|
||||
local service_name="$1"
|
||||
local port="$2"
|
||||
local max_attempts=$TEST_RETRIES
|
||||
local attempt=1
|
||||
local sleep_interval=2
|
||||
|
||||
log "${YELLOW}⏳ Waiting for $service_name to be ready on port $port...${NC}"
|
||||
log "Configuration: $max_attempts attempts, ${sleep_interval}s interval (total timeout: $((max_attempts * sleep_interval))s)"
|
||||
|
||||
while [ $attempt -le $max_attempts ]; do
|
||||
# Use appropriate health endpoint based on service
|
||||
local health_url="http://localhost:$port"
|
||||
if [ "$service_name" = "sirius-api" ]; then
|
||||
health_url="http://localhost:$port/health"
|
||||
fi
|
||||
|
||||
if curl -s -f "$health_url" > /dev/null 2>&1; then
|
||||
log "${GREEN}✅ $service_name is ready!${NC}"
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [ $((attempt % 10)) -eq 0 ] || [ "$LOG_LEVEL" = "debug" ]; then
|
||||
log "Attempt $attempt/$max_attempts: $service_name not ready yet..."
|
||||
fi
|
||||
sleep $sleep_interval
|
||||
attempt=$((attempt + 1))
|
||||
done
|
||||
|
||||
log "${RED}❌ $service_name failed to start within $((max_attempts * sleep_interval)) seconds${NC}"
|
||||
log "${YELLOW}💡 Tip: Increase timeout with TEST_RETRIES environment variable (e.g., TEST_RETRIES=120)${NC}"
|
||||
return 1
|
||||
}
|
||||
|
||||
# Test function
|
||||
run_test() {
|
||||
local test_name="$1"
|
||||
local test_command="$2"
|
||||
local expected_exit_code="${3:-0}"
|
||||
|
||||
TOTAL_TESTS=$((TOTAL_TESTS + 1))
|
||||
|
||||
log "${BLUE}🧪 Testing: $test_name${NC}"
|
||||
log "Command: $test_command"
|
||||
|
||||
if eval "$test_command" >> "$LOG_FILE" 2>&1; then
|
||||
if [ $? -eq $expected_exit_code ]; then
|
||||
log "${GREEN}✅ PASSED: $test_name${NC}"
|
||||
PASSED_TESTS=$((PASSED_TESTS + 1))
|
||||
return 0
|
||||
else
|
||||
log "${RED}❌ FAILED: $test_name (unexpected exit code: $?)${NC}"
|
||||
FAILED_TESTS=$((FAILED_TESTS + 1))
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
log "${RED}❌ FAILED: $test_name (command failed)${NC}"
|
||||
FAILED_TESTS=$((FAILED_TESTS + 1))
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Health check function
|
||||
check_service_health() {
|
||||
local service_name="$1"
|
||||
local health_url="$2"
|
||||
|
||||
log "${BLUE}🏥 Checking $service_name health...${NC}"
|
||||
|
||||
if curl -s -f "$health_url" > /dev/null 2>&1; then
|
||||
log "${GREEN}✅ $service_name health check passed${NC}"
|
||||
return 0
|
||||
else
|
||||
log "${RED}❌ $service_name health check failed${NC}"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Main test execution
|
||||
main() {
|
||||
local environment="${1:-base}"
|
||||
|
||||
log "${BLUE}🚀 Starting SiriusScan Container Health Tests${NC}"
|
||||
log "Environment: $environment"
|
||||
log "Timestamp: $(date)"
|
||||
log "Project Root: $PROJECT_ROOT"
|
||||
log "Log File: $LOG_FILE"
|
||||
log "Test Configuration: $TEST_RETRIES retries, $((TEST_RETRIES * 2))s total timeout"
|
||||
log ""
|
||||
|
||||
cd "$PROJECT_ROOT"
|
||||
|
||||
# Adjust timeout for development environment (API takes longer to download dependencies)
|
||||
if [ "$environment" = "dev" ] && [ "$TEST_RETRIES" = "60" ]; then
|
||||
log "${YELLOW}🔧 Development mode detected - increasing timeout for API dependency downloads${NC}"
|
||||
TEST_RETRIES=120 # 4 minutes total timeout for dev mode
|
||||
log "Adjusted timeout: $TEST_RETRIES retries, $((TEST_RETRIES * 2))s total timeout"
|
||||
fi
|
||||
|
||||
# Start services based on environment
|
||||
case $environment in
|
||||
"dev")
|
||||
log "${YELLOW}🚀 Starting development environment...${NC}"
|
||||
docker compose -f docker-compose.yaml -f docker-compose.dev.yaml up -d
|
||||
;;
|
||||
"prod")
|
||||
log "${YELLOW}🚀 Starting production environment...${NC}"
|
||||
docker compose up -d
|
||||
;;
|
||||
*)
|
||||
log "${YELLOW}🚀 Starting base environment...${NC}"
|
||||
docker compose up -d
|
||||
;;
|
||||
esac
|
||||
|
||||
# Wait for services to start
|
||||
log "${YELLOW}⏳ Waiting for services to start...${NC}"
|
||||
sleep 10
|
||||
|
||||
# Test 1: Check if all containers are running
|
||||
run_test "All Containers Running" "docker compose ps --format 'table {{.Name}}\t{{.Status}}' | grep -v 'NAME' | grep 'Up' | wc -l | tr -d ' ' | grep -q '^6$'"
|
||||
|
||||
# Test 2: sirius-ui health check
|
||||
wait_for_service "sirius-ui" "3000"
|
||||
run_test "sirius-ui Health Check" "curl -s -f http://localhost:3000/ | grep -q 'html'"
|
||||
|
||||
# Test 3: sirius-api health check (using correct /health endpoint)
|
||||
# Note: API takes time to download dependencies in dev mode, so we'll check if it's at least running
|
||||
run_test "sirius-api Container Running" "docker compose ps sirius-api | grep -q 'Up'"
|
||||
run_test "sirius-api Health Check" "curl -s -f http://localhost:9001/health | grep -q 'healthy' || echo 'API health endpoint not ready yet (still downloading dependencies)'"
|
||||
|
||||
# Test 4: sirius-engine health check (gRPC server on port 50051)
|
||||
run_test "sirius-engine Container Running" "docker compose ps sirius-engine | grep -q 'Up'"
|
||||
run_test "sirius-engine gRPC Health Check" "nc -z localhost 50051 && echo 'gRPC server is listening on port 50051'"
|
||||
run_test "sirius-engine Process Check" "docker exec sirius-engine ps aux | grep -q 'start-enhanced.sh' || echo 'Engine process not found, but container is running'"
|
||||
|
||||
# Test 5: Database connectivity
|
||||
run_test "PostgreSQL Connectivity" "docker exec sirius-postgres pg_isready -U postgres"
|
||||
|
||||
# Test 6: Redis connectivity
|
||||
run_test "Valkey Connectivity" "docker exec sirius-valkey redis-cli ping | grep -q PONG"
|
||||
|
||||
# Test 7: RabbitMQ connectivity
|
||||
run_test "RabbitMQ Connectivity" "docker exec sirius-rabbitmq rabbitmqctl status | grep -q 'RabbitMQ version'"
|
||||
|
||||
# Test 8: Port accessibility
|
||||
run_test "Port 3000 Accessible" "curl -s -f http://localhost:3000 | grep -q 'html'"
|
||||
run_test "Port 9001 Accessible" "curl -s -f http://localhost:9001/health | grep -q 'healthy' || (docker compose ps sirius-api | grep -q 'Up' && echo 'Port 9001 container running')"
|
||||
run_test "Port 5174 Accessible" "nc -z localhost 5174"
|
||||
|
||||
# Summary
|
||||
log ""
|
||||
log "${BLUE}📊 Health Test Summary${NC}"
|
||||
log "Total Tests: $TOTAL_TESTS"
|
||||
log "Passed: ${GREEN}$PASSED_TESTS${NC}"
|
||||
log "Failed: ${RED}$FAILED_TESTS${NC}"
|
||||
|
||||
if [ $FAILED_TESTS -eq 0 ]; then
|
||||
log "${GREEN}🎉 All health tests passed!${NC}"
|
||||
exit 0
|
||||
else
|
||||
log "${RED}💥 Some health tests failed. Check the log file: $LOG_FILE${NC}"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Cleanup function
|
||||
cleanup() {
|
||||
log "${YELLOW}🧹 Cleaning up...${NC}"
|
||||
docker compose down
|
||||
}
|
||||
|
||||
# Trap to ensure cleanup on exit
|
||||
trap cleanup EXIT
|
||||
|
||||
# Run main function
|
||||
main "$@"
|
||||
+235
@@ -0,0 +1,235 @@
|
||||
#!/bin/bash
|
||||
|
||||
# SiriusScan Simple Integration Test Script
|
||||
# Tests only endpoints that actually exist and work
|
||||
|
||||
set -e
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Configuration
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_ROOT="$(dirname "$(dirname "$SCRIPT_DIR")")"
|
||||
LOG_DIR="$PROJECT_ROOT/testing/logs"
|
||||
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
|
||||
LOG_FILE="$LOG_DIR/integration_simple_test_$TIMESTAMP.log"
|
||||
|
||||
# Environment variables for configuration
|
||||
TEST_RETRIES="${TEST_RETRIES:-60}" # Default 60 retries (2 seconds each = 120 seconds total)
|
||||
LOG_LEVEL="${LOG_LEVEL:-info}" # Default info level
|
||||
|
||||
# Create logs directory
|
||||
mkdir -p "$LOG_DIR"
|
||||
|
||||
# Logging function
|
||||
log() {
|
||||
echo -e "$1" | tee -a "$LOG_FILE"
|
||||
}
|
||||
|
||||
# Test result tracking
|
||||
TOTAL_TESTS=0
|
||||
PASSED_TESTS=0
|
||||
FAILED_TESTS=0
|
||||
|
||||
# Test function
|
||||
run_test() {
|
||||
local test_name="$1"
|
||||
local test_command="$2"
|
||||
local expected_exit_code="${3:-0}"
|
||||
|
||||
TOTAL_TESTS=$((TOTAL_TESTS + 1))
|
||||
|
||||
log "${BLUE}🧪 Testing: $test_name${NC}"
|
||||
log "Command: $test_command"
|
||||
|
||||
if eval "$test_command" >> "$LOG_FILE" 2>&1; then
|
||||
if [ $? -eq $expected_exit_code ]; then
|
||||
log "${GREEN}✅ PASSED: $test_name${NC}"
|
||||
PASSED_TESTS=$((PASSED_TESTS + 1))
|
||||
return 0
|
||||
else
|
||||
log "${RED}❌ FAILED: $test_name (unexpected exit code: $?)${NC}"
|
||||
FAILED_TESTS=$((FAILED_TESTS + 1))
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
log "${RED}❌ FAILED: $test_name (command failed)${NC}"
|
||||
FAILED_TESTS=$((FAILED_TESTS + 1))
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Wait for service to be ready
|
||||
wait_for_service() {
|
||||
local service_name="$1"
|
||||
local port="$2"
|
||||
local max_attempts=$TEST_RETRIES
|
||||
local attempt=1
|
||||
local sleep_interval=2
|
||||
|
||||
log "${YELLOW}⏳ Waiting for $service_name to be ready on port $port...${NC}"
|
||||
log "Configuration: $max_attempts attempts, ${sleep_interval}s interval (total timeout: $((max_attempts * sleep_interval))s)"
|
||||
|
||||
while [ $attempt -le $max_attempts ]; do
|
||||
# Use appropriate health endpoint based on service
|
||||
local health_url="http://localhost:$port"
|
||||
if [ "$service_name" = "sirius-api" ]; then
|
||||
health_url="http://localhost:$port/health"
|
||||
fi
|
||||
|
||||
if curl -s -f "$health_url" > /dev/null 2>&1; then
|
||||
log "${GREEN}✅ $service_name is ready!${NC}"
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [ $((attempt % 10)) -eq 0 ] || [ "$LOG_LEVEL" = "debug" ]; then
|
||||
log "Attempt $attempt/$max_attempts: $service_name not ready yet..."
|
||||
fi
|
||||
sleep $sleep_interval
|
||||
attempt=$((attempt + 1))
|
||||
done
|
||||
|
||||
log "${RED}❌ $service_name failed to start within $((max_attempts * sleep_interval)) seconds${NC}"
|
||||
log "${YELLOW}💡 Tip: Increase timeout with TEST_RETRIES environment variable (e.g., TEST_RETRIES=120)${NC}"
|
||||
return 1
|
||||
}
|
||||
|
||||
# Test core functionality
|
||||
test_core_functionality() {
|
||||
log "${BLUE}🔧 Testing Core Functionality${NC}"
|
||||
|
||||
# Test 1: All containers are running
|
||||
run_test "All Containers Running" "docker compose ps --format 'table {{.Name}}\t{{.Status}}' | grep -v 'NAME' | grep 'Up' | wc -l | tr -d ' ' | grep -q '^6$'"
|
||||
|
||||
# Test 2: UI is accessible
|
||||
run_test "UI Accessibility" "curl -s -f http://localhost:3000 | grep -q 'html'"
|
||||
|
||||
# Test 3: API health endpoint
|
||||
run_test "API Health Endpoint" "curl -s -f http://localhost:9001/health | grep -q 'healthy'"
|
||||
|
||||
# Test 4: API hosts endpoint (should return empty array)
|
||||
run_test "API Hosts Endpoint" "curl -s -f http://localhost:9001/host | grep -q '\\[\\]' || echo 'Hosts endpoint responding'"
|
||||
|
||||
# Test 5: Engine gRPC server
|
||||
run_test "Engine gRPC Server" "nc -z localhost 50051 && echo 'gRPC server is listening on port 50051'"
|
||||
|
||||
# Test 6: Database connectivity
|
||||
run_test "PostgreSQL Connectivity" "docker exec sirius-postgres pg_isready -U postgres"
|
||||
|
||||
# Test 7: Cache connectivity
|
||||
run_test "Valkey Connectivity" "docker exec sirius-valkey redis-cli ping | grep -q PONG"
|
||||
|
||||
# Test 8: Message queue connectivity
|
||||
run_test "RabbitMQ Connectivity" "docker exec sirius-rabbitmq rabbitmqctl status | grep -q 'RabbitMQ version'"
|
||||
}
|
||||
|
||||
# Test service communication
|
||||
test_service_communication() {
|
||||
log "${BLUE}🔗 Testing Service Communication${NC}"
|
||||
|
||||
# Test UI -> API communication
|
||||
run_test "UI to API Health Check" "curl -s -f http://localhost:3000 | grep -q 'html'"
|
||||
|
||||
# Test API -> Engine communication (via RabbitMQ, not HTTP)
|
||||
run_test "API Health Status" "curl -s http://localhost:9001/health | grep -q 'healthy'"
|
||||
|
||||
# Test Engine -> Database communication (gRPC server is ready)
|
||||
run_test "Engine gRPC Ready" "nc -z localhost 50051 && echo 'Engine gRPC server ready'"
|
||||
}
|
||||
|
||||
# Test error handling
|
||||
test_error_handling() {
|
||||
log "${BLUE}⚠️ Testing Error Handling${NC}"
|
||||
|
||||
# Test 404 handling
|
||||
run_test "UI 404 Error Handling" "curl -s -I http://localhost:3000/nonexistent | grep -q '404'"
|
||||
run_test "API 404 Error Handling" "curl -s -I http://localhost:9001/nonexistent | grep -q '404'"
|
||||
|
||||
# Test invalid API requests
|
||||
run_test "Invalid API Request Handling" "curl -s -X POST http://localhost:9001/host -H 'Content-Type: application/json' -d '{}' | grep -q 'error\\|invalid' || echo 'API error handling working'"
|
||||
}
|
||||
|
||||
# Main test execution
|
||||
main() {
|
||||
local environment="${1:-base}"
|
||||
|
||||
log "${BLUE}🚀 Starting SiriusScan Simple Integration Tests${NC}"
|
||||
log "Environment: $environment"
|
||||
log "Timestamp: $(date)"
|
||||
log "Project Root: $PROJECT_ROOT"
|
||||
log "Log File: $LOG_FILE"
|
||||
log "Test Configuration: $TEST_RETRIES retries, $((TEST_RETRIES * 2))s total timeout"
|
||||
log ""
|
||||
|
||||
cd "$PROJECT_ROOT"
|
||||
|
||||
# Adjust timeout for development environment (API takes longer to download dependencies)
|
||||
if [ "$environment" = "dev" ] && [ "$TEST_RETRIES" = "60" ]; then
|
||||
log "${YELLOW}🔧 Development mode detected - increasing timeout for API dependency downloads${NC}"
|
||||
TEST_RETRIES=120 # 4 minutes total timeout for dev mode
|
||||
log "Adjusted timeout: $TEST_RETRIES retries, $((TEST_RETRIES * 2))s total timeout"
|
||||
fi
|
||||
|
||||
# Start services based on environment
|
||||
case $environment in
|
||||
"dev")
|
||||
log "${YELLOW}🚀 Starting development environment...${NC}"
|
||||
docker compose -f docker-compose.yaml -f docker-compose.dev.yaml up -d
|
||||
;;
|
||||
"prod")
|
||||
log "${YELLOW}🚀 Starting production environment...${NC}"
|
||||
docker compose up -d
|
||||
;;
|
||||
*)
|
||||
log "${YELLOW}🚀 Starting base environment...${NC}"
|
||||
docker compose up -d
|
||||
;;
|
||||
esac
|
||||
|
||||
# Wait for services to start
|
||||
log "${YELLOW}⏳ Waiting for services to start...${NC}"
|
||||
sleep 15
|
||||
|
||||
# Wait for individual services
|
||||
wait_for_service "sirius-ui" "3000"
|
||||
wait_for_service "sirius-api" "9001"
|
||||
# Note: sirius-engine is a gRPC server, not HTTP, so we check port connectivity instead
|
||||
run_test "Engine gRPC Connectivity" "nc -z localhost 50051 && echo 'gRPC server is ready'"
|
||||
|
||||
# Run integration tests
|
||||
test_core_functionality
|
||||
test_service_communication
|
||||
test_error_handling
|
||||
|
||||
# Summary
|
||||
log ""
|
||||
log "${BLUE}📊 Integration Test Summary${NC}"
|
||||
log "Total Tests: $TOTAL_TESTS"
|
||||
log "Passed: ${GREEN}$PASSED_TESTS${NC}"
|
||||
log "Failed: ${RED}$FAILED_TESTS${NC}"
|
||||
|
||||
if [ $FAILED_TESTS -eq 0 ]; then
|
||||
log "${GREEN}🎉 All integration tests passed!${NC}"
|
||||
exit 0
|
||||
else
|
||||
log "${RED}💥 Some integration tests failed. Check the log file: $LOG_FILE${NC}"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Cleanup function
|
||||
cleanup() {
|
||||
log "${YELLOW}🧹 Cleaning up...${NC}"
|
||||
docker compose down
|
||||
}
|
||||
|
||||
# Trap to ensure cleanup on exit
|
||||
trap cleanup EXIT
|
||||
|
||||
# Run main function
|
||||
main "$@"
|
||||
+269
@@ -0,0 +1,269 @@
|
||||
#!/bin/bash
|
||||
|
||||
# SiriusScan Integration Test Script
|
||||
# Tests service integration and end-to-end functionality
|
||||
|
||||
set -e
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Configuration
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
# Check if we're in container-testing directory or testing directory
|
||||
if [[ "$SCRIPT_DIR" == *"/container-testing" ]]; then
|
||||
PROJECT_ROOT="$(dirname "$(dirname "$SCRIPT_DIR")")"
|
||||
else
|
||||
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
|
||||
fi
|
||||
LOG_DIR="$PROJECT_ROOT/testing/logs"
|
||||
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
|
||||
LOG_FILE="$LOG_DIR/integration_test_$TIMESTAMP.log"
|
||||
|
||||
# Required compose variables for strict startup contract.
|
||||
export POSTGRES_PASSWORD="${POSTGRES_PASSWORD:-test-postgres-password}"
|
||||
export NEXTAUTH_SECRET="${NEXTAUTH_SECRET:-test-nextauth-secret}"
|
||||
export INITIAL_ADMIN_PASSWORD="${INITIAL_ADMIN_PASSWORD:-test-admin-password}"
|
||||
INTERNAL_API_KEY_TEST_VALUE="${SIRIUS_INTERNAL_API_KEY_TEST_VALUE:-test-api-key}"
|
||||
|
||||
# Environment variables for configuration
|
||||
TEST_TIMEOUT="${TEST_TIMEOUT:-60}" # Default 60 seconds
|
||||
TEST_RETRIES="${TEST_RETRIES:-60}" # Default 60 retries (2 seconds each = 120 seconds total)
|
||||
LOG_LEVEL="${LOG_LEVEL:-info}" # Default info level
|
||||
|
||||
# Create logs directory
|
||||
mkdir -p "$LOG_DIR"
|
||||
|
||||
# Base compose mounts ./secrets/sirius_api_key.txt — ensure a placeholder exists
|
||||
# before `docker compose up` in local and CI test runs.
|
||||
if [ ! -f "$PROJECT_ROOT/secrets/sirius_api_key.txt" ]; then
|
||||
mkdir -p "$PROJECT_ROOT/secrets"
|
||||
printf '%s\n' "$INTERNAL_API_KEY_TEST_VALUE" > "$PROJECT_ROOT/secrets/sirius_api_key.txt"
|
||||
fi
|
||||
|
||||
# Logging function
|
||||
log() {
|
||||
echo -e "$1" | tee -a "$LOG_FILE"
|
||||
}
|
||||
|
||||
# Test result tracking
|
||||
TOTAL_TESTS=0
|
||||
PASSED_TESTS=0
|
||||
FAILED_TESTS=0
|
||||
|
||||
# Test function
|
||||
run_test() {
|
||||
local test_name="$1"
|
||||
local test_command="$2"
|
||||
local expected_exit_code="${3:-0}"
|
||||
|
||||
TOTAL_TESTS=$((TOTAL_TESTS + 1))
|
||||
|
||||
log "${BLUE}🧪 Testing: $test_name${NC}"
|
||||
log "Command: $test_command"
|
||||
|
||||
if eval "$test_command" >> "$LOG_FILE" 2>&1; then
|
||||
if [ $? -eq $expected_exit_code ]; then
|
||||
log "${GREEN}✅ PASSED: $test_name${NC}"
|
||||
PASSED_TESTS=$((PASSED_TESTS + 1))
|
||||
return 0
|
||||
else
|
||||
log "${RED}❌ FAILED: $test_name (unexpected exit code: $?)${NC}"
|
||||
FAILED_TESTS=$((FAILED_TESTS + 1))
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
log "${RED}❌ FAILED: $test_name (command failed)${NC}"
|
||||
FAILED_TESTS=$((FAILED_TESTS + 1))
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Wait for service to be ready
|
||||
wait_for_service() {
|
||||
local service_name="$1"
|
||||
local port="$2"
|
||||
local max_attempts=$TEST_RETRIES
|
||||
local attempt=1
|
||||
local sleep_interval=2
|
||||
|
||||
log "${YELLOW}⏳ Waiting for $service_name to be ready on port $port...${NC}"
|
||||
log "Configuration: $max_attempts attempts, ${sleep_interval}s interval (total timeout: $((max_attempts * sleep_interval))s)"
|
||||
|
||||
while [ $attempt -le $max_attempts ]; do
|
||||
# Use appropriate health endpoint based on service
|
||||
local health_url="http://localhost:$port"
|
||||
if [ "$service_name" = "sirius-api" ]; then
|
||||
health_url="http://localhost:$port/health"
|
||||
fi
|
||||
|
||||
if curl -s -f "$health_url" > /dev/null 2>&1; then
|
||||
log "${GREEN}✅ $service_name is ready!${NC}"
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [ $((attempt % 10)) -eq 0 ] || [ "$LOG_LEVEL" = "debug" ]; then
|
||||
log "Attempt $attempt/$max_attempts: $service_name not ready yet..."
|
||||
fi
|
||||
sleep $sleep_interval
|
||||
attempt=$((attempt + 1))
|
||||
done
|
||||
|
||||
log "${RED}❌ $service_name failed to start within $((max_attempts * sleep_interval)) seconds${NC}"
|
||||
log "${YELLOW}💡 Tip: Increase timeout with TEST_RETRIES environment variable (e.g., TEST_RETRIES=120)${NC}"
|
||||
return 1
|
||||
}
|
||||
|
||||
# Test API endpoints
|
||||
test_api_endpoints() {
|
||||
log "${BLUE}🔗 Testing API Endpoints${NC}"
|
||||
|
||||
# Test sirius-api endpoints (only test endpoints that actually exist)
|
||||
run_test "API Health Endpoint" "curl -s -f http://localhost:9001/health | grep -q 'healthy'"
|
||||
run_test "API Hosts Endpoint" "curl -s -f http://localhost:9001/host | grep -q '\\[\\]' || echo 'Hosts endpoint responding'"
|
||||
run_test "API Vulnerabilities Endpoint" "curl -s -f http://localhost:9001/vulnerability/test | grep -q 'error\\|not found' || echo 'Vulnerability endpoint responding'"
|
||||
|
||||
# Test sirius-engine gRPC server
|
||||
run_test "Engine gRPC Server" "nc -z localhost 50051 && echo 'gRPC server is listening on port 50051'"
|
||||
run_test "Engine Container Running" "docker compose ps sirius-engine | grep -q 'Up'"
|
||||
run_test "Engine Process Check" "docker exec sirius-engine ps aux | grep -q 'start-enhanced.sh' || echo 'Engine process not found, but container is running'"
|
||||
}
|
||||
|
||||
# Test database operations
|
||||
test_database_operations() {
|
||||
log "${BLUE}🗄️ Testing Database Operations${NC}"
|
||||
|
||||
# Test PostgreSQL operations
|
||||
run_test "PostgreSQL Connection" "docker exec sirius-postgres psql -U postgres -d sirius -c 'SELECT 1;'"
|
||||
run_test "PostgreSQL Tables Exist" "docker exec sirius-postgres psql -U postgres -d sirius -c '\\dt' | grep -q 'hosts\\|vulnerabilities\\|ports'"
|
||||
|
||||
# Test Valkey operations
|
||||
run_test "Valkey Set/Get" "docker exec sirius-valkey redis-cli set test_key 'test_value' && docker exec sirius-valkey redis-cli get test_key | grep -q 'test_value'"
|
||||
run_test "Valkey Keys Command" "docker exec sirius-valkey redis-cli keys '*' | grep -q 'test_key'"
|
||||
}
|
||||
|
||||
# Test service communication
|
||||
test_service_communication() {
|
||||
log "${BLUE}🔗 Testing Service Communication${NC}"
|
||||
|
||||
# Test UI -> API communication (using actual endpoints)
|
||||
run_test "UI to API Health Check" "curl -s -f http://localhost:3000 | grep -q 'html'"
|
||||
run_test "UI Accessibility" "curl -s -f http://localhost:3000 | grep -q 'Sirius\\|html' || echo 'UI is responding'"
|
||||
|
||||
# Test API -> Engine communication (via RabbitMQ, not HTTP)
|
||||
run_test "API Health Status" "curl -s http://localhost:9001/health | grep -q 'healthy'"
|
||||
run_test "API Hosts Endpoint" "curl -s http://localhost:9001/host | grep -q '\\[\\]' || echo 'API hosts endpoint responding'"
|
||||
|
||||
# Test Engine -> Database communication (gRPC server is ready)
|
||||
run_test "Engine gRPC Ready" "nc -z localhost 50051 && echo 'Engine gRPC server ready'"
|
||||
}
|
||||
|
||||
# Validate scanner script-linkage contracts in ValKey state.
|
||||
test_scanner_linkage_contract() {
|
||||
log "${BLUE}🧩 Testing Scanner Script-Linkage Contract${NC}"
|
||||
|
||||
run_test "NSE Manifest Exists in ValKey" "docker exec sirius-valkey redis-cli EXISTS nse:manifest | rg -q '^1$'"
|
||||
run_test "NSE Manifest Contains Scripts Block" "docker exec sirius-valkey redis-cli --raw GET nse:manifest | rg -q '\"scripts\"'"
|
||||
run_test "NSE Manifest Contains Script Entries" "docker exec sirius-valkey redis-cli --raw GET nse:manifest | python3 -c 'import json,sys; manifest=json.load(sys.stdin); scripts=manifest.get(\"scripts\", {}); count=len(scripts) if isinstance(scripts, (dict, list)) else 0; raise SystemExit(0 if count > 0 else 1)'"
|
||||
}
|
||||
|
||||
# Note: Authentication and UI functionality tests removed
|
||||
# These are not necessary for container health validation
|
||||
|
||||
# Test error handling
|
||||
test_error_handling() {
|
||||
log "${BLUE}⚠️ Testing Error Handling${NC}"
|
||||
|
||||
# Test 404 handling
|
||||
run_test "UI 404 Error Handling" "curl -s -I http://localhost:3000/nonexistent | grep -q '404'"
|
||||
run_test "API Error Handling" "curl -s -I http://localhost:9001/nonexistent | grep -Eq '401|404'"
|
||||
|
||||
# Test invalid API requests (using actual endpoints)
|
||||
run_test "Invalid API Request Handling" "curl -s -X POST http://localhost:9001/host -H 'Content-Type: application/json' -d '{}' | grep -q 'error\\|invalid' || echo 'API error handling working'"
|
||||
}
|
||||
|
||||
# Main test execution
|
||||
main() {
|
||||
local environment="${1:-base}"
|
||||
|
||||
log "${BLUE}🚀 Starting SiriusScan Integration Tests${NC}"
|
||||
log "Environment: $environment"
|
||||
log "Timestamp: $(date)"
|
||||
log "Project Root: $PROJECT_ROOT"
|
||||
log "Log File: $LOG_FILE"
|
||||
log "Test Configuration: $TEST_RETRIES retries, $((TEST_RETRIES * 2))s total timeout"
|
||||
log ""
|
||||
|
||||
cd "$PROJECT_ROOT"
|
||||
|
||||
# Adjust timeout for development environment (API takes longer to download dependencies)
|
||||
if [ "$environment" = "dev" ] && [ "$TEST_RETRIES" = "60" ]; then
|
||||
log "${YELLOW}🔧 Development mode detected - increasing timeout for API dependency downloads${NC}"
|
||||
TEST_RETRIES=120 # 4 minutes total timeout for dev mode
|
||||
log "Adjusted timeout: $TEST_RETRIES retries, $((TEST_RETRIES * 2))s total timeout"
|
||||
fi
|
||||
|
||||
# Start services based on environment
|
||||
case $environment in
|
||||
"dev")
|
||||
log "${YELLOW}🚀 Starting development environment...${NC}"
|
||||
docker compose -f docker-compose.yaml -f docker-compose.dev.yaml up -d
|
||||
;;
|
||||
"prod")
|
||||
log "${YELLOW}🚀 Starting production environment...${NC}"
|
||||
docker compose up -d
|
||||
;;
|
||||
*)
|
||||
log "${YELLOW}🚀 Starting base environment...${NC}"
|
||||
docker compose up -d
|
||||
;;
|
||||
esac
|
||||
|
||||
# Wait for services to start
|
||||
log "${YELLOW}⏳ Waiting for services to start...${NC}"
|
||||
sleep 15
|
||||
|
||||
# Wait for individual services
|
||||
wait_for_service "sirius-ui" "3000"
|
||||
wait_for_service "sirius-api" "9001"
|
||||
# Note: sirius-engine is a gRPC server, not HTTP, so we check port connectivity instead
|
||||
run_test "Engine gRPC Connectivity" "nc -z localhost 50051 && echo 'gRPC server is ready'"
|
||||
|
||||
# Run integration tests (only essential container health tests)
|
||||
test_api_endpoints
|
||||
test_database_operations
|
||||
test_service_communication
|
||||
test_scanner_linkage_contract
|
||||
test_error_handling
|
||||
|
||||
# Summary
|
||||
log ""
|
||||
log "${BLUE}📊 Integration Test Summary${NC}"
|
||||
log "Total Tests: $TOTAL_TESTS"
|
||||
log "Passed: ${GREEN}$PASSED_TESTS${NC}"
|
||||
log "Failed: ${RED}$FAILED_TESTS${NC}"
|
||||
|
||||
if [ $FAILED_TESTS -eq 0 ]; then
|
||||
log "${GREEN}🎉 All integration tests passed!${NC}"
|
||||
exit 0
|
||||
else
|
||||
log "${RED}💥 Some integration tests failed. Check the log file: $LOG_FILE${NC}"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Cleanup function
|
||||
cleanup() {
|
||||
log "${YELLOW}🧹 Cleaning up...${NC}"
|
||||
docker compose down
|
||||
}
|
||||
|
||||
# Trap to ensure cleanup on exit
|
||||
trap cleanup EXIT
|
||||
|
||||
# Run main function
|
||||
main "$@"
|
||||
Executable
+54
@@ -0,0 +1,54 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Quick timeout test script
|
||||
# Tests the new timeout configuration
|
||||
|
||||
set -e
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
echo -e "${BLUE}🧪 Testing Container Health Timeout Configuration${NC}"
|
||||
echo ""
|
||||
|
||||
# Test 1: Default timeout
|
||||
echo -e "${YELLOW}Test 1: Default timeout (60 retries = 120s)${NC}"
|
||||
export TEST_RETRIES=60
|
||||
export LOG_LEVEL=debug
|
||||
timeout 5s ./test-health.sh dev 2>&1 | head -20 || echo "Timeout test completed (expected)"
|
||||
|
||||
echo ""
|
||||
|
||||
# Test 2: Extended timeout
|
||||
echo -e "${YELLOW}Test 2: Extended timeout (120 retries = 240s)${NC}"
|
||||
export TEST_RETRIES=120
|
||||
export LOG_LEVEL=debug
|
||||
timeout 5s ./test-health.sh dev 2>&1 | head -20 || echo "Timeout test completed (expected)"
|
||||
|
||||
echo ""
|
||||
|
||||
# Test 3: Environment variable override
|
||||
echo -e "${YELLOW}Test 3: Environment variable override${NC}"
|
||||
export TEST_RETRIES=30
|
||||
export LOG_LEVEL=debug
|
||||
timeout 5s ./test-health.sh dev 2>&1 | head -20 || echo "Timeout test completed (expected)"
|
||||
|
||||
echo ""
|
||||
echo -e "${GREEN}✅ Timeout configuration tests completed${NC}"
|
||||
echo ""
|
||||
echo -e "${BLUE}💡 Usage examples:${NC}"
|
||||
echo " # Use default timeout (120s for dev, 60s for others)"
|
||||
echo " ./test-health.sh dev"
|
||||
echo ""
|
||||
echo " # Override timeout to 4 minutes"
|
||||
echo " TEST_RETRIES=120 ./test-health.sh dev"
|
||||
echo ""
|
||||
echo " # Enable debug logging"
|
||||
echo " LOG_LEVEL=debug ./test-health.sh dev"
|
||||
echo ""
|
||||
echo " # Quick test with short timeout"
|
||||
echo " TEST_RETRIES=10 ./test-health.sh dev"
|
||||
Reference in New Issue
Block a user