forked from Uninett/nav
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for case in DNS forwards lookup
- Loading branch information
1 parent
b181f5c
commit 9df36cb
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |