mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-06-03 10:50:20 +00:00
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:
parent
19f9436457
commit
5826d35ce5
@ -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"]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user