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

Function Test_Ctx_Host_UntrustedProxy

ctx_test.go:2851–2871  ·  view source on GitHub ↗

go test -run Test_Ctx_Host_UntrustedProxy

(t *testing.T)

Source from the content-addressed store, hash-verified

2849
2850// go test -run Test_Ctx_Host_UntrustedProxy
2851func Test_Ctx_Host_UntrustedProxy(t *testing.T) {
2852 t.Parallel()
2853 // Don't trust any proxy
2854 {
2855 app := New(Config{TrustProxy: true, TrustProxyConfig: TrustProxyConfig{Proxies: []string{}}})
2856 c := app.AcquireCtx(&fasthttp.RequestCtx{})
2857 c.Request().SetRequestURI("http://google.com/test")
2858 c.Request().Header.Set(HeaderXForwardedHost, "google1.com")
2859 require.Equal(t, "google.com", c.Host())
2860 app.ReleaseCtx(c)
2861 }
2862 // Trust to specific proxy list
2863 {
2864 app := New(Config{TrustProxy: true, TrustProxyConfig: TrustProxyConfig{Proxies: []string{"0.8.0.0", "0.8.0.1"}}})
2865 c := app.AcquireCtx(&fasthttp.RequestCtx{})
2866 c.Request().SetRequestURI("http://google.com/test")
2867 c.Request().Header.Set(HeaderXForwardedHost, "google1.com")
2868 require.Equal(t, "google.com", c.Host())
2869 app.ReleaseCtx(c)
2870 }
2871}
2872
2873// go test -run Test_Ctx_Host_TrustedProxy
2874func Test_Ctx_Host_TrustedProxy(t *testing.T) {

Callers

nothing calls this directly

Calls 6

AcquireCtxMethod · 0.80
ReleaseCtxMethod · 0.80
NewFunction · 0.70
RequestMethod · 0.65
SetMethod · 0.65
HostMethod · 0.65

Tested by

no test coverage detected