@@ -19,126 +19,130 @@ import {
1919test . describe ( "Encryption tab" , ( ) => {
2020 test . use ( { displayName : "Alice" } ) ;
2121
22- let recoveryKey : GeneratedSecretStorageKey ;
23- let expectedBackupVersion : string ;
24-
25- test . beforeEach ( async ( { page, homeserver, credentials } ) => {
26- // The bot bootstraps cross-signing, creates a key backup and sets up a recovery key
27- const res = await createBot ( page , homeserver , credentials ) ;
28- recoveryKey = res . recoveryKey ;
29- expectedBackupVersion = res . expectedBackupVersion ;
30- } ) ;
31-
32- test (
33- "should show a 'Verify this device' button if the device is unverified" ,
34- { tag : "@screenshot" } ,
35- async ( { page, app, util } ) => {
36- const dialog = await util . openEncryptionTab ( ) ;
37- const content = util . getEncryptionTabContent ( ) ;
38-
39- // The user's device is in an unverified state, therefore the only option available to them here is to verify it
40- const verifyButton = dialog . getByRole ( "button" , { name : "Verify this device" } ) ;
41- await expect ( verifyButton ) . toBeVisible ( ) ;
42- await expect ( content ) . toMatchScreenshot ( "verify-device-encryption-tab.png" ) ;
43- await verifyButton . click ( ) ;
44-
45- await util . verifyDevice ( recoveryKey ) ;
46-
47- await expect ( content ) . toMatchScreenshot ( "default-tab.png" , {
48- mask : [ content . getByTestId ( "deviceId" ) , content . getByTestId ( "sessionKey" ) ] ,
49- } ) ;
50-
51- // Check that our device is now cross-signed
52- await checkDeviceIsCrossSigned ( app ) ;
53-
54- // Check that the current device is connected to key backup
55- // The backup decryption key should be in cache also, as we got it directly from the 4S
56- await checkDeviceIsConnectedKeyBackup ( app , expectedBackupVersion , true ) ;
57- } ,
58- ) ;
59-
60- // Test what happens if the cross-signing secrets are in secret storage but are not cached in the local DB.
61- //
62- // This can happen if we verified another device and secret-gossiping failed, or the other device itself lacked the secrets.
63- // We simulate this case by deleting the cached secrets in the indexedDB.
64- test (
65- "should prompt to enter the recovery key when the secrets are not cached locally" ,
66- { tag : "@screenshot" } ,
67- async ( { page, app, util } ) => {
22+ test . describe ( "when encryption is set up" , ( ) => {
23+ let recoveryKey : GeneratedSecretStorageKey ;
24+ let expectedBackupVersion : string ;
25+
26+ test . beforeEach ( async ( { page, homeserver, credentials } ) => {
27+ // The bot bootstraps cross-signing, creates a key backup and sets up a recovery key
28+ const res = await createBot ( page , homeserver , credentials ) ;
29+ recoveryKey = res . recoveryKey ;
30+ expectedBackupVersion = res . expectedBackupVersion ;
31+ } ) ;
32+
33+ test (
34+ "should show a 'Verify this device' button if the device is unverified" ,
35+ { tag : "@screenshot" } ,
36+ async ( { page, app, util } ) => {
37+ const dialog = await util . openEncryptionTab ( ) ;
38+ const content = util . getEncryptionTabContent ( ) ;
39+
40+ // The user's device is in an unverified state, therefore the only option available to them here is to verify it
41+ const verifyButton = dialog . getByRole ( "button" , { name : "Verify this device" } ) ;
42+ await expect ( verifyButton ) . toBeVisible ( ) ;
43+ await expect ( content ) . toMatchScreenshot ( "verify-device-encryption-tab.png" ) ;
44+ await verifyButton . click ( ) ;
45+
46+ await util . verifyDevice ( recoveryKey ) ;
47+
48+ await expect ( content ) . toMatchScreenshot ( "default-tab.png" , {
49+ mask : [ content . getByTestId ( "deviceId" ) , content . getByTestId ( "sessionKey" ) ] ,
50+ } ) ;
51+
52+ // Check that our device is now cross-signed
53+ await checkDeviceIsCrossSigned ( app ) ;
54+
55+ // Check that the current device is connected to key backup
56+ // The backup decryption key should be in cache also, as we got it directly from the 4S
57+ await checkDeviceIsConnectedKeyBackup ( app , expectedBackupVersion , true ) ;
58+ } ,
59+ ) ;
60+
61+ // Test what happens if the cross-signing secrets are in secret storage but are not cached in the local DB.
62+ //
63+ // This can happen if we verified another device and secret-gossiping failed, or the other device itself lacked the secrets.
64+ // We simulate this case by deleting the cached secrets in the indexedDB.
65+ test (
66+ "should prompt to enter the recovery key when the secrets are not cached locally" ,
67+ { tag : "@screenshot" } ,
68+ async ( { page, app, util } ) => {
69+ await verifySession ( app , recoveryKey . encodedPrivateKey ) ;
70+ // We need to delete the cached secrets
71+ await deleteCachedSecrets ( page ) ;
72+
73+ await util . openEncryptionTab ( ) ;
74+ // We ask the user to enter the recovery key
75+ const dialog = util . getEncryptionTabContent ( ) ;
76+ const enterKeyButton = dialog . getByRole ( "button" , { name : "Enter recovery key" } ) ;
77+ await expect ( enterKeyButton ) . toBeVisible ( ) ;
78+ await expect ( dialog ) . toMatchScreenshot ( "out-of-sync-recovery.png" ) ;
79+ await enterKeyButton . click ( ) ;
80+
81+ // Fill the recovery key
82+ await util . enterRecoveryKey ( recoveryKey ) ;
83+ await expect ( dialog ) . toMatchScreenshot ( "default-tab.png" , {
84+ mask : [ dialog . getByTestId ( "deviceId" ) , dialog . getByTestId ( "sessionKey" ) ] ,
85+ } ) ;
86+
87+ // Check that our device is now cross-signed
88+ await checkDeviceIsCrossSigned ( app ) ;
89+
90+ // Check that the current device is connected to key backup
91+ // The backup decryption key should be in cache also, as we got it directly from the 4S
92+ await checkDeviceIsConnectedKeyBackup ( app , expectedBackupVersion , true ) ;
93+ } ,
94+ ) ;
95+
96+ test ( "should display the reset identity panel when the user clicks on 'Forgot recovery key?'" , async ( {
97+ page,
98+ app,
99+ util,
100+ } ) => {
68101 await verifySession ( app , recoveryKey . encodedPrivateKey ) ;
69102 // We need to delete the cached secrets
70103 await deleteCachedSecrets ( page ) ;
71104
105+ // The "Key storage is out sync" section is displayed and the user click on the "Forgot recovery key?" button
72106 await util . openEncryptionTab ( ) ;
73- // We ask the user to enter the recovery key
74107 const dialog = util . getEncryptionTabContent ( ) ;
75- const enterKeyButton = dialog . getByRole ( "button" , { name : "Enter recovery key" } ) ;
76- await expect ( enterKeyButton ) . toBeVisible ( ) ;
77- await expect ( dialog ) . toMatchScreenshot ( "out-of-sync-recovery.png" ) ;
78- await enterKeyButton . click ( ) ;
79-
80- // Fill the recovery key
81- await util . enterRecoveryKey ( recoveryKey ) ;
82- await expect ( dialog ) . toMatchScreenshot ( "default-tab.png" , {
83- mask : [ dialog . getByTestId ( "deviceId" ) , dialog . getByTestId ( "sessionKey" ) ] ,
84- } ) ;
85-
86- // Check that our device is now cross-signed
87- await checkDeviceIsCrossSigned ( app ) ;
88-
89- // Check that the current device is connected to key backup
90- // The backup decryption key should be in cache also, as we got it directly from the 4S
91- await checkDeviceIsConnectedKeyBackup ( app , expectedBackupVersion , true ) ;
92- } ,
93- ) ;
94-
95- test ( "should display the reset identity panel when the user clicks on 'Forgot recovery key?'" , async ( {
96- page,
97- app,
98- util,
99- } ) => {
100- await verifySession ( app , recoveryKey . encodedPrivateKey ) ;
101- // We need to delete the cached secrets
102- await deleteCachedSecrets ( page ) ;
103-
104- // The "Key storage is out sync" section is displayed and the user click on the "Forgot recovery key?" button
105- await util . openEncryptionTab ( ) ;
106- const dialog = util . getEncryptionTabContent ( ) ;
107- await dialog . getByRole ( "button" , { name : "Forgot recovery key?" } ) . click ( ) ;
108-
109- // The user is prompted to reset their identity
110- await expect ( dialog . getByText ( "Forgot your recovery key? You’ll need to reset your identity." ) ) . toBeVisible ( ) ;
111- } ) ;
108+ await dialog . getByRole ( "button" , { name : "Forgot recovery key?" } ) . click ( ) ;
112109
113- test ( "should warn before turning off key storage" , { tag : "@screenshot" } , async ( { page, app, util } ) => {
114- await verifySession ( app , recoveryKey . encodedPrivateKey ) ;
115- await util . openEncryptionTab ( ) ;
110+ // The user is prompted to reset their identity
111+ await expect (
112+ dialog . getByText ( "Forgot your recovery key? You’ll need to reset your identity." ) ,
113+ ) . toBeVisible ( ) ;
114+ } ) ;
115+
116+ test ( "should warn before turning off key storage" , { tag : "@screenshot" } , async ( { page, app, util } ) => {
117+ await verifySession ( app , recoveryKey . encodedPrivateKey ) ;
118+ await util . openEncryptionTab ( ) ;
116119
117- await page . getByRole ( "checkbox" , { name : "Allow key storage" } ) . click ( ) ;
120+ await page . getByRole ( "checkbox" , { name : "Allow key storage" } ) . click ( ) ;
118121
119- await expect (
120- page . getByRole ( "heading" , { name : "Are you sure you want to turn off key storage and delete it?" } ) ,
121- ) . toBeVisible ( ) ;
122+ await expect (
123+ page . getByRole ( "heading" , { name : "Are you sure you want to turn off key storage and delete it?" } ) ,
124+ ) . toBeVisible ( ) ;
122125
123- await expect ( util . getEncryptionTabContent ( ) ) . toMatchScreenshot ( "delete-key-storage-confirm.png" ) ;
126+ await expect ( util . getEncryptionTabContent ( ) ) . toMatchScreenshot ( "delete-key-storage-confirm.png" ) ;
124127
125- const deleteRequestPromises = [
126- page . waitForRequest ( ( req ) => req . url ( ) . endsWith ( "/account_data/m.cross_signing.master" ) ) ,
127- page . waitForRequest ( ( req ) => req . url ( ) . endsWith ( "/account_data/m.cross_signing.self_signing" ) ) ,
128- page . waitForRequest ( ( req ) => req . url ( ) . endsWith ( "/account_data/m.cross_signing.user_signing" ) ) ,
129- page . waitForRequest ( ( req ) => req . url ( ) . endsWith ( "/account_data/m.megolm_backup.v1" ) ) ,
130- page . waitForRequest ( ( req ) => req . url ( ) . endsWith ( "/account_data/m.secret_storage.default_key" ) ) ,
131- page . waitForRequest ( ( req ) => req . url ( ) . includes ( "/account_data/m.secret_storage.key." ) ) ,
132- ] ;
128+ const deleteRequestPromises = [
129+ page . waitForRequest ( ( req ) => req . url ( ) . endsWith ( "/account_data/m.cross_signing.master" ) ) ,
130+ page . waitForRequest ( ( req ) => req . url ( ) . endsWith ( "/account_data/m.cross_signing.self_signing" ) ) ,
131+ page . waitForRequest ( ( req ) => req . url ( ) . endsWith ( "/account_data/m.cross_signing.user_signing" ) ) ,
132+ page . waitForRequest ( ( req ) => req . url ( ) . endsWith ( "/account_data/m.megolm_backup.v1" ) ) ,
133+ page . waitForRequest ( ( req ) => req . url ( ) . endsWith ( "/account_data/m.secret_storage.default_key" ) ) ,
134+ page . waitForRequest ( ( req ) => req . url ( ) . includes ( "/account_data/m.secret_storage.key." ) ) ,
135+ ] ;
133136
134- await page . getByRole ( "button" , { name : "Delete key storage" } ) . click ( ) ;
137+ await page . getByRole ( "button" , { name : "Delete key storage" } ) . click ( ) ;
135138
136- await expect ( page . getByRole ( "checkbox" , { name : "Allow key storage" } ) ) . not . toBeChecked ( ) ;
139+ await expect ( page . getByRole ( "checkbox" , { name : "Allow key storage" } ) ) . not . toBeChecked ( ) ;
137140
138- for ( const prom of deleteRequestPromises ) {
139- const request = await prom ;
140- expect ( request . method ( ) ) . toBe ( "PUT" ) ;
141- expect ( request . postData ( ) ) . toBe ( JSON . stringify ( { } ) ) ;
142- }
141+ for ( const prom of deleteRequestPromises ) {
142+ const request = await prom ;
143+ expect ( request . method ( ) ) . toBe ( "PUT" ) ;
144+ expect ( request . postData ( ) ) . toBe ( JSON . stringify ( { } ) ) ;
145+ }
146+ } ) ;
143147 } ) ;
144148} ) ;
0 commit comments