Skip to content

Commit

Permalink
Fix broken test (#10266) (#10267)
Browse files Browse the repository at this point in the history
* Fix broken test build

* Fix broken test build

Co-authored-by: mattiagiupponi <51856725+mattiagiupponi@users.noreply.github.com>
  • Loading branch information
github-actions[bot] and mattiagiupponi authored Nov 8, 2022
1 parent 917928d commit e707b6a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
10 changes: 3 additions & 7 deletions geonode/base/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,8 @@ def visitor_ip_address(request):

def is_ipaddress_in_whitelist(visitor_ip, whitelist):
# Chech if an IP is in the whitelisted IP ranges
_results = []
if visitor_ip and whitelist and len(whitelist) > 0:
visitor_ipaddress = ipaddress.ip_address(visitor_ip)
for wip in whitelist:
try:
if visitor_ipaddress not in ipaddress.ip_network(wip):
return True
except Exception:
pass
return False
_results = [visitor_ipaddress in ipaddress.ip_network(wip) for wip in whitelist]
return False if not _results else any(_results)
9 changes: 9 additions & 0 deletions geonode/security/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2093,6 +2093,15 @@ def test_admin_whitelisted_access_middleware(self):
middleware.process_request(request)
self.assertTrue(request.user.is_superuser)

# Test valid IP in second element
with self.settings(ADMIN_IP_WHITELIST=['88.88.88.88', '127.0.0.1']):
request = HttpRequest()
request.user = admin
request.path = reverse('home')
request.META['REMOTE_ADDR'] = '127.0.0.1'
middleware.process_request(request)
self.assertTrue(request.user.is_superuser)


class SecurityRulesTests(TestCase):
"""
Expand Down

0 comments on commit e707b6a

Please sign in to comment.