Skip to content

Commit

Permalink
crypto: Test for plain JSON and typed deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
andybalaam committed Jul 4, 2024
1 parent 46b4d00 commit 1c5f302
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions crates/matrix-sdk-crypto/src/olm/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ mod tests {
use assert_matches2::assert_let;
use matrix_sdk_test::async_test;
use ruma::{device_id, user_id};
use serde_json;
use serde_json::{self, Value};
use vodozemac::olm::{OlmMessage, SessionConfig};

use crate::{
Expand Down Expand Up @@ -352,9 +352,16 @@ mod tests {
)
.unwrap();

// Also ensure that the encrypted payload has the device keys.
let plaintext: DecryptedOlmV1Event<DummyEventContent> =
// Also ensure that the encrypted payload has the device keys under the unstable prefix
let plaintext: Value = serde_json::from_str(&bob_session_result.plaintext).unwrap();
assert_eq!(
plaintext["org.matrix.msc4147.device_keys"]["user_id"].as_str(),
Some("@alice:localhost")
);

// And the serialized object matches the format as specified in DecryptedOlmV1Event
let event: DecryptedOlmV1Event<DummyEventContent> =
serde_json::from_str(&bob_session_result.plaintext).unwrap();
assert_eq!(plaintext.device_keys.unwrap(), alice.device_keys());
assert_eq!(event.device_keys.unwrap(), alice.device_keys());
}
}

0 comments on commit 1c5f302

Please sign in to comment.