You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note particularly the branch if hasattr(obj, 'ipaddress'). This is weird. First off, we check if the view is HostDetail (thus, obj is a Host), and if not we set the object to be obj.host. Ie, obj will always be a Host. But, Hosts do not have an ipaddress field. What they do have is a related_name, ip_addresses from the Ipaddress model: https://github.com/unioslo/mreg/blob/master/mreg/models.py#L398
This leads me to wonder what the logic is supposed to be here. Are we supposed to deny deletion of the object if the host is using any addresses that are reserved? If so, we want:
And we could then test this as such in api/v1/tests/tests_permission.py in the class class NetGroupRegexPermissionTestCaseAsAdmin(NetGroupRegexPermissionTestCase). Testing in TestIsGrantedNetGroupRegexPermission will give us a 204 due to the overall access given to superusers in the has_destroy_permission itself.
# Superusers get to zap hosts, so this is for admins and down only.deftest_403_from_reserved_ip(self):
network=Network.objects.create(network='172.16.0.0/30', reserved=3, description='Tiny network')
host=Host.objects.create(name='testhost')
ip_address=Ipaddress.objects.create(ipaddress='172.16.0.1', host=host)
self.assertTrue(is_reserved_ip(ip_address.ipaddress))
self.assert_get(f'/hosts/{host.name}')
self.assert_delete_and_403(f'/hosts/{host.name}')
network.delete()
host.delete()
ip_address.delete()
Can someone explain this to me? :)
The text was updated successfully, but these errors were encountered:
git blame shows a lot of different commits contributing to this code. I suspect each addition might not have taken into consideration the purpose of the whole thing.
We can only guess, but I think you're right: I think the code was supposed to deny deletion of the object if the host is using any addresses that are reserved (except to members of the NETWORK_ADMIN_GROUP, see _deny_reserved_ipaddress).
I would write the test first, verify that it fails, and then modify the code until all tests pass.
In mreg/api/permissions.py we have the following construct:
Note particularly the branch if hasattr(obj, 'ipaddress'). This is weird. First off, we check if the view is HostDetail (thus,
obj
is a Host), and if not we set the object to beobj.host
. Ie,obj
will always be a Host. But, Hosts do not have an ipaddress field. What they do have is a related_name,ip_addresses
from the Ipaddress model: https://github.com/unioslo/mreg/blob/master/mreg/models.py#L398This leads me to wonder what the logic is supposed to be here. Are we supposed to deny deletion of the object if the host is using any addresses that are reserved? If so, we want:
And we could then test this as such in
api/v1/tests/tests_permission.py
in the class classNetGroupRegexPermissionTestCaseAsAdmin(NetGroupRegexPermissionTestCase)
. Testing inTestIsGrantedNetGroupRegexPermission
will give us a 204 due to the overall access given to superusers in thehas_destroy_permission
itself.Can someone explain this to me? :)
The text was updated successfully, but these errors were encountered: