From c6bfc889260be3183c183dcb675fbc7692e8b480 Mon Sep 17 00:00:00 2001 From: Arnaud Date: Mon, 15 Jun 2026 22:47:22 +0400 Subject: [PATCH] Add more checks for nat integration tests --- tests/integration/nat/composehelper.nim | 4 ++++ tests/integration/nat/not-reachable/testnotreachable.nim | 7 +++++++ tests/integration/nat/pcp/testpcp.nim | 6 ++++++ tests/integration/nat/reachable/testreachable.nim | 5 +++++ tests/integration/nat/upnp/testupnp.nim | 5 +++++ 5 files changed, 27 insertions(+) diff --git a/tests/integration/nat/composehelper.nim b/tests/integration/nat/composehelper.nim index 4996de7a..8386ffc3 100644 --- a/tests/integration/nat/composehelper.nim +++ b/tests/integration/nat/composehelper.nim @@ -5,6 +5,10 @@ import std/[os, osproc] import ../utils +const + routerWanIp* = "7.7.7.2" ## public IP AutoNAT observes for a NATed node (masquerade) + bootstrapIp* = "7.7.7.10" ## relay + bootstrap public IP + proc composeCmd(composeFile: string): string = ## Prefer podman (where the Makefile builds the image), fall back to docker. let base = diff --git a/tests/integration/nat/not-reachable/testnotreachable.nim b/tests/integration/nat/not-reachable/testnotreachable.nim index 33f4b510..9298b37e 100644 --- a/tests/integration/nat/not-reachable/testnotreachable.nim +++ b/tests/integration/nat/not-reachable/testnotreachable.nim @@ -45,3 +45,10 @@ asyncchecksuite "NAT not reachable": check nat{"relayRunning"}.getBool check nat{"portMapping"}.getStr == "none" check info.announcesCircuitAddr() + let announced = info{"announceAddresses"}.getElems.mapIt(it.getStr) + # the announced circuit address points at the bootstrap's relay + check announced.anyIt( + ("/ip4/" & bootstrapIp & "/tcp/8070" in it) and ("p2p-circuit" in it) + ) + # relay addresses go only into the provider record, never the DHT routing record + check info{"dhtAddresses"}.getElems.len == 0 diff --git a/tests/integration/nat/pcp/testpcp.nim b/tests/integration/nat/pcp/testpcp.nim index 6300bc3e..64c99c21 100644 --- a/tests/integration/nat/pcp/testpcp.nim +++ b/tests/integration/nat/pcp/testpcp.nim @@ -52,3 +52,9 @@ asyncchecksuite "NAT pcp": check nat{"relayRunning"}.getBool == false check nat{"portMapping"}.getStr == "pcp" check info.announcesDirectAddr() + let announced = info{"announceAddresses"}.getElems.mapIt(it.getStr) + # PCP may map a port different from the listen port, so check the IP only + check announced.anyIt(("/ip4/" & routerWanIp & "/tcp/") in it) + # the public mapped address + # a reachable node announces its UDP address to the DHT routing record + check info{"dhtAddresses"}.getElems.len > 0 diff --git a/tests/integration/nat/reachable/testreachable.nim b/tests/integration/nat/reachable/testreachable.nim index 7d5b1110..2601f0fe 100644 --- a/tests/integration/nat/reachable/testreachable.nim +++ b/tests/integration/nat/reachable/testreachable.nim @@ -52,3 +52,8 @@ asyncchecksuite "NAT reachable": check nat{"reachability"}.getStr == "Reachable" check nat{"relayRunning"}.getBool == false check info.announcesDirectAddr() + let announced = info{"announceAddresses"}.getElems.mapIt(it.getStr) + check announced.anyIt(("/ip4/" & routerWanIp & "/tcp/8070") in it) + # public forwarded address + # a reachable node announces its UDP address to the DHT routing record + check info{"dhtAddresses"}.getElems.len > 0 diff --git a/tests/integration/nat/upnp/testupnp.nim b/tests/integration/nat/upnp/testupnp.nim index 7f69facc..0fd623ab 100644 --- a/tests/integration/nat/upnp/testupnp.nim +++ b/tests/integration/nat/upnp/testupnp.nim @@ -52,3 +52,8 @@ asyncchecksuite "NAT upnp": check nat{"relayRunning"}.getBool == false check nat{"portMapping"}.getStr == "upnp" check info.announcesDirectAddr() + let announced = info{"announceAddresses"}.getElems.mapIt(it.getStr) + check announced.anyIt(("/ip4/" & routerWanIp & "/tcp/8070") in it) + # public mapped address + # a reachable node announces its UDP address to the DHT routing record + check info{"dhtAddresses"}.getElems.len > 0