events: Fix deserialization of AnyGlobalAccountDataEvent for variants with type fragment
This commit is contained in:
parent
ceba4586d6
commit
00a17dbe9d
@ -1,5 +1,10 @@
|
||||
# [unreleased]
|
||||
|
||||
Bug fixes:
|
||||
|
||||
- Fix deserialization of `AnyGlobalAccountDataEvent` for variants with a type
|
||||
fragment.
|
||||
|
||||
Improvements:
|
||||
|
||||
- Add support for encrypted stickers as sent by several bridges under the flag `compat-encrypted-stickers`
|
||||
|
@ -182,7 +182,7 @@ mod tests {
|
||||
PassPhrase, SecretStorageEncryptionAlgorithm, SecretStorageKeyEventContent,
|
||||
SecretStorageV1AesHmacSha2Properties,
|
||||
};
|
||||
use crate::{EventContentFromType, GlobalAccountDataEvent};
|
||||
use crate::{AnyGlobalAccountDataEvent, EventContentFromType, GlobalAccountDataEvent};
|
||||
|
||||
#[test]
|
||||
fn key_description_serialization() {
|
||||
@ -326,7 +326,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn event_serialization() {
|
||||
fn event_content_serialization() {
|
||||
let mut content = SecretStorageKeyEventContent::new(
|
||||
"my_key_id".into(),
|
||||
SecretStorageEncryptionAlgorithm::V1AesHmacSha2(SecretStorageV1AesHmacSha2Properties {
|
||||
@ -346,6 +346,31 @@ mod tests {
|
||||
assert_eq!(to_json_value(&content).unwrap(), json);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn event_serialization() {
|
||||
let mut content = SecretStorageKeyEventContent::new(
|
||||
"my_key_id".into(),
|
||||
SecretStorageEncryptionAlgorithm::V1AesHmacSha2(SecretStorageV1AesHmacSha2Properties {
|
||||
iv: Some(Base64::parse("YWJjZGVmZ2hpamtsbW5vcA").unwrap()),
|
||||
mac: Some(Base64::parse("aWRvbnRrbm93d2hhdGFtYWNsb29rc2xpa2U").unwrap()),
|
||||
}),
|
||||
);
|
||||
content.name = Some("my_key".to_owned());
|
||||
let event = GlobalAccountDataEvent { content };
|
||||
|
||||
let json = json!({
|
||||
"type": "m.secret_storage.key.my_key_id",
|
||||
"content": {
|
||||
"name": "my_key",
|
||||
"algorithm": "m.secret_storage.v1.aes-hmac-sha2",
|
||||
"iv": "YWJjZGVmZ2hpamtsbW5vcA",
|
||||
"mac": "aWRvbnRrbm93d2hhdGFtYWNsb29rc2xpa2U"
|
||||
}
|
||||
});
|
||||
|
||||
assert_eq!(to_json_value(&event).unwrap(), json);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn event_deserialization() {
|
||||
let json = json!({
|
||||
@ -358,8 +383,8 @@ mod tests {
|
||||
}
|
||||
});
|
||||
|
||||
let ev =
|
||||
from_json_value::<GlobalAccountDataEvent<SecretStorageKeyEventContent>>(json).unwrap();
|
||||
let any_ev = from_json_value::<AnyGlobalAccountDataEvent>(json).unwrap();
|
||||
assert_matches!(any_ev, AnyGlobalAccountDataEvent::SecretStorageKey(ev));
|
||||
assert_eq!(ev.content.key_id, "my_key_id");
|
||||
assert_eq!(ev.content.name.unwrap(), "my_key");
|
||||
assert_matches!(ev.content.passphrase, None);
|
||||
|
@ -170,7 +170,17 @@ fn expand_deserialize_impl(
|
||||
};
|
||||
let self_variant = variant.ctor(quote! { Self });
|
||||
let content = event.to_event_path(kind, var);
|
||||
let ev_types = event.aliases.iter().chain([&event.ev_type]);
|
||||
let ev_types = event.aliases.iter().chain([&event.ev_type]).map(|ev_type| {
|
||||
if event.has_type_fragment() {
|
||||
let ev_type = ev_type.value();
|
||||
let prefix = ev_type
|
||||
.strip_suffix('*')
|
||||
.expect("event type with type fragment must end with *");
|
||||
quote! { t if t.starts_with(#prefix) }
|
||||
} else {
|
||||
quote! { #ev_type }
|
||||
}
|
||||
});
|
||||
|
||||
Ok(quote! {
|
||||
#variant_attrs #(#ev_types)|* => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user