def test_http_x_forwarded_for_no_proxy(self): request = { 'HTTP_X_FORWARDED_FOR': '3ffe:1900:4545:3:200:f8ff:fe21:67cf, 74dc::02ba', } ip = address_parser.get_trusted_ip(request, trusted_proxies=[]) self.assertIsNone(ip)
def test_http_x_forwarded_for_no_proxy(self): request = { 'HTTP_X_FORWARDED_FOR': '198.84.193.157, 177.139.200.139, 177.139.233.139', } ip = address_parser.get_trusted_ip(request, trusted_proxies=[]) self.assertIsNone(ip)
def test_x_forwarded_for_single_proxy_hyphens(self): request = { 'X-FORWARDED-FOR': '198.84.193.157, 177.139.200.139, 177.139.233.139', } ip = address_parser.get_trusted_ip(request, trusted_proxies=['177.139.233.139']) self.assertEqual(ip, "198.84.193.157")
def test_http_x_forwarded_for_all_proxies_in_subnet_2(self): request = { 'HTTP_X_FORWARDED_FOR': '198.84.193.157, 177.139.200.139, 177.139.233.139', } ip = address_parser.get_trusted_ip(request, trusted_proxies=['177.139']) self.assertEqual(ip, "198.84.193.157")
def test_http_x_forwarded_for_conf_settings(self): request = { 'HTTP_X_FORWARDED_FOR': '198.84.193.157, 177.139.200.139, 177.139.233.100', } ip = address_parser.get_trusted_ip(request) self.assertEqual(ip, "198.84.193.157")
def test_http_x_forwarded_for_single_proxy_with_right_most(self): request = { 'HTTP_X_FORWARDED_FOR': '177.139.233.139, 177.139.200.139, 198.84.193.157', } ip = address_parser.get_trusted_ip(request, right_most_proxy=True, trusted_proxies=['177.139.233.139']) self.assertEqual(ip, "198.84.193.157")
def test_http_x_forwarded_for_and_x_forward_for_single_proxy(self): request = { 'HTTP_X_FORWARDED_FOR': '198.84.193.156, 177.139.200.139, 177.139.233.139', 'X_FORWARDED_FOR': '198.84.193.157, 177.139.200.139, 177.139.233.139', } ip = address_parser.get_trusted_ip(request, trusted_proxies=['177.139.233.139']) self.assertEqual(ip, "198.84.193.156")
def test_meta_none(self): request = {} ip = address_parser.get_trusted_ip(request) self.assertIsNone(ip)