diff --git a/cypress/e2e/crypto/crypto.spec.ts b/cypress/e2e/crypto/crypto.spec.ts index f3fd9bba53..79e3a7d463 100644 --- a/cypress/e2e/crypto/crypto.spec.ts +++ b/cypress/e2e/crypto/crypto.spec.ts @@ -174,92 +174,110 @@ describe("Cryptography", function () { cy.stopHomeserver(this.homeserver); }); - describe("setting up secure key backup should work", () => { - /** - * Verify that the `m.cross_signing.${keyType}` key is available on the account data on the server - * @param keyType - */ - function verifyKey(keyType: string) { - return cy - .getClient() - .then((cli) => cy.wrap(cli.getAccountDataFromServer(`m.cross_signing.${keyType}`))) - .then((accountData: { encrypted: Record> }) => { - expect(accountData.encrypted).to.exist; - const keys = Object.keys(accountData.encrypted); - const key = accountData.encrypted[keys[0]]; - expect(key.ciphertext).to.exist; - expect(key.iv).to.exist; - expect(key.mac).to.exist; - }); - } - - /** - * Click on download button and continue - */ - function downloadKey() { - // Clicking download instead of Copy because of https://github.com/cypress-io/cypress/issues/2851 - cy.findByRole("button", { name: "Download" }).click(); - cy.contains(".mx_Dialog_primary:not([disabled])", "Continue").click(); - } - - it("by recovery code", () => { - skipIfRustCrypto(); - cy.openUserSettings("Security & Privacy"); - cy.findByRole("button", { name: "Set up Secure Backup" }).click(); - cy.get(".mx_Dialog").within(() => { - // Recovery key is selected by default - cy.findByRole("button", { name: "Continue" }).click(); - cy.get(".mx_CreateSecretStorageDialog_recoveryKey code").invoke("text").as("securityKey"); - - downloadKey(); - - cy.get(".mx_InteractiveAuthDialog").within(() => { - cy.get(".mx_Dialog_title").within(() => { - cy.findByText("Setting up keys").should("exist"); - cy.findByText("Setting up keys").should("not.exist"); + describe.each([{ isDeviceVerified: true }, { isDeviceVerified: false }])( + "setting up secure key backup should work %j", + ({ isDeviceVerified }) => { + /** + * Verify that the `m.cross_signing.${keyType}` key is available on the account data on the server + * @param keyType + */ + function verifyKey(keyType: string) { + return cy + .getClient() + .then((cli) => cy.wrap(cli.getAccountDataFromServer(`m.cross_signing.${keyType}`))) + .then((accountData: { encrypted: Record> }) => { + expect(accountData.encrypted).to.exist; + const keys = Object.keys(accountData.encrypted); + const key = accountData.encrypted[keys[0]]; + expect(key.ciphertext).to.exist; + expect(key.iv).to.exist; + expect(key.mac).to.exist; }); + } + + /** + * Click on download button and continue + */ + function downloadKey() { + // Clicking download instead of Copy because of https://github.com/cypress-io/cypress/issues/2851 + cy.findByRole("button", { name: "Download" }).click(); + cy.contains(".mx_Dialog_primary:not([disabled])", "Continue").click(); + } + + it("by recovery code", () => { + skipIfRustCrypto(); + + // Verified the device + if (isDeviceVerified) { + cy.bootstrapCrossSigning(aliceCredentials); + } + + cy.openUserSettings("Security & Privacy"); + cy.findByRole("button", { name: "Set up Secure Backup" }).click(); + cy.get(".mx_Dialog").within(() => { + // Recovery key is selected by default + cy.findByRole("button", { name: "Continue" }).click(); + cy.get(".mx_CreateSecretStorageDialog_recoveryKey code").invoke("text").as("securityKey"); + + downloadKey(); + + // When the device is verified, the `Setting up keys` step is skipped + if (!isDeviceVerified) { + cy.get(".mx_InteractiveAuthDialog").within(() => { + cy.get(".mx_Dialog_title").within(() => { + cy.findByText("Setting up keys").should("exist"); + cy.findByText("Setting up keys").should("not.exist"); + }); + }); + } + + cy.findByText("Secure Backup successful").should("exist"); + cy.findByRole("button", { name: "Done" }).click(); + cy.findByText("Secure Backup successful").should("not.exist"); }); - cy.findByText("Secure Backup successful").should("exist"); - cy.findByRole("button", { name: "Done" }).click(); - cy.findByText("Secure Backup successful").should("not.exist"); + // Verify that the SSSS keys are in the account data stored in the server + verifyKey("master"); + verifyKey("self_signing"); + verifyKey("user_signing"); }); - // Verify that the SSSS keys are in the account data stored in the server - verifyKey("master"); - verifyKey("self_signing"); - verifyKey("user_signing"); - }); + it("by passphrase", () => { + skipIfRustCrypto(); - it("by passphrase", () => { - skipIfRustCrypto(); - cy.openUserSettings("Security & Privacy"); - cy.findByRole("button", { name: "Set up Secure Backup" }).click(); - cy.get(".mx_Dialog").within(() => { - // Select passphrase option - cy.findByText("Enter a Security Phrase").click(); - cy.findByRole("button", { name: "Continue" }).click(); + // Verified the device + if (isDeviceVerified) { + cy.bootstrapCrossSigning(aliceCredentials); + } - // Fill passphrase input - cy.get("input").type("new passphrase for setting up a secure key backup"); - cy.contains(".mx_Dialog_primary:not([disabled])", "Continue").click(); - // Confirm passphrase - cy.get("input").type("new passphrase for setting up a secure key backup"); - cy.contains(".mx_Dialog_primary:not([disabled])", "Continue").click(); + cy.openUserSettings("Security & Privacy"); + cy.findByRole("button", { name: "Set up Secure Backup" }).click(); + cy.get(".mx_Dialog").within(() => { + // Select passphrase option + cy.findByText("Enter a Security Phrase").click(); + cy.findByRole("button", { name: "Continue" }).click(); - downloadKey(); + // Fill passphrase input + cy.get("input").type("new passphrase for setting up a secure key backup"); + cy.contains(".mx_Dialog_primary:not([disabled])", "Continue").click(); + // Confirm passphrase + cy.get("input").type("new passphrase for setting up a secure key backup"); + cy.contains(".mx_Dialog_primary:not([disabled])", "Continue").click(); - cy.findByText("Secure Backup successful").should("exist"); - cy.findByRole("button", { name: "Done" }).click(); - cy.findByText("Secure Backup successful").should("not.exist"); + downloadKey(); + + cy.findByText("Secure Backup successful").should("exist"); + cy.findByRole("button", { name: "Done" }).click(); + cy.findByText("Secure Backup successful").should("not.exist"); + }); + + // Verify that the SSSS keys are in the account data stored in the server + verifyKey("master"); + verifyKey("self_signing"); + verifyKey("user_signing"); }); - - // Verify that the SSSS keys are in the account data stored in the server - verifyKey("master"); - verifyKey("self_signing"); - verifyKey("user_signing"); - }); - }); + }, + ); it("creating a DM should work, being e2e-encrypted / user verification", function (this: CryptoTestContext) { skipIfRustCrypto(); diff --git a/cypress/support/util.ts b/cypress/support/util.ts index c61a8c755b..300ca0b191 100644 --- a/cypress/support/util.ts +++ b/cypress/support/util.ts @@ -16,6 +16,8 @@ limitations under the License. /// +import "cypress-each"; + declare global { // eslint-disable-next-line @typescript-eslint/no-namespace namespace Cypress { diff --git a/package.json b/package.json index ba399cadc4..67639835d2 100644 --- a/package.json +++ b/package.json @@ -181,6 +181,7 @@ "chokidar": "^3.5.1", "cypress": "^12.0.0", "cypress-axe": "^1.0.0", + "cypress-each": "^1.13.3", "cypress-multi-reporters": "^1.6.1", "cypress-real-events": "^1.7.1", "eslint": "8.42.0", diff --git a/yarn.lock b/yarn.lock index b2e53c9c28..9cee635139 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3638,6 +3638,11 @@ cypress-axe@^1.0.0: resolved "https://registry.yarnpkg.com/cypress-axe/-/cypress-axe-1.4.0.tgz#e67482bfe9e740796bf77c7823f19781a8a2faff" integrity sha512-Ut7NKfzjyKm0BEbt2WxuKtLkIXmx6FD2j0RwdvO/Ykl7GmB/qRQkwbKLk3VP35+83hiIr8GKD04PDdrTK5BnyA== +cypress-each@^1.13.3: + version "1.13.3" + resolved "https://registry.yarnpkg.com/cypress-each/-/cypress-each-1.13.3.tgz#c0f59628975164e23a3fd10090b587a66ed9438e" + integrity sha512-aNFoDuybFAQ7OObbeO5yxBGmXkGKVAcT1wLHLiL3+HQi+g+q3vECbn4J9cYOXJ7yYfbcBLh8dgQd/IG3Ls2z7A== + cypress-multi-reporters@^1.6.1: version "1.6.3" resolved "https://registry.yarnpkg.com/cypress-multi-reporters/-/cypress-multi-reporters-1.6.3.tgz#0f0da8db4caf8d7a21f94e5209148348416d7c71"