diff options
| author | Markus Pettersson <markus.pettersson@mullvad.net> | 2023-12-05 14:46:59 +0100 |
|---|---|---|
| committer | Markus Pettersson <markus.pettersson@mullvad.net> | 2023-12-07 13:28:37 +0100 |
| commit | 0b914a8796c15f25bdb3eb28903bb6a2a60dc12d (patch) | |
| tree | 95b1cfe2a21ada0f8cb28fc0bc556b0c9ba934d0 | |
| parent | f7a6919c2e3b8e8f973f4f380a6da82eaaf426f2 (diff) | |
| download | mullvadvpn-0b914a8796c15f25bdb3eb28903bb6a2a60dc12d.tar.xz mullvadvpn-0b914a8796c15f25bdb3eb28903bb6a2a60dc12d.zip | |
Refactoring
- Import qualified `network_monitor`
- Add `obtain_guest_ip`
- Fix docs
| -rw-r--r-- | test/test-manager/src/tests/helpers.rs | 48 | ||||
| -rw-r--r-- | test/test-manager/src/tests/install.rs | 10 |
2 files changed, 35 insertions, 23 deletions
diff --git a/test/test-manager/src/tests/helpers.rs b/test/test-manager/src/tests/helpers.rs index 647d23883a..48dba20aac 100644 --- a/test/test-manager/src/tests/helpers.rs +++ b/test/test-manager/src/tests/helpers.rs @@ -1,6 +1,6 @@ use super::{config::TEST_CONFIG, Error, PING_TIMEOUT, WAIT_FOR_TUNNEL_STATE_TIMEOUT}; use crate::network_monitor::{ - start_packet_monitor, MonitorOptions, MonitorUnexpectedlyStopped, PacketMonitor, + self, start_packet_monitor, MonitorOptions, MonitorUnexpectedlyStopped, PacketMonitor, }; use futures::StreamExt; use mullvad_management_interface::{types, ManagementServiceClient, MullvadProxyClient}; @@ -106,7 +106,7 @@ pub async fn send_guest_probes( let pktmon = start_packet_monitor( move |packet| packet.destination.ip() == destination.ip(), MonitorOptions { - direction: Some(crate::network_monitor::Direction::In), + direction: Some(network_monitor::Direction::In), timeout: Some(MONITOR_DURATION), ..Default::default() }, @@ -535,7 +535,7 @@ pub struct Pinger { // These values can be configured with [`PingerBuilder`]. destination: SocketAddr, interval: tokio::time::Interval, - // Run-time specifics + // Run-time specific values pub guest_ip: IpAddr, ping_task: AbortOnDrop<tokio::task::JoinHandle<()>>, monitor: PacketMonitor, @@ -546,7 +546,7 @@ impl Pinger { /// /// See [`PingerBuilder`] for details. pub async fn start(rpc: &test_rpc::ServiceClient) -> Pinger { - let defaults = PingerBuilder::new(); + let defaults = PingerBuilder::default(); Self::start_with(defaults, rpc).await } @@ -555,14 +555,8 @@ impl Pinger { /// See [`PingerBuilder`] for details on how to configure a [`Pinger`] /// before starting it. pub async fn start_with(builder: PingerBuilder, rpc: &test_rpc::ServiceClient) -> Pinger { - let guest_iface = rpc - .get_default_interface() - .await - .expect("failed to obtain default interface"); - let guest_ip = rpc - .get_interface_ip(guest_iface) - .await - .expect("failed to obtain non-tun IP"); + // Get the associated IP address of the test runner on the default, non-tunnel interface. + let guest_ip = obtain_guest_ip(rpc).await; log::debug!("Guest IP: {guest_ip}"); // Start a network monitor @@ -577,12 +571,14 @@ impl Pinger { MonitorOptions::default(), ) .await; + // Start pinging + // + // Create some network activity for the network monitor to sniff. let ping_rpc = rpc.clone(); let mut interval = tokio::time::interval(builder.interval.period()); #[allow(clippy::async_yields_async)] let ping_task = AbortOnDrop::new(tokio::spawn(async move { - // Send a ping once every second. loop { send_guest_probes_without_monitor(ping_rpc.clone(), None, builder.destination) .await; @@ -599,10 +595,9 @@ impl Pinger { } } - pub async fn stop( - self, - ) -> Result<crate::network_monitor::MonitorResult, MonitorUnexpectedlyStopped> { - // Abort the inner probe sender, which is accomplish by dropping the + /// Stop pinging and extract the result of the network monitor. + pub async fn stop(self) -> Result<network_monitor::MonitorResult, MonitorUnexpectedlyStopped> { + // Abort the inner probe sender, which is accomplished by dropping the // join handle to the running task. drop(self.ping_task); self.monitor.into_result().await @@ -614,6 +609,17 @@ impl Pinger { } } +/// Returns the [`IpAddr`] of the default non-tunnel interface. +async fn obtain_guest_ip(rpc: &ServiceClient) -> IpAddr { + let guest_iface = rpc + .get_default_interface() + .await + .expect("failed to obtain default interface"); + rpc.get_interface_ip(guest_iface) + .await + .expect("failed to obtain non-tun IP") +} + /// Configure a [`Pinger`] before starting it. pub struct PingerBuilder { destination: SocketAddr, @@ -622,8 +628,12 @@ pub struct PingerBuilder { #[allow(dead_code)] impl PingerBuilder { - // - pub fn new() -> PingerBuilder { + /// Create a default [`PingerBuilder`]. + /// + /// This is probably good enough for checking network traffic leaks when the + /// test-runner is supposed to be blocked from sending or receiving *any* + /// packets outside of localhost. + pub fn default() -> PingerBuilder { PingerBuilder { destination: "1.1.1.1:1337".parse().unwrap(), interval: tokio::time::interval(Duration::from_secs(1)), diff --git a/test/test-manager/src/tests/install.rs b/test/test-manager/src/tests/install.rs index a42f2af872..d2040771df 100644 --- a/test/test-manager/src/tests/install.rs +++ b/test/test-manager/src/tests/install.rs @@ -300,8 +300,11 @@ pub async fn test_installation_idempotency( .set_auto_connect(false) .await .expect("failed to enable auto-connect"); - // Start a tunnel monitor. No traffic should be observed going outside of - // the tunnel during either installation process. + // Check for traffic leaks during the installation processes. + // + // Start continously pinging while monitoring the network traffic. No + // traffic should be observed going outside of the tunnel during either + // installation process. let pinger = Pinger::start(&rpc).await; for _ in 1..=2 { // install package @@ -323,8 +326,7 @@ pub async fn test_installation_idempotency( tokio::time::sleep(delay).await; } } - - // Make sure that no traffic leak occured during any installation process. + // Make sure that no network leak occured during any installation process. let guest_ip = pinger.guest_ip; let monitor_result = pinger.stop().await.unwrap(); assert_eq!( |
