Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
dlon committed Nov 22, 2023
1 parent f79a0aa commit aeb52cf
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 67 deletions.
4 changes: 2 additions & 2 deletions test/test-manager/src/tests/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub async fn get_tunnel_interface(rpc: ManagementServiceClient) -> Option<String
/// Sends a number of probes and returns the number of observed packets (UDP, TCP, or ICMP)
pub async fn send_guest_probes(
rpc: ServiceClient,
interface: Option<String>,
interface: String,
destination: SocketAddr,
) -> Result<ProbeResult, Error> {
const MONITOR_DURATION: Duration = Duration::from_secs(8);
Expand All @@ -113,7 +113,7 @@ pub async fn send_guest_probes(

let send_handle = tokio::spawn(send_guest_probes_without_monitor(
rpc,
interface,
Some(interface),
destination,
));

Expand Down
40 changes: 10 additions & 30 deletions test/test-manager/src/tests/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,8 @@ pub async fn test_lan(
log::info!("Test whether outgoing LAN traffic is blocked");

let default_interface = rpc.get_default_interface().await?;
let detected_probes = send_guest_probes(
rpc.clone(),
Some(default_interface.clone()),
lan_destination,
)
.await?;
let detected_probes =
send_guest_probes(rpc.clone(), default_interface.clone(), lan_destination).await?;
assert!(
detected_probes.none(),
"observed unexpected outgoing LAN packets: {detected_probes:?}"
Expand Down Expand Up @@ -138,23 +134,15 @@ pub async fn test_lockdown(

let default_interface = rpc.get_default_interface().await?;

let detected_probes = send_guest_probes(
rpc.clone(),
Some(default_interface.clone()),
lan_destination,
)
.await?;
let detected_probes =
send_guest_probes(rpc.clone(), default_interface.clone(), lan_destination).await?;
assert!(
detected_probes.none(),
"observed outgoing packets to LAN: {detected_probes:?}"
);

let detected_probes = send_guest_probes(
rpc.clone(),
Some(default_interface.clone()),
inet_destination,
)
.await?;
let detected_probes =
send_guest_probes(rpc.clone(), default_interface.clone(), inet_destination).await?;
assert!(
detected_probes.none(),
"observed outgoing packets to internet: {detected_probes:?}"
Expand All @@ -175,23 +163,15 @@ pub async fn test_lockdown(
// Ensure private IPs are reachable, but not others
//

let detected_probes = send_guest_probes(
rpc.clone(),
Some(default_interface.clone()),
lan_destination,
)
.await?;
let detected_probes =
send_guest_probes(rpc.clone(), default_interface.clone(), lan_destination).await?;
assert!(
detected_probes.all(),
"did not observe some outgoing packets: {detected_probes:?}"
);

let detected_probes = send_guest_probes(
rpc.clone(),
Some(default_interface.clone()),
inet_destination,
)
.await?;
let detected_probes =
send_guest_probes(rpc.clone(), default_interface.clone(), inet_destination).await?;
assert!(
detected_probes.none(),
"observed outgoing packets to internet: {detected_probes:?}"
Expand Down
53 changes: 18 additions & 35 deletions test/test-manager/src/tests/tunnel_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub async fn test_disconnected_state(
.expect("failed to obtain non-tun interface");

let detected_probes =
send_guest_probes(rpc.clone(), Some(non_tunnel_interface), inet_destination).await?;
send_guest_probes(rpc.clone(), non_tunnel_interface, inet_destination).await?;
assert!(
detected_probes.all(),
"did not see (all) outgoing packets to destination: {detected_probes:?}",
Expand Down Expand Up @@ -129,33 +129,25 @@ pub async fn test_connecting_state(
.expect("failed to obtain non-tun interface");

assert!(
send_guest_probes(
rpc.clone(),
Some(non_tunnel_interface.clone()),
inet_destination
)
.await?
.none(),
send_guest_probes(rpc.clone(), non_tunnel_interface.clone(), inet_destination)
.await?
.none(),
"observed unexpected outgoing packets (inet)"
);
assert!(
send_guest_probes(
rpc.clone(),
Some(non_tunnel_interface.clone()),
lan_destination
)
.await?
.none(),
send_guest_probes(rpc.clone(), non_tunnel_interface.clone(), lan_destination)
.await?
.none(),
"observed unexpected outgoing packets (lan)"
);
assert!(
send_guest_probes(rpc.clone(), Some(non_tunnel_interface.clone()), inet_dns)
send_guest_probes(rpc.clone(), non_tunnel_interface.clone(), inet_dns)
.await?
.none(),
"observed unexpected outgoing packets (DNS, inet)"
);
assert!(
send_guest_probes(rpc.clone(), Some(non_tunnel_interface), lan_dns)
send_guest_probes(rpc.clone(), non_tunnel_interface, lan_dns)
.await?
.none(),
"observed unexpected outgoing packets (DNS, lan)"
Expand Down Expand Up @@ -217,33 +209,25 @@ pub async fn test_error_state(
.expect("failed to obtain non-tun interface");

assert!(
send_guest_probes(
rpc.clone(),
Some(default_interface.clone()),
inet_destination
)
.await?
.none(),
send_guest_probes(rpc.clone(), default_interface.clone(), inet_destination)
.await?
.none(),
"observed unexpected outgoing packets (inet)"
);
assert!(
send_guest_probes(
rpc.clone(),
Some(default_interface.clone()),
lan_destination
)
.await?
.none(),
send_guest_probes(rpc.clone(), default_interface.clone(), lan_destination)
.await?
.none(),
"observed unexpected outgoing packets (lan)"
);
assert!(
send_guest_probes(rpc.clone(), Some(default_interface.clone()), inet_dns)
send_guest_probes(rpc.clone(), default_interface.clone(), inet_dns)
.await?
.none(),
"observed unexpected outgoing packets (DNS, inet)"
);
assert!(
send_guest_probes(rpc.clone(), Some(default_interface), lan_dns)
send_guest_probes(rpc.clone(), default_interface, lan_dns)
.await?
.none(),
"observed unexpected outgoing packets (DNS, lan)"
Expand Down Expand Up @@ -338,8 +322,7 @@ pub async fn test_connected_state(
.await
.expect("failed to find non-tun interface");

let detected_probes =
send_guest_probes(rpc.clone(), Some(nontun_iface), inet_destination).await?;
let detected_probes = send_guest_probes(rpc.clone(), nontun_iface, inet_destination).await?;
assert!(
detected_probes.none(),
"observed unexpected outgoing packets: {detected_probes:?}"
Expand Down

0 comments on commit aeb52cf

Please sign in to comment.