fix(obp): VALIDATE_SERVER_IDS does not refuse every server while the list never loaded

An empty server list means its download failed; refusing every 4-5 digit source server on it cut off the whole mesh. A loaded list still refuses unknown servers.
pull/184/head
Rodrigo Pérez 4 days ago
parent 2510e61e49
commit a2932d366e

@ -239,7 +239,13 @@ def check_source_server(
args=(frame.system, envelope.source_server),
level=logging.WARNING,
)
if ctx.validate_server_ids and len(digits) in (4, 5) and digits[:4] not in ctx.known_server_prefixes:
# An empty list never loaded: refusing every server on it would cut the mesh off.
if (
ctx.validate_server_ids
and ctx.known_server_prefixes
and len(digits) in (4, 5)
and digits[:4] not in ctx.known_server_prefixes
):
return Rejection(
reason="source-server-unknown",
message="(%s) Source Server ID is 4 or 5 digits but not in list: %s",

@ -138,10 +138,9 @@ def _policy(config: dict[str, Any], name: str, sys_cfg: dict[str, Any], router:
tg1_acl=sys_cfg.get("TG1_ACL", (True, [])),
),
server_id=server_prefix(global_cfg.get("SERVER_ID", 0)),
# The server-id list and the alias tables are loaded at runtime, not from
# the YAML, so offline we cannot answer "is this server known?" and saying
# "no" would blame every frame on a table we do not have.
validate_server_ids=bool(global_cfg.get("VALIDATE_SERVER_IDS")) and bool(config.get("_SERVER_IDS")),
# The alias tables are loaded at runtime, not from the YAML: offline there is
# no server list, and no alias table to resolve a 6-7 digit server against.
validate_server_ids=bool(global_cfg.get("VALIDATE_SERVER_IDS")),
known_server_prefixes=config.get("_SERVER_IDS", set()),
resolve_server_id=lambda _sid: True
)

@ -185,6 +185,13 @@ def test_unknown_short_source_server_passes_when_validation_is_off() -> None:
assert check_source_server(_frame(), envelope, _ctx(known_server_prefixes={"2131"})) is None
def test_short_source_server_passes_while_the_server_list_never_loaded() -> None:
"""An empty list is a failed download, not a list that knows no server."""
envelope = _envelope(source_server=2084)
ctx = _ctx(validate_server_ids=True, known_server_prefixes={})
assert check_source_server(_frame(), envelope, ctx) is None
def test_long_source_server_must_resolve_to_a_dmr_id() -> None:
envelope = _envelope(source_server=2130001)
rejection = check_source_server(_frame(), envelope, _ctx(resolve_server_id=lambda _id: False))

@ -129,6 +129,8 @@ def build_config(case: dict[str, Any]) -> dict[str, Any]:
system["_TARGET_IP"] = case["dns_host"]
if case.get("stun"):
config["STUN"] = True
if "server_ids" in case: # the list as the alias loader left it
config["_SERVER_IDS"] = case["server_ids"]
return config

@ -0,0 +1,25 @@
"""VALIDATE_SERVER_IDS checks against the server list, not against its absence.
An empty list means the download never succeeded (the startup and every reload
log it as an error). Refusing every 4-5 digit source server on it cut the whole
mesh off over one failed download; a loaded list still refuses unknown servers.
"""
from __future__ import annotations
from tests.harness.obp_ingress import observe
def _case(**overrides: object) -> dict:
return {"kind": "v5", "name": "unloaded", "desc": "unloaded", "validate_server_ids": True,
"source_server": 2131, **overrides}
def test_a_list_that_never_loaded_lets_source_servers_through() -> None:
assert observe(_case(server_ids={}))["delivered"]
def test_a_loaded_list_still_refuses_an_unknown_server() -> None:
effects = observe(_case(server_ids={"2084": "ADN_2084_France"}))
assert not effects["delivered"]
assert any("not in list" in text for _, text in effects["log"])
Loading…
Cancel
Save

Powered by TurnKey Linux.