From 2571f54e8b2b8b06a3ac3a1090a660f7cedbc66a Mon Sep 17 00:00:00 2001 From: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> Date: Wed, 24 May 2023 10:50:05 +0100 Subject: [PATCH] Cypress: skip tests known to fail when using Rust crypto (#10873) * Cypress: skip tests known to fail when using Rust crypto ... which means we can then run the cypress test suite against Element Web R to check we aren't introducing regressions. * Update cypress/e2e/register/register.spec.ts * Use env var to detect rust crypto * Hoist `skipIfRustCrypto` call earlier --- cypress/e2e/crypto/complete-security.spec.ts | 3 +++ cypress/e2e/crypto/crypto.spec.ts | 5 +++++ cypress/e2e/crypto/decryption-failure.spec.ts | 2 ++ cypress/support/config.json.ts | 4 +++- cypress/support/util.ts | 19 +++++++++++++++++-- 5 files changed, 30 insertions(+), 3 deletions(-) diff --git a/cypress/e2e/crypto/complete-security.spec.ts b/cypress/e2e/crypto/complete-security.spec.ts index 0838abd459..5afbe542ce 100644 --- a/cypress/e2e/crypto/complete-security.spec.ts +++ b/cypress/e2e/crypto/complete-security.spec.ts @@ -18,6 +18,7 @@ import type { VerificationRequest } from "matrix-js-sdk/src/crypto/verification/ import { HomeserverInstance } from "../../plugins/utils/homeserver"; import { handleVerificationRequest, waitForVerificationRequest } from "./utils"; import { CypressBot } from "../../support/bot"; +import { skipIfRustCrypto } from "../../support/util"; describe("Complete security", () => { let homeserver: HomeserverInstance; @@ -46,6 +47,8 @@ describe("Complete security", () => { }); it("should walk through device verification if we have a signed device", () => { + skipIfRustCrypto(); + // create a new user, and have it bootstrap cross-signing let botClient: CypressBot; cy.getBot(homeserver, { displayName: "Jeff" }) diff --git a/cypress/e2e/crypto/crypto.spec.ts b/cypress/e2e/crypto/crypto.spec.ts index 5c3bb857fb..4e3aad3a1a 100644 --- a/cypress/e2e/crypto/crypto.spec.ts +++ b/cypress/e2e/crypto/crypto.spec.ts @@ -20,6 +20,7 @@ import type { CypressBot } from "../../support/bot"; import { HomeserverInstance } from "../../plugins/utils/homeserver"; import { UserCredentials } from "../../support/login"; import { EmojiMapping, handleVerificationRequest, waitForVerificationRequest } from "./utils"; +import { skipIfRustCrypto } from "../../support/util"; interface CryptoTestContext extends Mocha.Context { homeserver: HomeserverInstance; @@ -152,6 +153,7 @@ describe("Cryptography", function () { }); it("setting up secure key backup should work", () => { + skipIfRustCrypto(); cy.openUserSettings("Security & Privacy"); cy.findByRole("button", { name: "Set up Secure Backup" }).click(); cy.get(".mx_Dialog").within(() => { @@ -175,6 +177,7 @@ describe("Cryptography", function () { }); it("creating a DM should work, being e2e-encrypted / user verification", function (this: CryptoTestContext) { + skipIfRustCrypto(); cy.bootstrapCrossSigning(aliceCredentials); startDMWithBob.call(this); // send first message @@ -196,6 +199,7 @@ describe("Cryptography", function () { }); it("should allow verification when there is no existing DM", function (this: CryptoTestContext) { + skipIfRustCrypto(); cy.bootstrapCrossSigning(aliceCredentials); autoJoin(this.bob); @@ -214,6 +218,7 @@ describe("Cryptography", function () { }); it("should show the correct shield on edited e2e events", function (this: CryptoTestContext) { + skipIfRustCrypto(); cy.bootstrapCrossSigning(aliceCredentials); // bob has a second, not cross-signed, device diff --git a/cypress/e2e/crypto/decryption-failure.spec.ts b/cypress/e2e/crypto/decryption-failure.spec.ts index 64df3f5a2c..4de2af0e81 100644 --- a/cypress/e2e/crypto/decryption-failure.spec.ts +++ b/cypress/e2e/crypto/decryption-failure.spec.ts @@ -19,6 +19,7 @@ import type { MatrixClient } from "matrix-js-sdk/src/matrix"; import { HomeserverInstance } from "../../plugins/utils/homeserver"; import { UserCredentials } from "../../support/login"; import { handleVerificationRequest } from "./utils"; +import { skipIfRustCrypto } from "../../support/util"; const ROOM_NAME = "Test room"; const TEST_USER = "Alia"; @@ -67,6 +68,7 @@ describe("Decryption Failure Bar", () => { let roomId: string; beforeEach(function () { + skipIfRustCrypto(); cy.startHomeserver("default").then((hs: HomeserverInstance) => { homeserver = hs; cy.initTestUser(homeserver, TEST_USER) diff --git a/cypress/support/config.json.ts b/cypress/support/config.json.ts index fd3787939b..874b410e88 100644 --- a/cypress/support/config.json.ts +++ b/cypress/support/config.json.ts @@ -20,6 +20,8 @@ limitations under the License. * we make requests to the live `matrix.org`, which makes our tests dependent on matrix.org being up and responsive. */ +import { isRustCryptoEnabled } from "./util"; + const CONFIG_JSON = { // This is deliberately quite a minimal config.json, so that we can test that the default settings // actually work. @@ -40,7 +42,7 @@ beforeEach(() => { const configJson = CONFIG_JSON; // configure element to use rust crypto if the env var tells us so - if (Cypress.env("RUST_CRYPTO")) { + if (isRustCryptoEnabled()) { configJson["features"] = { feature_rust_crypto: true, }; diff --git a/cypress/support/util.ts b/cypress/support/util.ts index 6855379bda..c61a8c755b 100644 --- a/cypress/support/util.ts +++ b/cypress/support/util.ts @@ -56,5 +56,20 @@ cy.all = function all(commands): Cypress.Chainable { return cy.wrap(resultArray, { log: false }); }; -// Needed to make this file a module -export {}; +/** + * Check if Cypress has been configured to enable rust crypto, and bail out if so. + */ +export function skipIfRustCrypto() { + if (isRustCryptoEnabled()) { + cy.log("Skipping due to rust crypto"); + //@ts-ignore: 'state' is a secret internal command + cy.state("runnable").skip(); + } +} + +/** + * Determine if Cypress has been configured to enable rust crypto (by checking the environment variable) + */ +export function isRustCryptoEnabled(): boolean { + return !!Cypress.env("RUST_CRYPTO"); +}