|
|
3 ヶ月 前 | |
|---|---|---|
| .. | ||
| Makefile | 3 ヶ月 前 | |
| README.md | 3 ヶ月 前 | |
| s3_cors_http_test.go | 3 ヶ月 前 | |
| s3_cors_test.go | 3 ヶ月 前 | |
This directory contains comprehensive integration tests for the CORS (Cross-Origin Resource Sharing) functionality in SeaweedFS S3 API.
The CORS integration tests validate the complete CORS implementation including:
localhost:8333 by defaultcurl and netstat for health checksThe tests now automatically start their own SeaweedFS server, so you don't need to manually start one.
# Run all tests with automatic server management
make test-with-server
# Run core CORS tests only
make test-cors-quick
# Run comprehensive CORS tests
make test-cors-comprehensive
If you prefer to manage the server manually:
# Start server
make start-server
# Run tests (assuming server is running)
make test-cors-simple
# Stop server
make stop-server
# Run specific test types
make test-basic-cors # Basic CORS configuration
make test-preflight-cors # Preflight OPTIONS requests
make test-actual-cors # Actual CORS request handling
make test-origin-matching # Origin matching logic
make test-header-matching # Header matching logic
make test-method-matching # Method matching logic
make test-multiple-rules # Multiple CORS rules
make test-validation # CORS validation
make test-caching # CORS caching behavior
make test-error-handling # Error handling
The tests use a comprehensive server management system similar to other SeaweedFS integration tests:
S3_PORT)./test-volume-data (auto-created)weed-test.log../../../weed/weed_binary# Server management
make start-server # Start SeaweedFS server
make stop-server # Stop SeaweedFS server
make health-check # Check server health
make logs # View server logs
# Test execution
make test-with-server # Full test cycle with server management
make test-cors-simple # Run tests without server management
make test-cors-quick # Run core tests only
make test-cors-comprehensive # Run all tests
# Development
make dev-start # Start server for development
make dev-test # Run development tests
make build-weed # Build SeaweedFS binary
make check-deps # Check dependencies
# Maintenance
make clean # Clean up all artifacts
make coverage # Generate coverage report
make fmt # Format code
make lint # Run linter
The tests use these default settings (configurable via environment variables):
WEED_BINARY=../../../weed/weed_binary
S3_PORT=8333
TEST_TIMEOUT=10m
TEST_PATTERN=TestCORS
The test_config.json file contains S3 client configuration:
{
"endpoint": "http://localhost:8333",
"access_key": "some_access_key1",
"secret_key": "some_secret_key1",
"region": "us-east-1",
"bucket_prefix": "test-cors-",
"use_ssl": false,
"skip_verify_ssl": true
}
If you encounter compilation errors, the most common issues are:
AWS SDK v2 Type Mismatches: The MaxAgeSeconds field in types.CORSRule expects int32, not *int32. Use direct values like 3600 instead of aws.Int32(3600).
Field Name Issues: The GetBucketCorsOutput type has a CORSRules field directly, not a CORSConfiguration field.
Example fix:
// ❌ Incorrect
MaxAgeSeconds: aws.Int32(3600),
assert.Len(t, getResp.CORSConfiguration.CORSRules, 1)
// ✅ Correct
MaxAgeSeconds: 3600,
assert.Len(t, getResp.CORSRules, 1)
Server Won't Start
# Check for port conflicts
netstat -tlnp | grep 8333
# View server logs
make logs
# Force cleanup
make clean
Test Failures
# Run with server management
make test-with-server
# Run specific test
make test-basic-cors
# Check server health
make health-check
Connection Issues
# Verify server is running
curl -s http://localhost:8333
# Check server logs
tail -f weed-test.log
If tests are slow or timing out:
# Increase timeout
export TEST_TIMEOUT=30m
make test-with-server
# Run quick tests only
make test-cors-quick
# Check server resources
make debug-status
TestCORSConfigurationManagement)TestCORSMultipleRules)TestCORSValidation)TestCORSWithWildcards)*, https://*.example.com)*)TestCORSRuleLimit)TestCORSErrorHandling)TestCORSPreflightRequest)TestCORSActualRequest)TestCORSOriginMatching)*)https://*.example.com)TestCORSHeaderMatching)*)TestCORSMethodMatching)TestCORSMultipleRulesMatching)TestCORSCaching)TestCORSObjectOperations)TestCORSWithoutConfiguration)# Start server for development
make dev-start
# Run quick test
make dev-test
# View logs in real-time
make logs
TestCORSXxxYyy)getS3Client, createTestBucket, etc.)defer cleanupTestBucket(t, client, bucketName)require.NoError(t, err)assert.Equal(t, expected, actual)# Format code
make fmt
# Run linter
make lint
# Generate coverage report
make coverage
These tests validate the CORS implementation in:
weed/s3api/cors/ - Core CORS packageweed/s3api/s3api_bucket_cors_handlers.go - HTTP handlersweed/s3api/s3api_server.go - Router integrationweed/s3api/s3api_bucket_config.go - Configuration managementThe tests ensure AWS S3 API compatibility and proper CORS behavior across all supported scenarios.