@@ -15,6 +15,7 @@ import (
1515 "github.com/uwaserver/uwas/internal/cache"
1616 "github.com/uwaserver/uwas/internal/config"
1717 "github.com/uwaserver/uwas/internal/logger"
18+ "github.com/uwaserver/uwas/internal/middleware"
1819)
1920
2021func testConfig (root string ) * config.Config {
@@ -997,7 +998,7 @@ RewriteRule . /index.php [L]
997998 Global : config.GlobalConfig {WorkerCount : "1" , LogLevel : "error" , LogFormat : "text" },
998999 Domains : []config.Domain {{
9991000 Host : "wp.test" , Root : dir , Type : "php" ,
1000- SSL : config.SSLConfig {Mode : "off" },
1001+ SSL : config.SSLConfig {Mode : "off" },
10011002 Htaccess : config.HtaccessConfig {Mode : "import" },
10021003 }},
10031004 }
@@ -1259,7 +1260,7 @@ func TestHandleHTTPNonSSLServesContent(t *testing.T) {
12591260func TestHandleHTTPUnknownHostNonSSL (t * testing.T ) {
12601261 // No domains configured — no fallback, unknown host is rejected.
12611262 cfg := & config.Config {
1262- Global : config.GlobalConfig {LogLevel : "error" , LogFormat : "text" },
1263+ Global : config.GlobalConfig {LogLevel : "error" , LogFormat : "text" },
12631264 Domains : []config.Domain {},
12641265 }
12651266 log := logger .New ("error" , "text" )
@@ -1314,6 +1315,36 @@ func TestBuildMiddlewareChainWithRateLimit(t *testing.T) {
13141315 }
13151316}
13161317
1318+ func TestRealIPTrustedProxiesIncludesCloudflareRanges (t * testing.T ) {
1319+ cfg := & config.Config {
1320+ Global : config.GlobalConfig {
1321+ LogLevel : "error" ,
1322+ LogFormat : "text" ,
1323+ TrustedProxies : []string {"10.0.0.0/8" },
1324+ Cloudflare : config.CloudflareConfig {
1325+ IPRanges : []string {"203.0.113.0/24" },
1326+ },
1327+ },
1328+ }
1329+ log := logger .New ("error" , "text" )
1330+ s := New (cfg , log )
1331+
1332+ captured := ""
1333+ h := middleware .RealIP (s .realIPTrustedProxies ())(http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
1334+ captured = r .RemoteAddr
1335+ w .WriteHeader (http .StatusNoContent )
1336+ }))
1337+
1338+ req := httptest .NewRequest ("GET" , "/" , nil )
1339+ req .RemoteAddr = "203.0.113.44:443"
1340+ req .Header .Set ("CF-Connecting-IP" , "198.51.100.77" )
1341+ h .ServeHTTP (httptest .NewRecorder (), req )
1342+
1343+ if captured != "198.51.100.77:0" {
1344+ t .Fatalf ("captured RemoteAddr = %q, want real Cloudflare client IP" , captured )
1345+ }
1346+ }
1347+
13171348func TestBuildMiddlewareChainWithSecurityGuard (t * testing.T ) {
13181349 cfg := & config.Config {
13191350 Global : config.GlobalConfig {LogLevel : "error" , LogFormat : "text" },
0 commit comments