use pnet::datalink;
use std::net::{IpAddr, TcpListener};
use zond_engine::core::config::ZondConfig;
use zond_engine::core::models::ip::set::IpSet;
use zond_engine::scanner;
#[tokio::test]
async fn windows_hardware_heuristics() {
let interfaces = datalink::interfaces();
assert!(
!interfaces.is_empty(),
"No network interfaces found on the system"
);
let mut physically_found = 0;
for iface in interfaces {
let physical = zond_engine::core::net::interface::os::is_physical(&iface);
let wireless = zond_engine::core::net::interface::os::is_wireless(&iface);
if physical {
physically_found += 1;
}
if wireless {
assert!(
physical,
"Interface {} identified as wireless but not physical",
iface.name
);
}
}
assert!(
physically_found > 0,
"No physical adapters detected - verify Administrator privileges"
);
}
#[tokio::test]
async fn windows_local_discovery_integration() {
let cfg = ZondConfig {
no_banner: true,
no_dns: true,
quiet: 0,
..Default::default()
};
let interfaces = datalink::interfaces();
let target_ip = interfaces
.iter()
.filter(|i| i.is_up() && !i.is_loopback())
.flat_map(|i| i.ips.iter())
.find(|ip| ip.is_ipv4())
.map(|ip| ip.ip())
.expect("No active local IPv4 interface found for testing");
let listener = TcpListener::bind((target_ip, 0)).expect("Failed to bind mock listener");
let local_addr = listener.local_addr().unwrap();
let port = local_addr.port();
let mut targets = IpSet::new();
targets.insert(target_ip);
let handle = tokio::spawn(async move { scanner::discover(targets, &cfg).await });
let result = handle.await.unwrap();
assert!(
result.is_ok(),
"Scanner failed on Windows: {:?}",
result.err()
);
let hosts = result.unwrap();
assert!(
!hosts.is_empty(),
"Scanner did not find the local host on Windows"
);
assert_eq!(hosts[0].primary_ip, target_ip);
drop(listener);
}
#[tokio::test]
async fn windows_loopback_fidelity() {
let cfg = ZondConfig {
no_banner: true,
no_dns: true,
..Default::default()
};
let mut targets = IpSet::new();
let localhost = IpAddr::V4(std::net::Ipv4Addr::new(127, 0, 0, 1));
targets.insert(localhost);
let result = scanner::discover(targets, &cfg).await;
assert!(result.is_ok());
let hosts = result.unwrap();
assert!(!hosts.is_empty(), "Loopback discovery failed on Windows");
assert_eq!(hosts[0].primary_ip, localhost);
}