From 8af18a4df7ec18ad4325fe086fe949304eda8a44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Thu, 10 Sep 2020 16:21:23 +0200 Subject: [PATCH] crypto: Test the EncryptionSettings conversion. --- .../src/olm/group_sessions/outbound.rs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/matrix_sdk_crypto/src/olm/group_sessions/outbound.rs b/matrix_sdk_crypto/src/olm/group_sessions/outbound.rs index 453be884..ac521272 100644 --- a/matrix_sdk_crypto/src/olm/group_sessions/outbound.rs +++ b/matrix_sdk_crypto/src/olm/group_sessions/outbound.rs @@ -272,3 +272,32 @@ impl std::fmt::Debug for OutboundGroupSession { .finish() } } + +#[cfg(test)] +mod test { + use std::time::Duration; + + use matrix_sdk_common::{ + events::room::encryption::EncryptionEventContent, identifiers::EventEncryptionAlgorithm, + js_int::uint, + }; + + use super::{EncryptionSettings, ROTATION_MESSAGES, ROTATION_PERIOD}; + + #[test] + fn encryption_settings_conversion() { + let mut content = EncryptionEventContent::new(EventEncryptionAlgorithm::MegolmV1AesSha2); + let settings = EncryptionSettings::from(&content); + + assert_eq!(settings.rotation_period, ROTATION_PERIOD); + assert_eq!(settings.rotation_period_msgs, ROTATION_MESSAGES); + + content.rotation_period_ms = Some(uint!(3600)); + content.rotation_period_msgs = Some(uint!(500)); + + let settings = EncryptionSettings::from(&content); + + assert_eq!(settings.rotation_period, Duration::from_millis(3600)); + assert_eq!(settings.rotation_period_msgs, 500); + } +}