test(nat): verify public incoming profiles on isolated routed network

This commit is contained in:
evgeny committed 2026-10-18 00:55:37 +02:00
1 parent 918b5e55d5
commit bde6b2bee9
1 file changed
+8 -2
+8 -2
View File
@@ -46,6 +46,10 @@ def check_profiles(scenario):
# Отсутствие второго наблюдателя не превращается в STRICT/DIRECT.
first, second = public[:2]
connect(first, second)
accepted = profile(agents[second.name].rpc("stats"), transport)
if (accepted["mapping"], accepted["inbound"], accepted["source"]) != ("UNCHANGED", "OPEN", "ETCP"):
raise RuntimeError(f"NAT accepted public {transport} connection did not confirm DIRECT/OPEN: {accepted}")
print(f"NAT accepted public {transport}: {second.name} DIRECT/OPEN without helper", flush=True)
if not scenario.args.tcp_only:
incomplete = measure(first, second, "udp")
if (incomplete["mapping"], incomplete["inbound"], incomplete["reason"]) != ("UNKNOWN", "UNKNOWN", "no_helper"):
@@ -116,7 +120,8 @@ def check_profiles(scenario):
profile(statistics[owner.name], "tcp")["source"] == "ETCP" and
bool(profile(statistics[owner.name], "tcp")["external"]), 10)
actual = profile(data[owner.name], "tcp")
expected = ("UNKNOWN" if owner.nat else "UNCHANGED", "UNKNOWN")
# second принимает первый TCP от first; остальные проверяемые сокеты здесь исходящие.
expected = ("UNKNOWN" if owner.nat else "UNCHANGED", "OPEN" if owner.name == second.name else "UNKNOWN")
ip = next(item for item in NATS if item.name == owner.nat).ip if owner.nat else owner.ip
if (actual["mapping"], actual["inbound"], actual["external"]) != (*expected, f"{ip}:0"):
raise RuntimeError(f"{owner.name}/tcp: expected {expected}, IP={ip}:0, detector returned {actual}")
@@ -136,7 +141,8 @@ def check_profiles(scenario):
if again["inbound"] == "UNKNOWN" and again["reason"] != "contact_history":
raise RuntimeError(f"{first.name}: UNKNOWN without contact-history explanation: {again}")
result = {"nodes_checked": len(verified), "protocols": protocols, "no_helper_checked": not scenario.args.tcp_only,
result = {"nodes_checked": len(verified), "protocols": protocols, "accepted_connection_checked": True,
"no_helper_checked": not scenario.args.tcp_only,
"warm_recheck_checked": bool(first_profile), "verified": verified}
(scenario.network.directory / "nat-result.json").write_text(json.dumps(result, indent=2) + "\n")
return result