Makefile 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. # SeaweedFS S3 IAM Integration Tests Makefile
  2. .PHONY: all test clean setup start-services stop-services wait-for-services help
  3. # Default target
  4. all: test
  5. # Test configuration
  6. WEED_BINARY ?= $(shell go env GOPATH)/bin/weed
  7. LOG_LEVEL ?= 2
  8. S3_PORT ?= 8333
  9. FILER_PORT ?= 8888
  10. MASTER_PORT ?= 9333
  11. VOLUME_PORT ?= 8081
  12. TEST_TIMEOUT ?= 30m
  13. # Service PIDs
  14. MASTER_PID_FILE = /tmp/weed-master.pid
  15. VOLUME_PID_FILE = /tmp/weed-volume.pid
  16. FILER_PID_FILE = /tmp/weed-filer.pid
  17. S3_PID_FILE = /tmp/weed-s3.pid
  18. help: ## Show this help message
  19. @echo "SeaweedFS S3 IAM Integration Tests"
  20. @echo ""
  21. @echo "Usage:"
  22. @echo " make [target]"
  23. @echo ""
  24. @echo "Standard Targets:"
  25. @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " %-25s %s\n", $$1, $$2}' $(MAKEFILE_LIST) | head -20
  26. @echo ""
  27. @echo "New Test Targets (Previously Skipped):"
  28. @echo " test-distributed Run distributed IAM tests"
  29. @echo " test-performance Run performance tests"
  30. @echo " test-stress Run stress tests"
  31. @echo " test-versioning-stress Run S3 versioning stress tests"
  32. @echo " test-keycloak-full Run complete Keycloak integration tests"
  33. @echo " test-all-previously-skipped Run all previously skipped tests"
  34. @echo " setup-all-tests Setup environment for all tests"
  35. @echo ""
  36. @echo "Docker Compose Targets:"
  37. @echo " docker-test Run tests with Docker Compose including Keycloak"
  38. @echo " docker-up Start all services with Docker Compose"
  39. @echo " docker-down Stop all Docker Compose services"
  40. @echo " docker-logs Show logs from all services"
  41. test: clean setup start-services run-tests stop-services ## Run complete IAM integration test suite
  42. test-quick: run-tests ## Run tests assuming services are already running
  43. run-tests: ## Execute the Go tests
  44. @echo "🧪 Running S3 IAM Integration Tests..."
  45. go test -v -timeout $(TEST_TIMEOUT) ./...
  46. setup: ## Setup test environment
  47. @echo "🔧 Setting up test environment..."
  48. @mkdir -p test-volume-data/filerldb2
  49. @mkdir -p test-volume-data/m9333
  50. start-services: ## Start SeaweedFS services for testing
  51. @echo "🚀 Starting SeaweedFS services..."
  52. @echo "Starting master server..."
  53. @$(WEED_BINARY) master -port=$(MASTER_PORT) \
  54. -mdir=test-volume-data/m9333 > weed-master.log 2>&1 & \
  55. echo $$! > $(MASTER_PID_FILE)
  56. @echo "Waiting for master server to be ready..."
  57. @timeout 60 bash -c 'until curl -s http://localhost:$(MASTER_PORT)/cluster/status > /dev/null 2>&1; do echo "Waiting for master server..."; sleep 2; done' || (echo "❌ Master failed to start, checking logs..." && tail -20 weed-master.log && exit 1)
  58. @echo "✅ Master server is ready"
  59. @echo "Starting volume server..."
  60. @$(WEED_BINARY) volume -port=$(VOLUME_PORT) \
  61. -ip=localhost \
  62. -dataCenter=dc1 -rack=rack1 \
  63. -dir=test-volume-data \
  64. -max=100 \
  65. -mserver=localhost:$(MASTER_PORT) > weed-volume.log 2>&1 & \
  66. echo $$! > $(VOLUME_PID_FILE)
  67. @echo "Waiting for volume server to be ready..."
  68. @timeout 60 bash -c 'until curl -s http://localhost:$(VOLUME_PORT)/status > /dev/null 2>&1; do echo "Waiting for volume server..."; sleep 2; done' || (echo "❌ Volume server failed to start, checking logs..." && tail -20 weed-volume.log && exit 1)
  69. @echo "✅ Volume server is ready"
  70. @echo "Starting filer server..."
  71. @$(WEED_BINARY) filer -port=$(FILER_PORT) \
  72. -defaultStoreDir=test-volume-data/filerldb2 \
  73. -master=localhost:$(MASTER_PORT) > weed-filer.log 2>&1 & \
  74. echo $$! > $(FILER_PID_FILE)
  75. @echo "Waiting for filer server to be ready..."
  76. @timeout 60 bash -c 'until curl -s http://localhost:$(FILER_PORT)/status > /dev/null 2>&1; do echo "Waiting for filer server..."; sleep 2; done' || (echo "❌ Filer failed to start, checking logs..." && tail -20 weed-filer.log && exit 1)
  77. @echo "✅ Filer server is ready"
  78. @echo "Starting S3 API server with IAM..."
  79. @$(WEED_BINARY) -v=3 s3 -port=$(S3_PORT) \
  80. -filer=localhost:$(FILER_PORT) \
  81. -config=test_config.json \
  82. -iam.config=$(CURDIR)/iam_config.json > weed-s3.log 2>&1 & \
  83. echo $$! > $(S3_PID_FILE)
  84. @echo "Waiting for S3 API server to be ready..."
  85. @timeout 60 bash -c 'until curl -s http://localhost:$(S3_PORT) > /dev/null 2>&1; do echo "Waiting for S3 API server..."; sleep 2; done' || (echo "❌ S3 API failed to start, checking logs..." && tail -20 weed-s3.log && exit 1)
  86. @echo "✅ S3 API server is ready"
  87. @echo "✅ All services started and ready"
  88. wait-for-services: ## Wait for all services to be ready
  89. @echo "⏳ Waiting for services to be ready..."
  90. @echo "Checking master server..."
  91. @timeout 30 bash -c 'until curl -s http://localhost:$(MASTER_PORT)/cluster/status > /dev/null; do sleep 1; done' || (echo "❌ Master failed to start" && exit 1)
  92. @echo "Checking filer server..."
  93. @timeout 30 bash -c 'until curl -s http://localhost:$(FILER_PORT)/status > /dev/null; do sleep 1; done' || (echo "❌ Filer failed to start" && exit 1)
  94. @echo "Checking S3 API server..."
  95. @timeout 30 bash -c 'until curl -s http://localhost:$(S3_PORT) > /dev/null 2>&1; do sleep 1; done' || (echo "❌ S3 API failed to start" && exit 1)
  96. @echo "Pre-allocating volumes for concurrent operations..."
  97. @curl -s "http://localhost:$(MASTER_PORT)/vol/grow?collection=default&count=10&replication=000" > /dev/null || echo "⚠️ Volume pre-allocation failed, but continuing..."
  98. @sleep 3
  99. @echo "✅ All services are ready"
  100. stop-services: ## Stop all SeaweedFS services
  101. @echo "🛑 Stopping SeaweedFS services..."
  102. @if [ -f $(S3_PID_FILE) ]; then \
  103. echo "Stopping S3 API server..."; \
  104. kill $$(cat $(S3_PID_FILE)) 2>/dev/null || true; \
  105. rm -f $(S3_PID_FILE); \
  106. fi
  107. @if [ -f $(FILER_PID_FILE) ]; then \
  108. echo "Stopping filer server..."; \
  109. kill $$(cat $(FILER_PID_FILE)) 2>/dev/null || true; \
  110. rm -f $(FILER_PID_FILE); \
  111. fi
  112. @if [ -f $(VOLUME_PID_FILE) ]; then \
  113. echo "Stopping volume server..."; \
  114. kill $$(cat $(VOLUME_PID_FILE)) 2>/dev/null || true; \
  115. rm -f $(VOLUME_PID_FILE); \
  116. fi
  117. @if [ -f $(MASTER_PID_FILE) ]; then \
  118. echo "Stopping master server..."; \
  119. kill $$(cat $(MASTER_PID_FILE)) 2>/dev/null || true; \
  120. rm -f $(MASTER_PID_FILE); \
  121. fi
  122. @echo "✅ All services stopped"
  123. clean: stop-services ## Clean up test environment
  124. @echo "🧹 Cleaning up test environment..."
  125. @rm -rf test-volume-data
  126. @rm -f weed-*.log
  127. @rm -f *.test
  128. @echo "✅ Cleanup complete"
  129. logs: ## Show service logs
  130. @echo "📋 Service Logs:"
  131. @echo "=== Master Log ==="
  132. @tail -20 weed-master.log 2>/dev/null || echo "No master log"
  133. @echo ""
  134. @echo "=== Volume Log ==="
  135. @tail -20 weed-volume.log 2>/dev/null || echo "No volume log"
  136. @echo ""
  137. @echo "=== Filer Log ==="
  138. @tail -20 weed-filer.log 2>/dev/null || echo "No filer log"
  139. @echo ""
  140. @echo "=== S3 API Log ==="
  141. @tail -20 weed-s3.log 2>/dev/null || echo "No S3 log"
  142. status: ## Check service status
  143. @echo "📊 Service Status:"
  144. @echo -n "Master: "; curl -s http://localhost:$(MASTER_PORT)/cluster/status > /dev/null 2>&1 && echo "✅ Running" || echo "❌ Not running"
  145. @echo -n "Filer: "; curl -s http://localhost:$(FILER_PORT)/status > /dev/null 2>&1 && echo "✅ Running" || echo "❌ Not running"
  146. @echo -n "S3 API: "; curl -s http://localhost:$(S3_PORT) > /dev/null 2>&1 && echo "✅ Running" || echo "❌ Not running"
  147. debug: start-services wait-for-services ## Start services and keep them running for debugging
  148. @echo "🐛 Services started in debug mode. Press Ctrl+C to stop..."
  149. @trap 'make stop-services' INT; \
  150. while true; do \
  151. sleep 1; \
  152. done
  153. # Test specific scenarios
  154. test-auth: ## Test only authentication scenarios
  155. go test -v -run TestS3IAMAuthentication ./...
  156. test-policy: ## Test only policy enforcement
  157. go test -v -run TestS3IAMPolicyEnforcement ./...
  158. test-expiration: ## Test only session expiration
  159. go test -v -run TestS3IAMSessionExpiration ./...
  160. test-multipart: ## Test only multipart upload IAM integration
  161. go test -v -run TestS3IAMMultipartUploadPolicyEnforcement ./...
  162. test-bucket-policy: ## Test only bucket policy integration
  163. go test -v -run TestS3IAMBucketPolicyIntegration ./...
  164. test-context: ## Test only contextual policy enforcement
  165. go test -v -run TestS3IAMContextualPolicyEnforcement ./...
  166. test-presigned: ## Test only presigned URL integration
  167. go test -v -run TestS3IAMPresignedURLIntegration ./...
  168. # Performance testing
  169. benchmark: setup start-services wait-for-services ## Run performance benchmarks
  170. @echo "🏁 Running IAM performance benchmarks..."
  171. go test -bench=. -benchmem -timeout $(TEST_TIMEOUT) ./...
  172. @make stop-services
  173. # Continuous integration
  174. ci: ## Run tests suitable for CI environment
  175. @echo "🔄 Running CI tests..."
  176. @export CGO_ENABLED=0; make test
  177. # Development helpers
  178. watch: ## Watch for file changes and re-run tests
  179. @echo "👀 Watching for changes..."
  180. @command -v entr >/dev/null 2>&1 || (echo "entr is required for watch mode. Install with: brew install entr" && exit 1)
  181. @find . -name "*.go" | entr -r make test-quick
  182. install-deps: ## Install test dependencies
  183. @echo "📦 Installing test dependencies..."
  184. go mod tidy
  185. go get -u github.com/stretchr/testify
  186. go get -u github.com/aws/aws-sdk-go
  187. go get -u github.com/golang-jwt/jwt/v5
  188. # Docker support
  189. docker-test-legacy: ## Run tests in Docker container (legacy)
  190. @echo "🐳 Running tests in Docker..."
  191. docker build -f Dockerfile.test -t seaweedfs-s3-iam-test .
  192. docker run --rm -v $(PWD)/../../../:/app seaweedfs-s3-iam-test
  193. # Docker Compose support with Keycloak
  194. docker-up: ## Start all services with Docker Compose (including Keycloak)
  195. @echo "🐳 Starting services with Docker Compose including Keycloak..."
  196. @docker compose up -d
  197. @echo "⏳ Waiting for services to be healthy..."
  198. @timeout 120 bash -c 'until curl -s http://localhost:8080/health/ready > /dev/null 2>&1; do sleep 2; done' || (echo "❌ Keycloak failed to become ready" && exit 1)
  199. @timeout 60 bash -c 'until curl -s http://localhost:8333 > /dev/null 2>&1; do sleep 2; done' || (echo "❌ S3 API failed to become ready" && exit 1)
  200. @timeout 60 bash -c 'until curl -s http://localhost:8888 > /dev/null 2>&1; do sleep 2; done' || (echo "❌ Filer failed to become ready" && exit 1)
  201. @timeout 60 bash -c 'until curl -s http://localhost:9333 > /dev/null 2>&1; do sleep 2; done' || (echo "❌ Master failed to become ready" && exit 1)
  202. @echo "✅ All services are healthy and ready"
  203. docker-down: ## Stop all Docker Compose services
  204. @echo "🐳 Stopping Docker Compose services..."
  205. @docker compose down -v
  206. @echo "✅ All services stopped"
  207. docker-logs: ## Show logs from all services
  208. @docker compose logs -f
  209. docker-test: docker-up ## Run tests with Docker Compose including Keycloak
  210. @echo "🧪 Running Keycloak integration tests..."
  211. @export KEYCLOAK_URL="http://localhost:8080" && \
  212. export S3_ENDPOINT="http://localhost:8333" && \
  213. go test -v -timeout $(TEST_TIMEOUT) -run "TestKeycloak" ./...
  214. @echo "🐳 Stopping services after tests..."
  215. @make docker-down
  216. docker-build: ## Build custom SeaweedFS image for Docker tests
  217. @echo "🏗️ Building custom SeaweedFS image..."
  218. @docker build -f Dockerfile.s3 -t seaweedfs-iam:latest ../../..
  219. @echo "✅ Image built successfully"
  220. # All PHONY targets
  221. .PHONY: test test-quick run-tests setup start-services stop-services wait-for-services clean logs status debug
  222. .PHONY: test-auth test-policy test-expiration test-multipart test-bucket-policy test-context test-presigned
  223. .PHONY: benchmark ci watch install-deps docker-test docker-up docker-down docker-logs docker-build
  224. .PHONY: test-distributed test-performance test-stress test-versioning-stress test-keycloak-full test-all-previously-skipped setup-all-tests help-advanced
  225. # New test targets for previously skipped tests
  226. test-distributed: ## Run distributed IAM tests
  227. @echo "🌐 Running distributed IAM tests..."
  228. @export ENABLE_DISTRIBUTED_TESTS=true && go test -v -timeout $(TEST_TIMEOUT) -run "TestS3IAMDistributedTests" ./...
  229. test-performance: ## Run performance tests
  230. @echo "🏁 Running performance tests..."
  231. @export ENABLE_PERFORMANCE_TESTS=true && go test -v -timeout $(TEST_TIMEOUT) -run "TestS3IAMPerformanceTests" ./...
  232. test-stress: ## Run stress tests
  233. @echo "💪 Running stress tests..."
  234. @export ENABLE_STRESS_TESTS=true && ./run_stress_tests.sh
  235. test-versioning-stress: ## Run S3 versioning stress tests
  236. @echo "📚 Running versioning stress tests..."
  237. @cd ../versioning && ./enable_stress_tests.sh
  238. test-keycloak-full: docker-up ## Run complete Keycloak integration tests
  239. @echo "🔐 Running complete Keycloak integration tests..."
  240. @export KEYCLOAK_URL="http://localhost:8080" && \
  241. export S3_ENDPOINT="http://localhost:8333" && \
  242. go test -v -timeout $(TEST_TIMEOUT) -run "TestKeycloak" ./...
  243. @make docker-down
  244. test-all-previously-skipped: ## Run all previously skipped tests
  245. @echo "🎯 Running all previously skipped tests..."
  246. @./run_all_tests.sh
  247. setup-all-tests: ## Setup environment for all tests (including Keycloak)
  248. @echo "🚀 Setting up complete test environment..."
  249. @./setup_all_tests.sh