Update key::verification::start tests
This commit is contained in:
parent
18a37efcac
commit
a512df0321
@ -279,6 +279,7 @@ impl MSasV1Content {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use matches::assert_matches;
|
||||||
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
@ -387,19 +388,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn deserialization() {
|
fn deserialization() {
|
||||||
let key_verification_start_content = StartEventContent::MSasV1(
|
let json = json!({
|
||||||
MSasV1Content::new(MSasV1ContentOptions {
|
|
||||||
from_device: "123".to_string(),
|
|
||||||
transaction_id: "456".to_string(),
|
|
||||||
hashes: vec![HashAlgorithm::Sha256],
|
|
||||||
key_agreement_protocols: vec![KeyAgreementProtocol::Curve25519],
|
|
||||||
message_authentication_codes: vec![MessageAuthenticationCode::HkdfHmacSha256],
|
|
||||||
short_authentication_string: vec![ShortAuthenticationString::Decimal],
|
|
||||||
})
|
|
||||||
.unwrap(),
|
|
||||||
);
|
|
||||||
|
|
||||||
let json_data = json!({
|
|
||||||
"from_device": "123",
|
"from_device": "123",
|
||||||
"transaction_id": "456",
|
"transaction_id": "456",
|
||||||
"method": "m.sas.v1",
|
"method": "m.sas.v1",
|
||||||
@ -410,19 +399,27 @@ mod tests {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Deserialize the content struct separately to verify `TryFromRaw` is implemented for it.
|
// Deserialize the content struct separately to verify `TryFromRaw` is implemented for it.
|
||||||
assert_eq!(
|
assert_matches!(
|
||||||
from_json_value::<EventJson<StartEventContent>>(json_data)
|
from_json_value::<EventJson<StartEventContent>>(json)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.deserialize()
|
.deserialize()
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
key_verification_start_content
|
StartEventContent::MSasV1(MSasV1Content {
|
||||||
|
from_device,
|
||||||
|
transaction_id,
|
||||||
|
hashes,
|
||||||
|
key_agreement_protocols,
|
||||||
|
message_authentication_codes,
|
||||||
|
short_authentication_string,
|
||||||
|
}) if from_device == "123"
|
||||||
|
&& transaction_id == "456"
|
||||||
|
&& hashes == vec![HashAlgorithm::Sha256]
|
||||||
|
&& key_agreement_protocols == vec![KeyAgreementProtocol::Curve25519]
|
||||||
|
&& message_authentication_codes == vec![MessageAuthenticationCode::HkdfHmacSha256]
|
||||||
|
&& short_authentication_string == vec![ShortAuthenticationString::Decimal]
|
||||||
);
|
);
|
||||||
|
|
||||||
let key_verification_start = StartEvent {
|
let json = json!({
|
||||||
content: key_verification_start_content,
|
|
||||||
};
|
|
||||||
|
|
||||||
let json_data = json!({
|
|
||||||
"content": {
|
"content": {
|
||||||
"from_device": "123",
|
"from_device": "123",
|
||||||
"transaction_id": "456",
|
"transaction_id": "456",
|
||||||
@ -435,12 +432,26 @@ mod tests {
|
|||||||
"type": "m.key.verification.start"
|
"type": "m.key.verification.start"
|
||||||
});
|
});
|
||||||
|
|
||||||
assert_eq!(
|
assert_matches!(
|
||||||
from_json_value::<EventJson<StartEvent>>(json_data)
|
from_json_value::<EventJson<StartEvent>>(json)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.deserialize()
|
.deserialize()
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
key_verification_start
|
StartEvent {
|
||||||
|
content: StartEventContent::MSasV1(MSasV1Content {
|
||||||
|
from_device,
|
||||||
|
transaction_id,
|
||||||
|
hashes,
|
||||||
|
key_agreement_protocols,
|
||||||
|
message_authentication_codes,
|
||||||
|
short_authentication_string,
|
||||||
|
})
|
||||||
|
} if from_device == "123"
|
||||||
|
&& transaction_id == "456"
|
||||||
|
&& hashes == vec![HashAlgorithm::Sha256]
|
||||||
|
&& key_agreement_protocols == vec![KeyAgreementProtocol::Curve25519]
|
||||||
|
&& message_authentication_codes == vec![MessageAuthenticationCode::HkdfHmacSha256]
|
||||||
|
&& short_authentication_string == vec![ShortAuthenticationString::Decimal]
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user