Update README.md #6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Test | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| branches: | |
| - main | |
| jobs: | |
| test: | |
| name: Test Module | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.25' | |
| cache-dependency-path: go.sum | |
| - name: Install dependencies | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y curl jq | |
| - name: Install xcaddy | |
| run: | | |
| go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest | |
| - name: Build Caddy with module | |
| run: | | |
| xcaddy build --with github.com/azolfagharj/caddy_parspack_ip | |
| - name: Verify binary exists | |
| run: | | |
| if [ ! -f "./caddy" ]; then | |
| echo "Error: caddy binary not found" | |
| exit 1 | |
| fi | |
| ls -lh ./caddy | |
| ./caddy version | |
| - name: Verify module is included | |
| run: | | |
| ./caddy list-modules | grep -q "http.ip_sources.parspack" || (echo "Module not found in list-modules" && exit 1) | |
| echo "✅ Module found in list-modules" | |
| - name: Create test Caddyfile | |
| run: | | |
| cat > Caddyfile << 'EOF' | |
| { | |
| servers { | |
| trusted_proxies parspack { | |
| interval 5m | |
| timeout 10s | |
| } | |
| } | |
| } | |
| :8080 { | |
| respond "Hello from Caddy with ParsPack IP module!" | |
| log { | |
| output stdout | |
| format console | |
| } | |
| } | |
| EOF | |
| - name: Start Caddy server | |
| run: | | |
| ./caddy run --config Caddyfile & | |
| sleep 5 | |
| echo "Caddy started" | |
| - name: Wait for Caddy to be ready | |
| run: | | |
| for i in {1..30}; do | |
| if curl -f http://localhost:8080 > /dev/null 2>&1; then | |
| echo "Caddy is ready" | |
| exit 0 | |
| fi | |
| echo "Waiting for Caddy... ($i/30)" | |
| sleep 1 | |
| done | |
| echo "Caddy failed to start" | |
| exit 1 | |
| - name: Test HTTP request | |
| run: | | |
| response=$(curl -s http://localhost:8080) | |
| if [ "$response" != "Hello from Caddy with ParsPack IP module!" ]; then | |
| echo "Error: Unexpected response: $response" | |
| exit 1 | |
| fi | |
| echo "✅ HTTP request successful" | |
| - name: Test with X-Forwarded-For header (ParsPack IP) | |
| run: | | |
| # Test with real ParsPack IP | |
| response=$(curl -s -H "X-Forwarded-For: 185.8.173.1" http://localhost:8080) | |
| if [ "$response" != "Hello from Caddy with ParsPack IP module!" ]; then | |
| echo "Error: Unexpected response with X-Forwarded-For: $response" | |
| exit 1 | |
| fi | |
| echo "✅ Request with ParsPack IP (X-Forwarded-For) successful" | |
| - name: Test with different ParsPack IP | |
| run: | | |
| # Test with another ParsPack IP from the range | |
| response=$(curl -s -H "X-Forwarded-For: 195.248.241.161" http://localhost:8080) | |
| if [ -z "$response" ]; then | |
| echo "Error: Empty response" | |
| exit 1 | |
| fi | |
| echo "✅ Request with different ParsPack IP successful" | |
| - name: Verify config parsing | |
| run: | | |
| # Get only JSON from stdout (warnings go to stderr, ignore them) | |
| config=$(./caddy adapt --config Caddyfile 2>/dev/null) | |
| # Check with or without space after colon (JSON formatting may vary) | |
| if echo "$config" | grep -qE '"source"\s*:\s*"parspack"'; then | |
| echo "✅ Config parsed correctly with parspack source" | |
| else | |
| echo "Error: Config does not contain parspack source" | |
| echo "Checking for parspack in config:" | |
| echo "$config" | grep -i "parspack" || echo "No parspack found in config" | |
| echo "Full config (first 500 chars):" | |
| echo "$config" | head -c 500 | |
| exit 1 | |
| fi | |
| - name: Check Caddy logs for IP ranges | |
| run: | | |
| # Wait a bit for IP ranges to be fetched | |
| sleep 5 | |
| # Check if Caddy process is still running | |
| if ! pgrep -f "caddy run" > /dev/null; then | |
| echo "Error: Caddy process is not running" | |
| exit 1 | |
| fi | |
| echo "✅ Caddy is running" | |
| - name: Verify IP ranges are loaded | |
| run: | | |
| # Check config to verify IP ranges source | |
| # Get only JSON from stdout (warnings go to stderr) | |
| config=$(./caddy adapt --config Caddyfile 2>/dev/null) | |
| if echo "$config" | jq -e '.apps.http.servers.srv0.trusted_proxies.source == "parspack"' > /dev/null 2>&1; then | |
| echo "✅ ParsPack IP source configured correctly" | |
| echo "Config details:" | |
| echo "$config" | jq '.apps.http.servers.srv0.trusted_proxies' | |
| else | |
| echo "Error: ParsPack IP source not found in config" | |
| echo "Checking config structure:" | |
| echo "$config" | jq '.apps.http.servers.srv0.trusted_proxies' || echo "Failed to parse config" | |
| exit 1 | |
| fi | |
| - name: Stop Caddy | |
| if: always() | |
| run: | | |
| pkill -f "caddy run" || true | |
| sleep 2 | |
| - name: Test module compilation | |
| run: | | |
| go build ./... | |
| echo "✅ Module compiles successfully" | |
| - name: Run Go tests | |
| run: | | |
| go test -v ./... | |
| # | |
| # |