Skip to content

Commit

Permalink
test: Test the KnownSenderData migration with optimised [u8] serializ…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
BillCarsonFr authored and poljar committed Jan 10, 2025
1 parent e4b269e commit 1dd2b2c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions crates/matrix-sdk-crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ http = { workspace = true }
indoc = "2.0.5"
insta = { workspace = true }
matrix-sdk-test = { workspace = true }
rmp-serde = { workspace = true }
proptest = { workspace = true }
similar-asserts = { workspace = true }
# required for async_test macro
Expand Down
36 changes: 34 additions & 2 deletions crates/matrix-sdk-crypto/src/olm/group_sessions/sender_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,11 @@ mod tests {
device_id, owned_device_id, owned_user_id, user_id, DeviceKeyAlgorithm, DeviceKeyId,
};
use serde_json::json;
use vodozemac::{Curve25519PublicKey, Ed25519PublicKey};
use vodozemac::{base64_decode, Curve25519PublicKey, Ed25519PublicKey};

use super::SenderData;
use crate::{
olm::KnownSenderData,
olm::{KnownSenderData, PickledInboundGroupSession},
types::{DeviceKey, DeviceKeys, EventEncryptionAlgorithm, Signatures},
};

Expand Down Expand Up @@ -616,4 +616,36 @@ mod tests {
Ed25519PublicKey::from_slice(&[0u8; 32]).unwrap().to_base64()
);
}

#[test]
fn test_sender_known_data_migration_with_efficient_bytes_array() {
// This is an serialized PickledInboundGroupSession as rmp_serde will generate.
//
// This export usse a more efficient serialization format for bytes. This was
// exported when the `KnownSenderData` master_key was serialized as an byte
// array instead of a base64 encoded string.
const SERIALIZED_B64: &str =
"iaZwaWNrbGWEr2luaXRpYWxfcmF0Y2hldIKlaW5uZXLcAIABYMzfSnBRzMlPKF1uKjYbzLtkzNJ4RcylzN0HzP\
9DzON1Tm05zO7M2MzFQsy9Acz9zPnMqDvM4syQzNrMzxF5KzbM4sy9zPUbBWfM7m4/zJzM18zDzMESKgfMkE7M\
yszIHszqWjYyQURbzKTMkx7M58zANsy+AGPM2A8tbcyFYczge8ykzMFdbVxJMMyAzN8azJEXGsy8zPJazMMaP8\
ziDszmWwfM+My2ajLMr8y+eczTRm9TFadjb3VudGVyAKtzaWduaW5nX2tlecQgefpCr6Duu7QUWzKIeMOFmxv/\
NjfcsYwZz8IN2ZOhdaS0c2lnbmluZ19rZXlfdmVyaWZpZWTDpmNvbmZpZ4GndmVyc2lvbqJWMapzZW5kZXJfa2\
V52StoMkIySDg2ajFpYmk2SW13ak9UUkhzbTVMamtyT2kyUGtiSXVUb0w0TWtFq3NpZ25pbmdfa2V5gadlZDI1\
NTE52StUWHJqNS9UYXpia3Yram1CZDl4UlB4NWNVaFFzNUNnblc1Q1pNRjgvNjZzq3NlbmRlcl9kYXRhgbBTZW\
5kZXJVbnZlcmlmaWVkg6d1c2VyX2lks0B2YWxvdTM1Om1hdHJpeC5vcmepZGV2aWNlX2lkqkZJQlNaRlJLUE2q\
bWFzdGVyX2tlecQgkOp9s4ClyQujYD7rRZA8xgE6kvYlqKSNnMrQNmSrcuGncm9vbV9pZL4hRWt5VEtGdkViYl\
B6SmxhaUhFOm1hdHJpeC5vcmeoaW1wb3J0ZWTCqWJhY2tlZF91cMKyaGlzdG9yeV92aXNpYmlsaXR5wKlhbGdv\
cml0aG20bS5tZWdvbG0udjEuYWVzLXNoYTI";

let input = base64_decode(SERIALIZED_B64).unwrap();
let sender_data: PickledInboundGroupSession = rmp_serde::from_slice(&input)
.expect("Should be able to deserialize serialized inbound group session");

assert_let!(
SenderData::SenderUnverified(KnownSenderData { master_key, .. }) =
sender_data.sender_data
);

assert_eq!(master_key.to_base64(), "kOp9s4ClyQujYD7rRZA8xgE6kvYlqKSNnMrQNmSrcuE");
}
}

0 comments on commit 1dd2b2c

Please sign in to comment.