@@ -14,6 +14,7 @@ use zond_common::models::port::PortSet;
1414use zond_common:: models:: ip:: { set:: IpSet , range:: Ipv4Range } ;
1515use zond_core:: scanner:: { self , STOP_SIGNAL } ;
1616
17+ #[ cfg( target_os = "linux" ) ]
1718use crate :: utils:: NetnsContext ;
1819
1920#[ tokio:: test]
@@ -68,9 +69,11 @@ async fn test_discovery_range_loopback() {
6869 assert ! ( result. is_ok( ) , "Discovery failed: {:?}" , result. is_err( ) ) ;
6970 let hosts: Vec < Host > = result. unwrap ( ) ;
7071
72+ // macOS defaults to only assigning 127.0.0.1, whereas Linux assigns the full /8 block.
73+ // So macOS might just find 1, while Linux finds 3.
7174 assert ! (
72- hosts. len( ) = = 3 ,
73- "Found incorrect amount of hosts: {}" ,
75+ hosts. len( ) >= 1 && hosts . len ( ) < = 3 ,
76+ "Found anomalous amount of hosts: {}" ,
7477 hosts. len( )
7578 ) ;
7679}
@@ -96,11 +99,13 @@ async fn test_stop_signal_aborts() {
9699
97100 let handle = tokio:: spawn ( async move { scanner:: discover ( targets, & cfg) . await } ) ;
98101
99- tokio:: time:: sleep ( Duration :: from_millis ( 10 ) ) . await ;
102+ // Give it a moment to boot up the threads
103+ tokio:: time:: sleep ( Duration :: from_millis ( 50 ) ) . await ;
100104
101105 STOP_SIGNAL . store ( true , Ordering :: Relaxed ) ;
102106
103- let result = tokio:: time:: timeout ( Duration :: from_millis ( 50 ) , handle) . await ;
107+ // Give it a generous allowance to unwind pending connections/timers (macOS is slower with raw sockets)
108+ let result = tokio:: time:: timeout ( Duration :: from_millis ( 1500 ) , handle) . await ;
104109
105110 assert ! ( result. is_ok( ) , "Scanner did not stop in time" ) ;
106111}
@@ -149,3 +154,23 @@ async fn test_privileged_discovery_netns() {
149154 Err ( e) => panic ! ( "Discovery failed: {}" , e) ,
150155 }
151156}
157+
158+ #[ test]
159+ fn test_lan_network_resolution ( ) {
160+ // Assert that the machine running the integration test has at least 1 viable interface
161+ // that resolves via our platform agnostics hooks (macOS networksetup, Linux sysfs, Windows GetIfTable2).
162+ let result = zond_common:: net:: interface:: get_lan_network ( ) ;
163+ assert ! ( result. is_ok( ) , "Expected no OS or Viability errors during interface parsing" ) ;
164+
165+ // Virtualized headless CI runners might return None here since they use virtual bridges,
166+ // but the FFI/Syscalls must execute safely regardless!
167+ println ! ( "Resolved LAN network: {:?}" , result. unwrap( ) ) ;
168+ }
169+
170+ #[ test]
171+ fn test_prioritized_interfaces_resolution ( ) {
172+ let interfaces_res = zond_common:: net:: interface:: get_prioritized_interfaces ( 10 ) ;
173+ assert ! ( interfaces_res. is_ok( ) ) ;
174+ let interfaces = interfaces_res. unwrap ( ) ;
175+ assert ! ( !interfaces. is_empty( ) , "Expected at least 1 UP, non-loopback network interface on the host natively" ) ;
176+ }
0 commit comments