@@ -735,6 +735,35 @@ describe("verification", () => {
735735 expect ( request . cancellingUserId ) . toEqual ( "@alice:localhost" ) ;
736736 } ) ;
737737
738+ it ( "does not include cancelled requests in the list of requests" , async ( ) => {
739+ // Given Alice started a verification request
740+ const [ , request ] = await Promise . all ( [
741+ expectSendToDeviceMessage ( "m.key.verification.request" ) ,
742+ aliceClient . getCrypto ( ) ! . requestDeviceVerification ( TEST_USER_ID , TEST_DEVICE_ID ) ,
743+ ] ) ;
744+ const transactionId = request . transactionId ! ;
745+
746+ returnToDeviceMessageFromSync ( buildReadyMessage ( transactionId , [ "m.sas.v1" ] ) ) ;
747+ await waitForVerificationRequestChanged ( request ) ;
748+
749+ // Sanity: the request is listed
750+ const requestsBeforeCancel = aliceClient
751+ . getCrypto ( ) !
752+ . getVerificationRequestsToDeviceInProgress ( TEST_USER_ID ) ;
753+
754+ expect ( requestsBeforeCancel ) . toHaveLength ( 1 ) ;
755+
756+ // When Alice cancels it
757+ await Promise . all ( [ expectSendToDeviceMessage ( "m.key.verification.cancel" ) , request . cancel ( ) ] ) ;
758+
759+ // Then it is no longer listed as in progress
760+ const requestsAfterCancel = aliceClient
761+ . getCrypto ( ) !
762+ . getVerificationRequestsToDeviceInProgress ( TEST_USER_ID ) ;
763+
764+ expect ( requestsAfterCancel ) . toHaveLength ( 0 ) ;
765+ } ) ;
766+
738767 it ( "can cancel during the SAS phase" , async ( ) => {
739768 // have alice initiate a verification. She should send a m.key.verification.request
740769 const [ , request ] = await Promise . all ( [
@@ -1072,6 +1101,29 @@ describe("verification", () => {
10721101 ) . not . toBeDefined ( ) ;
10731102 } ) ;
10741103
1104+ it ( "ignores cancelled verification requests" , async ( ) => {
1105+ // Given a verification request exists
1106+ const event = createVerificationRequestEvent ( ) ;
1107+ returnRoomMessageFromSync ( TEST_ROOM_ID , event ) ;
1108+
1109+ // Wait for the request to be received
1110+ await emitPromise ( aliceClient , CryptoEvent . VerificationRequestReceived ) ;
1111+
1112+ const request = aliceClient . getCrypto ( ) ! . findVerificationRequestDMInProgress ( TEST_ROOM_ID , "@bob:xyz" ) ;
1113+
1114+ // When I cancel it
1115+ fetchMock . put ( "express:/_matrix/client/v3/rooms/:roomId/send/m.key.verification.cancel/:id" , {
1116+ event_id : event . event_id ,
1117+ } ) ;
1118+ await request ! . cancel ( ) ;
1119+ expect ( request ! . phase ) . toEqual ( VerificationPhase . Cancelled ) ;
1120+
1121+ // Then it is no longer found
1122+ expect (
1123+ aliceClient . getCrypto ( ) ! . findVerificationRequestDMInProgress ( TEST_ROOM_ID , "@bob:xyz" ) ,
1124+ ) . not . toBeDefined ( ) ;
1125+ } ) ;
1126+
10751127 it ( "Plaintext verification request from Bob to Alice" , async ( ) => {
10761128 // Add verification request from Bob to Alice in the DM between them
10771129 returnRoomMessageFromSync ( TEST_ROOM_ID , createVerificationRequestEvent ( ) ) ;
0 commit comments