MCPcopy Create free account
hub / github.com/EasyIME/PIME / test_ip_headers

Method test_ip_headers

python/python3/tornado/test/httpserver_test.py:594–632  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

592 return dict(xheaders=True, trusted_downstream=["5.5.5.5"])
593
594 def test_ip_headers(self):
595 self.assertEqual(self.fetch_json("/")["remote_ip"], "127.0.0.1")
596
597 valid_ipv4 = {"X-Real-IP": "4.4.4.4"}
598 self.assertEqual(
599 self.fetch_json("/", headers=valid_ipv4)["remote_ip"], "4.4.4.4"
600 )
601
602 valid_ipv4_list = {"X-Forwarded-For": "127.0.0.1, 4.4.4.4"}
603 self.assertEqual(
604 self.fetch_json("/", headers=valid_ipv4_list)["remote_ip"], "4.4.4.4"
605 )
606
607 valid_ipv6 = {"X-Real-IP": "2620:0:1cfe:face:b00c::3"}
608 self.assertEqual(
609 self.fetch_json("/", headers=valid_ipv6)["remote_ip"],
610 "2620:0:1cfe:face:b00c::3",
611 )
612
613 valid_ipv6_list = {"X-Forwarded-For": "::1, 2620:0:1cfe:face:b00c::3"}
614 self.assertEqual(
615 self.fetch_json("/", headers=valid_ipv6_list)["remote_ip"],
616 "2620:0:1cfe:face:b00c::3",
617 )
618
619 invalid_chars = {"X-Real-IP": "4.4.4.4<script>"}
620 self.assertEqual(
621 self.fetch_json("/", headers=invalid_chars)["remote_ip"], "127.0.0.1"
622 )
623
624 invalid_chars_list = {"X-Forwarded-For": "4.4.4.4, 5.5.5.5<script>"}
625 self.assertEqual(
626 self.fetch_json("/", headers=invalid_chars_list)["remote_ip"], "127.0.0.1"
627 )
628
629 invalid_host = {"X-Real-IP": "www.google.com"}
630 self.assertEqual(
631 self.fetch_json("/", headers=invalid_host)["remote_ip"], "127.0.0.1"
632 )
633
634 def test_trusted_downstream(self):
635 valid_ipv4_list = {"X-Forwarded-For": "127.0.0.1, 4.4.4.4, 5.5.5.5"}

Callers

nothing calls this directly

Calls 1

fetch_jsonMethod · 0.45

Tested by

no test coverage detected