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: misc confirmation fixes and tests #246

Merged
merged 1 commit into from
Jun 27, 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
24 changes: 22 additions & 2 deletions steamguard/src/confirmation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl<'a> Confirmer<'a> {
let mut deser = serde_json::Deserializer::from_str(text.as_str());
let body: ConfirmationListResponse = serde_path_to_error::deserialize(&mut deser)?;

if body.needsauth.unwrap_or(false) {
if body.needauth.unwrap_or(false) {
return Err(ConfirmerError::InvalidTokens);
}
if !body.success {
Expand Down Expand Up @@ -276,6 +276,7 @@ impl From<u32> for ConfirmationType {
1 => ConfirmationType::Generic,
2 => ConfirmationType::Trade,
3 => ConfirmationType::MarketSell,
5 => ConfirmationType::AccountDetails,
6 => ConfirmationType::AccountRecovery,
v => ConfirmationType::Unknown(v),
}
Expand All @@ -286,7 +287,8 @@ impl From<u32> for ConfirmationType {
pub struct ConfirmationListResponse {
pub success: bool,
#[serde(default)]
pub needsauth: Option<bool>,
pub needauth: Option<bool>,
#[serde(default)]
pub conf: Vec<Confirmation>,
}

Expand Down Expand Up @@ -347,6 +349,24 @@ mod tests {
Ok(())
}

#[test]
fn test_parse_confirmations_2() -> anyhow::Result<()> {
struct Test {
text: &'static str,
}
let cases = [Test {
text: include_str!("fixtures/confirmations/need-auth.json"),
}];
for case in cases.iter() {
let confirmations = serde_json::from_str::<ConfirmationListResponse>(case.text)?;

assert_eq!(confirmations.conf.len(), 0);
assert_eq!(confirmations.needauth, Some(true));
}

Ok(())
}

#[test]
fn test_generate_confirmation_hash_for_time() {
assert_eq!(
Expand Down
4 changes: 4 additions & 0 deletions steamguard/src/fixtures/confirmations/need-auth.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"success": false,
"needauth": true
}