trade: misc confirmation fixes and tests (#246)
This commit is contained in:
parent
0d24d12c55
commit
6af4374da3
2 changed files with 26 additions and 2 deletions
|
@ -92,7 +92,7 @@ impl<'a> Confirmer<'a> {
|
||||||
let mut deser = serde_json::Deserializer::from_str(text.as_str());
|
let mut deser = serde_json::Deserializer::from_str(text.as_str());
|
||||||
let body: ConfirmationListResponse = serde_path_to_error::deserialize(&mut deser)?;
|
let body: ConfirmationListResponse = serde_path_to_error::deserialize(&mut deser)?;
|
||||||
|
|
||||||
if body.needsauth.unwrap_or(false) {
|
if body.needauth.unwrap_or(false) {
|
||||||
return Err(ConfirmerError::InvalidTokens);
|
return Err(ConfirmerError::InvalidTokens);
|
||||||
}
|
}
|
||||||
if !body.success {
|
if !body.success {
|
||||||
|
@ -276,6 +276,7 @@ impl From<u32> for ConfirmationType {
|
||||||
1 => ConfirmationType::Generic,
|
1 => ConfirmationType::Generic,
|
||||||
2 => ConfirmationType::Trade,
|
2 => ConfirmationType::Trade,
|
||||||
3 => ConfirmationType::MarketSell,
|
3 => ConfirmationType::MarketSell,
|
||||||
|
5 => ConfirmationType::AccountDetails,
|
||||||
6 => ConfirmationType::AccountRecovery,
|
6 => ConfirmationType::AccountRecovery,
|
||||||
v => ConfirmationType::Unknown(v),
|
v => ConfirmationType::Unknown(v),
|
||||||
}
|
}
|
||||||
|
@ -286,7 +287,8 @@ impl From<u32> for ConfirmationType {
|
||||||
pub struct ConfirmationListResponse {
|
pub struct ConfirmationListResponse {
|
||||||
pub success: bool,
|
pub success: bool,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub needsauth: Option<bool>,
|
pub needauth: Option<bool>,
|
||||||
|
#[serde(default)]
|
||||||
pub conf: Vec<Confirmation>,
|
pub conf: Vec<Confirmation>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -347,6 +349,24 @@ mod tests {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_parse_confirmations_2() -> anyhow::Result<()> {
|
||||||
|
struct Test {
|
||||||
|
text: &'static str,
|
||||||
|
}
|
||||||
|
let cases = [Test {
|
||||||
|
text: include_str!("fixtures/confirmations/need-auth.json"),
|
||||||
|
}];
|
||||||
|
for case in cases.iter() {
|
||||||
|
let confirmations = serde_json::from_str::<ConfirmationListResponse>(case.text)?;
|
||||||
|
|
||||||
|
assert_eq!(confirmations.conf.len(), 0);
|
||||||
|
assert_eq!(confirmations.needauth, Some(true));
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_generate_confirmation_hash_for_time() {
|
fn test_generate_confirmation_hash_for_time() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
4
steamguard/src/fixtures/confirmations/need-auth.json
Normal file
4
steamguard/src/fixtures/confirmations/need-auth.json
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"success": false,
|
||||||
|
"needauth": true
|
||||||
|
}
|
Loading…
Reference in a new issue