@@ -980,12 +980,43 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("verification (%s)", (backend: st
980
980
} ) ;
981
981
}
982
982
983
+ it ( "Verification request not found" , async ( ) => {
984
+ // Expect to not find any verification request
985
+ const request = aliceClient . getCrypto ( ) ! . findVerificationRequestDMInProgress ( TEST_ROOM_ID , "@bob:xyz" ) ;
986
+ expect ( request ) . toBeUndefined ( ) ;
987
+ } ) ;
988
+
989
+ it ( "ignores old verification requests" , async ( ) => {
990
+ const eventHandler = jest . fn ( ) ;
991
+ aliceClient . on ( CryptoEvent . VerificationRequestReceived , eventHandler ) ;
992
+
993
+ const verificationRequestEvent = createVerificationRequestEvent ( ) ;
994
+ verificationRequestEvent . origin_server_ts -= 1000000 ;
995
+ returnRoomMessageFromSync ( TEST_ROOM_ID , verificationRequestEvent ) ;
996
+
997
+ await syncPromise ( aliceClient ) ;
998
+
999
+ // make sure the event has arrived
1000
+ const room = aliceClient . getRoom ( TEST_ROOM_ID ) ! ;
1001
+ const matrixEvent = room . getLiveTimeline ( ) . getEvents ( ) [ 0 ] ;
1002
+ expect ( matrixEvent . getId ( ) ) . toEqual ( verificationRequestEvent . event_id ) ;
1003
+
1004
+ // check that an event has not been raised, and that the request is not found
1005
+ expect ( eventHandler ) . not . toHaveBeenCalled ( ) ;
1006
+ expect (
1007
+ aliceClient . getCrypto ( ) ! . findVerificationRequestDMInProgress ( TEST_ROOM_ID , "@bob:xyz" ) ,
1008
+ ) . not . toBeDefined ( ) ;
1009
+ } ) ;
1010
+
983
1011
it ( "Plaintext verification request from Bob to Alice" , async ( ) => {
984
1012
// Add verification request from Bob to Alice in the DM between them
985
1013
returnRoomMessageFromSync ( TEST_ROOM_ID , createVerificationRequestEvent ( ) ) ;
986
1014
987
- // Wait for the sync response to be processed
988
- await syncPromise ( aliceClient ) ;
1015
+ // Wait for the request to be received
1016
+ const request1 = await emitPromise ( aliceClient , CryptoEvent . VerificationRequestReceived ) ;
1017
+ expect ( request1 . roomId ) . toBe ( TEST_ROOM_ID ) ;
1018
+ expect ( request1 . isSelfVerification ) . toBe ( false ) ;
1019
+ expect ( request1 . otherUserId ) . toBe ( "@bob:xyz" ) ;
989
1020
990
1021
const request = aliceClient . getCrypto ( ) ! . findVerificationRequestDMInProgress ( TEST_ROOM_ID , "@bob:xyz" ) ;
991
1022
// Expect to find the verification request received during the sync
@@ -994,12 +1025,6 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("verification (%s)", (backend: st
994
1025
expect ( request ?. otherUserId ) . toBe ( "@bob:xyz" ) ;
995
1026
} ) ;
996
1027
997
- it ( "Verification request not found" , async ( ) => {
998
- // Expect to not find any verification request
999
- const request = aliceClient . getCrypto ( ) ! . findVerificationRequestDMInProgress ( TEST_ROOM_ID , "@bob:xyz" ) ;
1000
- expect ( request ) . not . toBeDefined ( ) ;
1001
- } ) ;
1002
-
1003
1028
it ( "Encrypted verification request from Bob to Alice" , async ( ) => {
1004
1029
const p2pSession = await createOlmSession ( testOlmAccount , e2eKeyReceiver ) ;
1005
1030
const groupSession = new Olm . OutboundGroupSession ( ) ;
@@ -1021,14 +1046,19 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("verification (%s)", (backend: st
1021
1046
await awaitDecryption ( matrixEvent ) ;
1022
1047
expect ( matrixEvent . getContent ( ) . msgtype ) . toEqual ( "m.bad.encrypted" ) ;
1023
1048
1049
+ const requestEventPromise = emitPromise ( aliceClient , CryptoEvent . VerificationRequestReceived ) ;
1050
+
1024
1051
// Send Bob the room keys
1025
1052
returnToDeviceMessageFromSync ( toDeviceEvent ) ;
1026
1053
1027
1054
// advance the clock, because the devicelist likes to sleep for 5ms during key downloads
1028
1055
await jest . advanceTimersByTimeAsync ( 10 ) ;
1029
1056
1030
- // Wait for the message to be decrypted
1031
- await awaitDecryption ( matrixEvent , { waitOnDecryptionFailure : true } ) ;
1057
+ // Wait for the request to be decrypted
1058
+ const request1 = await requestEventPromise ;
1059
+ expect ( request1 . roomId ) . toBe ( TEST_ROOM_ID ) ;
1060
+ expect ( request1 . isSelfVerification ) . toBe ( false ) ;
1061
+ expect ( request1 . otherUserId ) . toBe ( "@bob:xyz" ) ;
1032
1062
1033
1063
const request = aliceClient . getCrypto ( ) ! . findVerificationRequestDMInProgress ( TEST_ROOM_ID , "@bob:xyz" ) ;
1034
1064
// Expect to find the verification request received during the sync
0 commit comments