From afafe44d609a7a9d2f8be2b50e105ff4e739fafe Mon Sep 17 00:00:00 2001 From: Carson McManus Date: Mon, 9 Aug 2021 19:49:53 -0400 Subject: [PATCH] sometimes webcookie field can be missing? I got a login response that did not include the `webcookie` field. Added a test case for it. --- .../login-response-missing-webcookie.json | 1 + steamguard/src/steamapi.rs | 27 ++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 steamguard/src/fixtures/api-responses/login-response-missing-webcookie.json diff --git a/steamguard/src/fixtures/api-responses/login-response-missing-webcookie.json b/steamguard/src/fixtures/api-responses/login-response-missing-webcookie.json new file mode 100644 index 0000000..94e933d --- /dev/null +++ b/steamguard/src/fixtures/api-responses/login-response-missing-webcookie.json @@ -0,0 +1 @@ +{"success":true,"requires_twofactor":false,"redirect_uri":"steammobile:\/\/mobileloginsucceeded","login_complete":true,"oauth":"{\"steamid\":\"92591609556178617\",\"account_name\":\"hydrastar2\",\"oauth_token\":\"1cc83205dab2979e558534dab29f6f3aa\",\"wgtoken\":\"3EDA9DEF07D7B39361D95203525D8AFE82A\",\"wgtoken_secure\":\"F31641B9AFC2F8B0EE7B6F44D7E73EA3FA48\"}"} \ No newline at end of file diff --git a/steamguard/src/steamapi.rs b/steamguard/src/steamapi.rs index 0e6f297..32a86a8 100644 --- a/steamguard/src/steamapi.rs +++ b/steamguard/src/steamapi.rs @@ -86,6 +86,7 @@ pub struct OAuthData { steamid: String, wgtoken: String, wgtoken_secure: String, + #[serde(default)] webcookie: String, } @@ -97,7 +98,7 @@ pub struct Session { pub steam_login: String, #[serde(rename = "SteamLoginSecure")] pub steam_login_secure: String, - #[serde(rename = "WebCookie")] + #[serde(default, rename = "WebCookie")] pub web_cookie: String, #[serde(rename = "OAuthToken")] pub token: String, @@ -445,6 +446,30 @@ fn test_login_response_parse() { assert_eq!(oauth.webcookie, "6298070A226E5DAD49938D78BCF36F7A7118FDD5"); } +#[test] +fn test_login_response_parse_missing_webcookie() { + let result = serde_json::from_str::(include_str!( + "fixtures/api-responses/login-response-missing-webcookie.json" + )); + + assert!( + matches!(result, Ok(_)), + "got error: {}", + result.unwrap_err() + ); + let resp = result.unwrap(); + + let oauth = resp.oauth.unwrap(); + assert_eq!(oauth.steamid, "92591609556178617"); + assert_eq!(oauth.oauth_token, "1cc83205dab2979e558534dab29f6f3aa"); + assert_eq!(oauth.wgtoken, "3EDA9DEF07D7B39361D95203525D8AFE82A"); + assert_eq!( + oauth.wgtoken_secure, + "F31641B9AFC2F8B0EE7B6F44D7E73EA3FA48" + ); + assert_eq!(oauth.webcookie, ""); +} + #[derive(Debug, Clone, Deserialize)] pub struct SteamApiResponse { pub response: T,