Skip to content

Commit

Permalink
Merge branch 'format-tests-folder'
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusPettersson98 committed Apr 9, 2024
2 parents 88bba34 + 8eea4ea commit 3b4eca7
Show file tree
Hide file tree
Showing 22 changed files with 136 additions and 166 deletions.
6 changes: 4 additions & 2 deletions test/connection-checker/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ use reqwest::blocking::Client;
use serde::Deserialize;
use std::{io::stdin, time::Duration};

use connection_checker::cli::Opt;
use connection_checker::net::{send_ping, send_tcp, send_udp};
use connection_checker::{
cli::Opt,
net::{send_ping, send_tcp, send_udp},
};

fn main() -> eyre::Result<()> {
let opt = Opt::parse();
Expand Down
2 changes: 1 addition & 1 deletion test/connection-checker/src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub fn send_udp(_opt: &Opt, destination: SocketAddr) -> Result<(), eyre::Error>
sock.bind(&socket2::SockAddr::from(bind_addr))
.wrap_err(eyre!("Failed to bind UDP socket to {bind_addr}"))?;

//log::debug!("Send message from {bind_addr} to {destination}/UDP");
// log::debug!("Send message from {bind_addr} to {destination}/UDP");

let std_socket = std::net::UdpSocket::from(sock);
std_socket
Expand Down
3 changes: 1 addition & 2 deletions test/socks-server/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use futures::StreamExt;
use std::io;
use std::net::SocketAddr;
use std::{io, net::SocketAddr};

#[derive(thiserror::Error, Debug)]
pub enum Error {
Expand Down
6 changes: 3 additions & 3 deletions test/test-manager/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ mod vm;

use std::path::PathBuf;

use anyhow::Context;
use anyhow::Result;
use anyhow::{Context, Result};
use clap::Parser;
use std::net::SocketAddr;
use tests::config::DEFAULT_MULLVAD_HOST;
Expand Down Expand Up @@ -81,7 +80,8 @@ enum Commands {
///
/// # Note
///
/// The gRPC interface must be compatible with the version specified for `mullvad-management-interface` in Cargo.toml.
/// The gRPC interface must be compatible with the version specified for
/// `mullvad-management-interface` in Cargo.toml.
#[arg(long, short)]
current_app: String,

Expand Down
3 changes: 1 addition & 2 deletions test/test-manager/src/network_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ use pnet_packet::{

pub use pnet_packet::ip::IpNextHeaderProtocols as IpHeaderProtocols;

use crate::tests::config::TEST_CONFIG;
use crate::vm::network::CUSTOM_TUN_INTERFACE_NAME;
use crate::{tests::config::TEST_CONFIG, vm::network::CUSTOM_TUN_INTERFACE_NAME};

struct Codec {
no_frame: bool,
Expand Down
15 changes: 7 additions & 8 deletions test/test-manager/src/run_tests.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
use crate::summary::{self, maybe_log_test_result};
use crate::tests::{config::TEST_CONFIG, TestContext};
use crate::{
logging::{panic_as_string, TestOutput},
mullvad_daemon, tests, vm,
mullvad_daemon,
summary::{self, maybe_log_test_result},
tests,
tests::{config::TEST_CONFIG, TestContext},
vm,
};
use anyhow::{Context, Result};
use futures::FutureExt;
use std::future::Future;
use std::panic;
use std::time::Duration;
use test_rpc::logging::Output;
use test_rpc::{mullvad_daemon::MullvadClientVersion, ServiceClient};
use std::{future::Future, panic, time::Duration};
use test_rpc::{logging::Output, mullvad_daemon::MullvadClientVersion, ServiceClient};

/// The baud rate of the serial connection between the test manager and the test runner.
/// There is a known issue with setting a baud rate at all or macOS, and the workaround
Expand Down
13 changes: 6 additions & 7 deletions test/test-manager/src/tests/account.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use crate::tests::helpers::{login_with_retries, THROTTLE_RETRY_DELAY};

use super::config::TEST_CONFIG;
use super::{helpers, ui, Error, TestContext};
use super::{config::TEST_CONFIG, helpers, ui, Error, TestContext};
use mullvad_api::DevicesProxy;
use mullvad_management_interface::{client::DaemonEvent, MullvadProxyClient};
use mullvad_types::device::{Device, DeviceState};
use mullvad_types::states::TunnelState;
use std::net::ToSocketAddrs;
use std::time::Duration;
use mullvad_types::{
device::{Device, DeviceState},
states::TunnelState,
};
use std::{net::ToSocketAddrs, time::Duration};
use talpid_types::net::wireguard;
use test_macro::test_function;
use test_rpc::ServiceClient;
Expand All @@ -19,7 +19,6 @@ pub async fn test_login(
_rpc: ServiceClient,
mut mullvad_client: MullvadProxyClient,
) -> Result<(), Error> {
//
// Instruct daemon to log in
//

Expand Down
24 changes: 10 additions & 14 deletions test/test-manager/src/tests/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ use super::{
helpers::{self, connect_and_wait, set_relay_settings},
Error, TestContext,
};
use crate::network_monitor::{
start_packet_monitor_until, start_tunnel_packet_monitor_until, Direction, IpHeaderProtocols,
MonitorOptions,
};
use crate::vm::network::{
CUSTOM_TUN_GATEWAY, CUSTOM_TUN_LOCAL_PRIVKEY, CUSTOM_TUN_LOCAL_TUN_ADDR,
CUSTOM_TUN_REMOTE_PUBKEY, CUSTOM_TUN_REMOTE_REAL_ADDR, CUSTOM_TUN_REMOTE_REAL_PORT,
CUSTOM_TUN_REMOTE_TUN_ADDR, NON_TUN_GATEWAY,
use crate::{
network_monitor::{
start_packet_monitor_until, start_tunnel_packet_monitor_until, Direction,
IpHeaderProtocols, MonitorOptions,
},
vm::network::{
CUSTOM_TUN_GATEWAY, CUSTOM_TUN_LOCAL_PRIVKEY, CUSTOM_TUN_LOCAL_TUN_ADDR,
CUSTOM_TUN_REMOTE_PUBKEY, CUSTOM_TUN_REMOTE_REAL_ADDR, CUSTOM_TUN_REMOTE_REAL_PORT,
CUSTOM_TUN_REMOTE_TUN_ADDR, NON_TUN_GATEWAY,
},
};

/// How long to wait for expected "DNS queries" to appear
Expand Down Expand Up @@ -130,7 +132,6 @@ async fn leak_test_dns(
use_tun: bool,
whitelisted_dest: IpAddr,
) -> Result<(), Error> {
//
// Connect to local wireguard relay
//

Expand Down Expand Up @@ -158,7 +159,6 @@ async fn leak_test_dns(
log::debug!("Tunnel (guest) IP: {tunnel_ip}");
log::debug!("Non-tunnel (guest) IP: {nontun_ip}");

//
// Spoof DNS packets
//

Expand Down Expand Up @@ -260,7 +260,6 @@ async fn leak_test_dns(
});

if use_tun {
//
// Examine tunnel traffic
//

Expand All @@ -281,7 +280,6 @@ async fn leak_test_dns(
);
}

//
// Examine non-tunnel traffic
//

Expand All @@ -297,7 +295,6 @@ async fn leak_test_dns(
probes.abort();
let _ = probes.await;

//
// Examine tunnel traffic
//

Expand All @@ -308,7 +305,6 @@ async fn leak_test_dns(
"expected no tunnel packets on port 53"
);

//
// Examine non-tunnel traffic
//

Expand Down
36 changes: 15 additions & 21 deletions test/test-manager/src/tests/install.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use super::config::TEST_CONFIG;
use super::helpers::{
connect_and_wait, get_app_env, get_package_desc, wait_for_tunnel_state, Pinger,
use super::{
config::TEST_CONFIG,
helpers::{connect_and_wait, get_app_env, get_package_desc, wait_for_tunnel_state, Pinger},
Error, TestContext,
};
use super::{Error, TestContext};

use mullvad_management_interface::MullvadProxyClient;
use mullvad_types::{constraints::Constraint, relay_constraints};
use test_macro::test_function;
use test_rpc::meta::Os;
use test_rpc::{mullvad_daemon::ServiceStatus, ServiceClient};
use test_rpc::{meta::Os, mullvad_daemon::ServiceStatus, ServiceClient};

use std::time::Duration;

Expand Down Expand Up @@ -57,12 +56,11 @@ pub async fn test_upgrade_app(ctx: TestContext, rpc: ServiceClient) -> Result<()

// Login to test preservation of device/account
// TODO: Cannot do this now because overriding the API is impossible for releases
//mullvad_client
// mullvad_client
// .login_account(TEST_CONFIG.account_number.clone())
// .await
// .expect("login failed");

//
// Start blocking
//
log::debug!("Entering blocking error state");
Expand Down Expand Up @@ -95,7 +93,6 @@ pub async fn test_upgrade_app(ctx: TestContext, rpc: ServiceClient) -> Result<()
.await
.map_err(|_error| Error::Daemon(String::from("Failed to enter blocking error state")))?;

//
// Begin monitoring outgoing traffic and pinging
//
let pinger = Pinger::start(&rpc).await;
Expand All @@ -113,7 +110,6 @@ pub async fn test_upgrade_app(ctx: TestContext, rpc: ServiceClient) -> Result<()
return Err(Error::DaemonNotRunning);
}

//
// Check if any traffic was observed
//
let guest_ip = pinger.guest_ip;
Expand Down Expand Up @@ -157,17 +153,15 @@ pub async fn test_upgrade_app(ctx: TestContext, rpc: ServiceClient) -> Result<()

// check if account history was preserved
// TODO: Cannot check account history because overriding the API is impossible for releases
/*
let history = mullvad_client
.get_account_history(())
.await
.expect("failed to obtain account history");
assert_eq!(
history.into_inner().token,
Some(TEST_CONFIG.account_number.clone()),
"lost account history"
);
*/
// let history = mullvad_client
// .get_account_history(())
// .await
// .expect("failed to obtain account history");
// assert_eq!(
// history.into_inner().token,
// Some(TEST_CONFIG.account_number.clone()),
// "lost account history"
// );

Ok(())
}
Expand Down
6 changes: 4 additions & 2 deletions test/test-manager/src/tests/relay_ip_overrides.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ use super::{
helpers::{self, AbortOnDrop},
TestContext,
};
use crate::vm;
use crate::vm::network::linux::{NON_TUN_GATEWAY, TEST_SUBNET};
use crate::{
vm,
vm::network::linux::{NON_TUN_GATEWAY, TEST_SUBNET},
};
use anyhow::{anyhow, bail, ensure, Context};
use futures::FutureExt;
use mullvad_management_interface::MullvadProxyClient;
Expand Down
34 changes: 10 additions & 24 deletions test/test-manager/src/tests/settings.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use super::helpers;
use super::helpers::{connect_and_wait, send_guest_probes};
use super::{Error, TestContext};
use crate::assert_tunnel_state;
use crate::vm::network::DUMMY_LAN_INTERFACE_IP;
use super::{
helpers,
helpers::{connect_and_wait, send_guest_probes},
Error, TestContext,
};
use crate::{assert_tunnel_state, vm::network::DUMMY_LAN_INTERFACE_IP};

use mullvad_management_interface::MullvadProxyClient;
use mullvad_types::states::TunnelState;
Expand All @@ -23,13 +24,11 @@ pub async fn test_lan(
) -> Result<(), Error> {
let lan_destination = SocketAddr::new(IpAddr::V4(DUMMY_LAN_INTERFACE_IP), 1234);

//
// Connect
//

connect_and_wait(&mut mullvad_client).await?;

//
// Disable LAN sharing
//

Expand All @@ -40,7 +39,6 @@ pub async fn test_lan(
.await
.expect("failed to disable LAN sharing");

//
// Ensure LAN is not reachable
//

Expand All @@ -54,7 +52,6 @@ pub async fn test_lan(
"observed unexpected outgoing LAN packets: {detected_probes:?}"
);

//
// Enable LAN sharing
//

Expand All @@ -65,7 +62,6 @@ pub async fn test_lan(
.await
.expect("failed to enable LAN sharing");

//
// Ensure LAN is reachable
//

Expand All @@ -83,13 +79,10 @@ pub async fn test_lan(

/// Enable lockdown mode. This test succeeds if:
///
/// * Disconnected state: Outgoing traffic leaks (UDP/TCP/ICMP)
/// cannot be produced.
/// * Disconnected state: Outgoing traffic to a single
/// private IP can be produced, if and only if LAN
/// sharing is enabled.
/// * Connected state: Outgoing traffic leaks (UDP/TCP/ICMP)
/// cannot be produced.
/// * Disconnected state: Outgoing traffic leaks (UDP/TCP/ICMP) cannot be produced.
/// * Disconnected state: Outgoing traffic to a single private IP can be produced, if and only if
/// LAN sharing is enabled.
/// * Connected state: Outgoing traffic leaks (UDP/TCP/ICMP) cannot be produced.
///
/// # Limitations
///
Expand All @@ -116,7 +109,6 @@ pub async fn test_lockdown(
.await
.expect("failed to enable lockdown mode");

//
// Disable LAN sharing
//

Expand All @@ -127,7 +119,6 @@ pub async fn test_lockdown(
.await
.expect("failed to disable LAN sharing");

//
// Ensure all destinations are unreachable
//

Expand All @@ -147,7 +138,6 @@ pub async fn test_lockdown(
"observed outgoing packets to internet: {detected_probes:?}"
);

//
// Enable LAN sharing
//

Expand All @@ -158,7 +148,6 @@ pub async fn test_lockdown(
.await
.expect("failed to enable LAN sharing");

//
// Ensure private IPs are reachable, but not others
//

Expand All @@ -176,13 +165,11 @@ pub async fn test_lockdown(
"observed outgoing packets to internet: {detected_probes:?}"
);

//
// Connect
//

connect_and_wait(&mut mullvad_client).await?;

//
// Leak test
//

Expand All @@ -200,7 +187,6 @@ pub async fn test_lockdown(
"observed outgoing packets to internet: {detected_probes:?}"
);

//
// Disable lockdown mode
//
mullvad_client
Expand Down
Loading

0 comments on commit 3b4eca7

Please sign in to comment.