From 4fed9486de574fcb85b3aca5d67c47c05adcb9c1 Mon Sep 17 00:00:00 2001 From: Carson McManus Date: Mon, 26 Jun 2023 19:11:15 -0400 Subject: [PATCH] trade: adjust logging for deserializing confirmations (#237) --- Cargo.lock | 1 + steamguard/Cargo.toml | 1 + steamguard/src/lib.rs | 22 +++++++++++++--------- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f93ca95..45f7973 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2217,6 +2217,7 @@ dependencies = [ "secrecy", "serde", "serde_json", + "serde_path_to_error", "standback", "thiserror", "uuid", diff --git a/steamguard/Cargo.toml b/steamguard/Cargo.toml index 31fdfec..6b38dc5 100644 --- a/steamguard/Cargo.toml +++ b/steamguard/Cargo.toml @@ -34,6 +34,7 @@ protobuf = "3.2.0" protobuf-json-mapping = "3.2.0" hmac-sha256 = "1.1.7" phonenumber = "0.3" +serde_path_to_error = "0.1.11" [build-dependencies] anyhow = "^1.0" diff --git a/steamguard/src/lib.rs b/steamguard/src/lib.rs index cafde52..631766f 100644 --- a/steamguard/src/lib.rs +++ b/steamguard/src/lib.rs @@ -179,10 +179,10 @@ impl SteamGuardAccount { trace!("{:?}", resp); let text = resp.text().unwrap(); - trace!("text: {:?}", text); - trace!("{}", text); + debug!("Confirmations response: {}", text); - let body: ConfirmationListResponse = serde_json::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)?; ensure!(body.success); Ok(body.conf) } @@ -222,7 +222,8 @@ impl SteamGuardAccount { let raw = resp.text()?; debug!("send_confirmation_ajax() response body: {:?}", &raw); - let body: SendConfirmationResponse = serde_json::from_str(raw.as_str())?; + let mut deser = serde_json::Deserializer::from_str(raw.as_str()); + let body: SendConfirmationResponse = serde_path_to_error::deserialize(&mut deser)?; if !body.success { return Err(anyhow!("Server responded with failure.")); @@ -256,16 +257,19 @@ impl SteamGuardAccount { let time = steamapi::get_server_time()?.server_time(); let query_params = self.get_confirmation_query_params("details", time); - let resp: ConfirmationDetailsResponse = client.get(format!("https://steamcommunity.com/mobileconf/details/{}", conf.id).parse::().unwrap()) + let resp = client.get(format!("https://steamcommunity.com/mobileconf/details/{}", conf.id).parse::().unwrap()) .header("X-Requested-With", "com.valvesoftware.android.steam.community") .header(USER_AGENT, "Mozilla/5.0 (Linux; U; Android 4.1.1; en-us; Google Nexus 4 - 4.1.1 - API 16 - 768x1280 Build/JRO03S) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30") .header(COOKIE, cookies.cookies(&url).unwrap()) .query(&query_params) - .send()? - .json()?; + .send()?; - ensure!(resp.success); - Ok(resp.html) + let text = resp.text()?; + let mut deser = serde_json::Deserializer::from_str(text.as_str()); + let body: ConfirmationDetailsResponse = serde_path_to_error::deserialize(&mut deser)?; + + ensure!(body.success); + Ok(body.html) } /// Removes the mobile authenticator from the steam account. If this operation succeeds, this object can no longer be considered valid.