From 096994a36af6d5c593220b0b8645848d8ba305d9 Mon Sep 17 00:00:00 2001 From: Sebastian Holmin Date: Fri, 15 Nov 2024 09:57:23 +0100 Subject: [PATCH] Set the default location for tests to "Nordic" Add to `prepare_daemon` a step where the default location, including for multihop and bridges, is set to the `Nordic` custom list. --- test/test-manager/src/tests/helpers.rs | 30 ++++++++++++++++++++++++++ test/test-manager/src/tests/mod.rs | 1 + 2 files changed, 31 insertions(+) diff --git a/test/test-manager/src/tests/helpers.rs b/test/test-manager/src/tests/helpers.rs index 84945aef795c..28a2fac84b89 100644 --- a/test/test-manager/src/tests/helpers.rs +++ b/test/test-manager/src/tests/helpers.rs @@ -1199,12 +1199,16 @@ fn parse_am_i_mullvad(result: String) -> anyhow::Result { pub mod custom_lists { use super::*; + use mullvad_relay_selector::query::builder::RelayQueryBuilder; use mullvad_types::custom_list::{CustomList, Id}; use std::sync::{LazyLock, Mutex}; // Expose all custom list variants as a shorthand. pub use List::*; + /// The default custom list to use as location for all tests. + pub const DEFAULT_LIST: List = List::Nordic; + /// Mapping between [List] to daemon custom lists. Since custom list ids are assigned by the /// daemon at the creation of the custom list settings object, we can't map a custom list /// name to a specific list before runtime. @@ -1308,6 +1312,32 @@ pub mod custom_lists { Ok(()) } + /// Set the default location to the custom list specified by `DEFAULT_LIST`. This includes entry + /// location for multihop and bridge location for OpenVPN. + pub async fn set_default_location( + mullvad_client: &mut MullvadProxyClient, + ) -> anyhow::Result<()> { + let mut query = RelayQueryBuilder::new() + .location(DEFAULT_LIST) + .wireguard() + .multihop() + .entry(DEFAULT_LIST) + .build(); + + // The typestate query builder cannot express openVPN bridge locations while specifying + // wireguard options, like multihop. So we need to create a new query for openVPN, and + // insert the OpenVPN constraints into the existing query. + let openvpn_constraints = RelayQueryBuilder::new() + .openvpn() + .bridge() + .bridge_location(DEFAULT_LIST) + .build() + .into_openvpn_constraints(); + query.set_openvpn_constraints(openvpn_constraints)?; + + apply_settings_from_relay_query(mullvad_client, query).await?; + Ok(()) + } /// Dig out a custom list from the daemon settings based on the custom list's name. /// There should be an rpc for this. async fn find_custom_list( diff --git a/test/test-manager/src/tests/mod.rs b/test/test-manager/src/tests/mod.rs index ca24cd63bf85..104b3cc6791e 100644 --- a/test/test-manager/src/tests/mod.rs +++ b/test/test-manager/src/tests/mod.rs @@ -122,6 +122,7 @@ pub async fn prepare_daemon( .context("Failed to disconnect daemon after test")?; helpers::ensure_logged_in(&mut mullvad_client).await?; helpers::custom_lists::add_default_lists(&mut mullvad_client).await?; + helpers::custom_lists::set_default_location(&mut mullvad_client).await?; Ok(()) }