Esempio n. 1
0
 def test_one_proxy(self, rf, settings):
     """
     If there is one proxy, the right-most value in HTTP_X_FORWARDED_FOR
     should be used.
     """
     settings.NUM_PROXIES = 1
     client_ip = '1.1.1.1'
     nginx_ip = '2.2.2.2'
     forwarded_for = ', '.join(['fake', client_ip])
     req = rf.get('/', HTTP_X_FORWARDED_FOR=forwarded_for, REMOTE_ADDR=nginx_ip)
     assert get_client_ip(req) == client_ip
Esempio n. 2
0
 def test_one_proxy(self, rf, settings):
     """
     If there is one proxy, the right-most value in HTTP_X_FORWARDED_FOR
     should be used.
     """
     settings.NUM_PROXIES = 1
     client_ip = "1.1.1.1"
     nginx_ip = "2.2.2.2"
     forwarded_for = ", ".join(["fake", client_ip])
     req = rf.get("/", HTTP_X_FORWARDED_FOR=forwarded_for, REMOTE_ADDR=nginx_ip)
     assert get_client_ip(req) == client_ip
Esempio n. 3
0
 def test_two_proxies(self, rf, settings):
     """
     If there are two proxies, the second-from-the-right value in
     HTTP_X_FORWARDED_FOR should be used.
     """
     settings.NUM_PROXIES = 2
     client_ip = '1.1.1.1'
     elb_ip = '2.2.2.2'
     nginx_ip = '3.3.3.3'
     forwarded_for = ', '.join(['fake', client_ip, elb_ip])
     req = rf.get('/', HTTP_X_FORWARDED_FOR=forwarded_for, REMOTE_ADDR=nginx_ip)
     assert get_client_ip(req) == client_ip
Esempio n. 4
0
 def test_two_proxies(self, rf, settings):
     """
     If there are two proxies, the second-from-the-right value in
     HTTP_X_FORWARDED_FOR should be used.
     """
     settings.NUM_PROXIES = 2
     client_ip = "1.1.1.1"
     elb_ip = "2.2.2.2"
     nginx_ip = "3.3.3.3"
     forwarded_for = ", ".join(["fake", client_ip, elb_ip])
     req = rf.get("/", HTTP_X_FORWARDED_FOR=forwarded_for, REMOTE_ADDR=nginx_ip)
     assert get_client_ip(req) == client_ip
Esempio n. 5
0
 def test_one_proxy(self, rf, settings):
     """
     If there is one proxy, the right-most value in HTTP_X_FORWARDED_FOR
     should be used.
     """
     settings.NUM_PROXIES = 1
     client_ip = '1.1.1.1'
     nginx_ip = '2.2.2.2'
     forwarded_for = ', '.join(['fake', client_ip])
     req = rf.get('/',
                  HTTP_X_FORWARDED_FOR=forwarded_for,
                  REMOTE_ADDR=nginx_ip)
     assert get_client_ip(req) == client_ip
Esempio n. 6
0
 def test_one_proxy(self, rf, settings):
     """
     If there is one proxy, the right-most value in HTTP_X_FORWARDED_FOR
     should be used.
     """
     settings.NUM_PROXIES = 1
     client_ip = "1.1.1.1"
     nginx_ip = "2.2.2.2"
     forwarded_for = ", ".join(["fake", client_ip])
     req = rf.get("/",
                  HTTP_X_FORWARDED_FOR=forwarded_for,
                  REMOTE_ADDR=nginx_ip)
     assert get_client_ip(req) == client_ip
Esempio n. 7
0
 def test_two_proxies(self, rf, settings):
     """
     If there are two proxies, the second-from-the-right value in
     HTTP_X_FORWARDED_FOR should be used.
     """
     settings.NUM_PROXIES = 2
     client_ip = '1.1.1.1'
     elb_ip = '2.2.2.2'
     nginx_ip = '3.3.3.3'
     forwarded_for = ', '.join(['fake', client_ip, elb_ip])
     req = rf.get('/',
                  HTTP_X_FORWARDED_FOR=forwarded_for,
                  REMOTE_ADDR=nginx_ip)
     assert get_client_ip(req) == client_ip
Esempio n. 8
0
 def test_two_proxies(self, rf, settings):
     """
     If there are two proxies, the second-from-the-right value in
     HTTP_X_FORWARDED_FOR should be used.
     """
     settings.NUM_PROXIES = 2
     client_ip = "1.1.1.1"
     elb_ip = "2.2.2.2"
     nginx_ip = "3.3.3.3"
     forwarded_for = ", ".join(["fake", client_ip, elb_ip])
     req = rf.get("/",
                  HTTP_X_FORWARDED_FOR=forwarded_for,
                  REMOTE_ADDR=nginx_ip)
     assert get_client_ip(req) == client_ip
Esempio n. 9
0
 def country(self):
     ip_address = get_client_ip(self.request)
     if ip_address is None:
         return None
     else:
         return get_country_code(ip_address)
Esempio n. 10
0
 def test_no_proxies(self, rf, settings):
     """If there are no proxies, REMOTE_ADDR should be used."""
     settings.NUM_PROXIES = 0
     client_ip = '1.1.1.1'
     req = rf.get('/', HTTP_X_FORWARDED_FOR='fake', REMOTE_ADDR=client_ip)
     assert get_client_ip(req) == client_ip
Esempio n. 11
0
 def test_no_proxies(self, rf, settings):
     """If there are no proxies, REMOTE_ADDR should be used."""
     settings.NUM_PROXIES = 0
     client_ip = '1.1.1.1'
     req = rf.get('/', HTTP_X_FORWARDED_FOR='fake', REMOTE_ADDR=client_ip)
     assert get_client_ip(req) == client_ip
Esempio n. 12
0
 def country(self):
     ip_address = get_client_ip(self.request)
     if ip_address is None:
         return None
     else:
         return get_country_code(ip_address)