Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trade: fix Account Details confirmation not parsing #239

Merged
merged 1 commit into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/commands/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![],
},
Expand All @@ -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![],
},
Expand Down
30 changes: 23 additions & 7 deletions steamguard/src/confirmation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct Confirmation {
pub creation_time: u64,
pub cancel: String,
pub accept: String,
pub icon: String,
pub icon: Option<String>,
pub multi: bool,
pub headline: String,
pub summary: Vec<String>,
Expand All @@ -38,6 +38,7 @@ pub enum ConfirmationType {
Generic = 1,
Trade = 2,
MarketSell = 3,
AccountDetails = 5,
AccountRecovery = 6,
Unknown(u32),
}
Expand Down Expand Up @@ -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::<ConfirmationListResponse>(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::<ConfirmationListResponse>(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(())
}
Expand Down
22 changes: 22 additions & 0 deletions steamguard/src/fixtures/confirmations/phone-number-change.json
Original file line number Diff line number Diff line change
@@ -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
}
]
}