Beispiel #1
0
func TestGetFromContextWithGlobalAndPrivateForwardedIps(t *testing.T) {
	var ctx iris.Context
	ctx.RequestCtx = &fasthttp.RequestCtx{}
	header := fasthttp.RequestHeader{}
	header.Add("X-Forwarded-For", "65.55.37.104, 100.64.0.0, 192.168.0.0, 192.0.0.0")
	ctx.RequestCtx.Request.Header = header
	ip := GetFromContext(&ctx)

	assert.Equal(t, ip, "65.55.37.104", "Should be the first ip, which is the global ip address.")
}
Beispiel #2
0
func TestGetFromContextWithPrivateForwadedIp(t *testing.T) {
	var ctx iris.Context
	ctx.RequestCtx = &fasthttp.RequestCtx{}
	header := fasthttp.RequestHeader{}
	header.Add("X-Forwarded-For", "100.64.0.0, 192.168.0.0")
	ctx.RequestCtx.Request.Header = header
	ip := GetFromContext(&ctx)

	assert.Equal(t, ip, "", "Should not find an ip address.")
}