chore(FLOW-2123): Fix tests
Signed-off-by: Cléo REBERT <cleo.rebert-ext@treezor.com>
This commit is contained in:
parent
d5b94dc0df
commit
cc1474a7d8
|
@ -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");
|
||||
}
|
||||
}
|
16
src/lib.rs
16
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()));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue