chore(FLOW-2123): Fix tests

Signed-off-by: Cléo REBERT <cleo.rebert-ext@treezor.com>
This commit is contained in:
Cléo REBERT 2023-01-06 11:30:24 +01:00
parent d5b94dc0df
commit cc1474a7d8
No known key found for this signature in database
GPG Key ID: 0FA097951CF65367
2 changed files with 27 additions and 6 deletions

View File

@ -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");
}
}

View File

@ -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()));
}