@@ -139,12 +139,12 @@ export async function checkDeviceIsCrossSigned(app: ElementAppPage): Promise<voi
139
139
* Check that the current device is connected to the expected key backup.
140
140
* Also checks that the decryption key is known and cached locally.
141
141
*
142
- * @param page - the page to check
142
+ * @param app - app page
143
143
* @param expectedBackupVersion - the version of the backup we expect to be connected to.
144
144
* @param checkBackupKeyInCache - whether to check that the backup key is cached locally.
145
145
*/
146
146
export async function checkDeviceIsConnectedKeyBackup (
147
- page : Page ,
147
+ app : ElementAppPage ,
148
148
expectedBackupVersion : string ,
149
149
checkBackupKeyInCache : boolean ,
150
150
) : Promise < void > {
@@ -155,23 +155,41 @@ export async function checkDeviceIsConnectedKeyBackup(
155
155
) ;
156
156
}
157
157
158
- await page . getByRole ( "button" , { name : "User menu" } ) . click ( ) ;
159
- await page . locator ( ".mx_UserMenu_contextMenu" ) . getByRole ( "menuitem" , { name : "Security & Privacy" } ) . click ( ) ;
160
- await expect ( page . locator ( ".mx_Dialog" ) . getByRole ( "button" , { name : "Restore from Backup" } ) ) . toBeVisible ( ) ;
158
+ const backupData = await app . client . evaluate ( async ( client : MatrixClient ) => {
159
+ const crypto = client . getCrypto ( ) ;
160
+ if ( ! crypto ) return ;
161
161
162
- // expand the advanced section to see the active version in the reports
163
- await page . locator ( ".mx_SecureBackupPanel_advanced" ) . locator ( ".." ) . click ( ) ;
162
+ const backupInfo = await crypto . getKeyBackupInfo ( ) ;
163
+ const backupKeyStored = Boolean ( await client . isKeyBackupKeyStored ( ) ) ;
164
+ const backupKeyFromCache = await crypto . getSessionBackupPrivateKey ( ) ;
165
+ const backupKeyCached = Boolean ( backupKeyFromCache ) ;
166
+ const backupKeyWellFormed = backupKeyFromCache instanceof Uint8Array ;
167
+ const activeBackupVersion = await crypto . getActiveSessionBackupVersion ( ) ;
164
168
165
- if ( checkBackupKeyInCache ) {
166
- const cacheDecryptionKeyStatusElement = page . locator ( ".mx_SecureBackupPanel_statusList tr:nth-child(2) td" ) ;
167
- await expect ( cacheDecryptionKeyStatusElement ) . toHaveText ( "cached locally, well formed" ) ;
169
+ return { backupInfo, backupKeyStored, backupKeyCached, backupKeyWellFormed, activeBackupVersion } ;
170
+ } ) ;
171
+
172
+ if ( ! backupData ) {
173
+ throw new Error ( "Crypo module is not available" ) ;
168
174
}
169
175
170
- await expect ( page . locator ( ".mx_SecureBackupPanel_statusList tr:nth-child(5) td" ) ) . toHaveText (
171
- expectedBackupVersion + " (Algorithm: m.megolm_backup.v1.curve25519-aes-sha2)" ,
172
- ) ;
176
+ const { backupInfo, backupKeyStored, backupKeyCached, backupKeyWellFormed, activeBackupVersion } = backupData ;
177
+
178
+ // We have a key backup
179
+ expect ( backupInfo ) . toBeDefined ( ) ;
180
+ // The key backup version is as expected
181
+ expect ( backupInfo . version ) . toBe ( expectedBackupVersion ) ;
182
+ // The active backup version is as expected
183
+ expect ( activeBackupVersion ) . toBe ( expectedBackupVersion ) ;
184
+ // The backup key is stored in 4S
185
+ expect ( backupKeyStored ) . toBe ( true ) ;
173
186
174
- await expect ( page . locator ( ".mx_SecureBackupPanel_statusList tr:nth-child(6) td" ) ) . toHaveText ( expectedBackupVersion ) ;
187
+ if ( checkBackupKeyInCache ) {
188
+ // The backup key is available locally
189
+ expect ( backupKeyCached ) . toBe ( true ) ;
190
+ // The backup key is well-formed
191
+ expect ( backupKeyWellFormed ) . toBe ( true ) ;
192
+ }
175
193
}
176
194
177
195
/**
0 commit comments