1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
mod access_methods;
mod account;
pub mod config;
mod dns;
mod helpers;
mod install;
mod settings;
mod software;
mod test_metadata;
mod tunnel;
mod tunnel_state;
mod ui;
use crate::mullvad_daemon::RpcClientProvider;
use anyhow::Context;
pub use test_metadata::TestMetadata;
use test_rpc::ServiceClient;
use futures::future::BoxFuture;
use mullvad_management_interface::MullvadProxyClient;
use std::time::Duration;
const PING_TIMEOUT: Duration = Duration::from_secs(3);
const WAIT_FOR_TUNNEL_STATE_TIMEOUT: Duration = Duration::from_secs(40);
#[derive(Clone)]
pub struct TestContext {
pub rpc_provider: RpcClientProvider,
}
pub type TestWrapperFunction = Box<
dyn Fn(
TestContext,
ServiceClient,
Box<dyn std::any::Any + Send>,
) -> BoxFuture<'static, Result<(), Error>>,
>;
#[derive(err_derive::Error, Debug)]
pub enum Error {
#[error(display = "RPC call failed")]
Rpc(#[source] test_rpc::Error),
#[error(display = "Timeout waiting for ping")]
PingTimeout,
#[error(display = "geoip lookup failed")]
GeoipLookup(test_rpc::Error),
#[error(display = "Found running daemon unexpectedly")]
DaemonRunning,
#[error(display = "Daemon unexpectedly not running")]
DaemonNotRunning,
#[error(display = "The daemon returned an error: {}", _0)]
Daemon(String),
#[error(display = "The daemon ended up in the error state")]
UnexpectedErrorState(talpid_types::tunnel::ErrorState),
#[error(display = "The gRPC client ran into an error: {}", _0)]
ManagementInterface(#[source] mullvad_management_interface::Error),
#[cfg(target_os = "macos")]
#[error(display = "An error occurred: {}", _0)]
Other(String),
}
/// 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");
helpers::disconnect_and_wait(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")?;
mullvad_client
.set_allow_lan(default_settings.allow_lan)
.await
.context("Could not set allow lan in cleanup")?;
mullvad_client
.set_show_beta_releases(default_settings.show_beta_releases)
.await
.context("Could not set show beta releases in cleanup")?;
mullvad_client
.set_bridge_state(default_settings.bridge_state)
.await
.context("Could not set bridge state in cleanup")?;
mullvad_client
.set_bridge_settings(default_settings.bridge_settings.clone())
.await
.context("Could not set bridge settings in cleanup")?;
mullvad_client
.set_obfuscation_settings(default_settings.obfuscation_settings.clone())
.await
.context("Could set obfuscation settings in cleanup")?;
mullvad_client
.set_block_when_disconnected(default_settings.block_when_disconnected)
.await
.context("Could not set block when disconnected setting in cleanup")?;
#[cfg(target_os = "windows")]
mullvad_client
.clear_split_tunnel_apps()
.await
.context("Could not clear split tunnel apps in cleanup")?;
#[cfg(target_os = "linux")]
mullvad_client
.clear_split_tunnel_processes()
.await
.context("Could not clear split tunnel processes in cleanup")?;
mullvad_client
.set_dns_options(default_settings.tunnel_options.dns_options.clone())
.await
.context("Could not clear dns options in cleanup")?;
mullvad_client
.set_quantum_resistant_tunnel(default_settings.tunnel_options.wireguard.quantum_resistant)
.await
.context("Could not clear PQ options in cleanup")?;
Ok(())
}
|