summaryrefslogtreecommitdiffhomepage
path: root/mullvad-cli
diff options
context:
space:
mode:
authorMarkus Pettersson <markus.pettersson@mullvad.net>2023-09-20 13:41:43 +0200
committerDavid Lönnhager <david.l@mullvad.net>2023-10-09 14:40:06 +0200
commit7fcaad31643ca324c5dd4a17ddf0f445ac679384 (patch)
tree9a913059321b437857863efed43b4d47ed9c0eb4 /mullvad-cli
parentfc477f4e4df6db2973ff88fc4b6819d38d64d8cc (diff)
downloadmullvadvpn-7fcaad31643ca324c5dd4a17ddf0f445ac679384.tar.xz
mullvadvpn-7fcaad31643ca324c5dd4a17ddf0f445ac679384.zip
Add `mullvad proxy test`
For quickly assessing whether an api access method can reach the API or not.
Diffstat (limited to 'mullvad-cli')
-rw-r--r--mullvad-cli/src/cmds/proxy.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/mullvad-cli/src/cmds/proxy.rs b/mullvad-cli/src/cmds/proxy.rs
index c876a25d2e..fa05081f89 100644
--- a/mullvad-cli/src/cmds/proxy.rs
+++ b/mullvad-cli/src/cmds/proxy.rs
@@ -24,6 +24,8 @@ pub enum Proxy {
Enable(SelectItem),
/// Disable an API proxy
Disable(SelectItem),
+ /// Test an API proxy
+ Test(SelectItem),
/// Force the use of a specific API proxy.
Use(SelectItem),
}
@@ -59,6 +61,10 @@ impl Proxy {
let enabled = false;
Self::toggle(index, enabled).await?;
}
+ Proxy::Test(cmd) => {
+ let index = Self::zero_to_one_based_index(cmd.index)?;
+ Self::test(index).await?;
+ }
Proxy::Use(cmd) => {
let index = Self::zero_to_one_based_index(cmd.index)?;
Self::set(index).await?;
@@ -199,6 +205,34 @@ impl Proxy {
Ok(())
}
+ /// Test an access method to see if it successfully reaches the Mullvad API.
+ async fn test(index: usize) -> Result<()> {
+ let mut rpc = MullvadProxyClient::new().await?;
+ // TODO: Refactor this into some helper function. This code has been copy-pastead a lot already ..
+ // Step 1.
+ let access_method = rpc
+ .get_api_access_methods()
+ .await?
+ .get(index)
+ .ok_or(anyhow!(format!(
+ "Access method {} does not exist",
+ index + 1
+ )))?
+ .clone();
+
+ // Step 2.
+ rpc.set_access_method(access_method).await?;
+ // Step 3.
+ let api_call = rpc.test_api().await;
+ // Step 4.
+ match api_call {
+ Ok(_) => println!("API call succeeded!"),
+ Err(_) => println!("API call failed :-("),
+ }
+
+ Ok(())
+ }
+
/// Force the use of a specific access method when trying to reach the
/// Mullvad API. If this method fails, the daemon will resume the automatic
/// roll-over behavior (which is the default).