field = _field(action)
if getattr(self, field) and _field(self.action) != field:
raise ValueError(f"'{field}' field can only be defined for '{action}' action")
+
+ # ForwardServerSchema is valid only for 'forward' action
+ if self.servers:
+ for server in self.servers: # pylint: disable=not-an-iterable
+ if self.action != "forward" and isinstance(server, ForwardServerSchema):
+ raise ValueError(
+ f"'ForwardServerSchema' in 'servers' is valid only for 'forward' action, got '{self.action}'"
+ )
{"action": "mirror", "servers": ["192.0.2.1@5353", "2001:148f:ffff::1"]},
{"action": "forward", "servers": ["192.0.2.1@5353", "2001:148f:ffff::1"]},
{"action": "stub", "servers": ["192.0.2.1@5353", "2001:148f:ffff::1"]},
+ {"action": "forward", "servers": [{"address": "127.0.0.1@5353"}]},
],
)
def test_policy_valid(val: Dict[str, Any]):
{"action": "pass", "reroute": [{"source": "192.0.2.0/24", "destination": "127.0.0.0"}]},
{"action": "pass", "answer": {"rtype": "AAAA", "rdata": "::1"}},
{"action": "pass", "servers": ["127.0.0.1@5353"]},
+ {"action": "mirror", "servers": [{"address": "127.0.0.1@5353"}]},
],
)
def test_policy_invalid(val: Dict[str, Any]):