From f3bea23321a22299fc92a4a1182d777d4d338979 Mon Sep 17 00:00:00 2001 From: Johanna Larsson Date: Wed, 5 Feb 2020 15:08:58 +0100 Subject: [PATCH 1/2] Drop special IP header handling --- castle/extractors/ip.py | 13 ------------- castle/test/extractors/ip_test.py | 24 ------------------------ 2 files changed, 37 deletions(-) diff --git a/castle/extractors/ip.py b/castle/extractors/ip.py index 08c7ae9..d641d7a 100644 --- a/castle/extractors/ip.py +++ b/castle/extractors/ip.py @@ -6,17 +6,4 @@ def call(self): if hasattr(self.request, 'ip'): return self.request.ip - return self.wsgi_request_ip() - - def wsgi_request_ip(self): - cf_ip = self.request.environ.get('HTTP_CF_CONNECTING_IP') - - if cf_ip: - return cf_ip.split(',')[0] - - x_forwarded_for = self.request.environ.get('HTTP_X_FORWARDED_FOR') - - if x_forwarded_for: - return x_forwarded_for.split(',')[0] - return self.request.environ.get('REMOTE_ADDR') diff --git a/castle/test/extractors/ip_test.py b/castle/test/extractors/ip_test.py index aabd66a..3114000 100644 --- a/castle/test/extractors/ip_test.py +++ b/castle/test/extractors/ip_test.py @@ -22,18 +22,6 @@ def request_with_ip_remote_addr(): return req -def request_with_ip_x_forwarded_for(): - req = mock.Mock(spec=['environ']) - req.environ = {'HTTP_X_FORWARDED_FOR': request_ip()} - return req - - -def request_with_ip_cf_connecting_ip(): - req = mock.Mock(spec=['environ']) - req.environ = {'HTTP_CF_CONNECTING_IP': request_ip_next()} - return req - - class ExtractorsIpTestCase(unittest.TestCase): def test_extract_ip(self): self.assertEqual(ExtractorsIp(request()).call(), request_ip()) @@ -43,15 +31,3 @@ def test_extract_ip_from_wsgi_request_remote_addr(self): ExtractorsIp(request_with_ip_remote_addr()).call(), request_ip() ) - - def test_extract_ip_from_wsgi_request_x_forwarded_for(self): - self.assertEqual( - ExtractorsIp(request_with_ip_x_forwarded_for()).call(), - request_ip() - ) - - def test_extract_ip_from_wsgi_request_cf_connection_ip(self): - self.assertEqual( - ExtractorsIp(request_with_ip_cf_connecting_ip()).call(), - request_ip_next() - ) From 5d38f26ab3b8af1dcb0855defeb6e0d81e68dbe3 Mon Sep 17 00:00:00 2001 From: Johanna Larsson Date: Thu, 6 Feb 2020 14:16:33 +0100 Subject: [PATCH 2/2] Update history --- HISTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/HISTORY.md b/HISTORY.md index baf44ae..228afbc 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,6 +1,7 @@ ## master - [#59](https://github.com/castle/castle-python/pull/59) drop requests min version in ci +- [#56](https://github.com/castle/castle-python/pull/56) drop special ip header behavior ### Breaking Changes: