Skip to content

Commit

Permalink
Re-phrase mullvad api-access test
Browse files Browse the repository at this point in the history
If the API call failed, point out which api-access-method-under-test
which did not work.
  • Loading branch information
MarkusPettersson98 committed Sep 21, 2023
1 parent eb7db04 commit 9a67f1a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
8 changes: 6 additions & 2 deletions mullvad-cli/src/cmds/api_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,15 @@ impl ApiAccess {
async fn test(item: SelectItem) -> Result<()> {
let mut rpc = MullvadProxyClient::new().await?;
let access_method = Self::get_access_method(&mut rpc, &item).await?;
let name = access_method.get_name();
rpc.set_access_method(access_method).await?;
// Make the daemon perform an network request which involves talking to the Mullvad API.
match rpc.get_api_addressess().await {
Ok(_) => println!("API call succeeded!"),
Err(_) => println!("API call failed :-("),
Ok(_) => println!("Connected to the Mullvad API!"),
Err(_) => println!(
"Could *not* connect to the Mullvad API using access method \"{}\"",
name
),
}

Ok(())
Expand Down
18 changes: 18 additions & 0 deletions mullvad-types/src/access_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,24 @@ pub enum AccessMethod {
Custom(CustomAccessMethod),
}

impl AccessMethod {
pub fn get_name(&self) -> String {
match self {
AccessMethod::BuiltIn(x) => match x {
BuiltInAccessMethod::Direct(_) => "Direct".to_string(),
BuiltInAccessMethod::Bridge(_) => "Mullvad Bridges".to_string(),
},
AccessMethod::Custom(c) => match &c.access_method {
ObfuscationProtocol::Shadowsocks(s) => s.name.clone(),
ObfuscationProtocol::Socks5(s) => match s {
Socks5::Local(l) => l.name.clone(),
Socks5::Remote(r) => r.name.clone(),
},
},
}
}
}

/// Built-In access method datastructure.
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub enum BuiltInAccessMethod {
Expand Down

0 comments on commit 9a67f1a

Please sign in to comment.