Skip to content

Commit

Permalink
Ignore unknown events in the client, at deserialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
AureliaDolo committed Jan 30, 2025
1 parent 682df5f commit 246118a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
11 changes: 8 additions & 3 deletions libparsec/crates/client_connection/src/authenticated_cmds/sse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,15 @@ where
let raw = BASE64
.decode(event.data.as_bytes())
.map_err(|_| ConnectionError::BadContent)?;
let cooked =
T::api_load_response(raw.as_ref()).map_err(|_| ConnectionError::BadContent)?;
SSEResponseOrMissedEvents::Response(cooked)
match T::api_load_response(raw.as_ref()) {
Ok(cooked) => SSEResponseOrMissedEvents::Response(dbg!(cooked)),
Err(_e) => {
// we ignore bad deserialization
SSEResponseOrMissedEvents::Empty
}
}
}

// Unknown event should still be returned given it can modify `retry` param
_ => SSEResponseOrMissedEvents::Empty,
};
Expand Down
17 changes: 16 additions & 1 deletion libparsec/crates/client_connection/tests/unit/authenticated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,14 @@ async fn sse_event_id_mocked(
#[cfg(not(target_arch = "wasm32"))]
#[parsec_test(testbed = "minimal")]
async fn sse_retry_mocked(
#[values("good", "good_with_data", "empty", "not_a_number")] kind: &'static str,
#[values(
"good",
"good_with_data",
"empty",
"not_a_number",
"bad_deserialization"
)]
kind: &'static str,
env: &TestbedEnv,
) {
let alice = env.local_device("alice@dev1");
Expand Down Expand Up @@ -548,6 +555,10 @@ async fn sse_retry_mocked(
),
"empty" => register_send_hook!("retry: \ndata:\n\n"),
"not_a_number" => register_send_hook!("retry: <dummy>\ndata:\n\n"),
// "bad_deserialization" in base46
"bad_deserialization" => {
register_send_hook!("data: YmFkX2Rlc2VyaWFsaXphdGlvbg==\nretry: 1000\n\n")

Check warning on line 560 in libparsec/crates/client_connection/tests/unit/authenticated.rs

View workflow job for this annotation

GitHub Actions / spelling / cspell

Unknown word (Xphd)

Check warning on line 560 in libparsec/crates/client_connection/tests/unit/authenticated.rs

View workflow job for this annotation

GitHub Actions / spelling / cspell

Unknown word (Glvbg)
}
unknown => unreachable!("{}", unknown),
}

Expand Down Expand Up @@ -578,6 +589,10 @@ async fn sse_retry_mocked(
p_assert_matches!(event.message, SSEResponseOrMissedEvents::Empty);
p_assert_eq!(event.retry, None);
}
"bad_deserialization" => {
p_assert_matches!(event.message, SSEResponseOrMissedEvents::Empty);
p_assert_eq!(event.retry, Some(std::time::Duration::from_millis(1000)));
}
unknown => unreachable!("{}", unknown),
}
}
Expand Down

0 comments on commit 246118a

Please sign in to comment.