chore(FLOW-2123): Fix tests Signed-off-by: Cléo REBERT <cleo.rebert-ext@treezor.com>
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
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<u8>, 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::<String>()
- .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()));
}