#!/bin/bash # ============================================ # Grav CMS .htaccess Rules Test Script # ============================================ # This script tests each rule from cms/grav/.htaccess # Domain: test.my.brp # ============================================ BASE_URL="http://test.my.brp" echo "==============================================" echo "Grav CMS .htaccess Rules Test Suite" echo "==============================================" echo "" # Function to test a rule and report result (status only) test_rule() { local description="$1" local url="$2" local expected_status="$3" # e.g., 403, 404, 200 echo "--- Test: $description ---" response=$(curl -s -o /dev/null -w "%{http_code}" "$url") if [ "$response" = "$expected_status" ]; then echo "✓ PASS (HTTP $response)" else echo "✗ FAIL (Expected: HTTP $expected_status, Got: HTTP $response)" fi echo "" } # Function to test a rule and verify content contains expected string test_rule_content() { local description="$1" local url="$2" local expected_status="$3" # e.g., 403, 404, 200 local expected_content="$4" # Expected substring in response body echo "--- Test: $description ---" response=$(curl -s "$url") http_code=$(curl -s -o /dev/null -w "%{http_code}" "$url") # Check status code if [ "$http_code" != "$expected_status" ]; then echo "✗ FAIL (Status: HTTP $http_code, Expected: HTTP $expected_status)" return 1 fi # Check content contains expected substring if [[ "$response" == *"$expected_content"* ]]; then echo "✓ PASS (HTTP $http_code, Content matches '$expected_content')" else echo "✗ FAIL (Content missing: '$expected_content') - Response:" echo "$response" | head -5 fi echo "" } echo "==============================================" echo "1. Security Rules - Test malicious patterns" echo "==============================================" # Template injection via query string with {{ }} Mustache syntax test_rule "Template injection via query string ({{ }}" \ "$BASE_URL/test-mustache.php?\{\{config.secret\}\}" \ "403" # Base64 encoded payloads (base64_encode function call) test_rule "Base64 payload pattern" \ "$BASE_URL/test.php?data=base64_encode(some_secret)" \ "403" # Script injection (