From eeff5bbbb1de478a2391406e936c24c47dabc76d 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 | 32 ++++++++++++++++++++++++++ test/test-manager/src/tests/mod.rs | 1 + 2 files changed, 33 insertions(+) diff --git a/test/test-manager/src/tests/helpers.rs b/test/test-manager/src/tests/helpers.rs index 3aca4254f92a..15328d325833 100644 --- a/test/test-manager/src/tests/helpers.rs +++ b/test/test-manager/src/tests/helpers.rs @@ -1201,12 +1201,16 @@ fn parse_am_i_mullvad(result: String) -> anyhow::Result { pub mod custom_lists { use super::*; + 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. @@ -1310,6 +1314,34 @@ pub mod custom_lists { Ok(()) } + /// Set the default location to the custom list specified by `DEFAULT_LIST`. This also includes + /// entry location for multihop. It does not, however, affect bridge location for OpenVPN. + /// This is for simplify, as bridges default to using the server closest to the exit anyway, and + /// OpenVPN is slated for removal. + pub async fn set_default_location( + mullvad_client: &mut MullvadProxyClient, + ) -> anyhow::Result<()> { + let constraints = dbg!(get_custom_list_location_relay_constraints(DEFAULT_LIST)); + + mullvad_client + .set_relay_settings(constraints.into()) + .await + .context("Failed to set relay settings") + } + + fn get_custom_list_location_relay_constraints(custom_list: List) -> RelayConstraints { + let wireguard_constraints = mullvad_types::relay_constraints::WireguardConstraints { + entry_location: Constraint::Only(custom_list.into()), + ..Default::default() + }; + + RelayConstraints { + location: Constraint::Only(custom_list.into()), + wireguard_constraints, + ..Default::default() + } + } + /// 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 0c595320f3a7..a7b3778907bb 100644 --- a/test/test-manager/src/tests/mod.rs +++ b/test/test-manager/src/tests/mod.rs @@ -124,6 +124,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(()) }