Use bootstrap() in pytest where applicable

Replace the autouse fixtures which were only used to change the initial
server configuration into proper bootstrap() functions. This gets rid of
an extraneous reconfigure.

In the tests_validation_many_anchors.py, split the fixture into a proper
bootstrap() and a separate test for checking the expected log lines for
the ignored keys. Previously, the test was broken - it should check for
all the messages being present in the log, and some of the keys are
actually initial-key rather than static-key. This has been fixed in the
parametrized test.
This commit is contained in:
Nicki Křížek 2025-09-25 17:30:12 +02:00
parent 7474d38295
commit fb4345afd4
11 changed files with 76 additions and 74 deletions

View file

@ -11,18 +11,14 @@
from dns import flags
import pytest
import isctest
@pytest.fixture(scope="module", autouse=True)
def reconfigure(ns5, ns9, templates):
templates.render("ns5/named.conf", {"broken_key": True})
ns5.reconfigure(log=False)
templates.render("ns9/named.conf", {"forward_badkey": True})
ns9.reconfigure(log=False)
def bootstrap():
return {
"broken_key": True,
"forward_badkey": True,
}
def test_broken_forwarding(ns9):

View file

@ -9,15 +9,13 @@
# See the COPYRIGHT file distributed with this work for additional
# information regarding copyright ownership.
import pytest
import isctest
@pytest.fixture(scope="module", autouse=True)
def reconfigure(ns5, templates):
templates.render("ns5/named.conf", {"revoked_key": True})
ns5.reconfigure(log=False)
def bootstrap():
return {
"revoked_key": True,
}
def test_revoked_init():

View file

@ -11,15 +11,13 @@
from dns import flags
import pytest
import isctest
@pytest.fixture(scope="module", autouse=True)
def reconfigure(ns4, templates):
templates.render("ns4/named.conf", {"accept_expired": True})
ns4.reconfigure(log=False)
def bootstrap():
return {
"accept_expired": True,
}
def test_accept_expired(ns4):

View file

@ -12,17 +12,15 @@
import os
import shutil
import pytest
import isctest
@pytest.fixture(scope="module", autouse=True)
def reconfigure(ns4, templates):
assert os.path.exists("ns4/managed-keys.bind.jnl") is False
def bootstrap():
assert not os.path.exists("ns4/managed-keys.bind.jnl")
shutil.copyfile("ns4/managed-keys.bind.in", "ns4/managed-keys.bind")
templates.render("ns4/named.conf", {"managed_key": True})
ns4.reconfigure(log=False)
return {
"managed_key": True,
}
# helper functions

View file

@ -10,27 +10,33 @@
# information regarding copyright ownership.
from dns import edns
import pytest
import isctest
from isctest.util import param
@pytest.fixture(scope="module", autouse=True)
def reconfigure(ns5, templates):
templates.render("ns5/named.conf", {"many_anchors": True})
with ns5.watch_log_from_here() as watcher:
ns5.reconfigure(log=False)
watcher.wait_for_line(
[
"ignoring static-key for 'disabled.trusted.': algorithm is disabled",
"ignoring static-key for 'disabled.managed.': algorithm is disabled",
"ignoring static-key for 'unsupported.trusted.': algorithm is unsupported",
"ignoring static-key for 'unsupported.managed.': algorithm is unsupported",
"ignoring static-key for 'unsupported.managed.': algorithm is unsupported",
"ignoring static-key for 'revoked.trusted.': bad key type",
"ignoring static-key for 'revoked.managed.': bad key type",
]
)
def bootstrap():
return {
"many_anchors": True,
}
@pytest.mark.parametrize(
"zone, keytype, msg",
[
param("disabled.trusted.", "static-key", "algorithm is disabled"),
param("disabled.managed.", "initial-key", "algorithm is disabled"),
param("unsupported.trusted.", "static-key", "algorithm is unsupported"),
param("unsupported.managed.", "initial-key", "algorithm is unsupported"),
param("revoked.trusted.", "static-key", "bad key type"),
param("revoked.managed.", "initial-key", "bad key type"),
],
)
def test_log_ignoring_key(zone, keytype, msg, ns5):
with ns5.watch_log_from_start() as watcher:
watcher.wait_for_line(f"ignoring {keytype} for '{zone}': {msg}")
def test_trust_anchors():

View file

@ -12,15 +12,13 @@
import os
import re
import pytest
import isctest
@pytest.fixture(scope="module", autouse=True)
def reconfigure(ns4, templates):
templates.render("ns4/named.conf", {"multi_view": True})
ns4.reconfigure(log=False)
def bootstrap():
return {
"multi_view": True,
}
def getfrom(file):

View file

@ -25,14 +25,6 @@ ARTIFACTS = [
]
def reconfigure_servers(ftype, family, servers, templates):
for server_id in ["ns1", "ns2", "ns3", "ns4"]:
templates.render(
f"{server_id}/named.conf", {"family": family, "filtertype": ftype}
)
servers[server_id].reconfigure(log=False)
def check_filtertype_only(dest, source, qname, ftype, expected, adflag):
qname = dns.name.from_text(qname)

View file

@ -18,17 +18,21 @@ from filters.common import (
check_filter,
check_filter_other_family,
prime_cache,
reconfigure_servers,
)
pytestmark = pytest.mark.extra_artifacts(ARTIFACTS)
def bootstrap():
return {
"family": "v4",
"filtertype": "a",
}
@pytest.fixture(scope="module", autouse=True)
def setup_filters(servers, templates):
isctest.log.info("configuring server to filter A on V4")
reconfigure_servers("a", "v4", servers, templates)
def setup_filters():
prime_cache("10.53.0.2")
prime_cache("10.53.0.3")

View file

@ -18,17 +18,21 @@ from filters.common import (
check_filter,
check_filter_other_family,
prime_cache,
reconfigure_servers,
)
pytestmark = pytest.mark.extra_artifacts(ARTIFACTS)
def bootstrap():
return {
"family": "v6",
"filtertype": "a",
}
@pytest.fixture(scope="module", autouse=True)
def setup_filters(servers, templates):
isctest.log.info("configuring server to filter A on V6")
reconfigure_servers("a", "v6", servers, templates)
def setup_filters():
prime_cache("fd92:7065:b8e:ffff::2")
prime_cache("fd92:7065:b8e:ffff::3")

View file

@ -19,17 +19,21 @@ from filters.common import (
check_filter,
check_filter_other_family,
prime_cache,
reconfigure_servers,
)
pytestmark = pytest.mark.extra_artifacts(ARTIFACTS)
def bootstrap():
return {
"family": "v4",
"filtertype": "aaaa",
}
@pytest.fixture(scope="module", autouse=True)
def setup_filters(servers, templates):
isctest.log.info("configuring server to filter AAAA on V4")
reconfigure_servers("aaaa", "v4", servers, templates)
def setup_filters():
prime_cache("10.53.0.2")
prime_cache("10.53.0.3")

View file

@ -18,17 +18,21 @@ from filters.common import (
check_filter,
check_filter_other_family,
prime_cache,
reconfigure_servers,
)
pytestmark = pytest.mark.extra_artifacts(ARTIFACTS)
def bootstrap():
return {
"family": "v6",
"filtertype": "aaaa",
}
@pytest.fixture(scope="module", autouse=True)
def setup_filters(servers, templates):
isctest.log.info("configuring server to filter AAAA on V6")
reconfigure_servers("aaaa", "v6", servers, templates)
def setup_filters():
prime_cache("fd92:7065:b8e:ffff::2")
prime_cache("fd92:7065:b8e:ffff::3")