Skip to content

Commit 15b5cb5

Browse files
committed
Merge branch 'testing-simplify-settings-reset'
2 parents 7d2663a + f41d0cb commit 15b5cb5

File tree

3 files changed

+9
-76
lines changed

3 files changed

+9
-76
lines changed

test/test-manager/src/run_tests.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use crate::{
88
};
99
use anyhow::{Context, Result};
1010
use futures::FutureExt;
11-
use mullvad_management_interface::MullvadProxyClient;
1211
use std::future::Future;
1312
use std::panic;
1413
use std::time::Duration;
@@ -84,15 +83,11 @@ pub async fn run(
8483
let logger = super::logging::Logger::get_or_init();
8584

8685
for test in tests {
87-
let mut mclient = test_context
86+
let mclient = test_context
8887
.rpc_provider
8988
.as_type(test.mullvad_client_version)
9089
.await;
9190

92-
if let Some(client) = mclient.downcast_mut::<MullvadProxyClient>() {
93-
crate::tests::init_default_settings(client).await;
94-
}
95-
9691
log::info!("Running {}", test.name);
9792

9893
if print_failed_tests_only {

test/test-manager/src/tests/helpers.rs

+1-45
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ use mullvad_management_interface::{client::DaemonEvent, MullvadProxyClient};
77
use mullvad_types::{
88
location::Location,
99
relay_constraints::{
10-
BridgeSettings, BridgeState, Constraint, GeographicLocationConstraint, LocationConstraint,
11-
ObfuscationSettings, OpenVpnConstraints, RelayConstraints, RelaySettings,
12-
WireguardConstraints,
10+
BridgeSettings, Constraint, GeographicLocationConstraint, LocationConstraint, RelaySettings,
1311
},
1412
relay_list::{Relay, RelayList},
1513
states::TunnelState,
@@ -335,48 +333,6 @@ impl<T> Drop for AbortOnDrop<T> {
335333
}
336334
}
337335

338-
/// Disconnect and reset all relay, bridge, and obfuscation settings.
339-
///
340-
/// See [`mullvad_types::relay_constraints::RelayConstraints`] for details, but in short:
341-
/// * Location constraint is [`Constraint::Any`]
342-
/// * Provider constraint is [`Constraint::Any`]
343-
/// * Ownership constraint is [`Constraint::Any`]
344-
/// * The default tunnel protocol is [`talpid_types::net::TunnelType::Wireguard`]
345-
/// * Wireguard settings are default (i.e. any port is used, no obfuscation ..)
346-
/// see [`mullvad_types::relay_constraints::WireguardConstraints`] for details.
347-
/// * OpenVPN settings are default (i.e. any port is used, no obfuscation ..)
348-
/// see [`mullvad_types::relay_constraints::OpenVpnConstraints`] for details.
349-
pub async fn reset_relay_settings(mullvad_client: &mut MullvadProxyClient) -> Result<(), Error> {
350-
disconnect_and_wait(mullvad_client).await?;
351-
352-
let relay_settings = RelaySettings::Normal(RelayConstraints {
353-
location: Constraint::Any,
354-
tunnel_protocol: Constraint::Any,
355-
openvpn_constraints: OpenVpnConstraints::default(),
356-
wireguard_constraints: WireguardConstraints::default(),
357-
providers: Constraint::Any,
358-
ownership: Constraint::Any,
359-
});
360-
let bridge_state = BridgeState::Auto;
361-
let obfuscation_settings = ObfuscationSettings::default();
362-
363-
set_relay_settings(mullvad_client, relay_settings)
364-
.await
365-
.map_err(|error| Error::Daemon(format!("Failed to reset relay settings: {}", error)))?;
366-
367-
mullvad_client
368-
.set_bridge_state(bridge_state)
369-
.await
370-
.map_err(|error| Error::Daemon(format!("Failed to reset bridge mode: {}", error)))?;
371-
372-
mullvad_client
373-
.set_obfuscation_settings(obfuscation_settings)
374-
.await
375-
.map_err(|error| Error::Daemon(format!("Failed to reset obfuscation: {}", error)))?;
376-
377-
Ok(())
378-
}
379-
380336
pub async fn set_relay_settings(
381337
mullvad_client: &mut MullvadProxyClient,
382338
relay_settings: RelaySettings,

test/test-manager/src/tests/mod.rs

+7-25
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@ mod ui;
1212

1313
use crate::mullvad_daemon::RpcClientProvider;
1414
use anyhow::Context;
15-
use helpers::reset_relay_settings;
1615
pub use test_metadata::TestMetadata;
1716
use test_rpc::ServiceClient;
1817

1918
use futures::future::BoxFuture;
2019

2120
use mullvad_management_interface::MullvadProxyClient;
22-
use once_cell::sync::OnceCell;
2321
use std::time::Duration;
2422

2523
const PING_TIMEOUT: Duration = Duration::from_secs(3);
@@ -69,34 +67,18 @@ pub enum Error {
6967
Other(String),
7068
}
7169

72-
static DEFAULT_SETTINGS: OnceCell<mullvad_types::settings::Settings> = OnceCell::new();
73-
74-
/// Initializes `DEFAULT_SETTINGS`. This has only has an effect the first time it's called.
75-
pub async fn init_default_settings(mullvad_client: &mut MullvadProxyClient) {
76-
if DEFAULT_SETTINGS.get().is_none() {
77-
let settings = mullvad_client
78-
.get_settings()
79-
.await
80-
.expect("Failed to obtain settings");
81-
DEFAULT_SETTINGS.set(settings).unwrap();
82-
}
83-
}
84-
85-
/// Restore settings to `DEFAULT_SETTINGS`.
86-
///
87-
/// # Panics
88-
///
89-
/// `DEFAULT_SETTINGS` must be initialized using `init_default_settings` before any settings are
90-
/// modified, or this function panics.
70+
/// Restore settings to the defaults.
9171
pub async fn cleanup_after_test(mullvad_client: &mut MullvadProxyClient) -> anyhow::Result<()> {
9272
log::debug!("Cleaning up daemon in test cleanup");
9373

94-
let default_settings = DEFAULT_SETTINGS
95-
.get()
96-
.expect("default settings were not initialized");
74+
helpers::disconnect_and_wait(mullvad_client).await?;
9775

98-
reset_relay_settings(mullvad_client).await?;
76+
let default_settings = mullvad_types::settings::Settings::default();
9977

78+
mullvad_client
79+
.set_relay_settings(default_settings.relay_settings)
80+
.await
81+
.context("Could not set relay settings")?;
10082
mullvad_client
10183
.set_auto_connect(default_settings.auto_connect)
10284
.await

0 commit comments

Comments
 (0)