MCPcopy
hub / github.com/gofiber/fiber / Test_Proxy_Forward_OverwritesXRealIP

Function Test_Proxy_Forward_OverwritesXRealIP

middleware/proxy/proxy_test.go:1134–1155  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1132}
1133
1134func Test_Proxy_Forward_OverwritesXRealIP(t *testing.T) {
1135 t.Parallel()
1136
1137 const spoofedIP = "10.0.0.1"
1138 // app.Test injects 0.0.0.0 as the remote address, so c.IP() returns IPv4zero.
1139 appTestClientIP := net.IPv4zero.String()
1140
1141 _, addr := createProxyTestServerIPv4(t, func(c fiber.Ctx) error {
1142 require.Equal(t, appTestClientIP, c.Get("X-Real-IP"))
1143 return c.SendStatus(fiber.StatusOK)
1144 })
1145
1146 app := fiber.New()
1147 app.Use(Forward("http://" + addr))
1148
1149 req := httptest.NewRequest(fiber.MethodGet, "/", http.NoBody)
1150 req.Header.Set("X-Real-IP", spoofedIP)
1151
1152 resp, err := app.Test(req)
1153 require.NoError(t, err)
1154 require.Equal(t, fiber.StatusOK, resp.StatusCode)
1155}
1156
1157func Test_Proxy_DomainForward_OverwritesXRealIP(t *testing.T) {
1158 t.Parallel()

Callers

nothing calls this directly

Calls 9

ForwardFunction · 0.85
TestMethod · 0.80
StringMethod · 0.65
GetMethod · 0.65
SendStatusMethod · 0.65
NewMethod · 0.65
UseMethod · 0.65
SetMethod · 0.65

Tested by

no test coverage detected