From ad5a9b313187af2e0a9a69b274f6eee7b9705751 Mon Sep 17 00:00:00 2001 From: Carson McManus Date: Mon, 26 Jun 2023 19:57:17 -0400 Subject: [PATCH] trade: fix Account Details confirmation not parsing (#239) fixes #238 --- src/commands/debug.rs | 4 +-- steamguard/src/confirmation.rs | 30 ++++++++++++++----- .../confirmations/phone-number-change.json | 22 ++++++++++++++ 3 files changed, 47 insertions(+), 9 deletions(-) create mode 100644 steamguard/src/fixtures/confirmations/phone-number-change.json diff --git a/src/commands/debug.rs b/src/commands/debug.rs index 8110294..ac1e7b5 100644 --- a/src/commands/debug.rs +++ b/src/commands/debug.rs @@ -83,7 +83,7 @@ pub fn demo_confirmation_menu() { creation_time: 1687457923, cancel: "Cancel".to_owned(), accept: "Confirm".to_owned(), - icon: "".to_owned(), + icon: Some("".to_owned()), multi: false, summary: vec![], }, @@ -97,7 +97,7 @@ pub fn demo_confirmation_menu() { creation_time: 1687457923, cancel: "Cancel".to_owned(), accept: "Confirm".to_owned(), - icon: "".to_owned(), + icon: Some("".to_owned()), multi: false, summary: vec![], }, diff --git a/steamguard/src/confirmation.rs b/steamguard/src/confirmation.rs index fc27441..404b77c 100644 --- a/steamguard/src/confirmation.rs +++ b/steamguard/src/confirmation.rs @@ -13,7 +13,7 @@ pub struct Confirmation { pub creation_time: u64, pub cancel: String, pub accept: String, - pub icon: String, + pub icon: Option, pub multi: bool, pub headline: String, pub summary: Vec, @@ -38,6 +38,7 @@ pub enum ConfirmationType { Generic = 1, Trade = 2, MarketSell = 3, + AccountDetails = 5, AccountRecovery = 6, Unknown(u32), } @@ -70,15 +71,30 @@ mod tests { use super::*; #[test] - fn test_parse_email_change() -> anyhow::Result<()> { - let text = include_str!("fixtures/confirmations/email-change.json"); - let confirmations = serde_json::from_str::(text)?; + fn test_parse_confirmations() -> anyhow::Result<()> { + struct Test { + text: &'static str, + confirmation_type: ConfirmationType, + } + let cases = [ + Test { + text: include_str!("fixtures/confirmations/email-change.json"), + confirmation_type: ConfirmationType::AccountRecovery, + }, + Test { + text: include_str!("fixtures/confirmations/phone-number-change.json"), + confirmation_type: ConfirmationType::AccountDetails, + }, + ]; + for case in cases.iter() { + let confirmations = serde_json::from_str::(case.text)?; - assert_eq!(confirmations.conf.len(), 1); + assert_eq!(confirmations.conf.len(), 1); - let confirmation = &confirmations.conf[0]; + let confirmation = &confirmations.conf[0]; - assert_eq!(confirmation.conf_type, ConfirmationType::AccountRecovery); + assert_eq!(confirmation.conf_type, case.confirmation_type); + } Ok(()) } diff --git a/steamguard/src/fixtures/confirmations/phone-number-change.json b/steamguard/src/fixtures/confirmations/phone-number-change.json new file mode 100644 index 0000000..e9dc533 --- /dev/null +++ b/steamguard/src/fixtures/confirmations/phone-number-change.json @@ -0,0 +1,22 @@ +{ + "success": true, + "conf": [ + { + "type": 5, + "type_name": "Account details", + "id": "13831364158", + "creator_id": "4486196268090979848", + "nonce": "11118003665658287603", + "creation_time": 1687821676, + "cancel": "Cancel", + "accept": "Confirm", + "icon": null, + "multi": false, + "headline": "Change phone number", + "summary": [ + "" + ], + "warn": null + } + ] +} \ No newline at end of file