Files
defiQUG bdae5a9f6e feat: explorer API, wallet, CCIP scripts, and config refresh
- Backend REST/gateway/track routes, analytics, Blockscout proxy paths.
- Frontend wallet and liquidity surfaces; MetaMask token list alignment.
- Deployment docs, verification scripts, address inventory updates.

Check: go build ./... under backend/ (pass).
Made-with: Cursor
2026-04-07 23:22:12 -07:00

32 lines
814 B
Go

package httpmiddleware
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/require"
)
func TestClientIPFallsBackToRemoteAddrWhenProxyIsUntrusted(t *testing.T) {
t.Setenv("TRUST_PROXY_IPS", "")
t.Setenv("TRUST_PROXY_CIDRS", "")
req := httptest.NewRequest(http.MethodGet, "/", nil)
req.RemoteAddr = "10.0.0.10:8443"
req.Header.Set("X-Forwarded-For", "203.0.113.9, 10.0.0.10")
require.Equal(t, "10.0.0.10", ClientIP(req))
}
func TestClientIPUsesForwardedHeadersFromTrustedProxy(t *testing.T) {
t.Setenv("TRUST_PROXY_IPS", "")
t.Setenv("TRUST_PROXY_CIDRS", "10.0.0.0/8")
req := httptest.NewRequest(http.MethodGet, "/", nil)
req.RemoteAddr = "10.0.0.10:8443"
req.Header.Set("X-Forwarded-For", "203.0.113.9, 10.0.0.10")
require.Equal(t, "203.0.113.9", ClientIP(req))
}