@@ -174,92 +174,110 @@ describe("Cryptography", function () {
174
174
cy . stopHomeserver ( this . homeserver ) ;
175
175
} ) ;
176
176
177
- describe ( "setting up secure key backup should work" , ( ) => {
178
- /**
179
- * Verify that the `m.cross_signing.${keyType}` key is available on the account data on the server
180
- * @param keyType
181
- */
182
- function verifyKey ( keyType : string ) {
183
- return cy
184
- . getClient ( )
185
- . then ( ( cli ) => cy . wrap ( cli . getAccountDataFromServer ( `m.cross_signing.${ keyType } ` ) ) )
186
- . then ( ( accountData : { encrypted : Record < string , Record < string , string > > } ) => {
187
- expect ( accountData . encrypted ) . to . exist ;
188
- const keys = Object . keys ( accountData . encrypted ) ;
189
- const key = accountData . encrypted [ keys [ 0 ] ] ;
190
- expect ( key . ciphertext ) . to . exist ;
191
- expect ( key . iv ) . to . exist ;
192
- expect ( key . mac ) . to . exist ;
193
- } ) ;
194
- }
195
-
196
- /**
197
- * Click on download button and continue
198
- */
199
- function downloadKey ( ) {
200
- // Clicking download instead of Copy because of https://github.com/cypress-io/cypress/issues/2851
201
- cy . findByRole ( "button" , { name : "Download" } ) . click ( ) ;
202
- cy . contains ( ".mx_Dialog_primary:not([disabled])" , "Continue" ) . click ( ) ;
203
- }
204
-
205
- it ( "by recovery code" , ( ) => {
206
- skipIfRustCrypto ( ) ;
207
- cy . openUserSettings ( "Security & Privacy" ) ;
208
- cy . findByRole ( "button" , { name : "Set up Secure Backup" } ) . click ( ) ;
209
- cy . get ( ".mx_Dialog" ) . within ( ( ) => {
210
- // Recovery key is selected by default
211
- cy . findByRole ( "button" , { name : "Continue" } ) . click ( ) ;
212
- cy . get ( ".mx_CreateSecretStorageDialog_recoveryKey code" ) . invoke ( "text" ) . as ( "securityKey" ) ;
213
-
214
- downloadKey ( ) ;
215
-
216
- cy . get ( ".mx_InteractiveAuthDialog" ) . within ( ( ) => {
217
- cy . get ( ".mx_Dialog_title" ) . within ( ( ) => {
218
- cy . findByText ( "Setting up keys" ) . should ( "exist" ) ;
219
- cy . findByText ( "Setting up keys" ) . should ( "not.exist" ) ;
177
+ describe . each ( [ { isDeviceVerified : true } , { isDeviceVerified : false } ] ) (
178
+ "setting up secure key backup should work %j" ,
179
+ ( { isDeviceVerified } ) => {
180
+ /**
181
+ * Verify that the `m.cross_signing.${keyType}` key is available on the account data on the server
182
+ * @param keyType
183
+ */
184
+ function verifyKey ( keyType : string ) {
185
+ return cy
186
+ . getClient ( )
187
+ . then ( ( cli ) => cy . wrap ( cli . getAccountDataFromServer ( `m.cross_signing.${ keyType } ` ) ) )
188
+ . then ( ( accountData : { encrypted : Record < string , Record < string , string > > } ) => {
189
+ expect ( accountData . encrypted ) . to . exist ;
190
+ const keys = Object . keys ( accountData . encrypted ) ;
191
+ const key = accountData . encrypted [ keys [ 0 ] ] ;
192
+ expect ( key . ciphertext ) . to . exist ;
193
+ expect ( key . iv ) . to . exist ;
194
+ expect ( key . mac ) . to . exist ;
220
195
} ) ;
221
- } ) ;
222
-
223
- cy . findByText ( "Secure Backup successful" ) . should ( "exist" ) ;
224
- cy . findByRole ( "button" , { name : "Done" } ) . click ( ) ;
225
- cy . findByText ( "Secure Backup successful" ) . should ( "not.exist" ) ;
226
- } ) ;
227
-
228
- // Verify that the SSSS keys are in the account data stored in the server
229
- verifyKey ( "master" ) ;
230
- verifyKey ( "self_signing" ) ;
231
- verifyKey ( "user_signing" ) ;
232
- } ) ;
196
+ }
233
197
234
- it ( "by passphrase" , ( ) => {
235
- skipIfRustCrypto ( ) ;
236
- cy . openUserSettings ( "Security & Privacy" ) ;
237
- cy . findByRole ( "button" , { name : "Set up Secure Backup" } ) . click ( ) ;
238
- cy . get ( ".mx_Dialog" ) . within ( ( ) => {
239
- // Select passphrase option
240
- cy . findByText ( "Enter a Security Phrase" ) . click ( ) ;
241
- cy . findByRole ( "button" , { name : "Continue" } ) . click ( ) ;
242
-
243
- // Fill passphrase input
244
- cy . get ( "input" ) . type ( "new passphrase for setting up a secure key backup" ) ;
245
- cy . contains ( ".mx_Dialog_primary:not([disabled])" , "Continue" ) . click ( ) ;
246
- // Confirm passphrase
247
- cy . get ( "input" ) . type ( "new passphrase for setting up a secure key backup" ) ;
198
+ /**
199
+ * Click on download button and continue
200
+ */
201
+ function downloadKey ( ) {
202
+ // Clicking download instead of Copy because of https://github.com/cypress-io/cypress/issues/2851
203
+ cy . findByRole ( "button" , { name : "Download" } ) . click ( ) ;
248
204
cy . contains ( ".mx_Dialog_primary:not([disabled])" , "Continue" ) . click ( ) ;
205
+ }
249
206
250
- downloadKey ( ) ;
207
+ it ( "by recovery code" , ( ) => {
208
+ skipIfRustCrypto ( ) ;
209
+
210
+ // Verified the device
211
+ if ( isDeviceVerified ) {
212
+ cy . bootstrapCrossSigning ( aliceCredentials ) ;
213
+ }
214
+
215
+ cy . openUserSettings ( "Security & Privacy" ) ;
216
+ cy . findByRole ( "button" , { name : "Set up Secure Backup" } ) . click ( ) ;
217
+ cy . get ( ".mx_Dialog" ) . within ( ( ) => {
218
+ // Recovery key is selected by default
219
+ cy . findByRole ( "button" , { name : "Continue" } ) . click ( ) ;
220
+ cy . get ( ".mx_CreateSecretStorageDialog_recoveryKey code" ) . invoke ( "text" ) . as ( "securityKey" ) ;
221
+
222
+ downloadKey ( ) ;
223
+
224
+ // When the device is verified, the `Setting up keys` step is skipped
225
+ if ( ! isDeviceVerified ) {
226
+ cy . get ( ".mx_InteractiveAuthDialog" ) . within ( ( ) => {
227
+ cy . get ( ".mx_Dialog_title" ) . within ( ( ) => {
228
+ cy . findByText ( "Setting up keys" ) . should ( "exist" ) ;
229
+ cy . findByText ( "Setting up keys" ) . should ( "not.exist" ) ;
230
+ } ) ;
231
+ } ) ;
232
+ }
233
+
234
+ cy . findByText ( "Secure Backup successful" ) . should ( "exist" ) ;
235
+ cy . findByRole ( "button" , { name : "Done" } ) . click ( ) ;
236
+ cy . findByText ( "Secure Backup successful" ) . should ( "not.exist" ) ;
237
+ } ) ;
251
238
252
- cy . findByText ( "Secure Backup successful" ) . should ( "exist" ) ;
253
- cy . findByRole ( "button" , { name : "Done" } ) . click ( ) ;
254
- cy . findByText ( "Secure Backup successful" ) . should ( "not.exist" ) ;
239
+ // Verify that the SSSS keys are in the account data stored in the server
240
+ verifyKey ( "master" ) ;
241
+ verifyKey ( "self_signing" ) ;
242
+ verifyKey ( "user_signing" ) ;
255
243
} ) ;
256
244
257
- // Verify that the SSSS keys are in the account data stored in the server
258
- verifyKey ( "master" ) ;
259
- verifyKey ( "self_signing" ) ;
260
- verifyKey ( "user_signing" ) ;
261
- } ) ;
262
- } ) ;
245
+ it ( "by passphrase" , ( ) => {
246
+ skipIfRustCrypto ( ) ;
247
+
248
+ // Verified the device
249
+ if ( isDeviceVerified ) {
250
+ cy . bootstrapCrossSigning ( aliceCredentials ) ;
251
+ }
252
+
253
+ cy . openUserSettings ( "Security & Privacy" ) ;
254
+ cy . findByRole ( "button" , { name : "Set up Secure Backup" } ) . click ( ) ;
255
+ cy . get ( ".mx_Dialog" ) . within ( ( ) => {
256
+ // Select passphrase option
257
+ cy . findByText ( "Enter a Security Phrase" ) . click ( ) ;
258
+ cy . findByRole ( "button" , { name : "Continue" } ) . click ( ) ;
259
+
260
+ // Fill passphrase input
261
+ cy . get ( "input" ) . type ( "new passphrase for setting up a secure key backup" ) ;
262
+ cy . contains ( ".mx_Dialog_primary:not([disabled])" , "Continue" ) . click ( ) ;
263
+ // Confirm passphrase
264
+ cy . get ( "input" ) . type ( "new passphrase for setting up a secure key backup" ) ;
265
+ cy . contains ( ".mx_Dialog_primary:not([disabled])" , "Continue" ) . click ( ) ;
266
+
267
+ downloadKey ( ) ;
268
+
269
+ cy . findByText ( "Secure Backup successful" ) . should ( "exist" ) ;
270
+ cy . findByRole ( "button" , { name : "Done" } ) . click ( ) ;
271
+ cy . findByText ( "Secure Backup successful" ) . should ( "not.exist" ) ;
272
+ } ) ;
273
+
274
+ // Verify that the SSSS keys are in the account data stored in the server
275
+ verifyKey ( "master" ) ;
276
+ verifyKey ( "self_signing" ) ;
277
+ verifyKey ( "user_signing" ) ;
278
+ } ) ;
279
+ } ,
280
+ ) ;
263
281
264
282
it ( "creating a DM should work, being e2e-encrypted / user verification" , function ( this : CryptoTestContext ) {
265
283
skipIfRustCrypto ( ) ;
0 commit comments