INNER CODE UNIT · Go
TestConfigureTrustedProxiesUsesForwardedForFromTrustedProxy
kite-org/kite · main_test.go:81
func TestConfigureTrustedProxiesUsesForwardedForFromTrustedProxy(t *testing.T) {
if got := clientIPForForwardedRequest(t, []string{"192.0.2.0/24"}, "192.0.2.10:12345", "203.0.113.9"); got != "203.0.113.9" {
t.Fatalf("ClientIP() = %q, want forwarded client IP", got)
}
}
func clientIPForForwardedRequest(t *testing.T, trustedProxies []string, remoteAddr, forwardedFor string) string {
t.Helper()
gin.SetMode(gin.TestMode)
oldTrustedProxies := common.TrustedProxies
t.Cleanup(func() {
common.TrustedProxies = oldTrustedProxies
})
if trustedProxies != nil {
common.TrustedProxies = trustedProxies
}