bind: Use privileged decorator for actions

Tests:

- Initial setup:
  - Creates zones directory
  - Write default configuration
  - named is restarted
- Forwarders
  - Setting forwarders works as expected.
  - Current list of forwarders is shown as expected
- List of served domains is shown properly

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa authored and James Valleroy committed 2022-10-08 18:51:21 -04:00
1 parent 212364ba2a
commit cdb04bb46a
5 files changed
+231 -283

No files matched your search

+21 -22
View File
@@ -13,11 +13,11 @@ from plinth.modules import bind
def fixture_configuration_file(tmp_path):
"""Setup the a bind configuration file temporary directory."""
conf_file = tmp_path / 'named.conf.options'
conf_file.write_text(bind.DEFAULT_CONFIG)
old_config_file = bind.CONFIG_FILE
bind.CONFIG_FILE = str(conf_file)
conf_file.write_text(bind.privileged.DEFAULT_CONFIG)
old_config_file = bind.privileged.CONFIG_FILE
bind.privileged.CONFIG_FILE = str(conf_file)
yield
bind.CONFIG_FILE = old_config_file
bind.privileged.CONFIG_FILE = old_config_file
@pytest.fixture
@@ -40,51 +40,49 @@ $TTL 604800
@ IN AAAA {aaaa_record}
""" # noqa
old_zones_dir = bind.ZONES_DIR
bind.ZONES_DIR = tmp_path
zones_dir_path = Path(bind.ZONES_DIR)
old_zones_dir = bind.privileged.ZONES_DIR
bind.privileged.ZONES_DIR = tmp_path
zones_dir_path = Path(bind.privileged.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")
)
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")
)
aaaa_record="fe80::c6e9:84ff:fe16:95da"))
yield
local_path.unlink()
custom_zone_path.unlink()
bind.ZONES_DIR = old_zones_dir
bind.privileged.ZONES_DIR = old_zones_dir
@pytest.mark.usefixtures('configuration_file')
def test_set_forwarders():
"""Test that setting forwarders works."""
bind.set_forwarders('8.8.8.8 8.8.4.4')
conf = bind.get_config()
bind.privileged._set_forwarders('8.8.8.8 8.8.4.4')
conf = bind.privileged.get_config()
assert conf['forwarders'] == '8.8.8.8 8.8.4.4'
bind.set_forwarders('')
conf = bind.get_config()
bind.privileged._set_forwarders('')
conf = bind.privileged.get_config()
assert conf['forwarders'] == ''
@pytest.mark.usefixtures('configuration_file')
def test_enable_dnssec():
"""Test that enabling DNSSEC works."""
bind.set_dnssec('enable')
conf = bind.get_config()
bind.privileged._set_dnssec(True)
conf = bind.privileged.get_config()
assert conf['enable_dnssec']
bind.set_dnssec('disable')
conf = bind.get_config()
bind.privileged._set_dnssec(False)
conf = bind.privileged.get_config()
assert not conf['enable_dnssec']
@@ -94,8 +92,9 @@ 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()
served_domains = bind.privileged.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"]
"10.10.10.1", "fe80::c6e9:84ff:fe16:95da"
]