From cc1474a7d8c51a04756a43c1a8e8984859cb76e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9o=20REBERT?= Date: Fri, 6 Jan 2023 11:30:24 +0100 Subject: [PATCH] chore(FLOW-2123): Fix tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cléo REBERT --- src/custom_providers.rs | 17 +++++++++++++++-- src/lib.rs | 16 ++++++++++++---- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/custom_providers.rs b/src/custom_providers.rs index 8f9487b..780699d 100644 --- a/src/custom_providers.rs +++ b/src/custom_providers.rs @@ -11,8 +11,8 @@ impl TOTP { /// /// ```rust /// use totp_rs::{Secret, TOTP}; - /// let secret = Secret::Encoded("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567".to_string()); - /// let totp = TOTP::new_steam(secret.to_bytes().unwrap(), Some("username".to_string())); + /// let secret = Secret::Encoded("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567".into()); + /// let totp = TOTP::new_steam(secret.to_bytes().unwrap(), "username".into()); /// ``` pub fn new_steam(secret: Vec, account_name: String) -> TOTP { Self::new_unchecked( @@ -41,3 +41,16 @@ impl TOTP { Self::new_unchecked(Algorithm::Steam, 5, 1, 30, secret) } } + +#[cfg(all(test, feature = "steam"))] +mod test { + use super::*; + + #[test] + #[cfg(feature = "otpauth")] + fn get_url_steam() { + let totp = TOTP::new_steam("TestSecretSuperSecret".into(), "constantoine".into()); + let url = totp.get_url(); + assert_eq!(url.as_str(), "otpauth://steam/Steam:constantoine?issuer=Steam&secret=KRSXG5CTMVRXEZLUKN2XAZLSKNSWG4TFOQ&digits=5&algorithm=SHA1"); + } +} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 3b08937..d770291 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -518,7 +518,6 @@ impl TOTP { #[cfg(feature = "steam")] Some(Host::Domain("steam")) => { algorithm = Algorithm::Steam; - digits = 5; } _ => { return Err(TotpUrlError::Host(url.host().unwrap().to_string())); @@ -580,9 +579,7 @@ impl TOTP { issuer = Some(value.into()); } "issuer" => { - let param_issuer = value - .parse::() - .map_err(|_| TotpUrlError::Issuer(value.to_string()))?; + let param_issuer: String = value.into(); if issuer.is_some() && param_issuer.as_str() != issuer.as_ref().unwrap() { return Err(TotpUrlError::IssuerMistmatch( issuer.as_ref().unwrap().to_string(), @@ -590,11 +587,22 @@ impl TOTP { )); } issuer = Some(param_issuer); + #[cfg(feature = "steam")] + if issuer == Some("Steam".into()) { + algorithm = Algorithm::Steam; + } } _ => {} } } + #[cfg(feature = "steam")] + if algorithm == Algorithm::Steam { + digits = 5; + step = 30; + issuer = Some("Steam".into()); + } + if secret.is_empty() { return Err(TotpUrlError::Secret("".to_string())); }