Skip to content

Commit 4cc3fd3

Browse files
committed
ci: implement cross-platform network interface integration tests
1 parent f51dbbe commit 4cc3fd3

2 files changed

Lines changed: 40 additions & 9 deletions

File tree

.github/workflows/build.yml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ name: Build Zond
33
on:
44
release:
55
types: [published]
6+
push:
7+
branches: [ "main" ]
68
pull_request:
79
branches: [ "main" ]
810

@@ -35,13 +37,18 @@ jobs:
3537
Expand-Archive -Path "npcap-sdk.zip" -DestinationPath "npcap-sdk"
3638
echo "LIB=$env:GITHUB_WORKSPACE\npcap-sdk\Lib\x64;$env:LIB" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
3739
40+
- name: Run Tests (macOS & Linux)
41+
if: matrix.os != 'windows-latest'
42+
run: cargo test --workspace
43+
44+
- name: Verify Compilation (Windows)
45+
if: matrix.os == 'windows-latest'
46+
run: cargo check --workspace
47+
3848
- name: Build Release Binary
49+
if: github.event_name == 'release'
3950
run: cargo build --release
4051

41-
- name: Package Windows Binary
42-
if: matrix.os == 'windows-latest' && github.event_name == 'release'
43-
run: |
44-
powershell Compress-Archive -Path target/release/zond.exe -DestinationPath target/release/zond-windows.zip
4552

4653
- name: Package MacOS Binary
4754
if: matrix.os == 'macos-latest' && github.event_name == 'release'
@@ -73,7 +80,6 @@ jobs:
7380
with:
7481
# The action automatically detects the tag from the release event
7582
files: |
76-
target/release/zond-windows.zip
7783
target/release/zond-macos.zip
7884
target/release/zond-linux.tar.gz
7985
target/release/Zond_Setup.exe

tests/src/discovery/integration.rs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use zond_common::models::port::PortSet;
1414
use zond_common::models::ip::{set::IpSet, range::Ipv4Range};
1515
use zond_core::scanner::{self, STOP_SIGNAL};
1616

17+
#[cfg(target_os = "linux")]
1718
use 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

Comments
 (0)