From 334dbdb8acb42ebd39527e5f6ec1b8e21e6d2be8 Mon Sep 17 00:00:00 2001 From: Shirshendu Bhowmick <12836504+shirshendubhowmick@users.noreply.github.com> Date: Sat, 9 May 2026 13:44:33 +0530 Subject: [PATCH] test(context): add test for ClientIP method with no valid forwarded headers --- context_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/context_test.go b/context_test.go index 7f364286..a408c064 100644 --- a/context_test.go +++ b/context_test.go @@ -1984,6 +1984,12 @@ func TestContextClientIP(t *testing.T) { c.Request.RemoteAddr = addr.String() assert.Equal(t, "20.20.20.20", c.ClientIP()) + // unix address with no valid forwarded header: remoteIP stays zero, must return "" + c.Request.Header.Del("X-Forwarded-For") + c.Request.Header.Del("X-Real-IP") + assert.Empty(t, c.ClientIP()) + resetContextForClientIPTests(c) + // reset c.Request = c.Request.WithContext(context.Background()) resetContextForClientIPTests(c)