コード例 #1
0
ファイル: user_ip_test.go プロジェクト: vaot/user_ip
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.")
}
コード例 #2
0
ファイル: user_ip_test.go プロジェクト: vaot/user_ip
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.")
}