bind: test for parsing zones file with specific format

Signed-off-by: Nektarios Katakis <iam@nektarioskatakis.xyz>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Nektarios Katakis 2020-02-04 14:21:14 +00:00 committed by James Valleroy
parent 19f9436457
commit 5826d35ce5
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808

View File

@ -17,6 +17,7 @@
"""
Test actions for configuring bind
"""
from pathlib import Path
import pytest
@ -34,6 +35,50 @@ def fixture_configuration_file(tmp_path):
bind.CONFIG_FILE = old_config_file
@pytest.fixture
def bind_zones_folder(tmp_path):
"""Setup the a bind configuration file temporary directory."""
test_zone_file = """
;
; BIND data file for local loopback interface
;
$TTL 604800
@ IN SOA {name} root.localhost. (
2 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS {name}
@ IN A {a_record}
@ IN AAAA {aaaa_record}
""" # noqa
old_zones_dir = bind.ZONES_DIR
bind.ZONES_DIR = tmp_path
zones_dir_path = Path(bind.ZONES_DIR)
zones_dir_path.mkdir(exist_ok=True, parents=True)
local_path = zones_dir_path / "local.zone"
local_path.write_text(
test_zone_file.format(name='localhost.', a_record="127.0.0.1",
aaaa_record="::1")
)
custom_zone_path = zones_dir_path / "custom.zone"
custom_zone_path.write_text(
test_zone_file.format(name='custom.domain.', a_record="10.10.10.1",
aaaa_record="fe80::c6e9:84ff:fe16:95da")
)
yield
local_path.unlink()
custom_zone_path.unlink()
bind.ZONES_DIR = old_zones_dir
@pytest.mark.usefixtures('configuration_file')
def test_set_forwarders():
"""Test that setting forwarders works."""
@ -56,3 +101,16 @@ def test_enable_dnssec():
bind.set_dnssec('disable')
conf = bind.get_config()
assert not conf['enable_dnssec']
@pytest.mark.usefixtures('bind_zones_folder')
def test_get_correct_served_domains():
"""
Test that get_served_domains collects the right a/aaaa records from zone
files
"""
served_domains = bind.get_served_domains()
assert served_domains['localhost.'] == ["127.0.0.1", "::1"]
assert served_domains['custom.domain.'] == [
"10.10.10.1", "fe80::c6e9:84ff:fe16:95da"]