diff options
| author | David Lönnhager <david.l@mullvad.net> | 2022-09-21 10:38:00 +0200 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2022-11-29 19:06:36 +0100 |
| commit | 9fffb1e6636508dcb0878970349aa2eb699c2212 (patch) | |
| tree | ddac342bac92af1c07b9ddae23241c45e9dd850b | |
| parent | 8d102a013ecafca58ebfd60fae1f117e455681a3 (diff) | |
| download | mullvadvpn-9fffb1e6636508dcb0878970349aa2eb699c2212.tar.xz mullvadvpn-9fffb1e6636508dcb0878970349aa2eb699c2212.zip | |
Parse new AuthFailed error correctly in the CLI
| -rw-r--r-- | mullvad-cli/src/format.rs | 22 | ||||
| -rw-r--r-- | mullvad-types/src/auth_failed.rs | 19 |
2 files changed, 21 insertions, 20 deletions
diff --git a/mullvad-cli/src/format.rs b/mullvad-cli/src/format.rs index 693f5c9c7e..b4aa96a719 100644 --- a/mullvad-cli/src/format.rs +++ b/mullvad-cli/src/format.rs @@ -1,4 +1,4 @@ -use mullvad_types::{location::GeoIpLocation, states::TunnelState}; +use mullvad_types::{auth_failed::AuthFailed, location::GeoIpLocation, states::TunnelState}; use talpid_types::{ net::{Endpoint, TunnelEndpoint}, tunnel::ErrorState, @@ -166,6 +166,26 @@ fn print_error_state(error_state: &ErrorState) { println!("Blocked: {}", cause); println!("Your kernel might be terribly out of date or missing nftables"); } + talpid_types::tunnel::ErrorStateCause::AuthFailed(Some(auth_failed)) => { + println!( + "Blocked: Authentication with remote server failed: {}", + get_auth_failed_message(AuthFailed::from(auth_failed.as_str())) + ); + } cause => println!("Blocked: {}", cause), } } + +const fn get_auth_failed_message(auth_failed: AuthFailed) -> &'static str { + const INVALID_ACCOUNT_MSG: &str = "You've logged in with an account number that is not valid. Please log out and try another one."; + const EXPIRED_ACCOUNT_MSG: &str = "You have no more VPN time left on this account. Please log in on our website to buy more credit."; + const TOO_MANY_CONNECTIONS_MSG: &str = "This account has too many simultaneous connections. Disconnect another device or try connecting again shortly."; + const UNKNOWN_MSG: &str = "Unknown error."; + + match auth_failed { + AuthFailed::InvalidAccount => INVALID_ACCOUNT_MSG, + AuthFailed::ExpiredAccount => EXPIRED_ACCOUNT_MSG, + AuthFailed::TooManyConnections => TOO_MANY_CONNECTIONS_MSG, + AuthFailed::Unknown => UNKNOWN_MSG, + } +} diff --git a/mullvad-types/src/auth_failed.rs b/mullvad-types/src/auth_failed.rs index d36c531441..43b991da72 100644 --- a/mullvad-types/src/auth_failed.rs +++ b/mullvad-types/src/auth_failed.rs @@ -1,6 +1,5 @@ use lazy_static::lazy_static; use regex::Regex; -use std::fmt; use talpid_types::tunnel::ErrorStateCause; /// Used to parse [`talpid_types::tunnel::ErrorStateCause::AuthFailed`], which may be returned @@ -14,12 +13,6 @@ pub enum AuthFailed { Unknown, } -// These strings should match up with gui/packages/desktop/src/renderer/lib/auth-failure.js -const INVALID_ACCOUNT_MSG: &str = "You've logged in with an account number that is not valid. Please log out and try another one."; -const EXPIRED_ACCOUNT_MSG: &str = "You have no more VPN time left on this account. Please log in on our website to buy more credit."; -const TOO_MANY_CONNECTIONS_MSG: &str = "This account has too many simultaneous connections. Disconnect another device or try connecting again shortly."; -const UNKNOWN_MSG: &str = "Unknown error."; - impl<'a> From<&'a str> for AuthFailed { fn from(reason: &'a str) -> AuthFailed { use AuthFailed::*; @@ -57,18 +50,6 @@ impl TryFrom<&ErrorStateCause> for AuthFailed { } } -impl fmt::Display for AuthFailed { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - use AuthFailed::*; - match self { - InvalidAccount => f.write_str(INVALID_ACCOUNT_MSG), - ExpiredAccount => f.write_str(EXPIRED_ACCOUNT_MSG), - TooManyConnections => f.write_str(TOO_MANY_CONNECTIONS_MSG), - Unknown => f.write_str(UNKNOWN_MSG), - } - } -} - // Expects to take a string like "[INVALID_ACCOUNT] This is not a valid Mullvad account". // The example input string would be split into: // * "INVALID_ACCOUNT" - the ID of the failure reason. |
