1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
import pytest
from pytest import raises
from knot_resolver_manager.manager.datamodel.forward_schema import ForwardSchema
from knot_resolver_manager.utils.modeling.exceptions import DataValidationError
@pytest.mark.parametrize("port,auth", [(5353, False), (53, True)])
def test_forward_valid(port: int, auth: bool):
assert ForwardSchema(
{"subtree": ".", "options": {"authoritative": auth, "dnssec": True}, "servers": [f"127.0.0.1", "::1"]}
)
assert ForwardSchema(
{"subtree": ".", "options": {"authoritative": auth, "dnssec": False}, "servers": [f"127.0.0.1@{port}", "::1"]}
)
assert ForwardSchema(
{
"subtree": ".",
"options": {"authoritative": auth, "dnssec": False},
"servers": [{"address": [f"127.0.0.1@{port}", "::1"]}],
}
)
assert ForwardSchema(
{
"subtree": ".",
"options": {"authoritative": auth, "dnssec": False},
"servers": [{"address": [f"127.0.0.1", "::1"]}],
}
)
@pytest.mark.parametrize(
"port,auth,tls",
[(5353, True, False), (53, True, True)],
)
def test_forward_invalid(port: int, auth: bool, tls: bool):
if not tls:
with raises(DataValidationError):
ForwardSchema(
{
"subtree": ".",
"options": {"authoritative": auth, "dnssec": False},
"servers": [f"127.0.0.1@{port}", "::1"],
}
)
with raises(DataValidationError):
ForwardSchema(
{
"subtree": ".",
"options": {"authoritative": auth, "dnssec": False},
"servers": [{"address": [f"127.0.0.1{port}", f"::1{port}"], "transport": "tls" if tls else None}],
}
)
|