From 6af4374da3cc19c65ec6c8222a969f538967ed1c Mon Sep 17 00:00:00 2001 From: Carson McManus Date: Tue, 27 Jun 2023 15:13:26 -0400 Subject: [PATCH] trade: misc confirmation fixes and tests (#246) --- steamguard/src/confirmation.rs | 24 +++++++++++++++++-- .../src/fixtures/confirmations/need-auth.json | 4 ++++ 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 steamguard/src/fixtures/confirmations/need-auth.json diff --git a/steamguard/src/confirmation.rs b/steamguard/src/confirmation.rs index faf3f71..69d448b 100644 --- a/steamguard/src/confirmation.rs +++ b/steamguard/src/confirmation.rs @@ -92,7 +92,7 @@ impl<'a> Confirmer<'a> { let mut deser = serde_json::Deserializer::from_str(text.as_str()); 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); } if !body.success { @@ -276,6 +276,7 @@ impl From for ConfirmationType { 1 => ConfirmationType::Generic, 2 => ConfirmationType::Trade, 3 => ConfirmationType::MarketSell, + 5 => ConfirmationType::AccountDetails, 6 => ConfirmationType::AccountRecovery, v => ConfirmationType::Unknown(v), } @@ -286,7 +287,8 @@ impl From for ConfirmationType { pub struct ConfirmationListResponse { pub success: bool, #[serde(default)] - pub needsauth: Option, + pub needauth: Option, + #[serde(default)] pub conf: Vec, } @@ -347,6 +349,24 @@ mod tests { 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::(case.text)?; + + assert_eq!(confirmations.conf.len(), 0); + assert_eq!(confirmations.needauth, Some(true)); + } + + Ok(()) + } + #[test] fn test_generate_confirmation_hash_for_time() { assert_eq!( diff --git a/steamguard/src/fixtures/confirmations/need-auth.json b/steamguard/src/fixtures/confirmations/need-auth.json new file mode 100644 index 0000000..bc9286c --- /dev/null +++ b/steamguard/src/fixtures/confirmations/need-auth.json @@ -0,0 +1,4 @@ +{ + "success": false, + "needauth": true +} \ No newline at end of file