Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit b84a230

Browse files
authored
Cypress: Run setting up secure key backup should work test for both verified and unverified devices (#11119)
* Add `cypress-each` dev dependencies * Run `setting up secure key backup should work` test for both verified and unverified device.
1 parent 8aa46b3 commit b84a230

File tree

4 files changed

+105
-79
lines changed

4 files changed

+105
-79
lines changed

cypress/e2e/crypto/crypto.spec.ts

+97-79
Original file line numberDiff line numberDiff line change
@@ -174,92 +174,110 @@ describe("Cryptography", function () {
174174
cy.stopHomeserver(this.homeserver);
175175
});
176176

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;
220195
});
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+
}
233197

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();
248204
cy.contains(".mx_Dialog_primary:not([disabled])", "Continue").click();
205+
}
249206

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+
});
251238

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");
255243
});
256244

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+
);
263281

264282
it("creating a DM should work, being e2e-encrypted / user verification", function (this: CryptoTestContext) {
265283
skipIfRustCrypto();

cypress/support/util.ts

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ limitations under the License.
1616

1717
/// <reference types="cypress" />
1818

19+
import "cypress-each";
20+
1921
declare global {
2022
// eslint-disable-next-line @typescript-eslint/no-namespace
2123
namespace Cypress {

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@
181181
"chokidar": "^3.5.1",
182182
"cypress": "^12.0.0",
183183
"cypress-axe": "^1.0.0",
184+
"cypress-each": "^1.13.3",
184185
"cypress-multi-reporters": "^1.6.1",
185186
"cypress-real-events": "^1.7.1",
186187
"eslint": "8.42.0",

yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -3638,6 +3638,11 @@ cypress-axe@^1.0.0:
36383638
resolved "https://registry.yarnpkg.com/cypress-axe/-/cypress-axe-1.4.0.tgz#e67482bfe9e740796bf77c7823f19781a8a2faff"
36393639
integrity sha512-Ut7NKfzjyKm0BEbt2WxuKtLkIXmx6FD2j0RwdvO/Ykl7GmB/qRQkwbKLk3VP35+83hiIr8GKD04PDdrTK5BnyA==
36403640

3641+
cypress-each@^1.13.3:
3642+
version "1.13.3"
3643+
resolved "https://registry.yarnpkg.com/cypress-each/-/cypress-each-1.13.3.tgz#c0f59628975164e23a3fd10090b587a66ed9438e"
3644+
integrity sha512-aNFoDuybFAQ7OObbeO5yxBGmXkGKVAcT1wLHLiL3+HQi+g+q3vECbn4J9cYOXJ7yYfbcBLh8dgQd/IG3Ls2z7A==
3645+
36413646
cypress-multi-reporters@^1.6.1:
36423647
version "1.6.3"
36433648
resolved "https://registry.yarnpkg.com/cypress-multi-reporters/-/cypress-multi-reporters-1.6.3.tgz#0f0da8db4caf8d7a21f94e5209148348416d7c71"

0 commit comments

Comments
 (0)