From 555b47b3fbf8eb0e74617e01c690c6ecae544afc Mon Sep 17 00:00:00 2001 From: Carson McManus Date: Mon, 9 Aug 2021 22:46:50 -0400 Subject: [PATCH] fix add authenticator response parsing again --- .../api-responses/add-authenticator-2.json | 1 + steamguard/src/steamapi.rs | 28 +++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 steamguard/src/fixtures/api-responses/add-authenticator-2.json diff --git a/steamguard/src/fixtures/api-responses/add-authenticator-2.json b/steamguard/src/fixtures/api-responses/add-authenticator-2.json new file mode 100644 index 0000000..55bac0a --- /dev/null +++ b/steamguard/src/fixtures/api-responses/add-authenticator-2.json @@ -0,0 +1 @@ +{"response":{"status":29}} \ No newline at end of file diff --git a/steamguard/src/steamapi.rs b/steamguard/src/steamapi.rs index bb9661e..bb92665 100644 --- a/steamguard/src/steamapi.rs +++ b/steamguard/src/steamapi.rs @@ -509,23 +509,31 @@ pub struct SteamApiResponse { #[derive(Debug, Clone, Deserialize)] pub struct AddAuthenticatorResponse { /// Shared secret between server and authenticator + #[serde(default)] pub shared_secret: String, /// Authenticator serial number (unique per token) + #[serde(default)] pub serial_number: String, /// code used to revoke authenticator + #[serde(default)] pub revocation_code: String, /// URI for QR code generation + #[serde(default)] pub uri: String, /// Current server time - #[serde(deserialize_with = "parse_json_string_as_number")] + #[serde(default, deserialize_with = "parse_json_string_as_number")] pub server_time: u64, /// Account name to display on token client + #[serde(default)] pub account_name: String, /// Token GID assigned by server + #[serde(default)] pub token_gid: String, /// Secret used for identity attestation (e.g., for eventing) + #[serde(default)] pub identity_secret: String, /// Spare shared secret + #[serde(default)] pub secret_1: String, /// Result code pub status: i32, @@ -584,4 +592,20 @@ fn test_parse_add_auth_response() { assert_eq!(resp.server_time, 1628559846); assert_eq!(resp.shared_secret, "wGwZx=sX5MmTxi6QgA3Gi"); assert_eq!(resp.revocation_code, "R123456"); -} \ No newline at end of file +} + +#[test] +fn test_parse_add_auth_response2() { + let result = serde_json::from_str::>(include_str!( + "fixtures/api-responses/add-authenticator-2.json" + )); + + assert!( + matches!(result, Ok(_)), + "got error: {}", + result.unwrap_err() + ); + let resp = result.unwrap().response; + + assert_eq!(resp.status, 29); +}