@@ -22,7 +22,6 @@ import { Mocked } from "jest-mock";
22
22
import {
23
23
createClient ,
24
24
Crypto ,
25
- CryptoEvent ,
26
25
encodeBase64 ,
27
26
ICreateClientOpts ,
28
27
IEvent ,
@@ -45,7 +44,7 @@ import * as testData from "../../test-utils/test-data";
45
44
import { KeyBackupInfo , KeyBackupSession } from "../../../src/crypto-api/keybackup" ;
46
45
import { flushPromises } from "../../test-utils/flushPromises" ;
47
46
import { defer , IDeferred } from "../../../src/utils" ;
48
- import { decodeRecoveryKey , DecryptionFailureCode } from "../../../src/crypto-api" ;
47
+ import { decodeRecoveryKey , DecryptionFailureCode , CryptoEvent } from "../../../src/crypto-api" ;
49
48
import { KeyBackup } from "../../../src/rust-crypto/backup.ts" ;
50
49
51
50
const ROOM_ID = testData . TEST_ROOM_ID ;
@@ -969,6 +968,40 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("megolm-keys backup (%s)", (backe
969
968
expect ( backupStatus ) . toStrictEqual ( testData . SIGNED_BACKUP_DATA . version ) ;
970
969
} ) ;
971
970
971
+ newBackendOnly ( "getKeyBackupInfo() should not return a backup if the active backup has been deleted" , async ( ) => {
972
+ // 404 means that there is no active backup
973
+ fetchMock . get ( "express:/_matrix/client/v3/room_keys/version" , 404 ) ;
974
+ fetchMock . delete ( `express:/_matrix/client/v3/room_keys/version/${ testData . SIGNED_BACKUP_DATA . version } ` , { } ) ;
975
+
976
+ aliceClient = await initTestClient ( ) ;
977
+ const aliceCrypto = aliceClient . getCrypto ( ) ! ;
978
+ await aliceClient . startClient ( ) ;
979
+
980
+ // tell Alice to trust the dummy device that signed the backup
981
+ await waitForDeviceList ( ) ;
982
+ await aliceCrypto . setDeviceVerified ( testData . TEST_USER_ID , testData . TEST_DEVICE_ID ) ;
983
+ await aliceCrypto . checkKeyBackupAndEnable ( ) ;
984
+
985
+ // At this point there is no backup
986
+ expect ( await aliceCrypto . getKeyBackupInfo ( ) ) . toBeNull ( ) ;
987
+
988
+ // Return now the backup
989
+ fetchMock . get ( "express:/_matrix/client/v3/room_keys/version" , testData . SIGNED_BACKUP_DATA , {
990
+ overwriteRoutes : true ,
991
+ } ) ;
992
+
993
+ expect ( await aliceCrypto . getKeyBackupInfo ( ) ) . toStrictEqual ( testData . SIGNED_BACKUP_DATA ) ;
994
+
995
+ // Delete the backup and we are expecting the key backup to be disabled
996
+ const keyBackupStatus = defer < boolean > ( ) ;
997
+ aliceClient . once ( CryptoEvent . KeyBackupStatus , ( enabled ) => keyBackupStatus . resolve ( enabled ) ) ;
998
+ await aliceCrypto . deleteKeyBackupVersion ( testData . SIGNED_BACKUP_DATA . version ! ) ;
999
+ expect ( await keyBackupStatus . promise ) . toBe ( false ) ;
1000
+
1001
+ // The backup info should not be available anymore
1002
+ expect ( await aliceCrypto . getKeyBackupInfo ( ) ) . toBeNull ( ) ;
1003
+ } ) ;
1004
+
972
1005
describe ( "isKeyBackupTrusted" , ( ) => {
973
1006
it ( "does not trust a backup signed by an untrusted device" , async ( ) => {
974
1007
aliceClient = await initTestClient ( ) ;
0 commit comments