Skip to content

Commit

Permalink
Add tests for case in DNS forwards lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
johannaengland committed Aug 7, 2023
1 parent b181f5c commit 9df36cb
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/unittests/asyncdns_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from mock import Mock
from twisted.names import dns

from nav.asyncdns import ForwardResolver

BUICK_NAME = "buick.lab.uninett.no"


def test_forward_lookup_should_work_with_ipv4_results():
record = Mock()
record.name = BUICK_NAME
record.type = dns.A
record.payload.address = b"\xac\x00\x00\x01"
result = [[record]]
result_name, address_list = ForwardResolver._extract_records(result, BUICK_NAME)

assert result_name == BUICK_NAME
assert address_list == ["172.0.0.1"]


def test_forward_lookup_should_work_with_ipv6_results():
record = Mock()
record.name = BUICK_NAME
record.type = dns.AAAA
record.payload.address = b" \x01\r\xb833DDUUffww\x88\x88"
result = [[record]]
result_name, address_list = ForwardResolver._extract_records(result, BUICK_NAME)

assert result_name == BUICK_NAME
assert address_list == ["2001:db8:3333:4444:5555:6666:7777:8888"]


def test_forward_lookup_should_work_with_different_case_name_results():
record = Mock()
record.name = "bUiCk.LaB.uNiNeTt.No"
record.type = dns.A
record.payload.address = b"\x9e&\x98\xa2"
result = [[record]]
result_name, address_list = ForwardResolver._extract_records(result, BUICK_NAME)

assert result_name == BUICK_NAME
assert address_list == ["158.38.152.162"]

0 comments on commit 9df36cb

Please sign in to comment.