Skip to content

Commit

Permalink
Merge pull request Uninett#2990 from lunkwill42/bugfix/ipam-tree-api-…
Browse files Browse the repository at this point in the history
…crash

Fix incorrect handling of non-existant scopes
  • Loading branch information
lunkwill42 authored Sep 19, 2024
2 parents 807deb4 + 4f8305c commit c5dfce2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog.d/2989.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix IPAM API crash bug that caused unnecessary error reports sent as e-mail to site admins
6 changes: 3 additions & 3 deletions python/nav/web/ipam/prefix_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,10 +467,10 @@ def make_tree(prefixes, family=None, root_ip=None, show_all=None, sort_by="ip"):
init = []

if root_ip is not None and root_ip:
scope = Prefix.objects.get(net_address=root_ip)
if scope is not None:
try:
scope = Prefix.objects.get(net_address=root_ip)
node = PrefixNode(scope)
else:
except Prefix.DoesNotExist:
node = FauxNode(root_ip, "scope", "scope")
init.append(node)

Expand Down
12 changes: 12 additions & 0 deletions tests/integration/web/ipam/api_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class TestPrefixViewSet:
def test_when_prefix_address_is_unknown_it_should_not_crash(self, client):
response = client.get(
"/ipam/api/",
follow=True,
data={
"net_type": "all",
"within": "192.168.42.0/24",
"show_all": "True",
},
)
assert response.status_code == 200

0 comments on commit c5dfce2

Please sign in to comment.