Skip to content

Commit

Permalink
ip test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
deepakdinesh1123 committed Dec 3, 2024
1 parent 396ee6a commit 239376f
Showing 1 changed file with 28 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,61 +25,59 @@ def sync_policies(self):
ws = Workspace(self.tenant, as_systemuser=True)
ws.ready()
ws.sync_policies()

def test_role_ip_permissions(self):

self.sync_policies()
# delete the all ip view policy as we have to check for specific IPs.
PolicyModel.objects.get(name="AllIPGetViewAccess").delete()
PolicyModel.objects.get(name="AllowFromAnywhere").delete()

self.client = ZangoClient(self.tenant)
res = self.client.get("/customers/customer/",**{
'REMOTE_ADDR': '1.2.3.4'
})
self.assertHTMLEqual(res.content.decode(), "<h1>Hey! This is IP testing response</h1>")
res = self.client.get("/customers/customer/", **{"REMOTE_ADDR": "1.2.3.4"})
self.assertHTMLEqual(
res.content.decode(), "<h1>Hey! This is IP testing response</h1>"
)

# Permission denied for IP not listed in policies.json.
res = self.client.get("/customers/customer/",**{
'REMOTE_ADDR': '1.2.3.5'
})
res = self.client.get("/customers/customer/", **{"REMOTE_ADDR": "1.2.3.5"})
self.assertEqual(res.status_code, 403)

def test_cidr_ip_permissions(self):

self.sync_policies()
# delete the all ip view policy as we have to check for specific IPs.
PolicyModel.objects.get(name="AllIPGetViewAccess").delete()
PolicyModel.objects.get(name="AllowFromAnywhere").delete()

self.client = ZangoClient(self.tenant)
res = self.client.get("/customers/cidr/",**{
'REMOTE_ADDR': '10.0.0.2'
})
self.assertHTMLEqual(res.content.decode(), "<h1>Hey! This is CIDR IP testing response</h1>")
res = self.client.get("/customers/cidr/", **{"REMOTE_ADDR": "10.0.0.2"})
self.assertHTMLEqual(
res.content.decode(), "<h1>Hey! This is CIDR IP testing response</h1>"
)

# Permission denied for IP outside the range of "10.0.0.0/24" as listed in policies.json.
res = self.client.get("/customers/cidr/",**{
'REMOTE_ADDR': '10.0.1.252'
})
res = self.client.get("/customers/cidr/", **{"REMOTE_ADDR": "10.0.1.252"})
self.assertEqual(res.status_code, 403)

def test_all_ip_permissions(self):

self.sync_policies()

self.client = ZangoClient(self.tenant)

# returns a response to all IPs.
res = self.client.get("/customers/all-ip/",**{
'REMOTE_ADDR': '1.2.3.9'
})
self.assertHTMLEqual(res.content.decode(), "<h1>Hey! This view can be viewed from all IPs.</h1>")

res = self.client.get("/customers/all-ip/",**{
'REMOTE_ADDR': '10.0.4.2'
})
self.assertHTMLEqual(res.content.decode(), "<h1>Hey! This view can be viewed from all IPs.</h1>")

res = self.client.get("/customers/all-ip/",**{
'REMOTE_ADDR': '10.0.3.1'
})
self.assertHTMLEqual(res.content.decode(), "<h1>Hey! This view can be viewed from all IPs.</h1>")
res = self.client.get("/customers/all-ip/", **{"REMOTE_ADDR": "1.2.3.9"})
self.assertHTMLEqual(
res.content.decode(), "<h1>Hey! This view can be viewed from all IPs.</h1>"
)

res = self.client.get("/customers/all-ip/", **{"REMOTE_ADDR": "10.0.4.2"})
self.assertHTMLEqual(
res.content.decode(), "<h1>Hey! This view can be viewed from all IPs.</h1>"
)

res = self.client.get("/customers/all-ip/", **{"REMOTE_ADDR": "10.0.3.1"})
self.assertHTMLEqual(
res.content.decode(), "<h1>Hey! This view can be viewed from all IPs.</h1>"
)

0 comments on commit 239376f

Please sign in to comment.