summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2024-02-06 15:31:47 +0100
committerDavid Lönnhager <david.l@mullvad.net>2024-02-06 17:46:26 +0100
commitf41d0cb28be4bb1f9e4235986796ec69f97d4729 (patch)
tree34bc2aa6db0ba94d1bd3923684fd50917f875468 /test
parent7d2663a2d9b83402591aa9063471846b500aca91 (diff)
downloadmullvadvpn-f41d0cb28be4bb1f9e4235986796ec69f97d4729.tar.xz
mullvadvpn-f41d0cb28be4bb1f9e4235986796ec69f97d4729.zip
Simplify how settings are reset in tests
Diffstat (limited to 'test')
-rw-r--r--test/test-manager/src/run_tests.rs7
-rw-r--r--test/test-manager/src/tests/helpers.rs46
-rw-r--r--test/test-manager/src/tests/mod.rs32
3 files changed, 9 insertions, 76 deletions
diff --git a/test/test-manager/src/run_tests.rs b/test/test-manager/src/run_tests.rs
index 7b636643ff..6af1536562 100644
--- a/test/test-manager/src/run_tests.rs
+++ b/test/test-manager/src/run_tests.rs
@@ -8,7 +8,6 @@ use crate::{
};
use anyhow::{Context, Result};
use futures::FutureExt;
-use mullvad_management_interface::MullvadProxyClient;
use std::future::Future;
use std::panic;
use std::time::Duration;
@@ -84,15 +83,11 @@ pub async fn run(
let logger = super::logging::Logger::get_or_init();
for test in tests {
- let mut mclient = test_context
+ let mclient = test_context
.rpc_provider
.as_type(test.mullvad_client_version)
.await;
- if let Some(client) = mclient.downcast_mut::<MullvadProxyClient>() {
- crate::tests::init_default_settings(client).await;
- }
-
log::info!("Running {}", test.name);
if print_failed_tests_only {
diff --git a/test/test-manager/src/tests/helpers.rs b/test/test-manager/src/tests/helpers.rs
index 9f092f60f2..32e7c33b7a 100644
--- a/test/test-manager/src/tests/helpers.rs
+++ b/test/test-manager/src/tests/helpers.rs
@@ -7,9 +7,7 @@ use mullvad_management_interface::{client::DaemonEvent, MullvadProxyClient};
use mullvad_types::{
location::Location,
relay_constraints::{
- BridgeSettings, BridgeState, Constraint, GeographicLocationConstraint, LocationConstraint,
- ObfuscationSettings, OpenVpnConstraints, RelayConstraints, RelaySettings,
- WireguardConstraints,
+ BridgeSettings, Constraint, GeographicLocationConstraint, LocationConstraint, RelaySettings,
},
relay_list::{Relay, RelayList},
states::TunnelState,
@@ -335,48 +333,6 @@ impl<T> Drop for AbortOnDrop<T> {
}
}
-/// Disconnect and reset all relay, bridge, and obfuscation settings.
-///
-/// See [`mullvad_types::relay_constraints::RelayConstraints`] for details, but in short:
-/// * Location constraint is [`Constraint::Any`]
-/// * Provider constraint is [`Constraint::Any`]
-/// * Ownership constraint is [`Constraint::Any`]
-/// * The default tunnel protocol is [`talpid_types::net::TunnelType::Wireguard`]
-/// * Wireguard settings are default (i.e. any port is used, no obfuscation ..)
-/// see [`mullvad_types::relay_constraints::WireguardConstraints`] for details.
-/// * OpenVPN settings are default (i.e. any port is used, no obfuscation ..)
-/// see [`mullvad_types::relay_constraints::OpenVpnConstraints`] for details.
-pub async fn reset_relay_settings(mullvad_client: &mut MullvadProxyClient) -> Result<(), Error> {
- disconnect_and_wait(mullvad_client).await?;
-
- let relay_settings = RelaySettings::Normal(RelayConstraints {
- location: Constraint::Any,
- tunnel_protocol: Constraint::Any,
- openvpn_constraints: OpenVpnConstraints::default(),
- wireguard_constraints: WireguardConstraints::default(),
- providers: Constraint::Any,
- ownership: Constraint::Any,
- });
- let bridge_state = BridgeState::Auto;
- let obfuscation_settings = ObfuscationSettings::default();
-
- set_relay_settings(mullvad_client, relay_settings)
- .await
- .map_err(|error| Error::Daemon(format!("Failed to reset relay settings: {}", error)))?;
-
- mullvad_client
- .set_bridge_state(bridge_state)
- .await
- .map_err(|error| Error::Daemon(format!("Failed to reset bridge mode: {}", error)))?;
-
- mullvad_client
- .set_obfuscation_settings(obfuscation_settings)
- .await
- .map_err(|error| Error::Daemon(format!("Failed to reset obfuscation: {}", error)))?;
-
- Ok(())
-}
-
pub async fn set_relay_settings(
mullvad_client: &mut MullvadProxyClient,
relay_settings: RelaySettings,
diff --git a/test/test-manager/src/tests/mod.rs b/test/test-manager/src/tests/mod.rs
index c79c0318e0..d1a0ab216d 100644
--- a/test/test-manager/src/tests/mod.rs
+++ b/test/test-manager/src/tests/mod.rs
@@ -12,14 +12,12 @@ mod ui;
use crate::mullvad_daemon::RpcClientProvider;
use anyhow::Context;
-use helpers::reset_relay_settings;
pub use test_metadata::TestMetadata;
use test_rpc::ServiceClient;
use futures::future::BoxFuture;
use mullvad_management_interface::MullvadProxyClient;
-use once_cell::sync::OnceCell;
use std::time::Duration;
const PING_TIMEOUT: Duration = Duration::from_secs(3);
@@ -69,35 +67,19 @@ pub enum Error {
Other(String),
}
-static DEFAULT_SETTINGS: OnceCell<mullvad_types::settings::Settings> = OnceCell::new();
-
-/// Initializes `DEFAULT_SETTINGS`. This has only has an effect the first time it's called.
-pub async fn init_default_settings(mullvad_client: &mut MullvadProxyClient) {
- if DEFAULT_SETTINGS.get().is_none() {
- let settings = mullvad_client
- .get_settings()
- .await
- .expect("Failed to obtain settings");
- DEFAULT_SETTINGS.set(settings).unwrap();
- }
-}
-
-/// Restore settings to `DEFAULT_SETTINGS`.
-///
-/// # Panics
-///
-/// `DEFAULT_SETTINGS` must be initialized using `init_default_settings` before any settings are
-/// modified, or this function panics.
+/// Restore settings to the defaults.
pub async fn cleanup_after_test(mullvad_client: &mut MullvadProxyClient) -> anyhow::Result<()> {
log::debug!("Cleaning up daemon in test cleanup");
- let default_settings = DEFAULT_SETTINGS
- .get()
- .expect("default settings were not initialized");
+ helpers::disconnect_and_wait(mullvad_client).await?;
- reset_relay_settings(mullvad_client).await?;
+ let default_settings = mullvad_types::settings::Settings::default();
mullvad_client
+ .set_relay_settings(default_settings.relay_settings)
+ .await
+ .context("Could not set relay settings")?;
+ mullvad_client
.set_auto_connect(default_settings.auto_connect)
.await
.context("Could not set auto connect in cleanup")?;