Skip to content

Commit 6110e66

Browse files
committed
refactor(crypto): Simplify some tests by using a session created from a helper function
1 parent 61fa339 commit 6110e66

File tree

1 file changed

+4
-33
lines changed
  • crates/matrix-sdk-crypto/src/olm

1 file changed

+4
-33
lines changed

crates/matrix-sdk-crypto/src/olm/mod.rs

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,10 @@ pub(crate) mod tests {
5555
user_id, DeviceId, UserId,
5656
};
5757
use serde_json::{from_value, json, Value};
58-
use vodozemac::{
59-
olm::{OlmMessage, SessionConfig},
60-
Curve25519PublicKey, Ed25519PublicKey,
61-
};
58+
use vodozemac::olm::{OlmMessage, SessionConfig};
6259

6360
use crate::{
64-
olm::{Account, ExportedRoomKey, InboundGroupSession, SenderData, Session},
61+
olm::{Account, ExportedRoomKey, InboundGroupSession, Session},
6562
types::events::{
6663
forwarded_room_key::ForwardedRoomKeyContent, room::encrypted::EncryptedEvent,
6764
},
@@ -175,27 +172,14 @@ pub(crate) mod tests {
175172
let alice = Account::with_device_id(alice_id(), alice_device_id());
176173
let room_id = room_id!("!test:localhost");
177174

178-
let (outbound, _) = alice.create_group_session_pair_with_defaults(room_id).await;
175+
let (outbound, inbound) = alice.create_group_session_pair_with_defaults(room_id).await;
179176

180177
assert_eq!(0, outbound.message_index().await);
181178
assert!(!outbound.shared());
182179
outbound.mark_as_shared();
183180
assert!(outbound.shared());
184181

185-
let inbound = InboundGroupSession::new(
186-
Curve25519PublicKey::from_base64("Nn0L2hkcCMFKqynTjyGsJbth7QrVmX3lbrksMkrGOAw")
187-
.unwrap(),
188-
Ed25519PublicKey::from_base64("ee3Ek+J2LkkPmjGPGLhMxiKnhiX//xcqaVL4RP6EypE").unwrap(),
189-
room_id,
190-
&outbound.session_key().await,
191-
SenderData::unknown(),
192-
outbound.settings().algorithm.to_owned(),
193-
None,
194-
)
195-
.expect("We can always create an inbound group session from an outbound one");
196-
197182
assert_eq!(0, inbound.first_known_index());
198-
199183
assert_eq!(outbound.session_id(), inbound.session_id());
200184

201185
let plaintext = "This is a secret to everybody".to_owned();
@@ -213,7 +197,7 @@ pub(crate) mod tests {
213197
let room_id = room_id!("!test:localhost");
214198
let event_id = event_id!("$1234adfad:asdf");
215199

216-
let (outbound, _) = alice.create_group_session_pair_with_defaults(room_id).await;
200+
let (outbound, inbound) = alice.create_group_session_pair_with_defaults(room_id).await;
217201

218202
assert_eq!(0, outbound.message_index().await);
219203
assert!(!outbound.shared());
@@ -226,20 +210,7 @@ pub(crate) mod tests {
226210
RoomMessageEventContent::text_plain("Hello edit").into(),
227211
)));
228212

229-
let inbound = InboundGroupSession::new(
230-
Curve25519PublicKey::from_base64("Nn0L2hkcCMFKqynTjyGsJbth7QrVmX3lbrksMkrGOAw")
231-
.unwrap(),
232-
Ed25519PublicKey::from_base64("ee3Ek+J2LkkPmjGPGLhMxiKnhiX//xcqaVL4RP6EypE").unwrap(),
233-
room_id,
234-
&outbound.session_key().await,
235-
SenderData::unknown(),
236-
outbound.settings().algorithm.to_owned(),
237-
None,
238-
)
239-
.unwrap();
240-
241213
assert_eq!(0, inbound.first_known_index());
242-
243214
assert_eq!(outbound.session_id(), inbound.session_id());
244215

245216
let encrypted_content =

0 commit comments

Comments
 (0)