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

Commit

Permalink
fix package.json conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
Alun Turner committed Jul 12, 2023
2 parents 7e2f37d + 44615b2 commit 798e571
Show file tree
Hide file tree
Showing 29 changed files with 674 additions and 360 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cypress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ jobs:
record: true
parallel: true
command-prefix: "yarn percy exec --parallel --"
config: '{"reporter":"cypress-multi-reporters", "reporterOptions": { "configFile": "cypress-ci-reporter-config.json" } }'
config: '{"reporter":"cypress-multi-reporters", "reporterOptions": { "configFile": "cypress-ci-reporter-config.json" }, "morgan": false }'
ci-build-id: ${{ needs.prepare.outputs.uuid }}
env:
# pass the Dashboard record key as an environment variable
Expand Down
4 changes: 4 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,8 @@ export default defineConfig({
runMode: 4,
openMode: 0,
},

// disable logging of HTTP requests made to the Cypress server. They are noisy and not very helpful.
// @ts-ignore https://github.com/cypress-io/cypress/issues/26284
morgan: false,
});
51 changes: 50 additions & 1 deletion cypress/e2e/crypto/verification.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ describe("Device verification", () => {
cy.window({ log: false }).should("have.property", "matrixcs");

// Create a new device for alice
cy.getBot(homeserver, { rustCrypto: true, bootstrapCrossSigning: true }).then((bot) => {
cy.getBot(homeserver, {
rustCrypto: true,
bootstrapCrossSigning: true,
bootstrapSecretStorage: true,
}).then((bot) => {
aliceBotClient = bot;
});
});
Expand Down Expand Up @@ -87,6 +91,51 @@ describe("Device verification", () => {
checkDeviceIsCrossSigned();
});

it("Verify device during login with Security Phrase", () => {
logIntoElement(homeserver.baseUrl, aliceBotClient.getUserId(), aliceBotClient.__cypress_password);

// Select the security phrase
cy.get(".mx_AuthPage").within(() => {
cy.findByRole("button", { name: "Verify with Security Key or Phrase" }).click();
});

// Fill the passphrase
cy.get(".mx_Dialog").within(() => {
cy.get("input").type("new passphrase");
cy.contains(".mx_Dialog_primary:not([disabled])", "Continue").click();
});

cy.get(".mx_AuthPage").within(() => {
cy.findByRole("button", { name: "Done" }).click();
});

// Check that our device is now cross-signed
checkDeviceIsCrossSigned();
});

it("Verify device during login with Security Key", () => {
logIntoElement(homeserver.baseUrl, aliceBotClient.getUserId(), aliceBotClient.__cypress_password);

// Select the security phrase
cy.get(".mx_AuthPage").within(() => {
cy.findByRole("button", { name: "Verify with Security Key or Phrase" }).click();
});

// Fill the security key
cy.get(".mx_Dialog").within(() => {
cy.findByRole("button", { name: "use your Security Key" }).click();
cy.get("#mx_securityKey").type(aliceBotClient.__cypress_recovery_key.encodedPrivateKey);
cy.contains(".mx_Dialog_primary:not([disabled])", "Continue").click();
});

cy.get(".mx_AuthPage").within(() => {
cy.findByRole("button", { name: "Done" }).click();
});

// Check that our device is now cross-signed
checkDeviceIsCrossSigned();
});

it("Handle incoming verification request with SAS", () => {
logIntoElement(homeserver.baseUrl, aliceBotClient.getUserId(), aliceBotClient.__cypress_password);

Expand Down
4 changes: 4 additions & 0 deletions cypress/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ limitations under the License.
*/

/// <reference types="cypress" />
import installLogsPrinter from "cypress-terminal-report/src/installLogsPrinter";

import PluginEvents = Cypress.PluginEvents;
import PluginConfigOptions = Cypress.PluginConfigOptions;
Expand All @@ -35,4 +36,7 @@ export default function (on: PluginEvents, config: PluginConfigOptions) {
slidingSyncProxyDocker(on, config);
webserver(on, config);
log(on, config);
installLogsPrinter(on, {
// printLogsToConsole: "always",
});
}
39 changes: 38 additions & 1 deletion cypress/support/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
/// <reference types="cypress" />

import type { ISendEventResponse, MatrixClient, Room } from "matrix-js-sdk/src/matrix";
import type { GeneratedSecretStorageKey } from "matrix-js-sdk/src/crypto-api";
import type { AddSecretStorageKeyOpts } from "matrix-js-sdk/src/secret-storage";
import { HomeserverInstance } from "../plugins/utils/homeserver";
import { Credentials } from "./homeserver";
import Chainable = Cypress.Chainable;
Expand Down Expand Up @@ -47,6 +49,10 @@ interface CreateBotOpts {
* Whether to use the rust crypto impl. Defaults to false (for now!)
*/
rustCrypto?: boolean;
/**
* Whether or not to bootstrap the secret storage
*/
bootstrapSecretStorage?: boolean;
}

const defaultCreateBotOptions = {
Expand All @@ -58,6 +64,7 @@ const defaultCreateBotOptions = {

export interface CypressBot extends MatrixClient {
__cypress_password: string;
__cypress_recovery_key: GeneratedSecretStorageKey;
}

declare global {
Expand Down Expand Up @@ -143,6 +150,24 @@ function setupBotClient(
Object.assign(keys, k);
};

// Store the cached secret storage key and return it when `getSecretStorageKey` is called
let cachedKey: { keyId: string; key: Uint8Array };
const cacheSecretStorageKey = (keyId: string, keyInfo: AddSecretStorageKeyOpts, key: Uint8Array) => {
cachedKey = {
keyId,
key,
};
};

const getSecretStorageKey = () => Promise.resolve<[string, Uint8Array]>([cachedKey.keyId, cachedKey.key]);

const cryptoCallbacks = {
getCrossSigningKey,
saveCrossSigningKeys,
cacheSecretStorageKey,
getSecretStorageKey,
};

const cli = new win.matrixcs.MatrixClient({
baseUrl: homeserver.baseUrl,
userId: credentials.userId,
Expand All @@ -151,7 +176,7 @@ function setupBotClient(
store: new win.matrixcs.MemoryStore(),
scheduler: new win.matrixcs.MatrixScheduler(),
cryptoStore: new win.matrixcs.MemoryCryptoStore(),
cryptoCallbacks: { getCrossSigningKey, saveCrossSigningKeys },
cryptoCallbacks,
});

if (opts.autoAcceptInvites) {
Expand Down Expand Up @@ -192,6 +217,18 @@ function setupBotClient(
},
});
}

if (opts.bootstrapSecretStorage) {
const passphrase = "new passphrase";
const recoveryKey = await cli.getCrypto().createRecoveryKeyFromPassphrase(passphrase);
Object.assign(cli, { __cypress_recovery_key: recoveryKey });

await cli.getCrypto()!.bootstrapSecretStorage({
setupNewSecretStorage: true,
createSecretStorageKey: () => Promise.resolve(recoveryKey),
});
}

return cli;
},
);
Expand Down
18 changes: 18 additions & 0 deletions cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ limitations under the License.
import "@percy/cypress";
import "cypress-real-events";
import "@testing-library/cypress/add-commands";
import installLogsCollector from "cypress-terminal-report/src/installLogsCollector";

import "./config.json";
import "./homeserver";
Expand All @@ -39,3 +40,20 @@ import "./network";
import "./composer";
import "./proxy";
import "./axe";

installLogsCollector({
// specify the types of logs to collect (and report to the node console at the end of the test)
collectTypes: [
"cons:log",
"cons:info",
"cons:warn",
"cons:error",
// "cons:debug",
"cy:log",
"cy:xhr",
"cy:fetch",
"cy:request",
"cy:intercept",
"cy:command",
],
});
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"@babel/runtime": "^7.12.5",
"@matrix-org/analytics-events": "^0.5.0",
"@matrix-org/matrix-wysiwyg": "^2.3.1",
"@matrix-org/react-sdk-module-api": "^0.0.6",
"@matrix-org/react-sdk-module-api": "^1.0.0",
"@sentry/browser": "^7.0.0",
"@sentry/tracing": "^7.0.0",
"@testing-library/react-hooks": "^8.0.1",
Expand Down Expand Up @@ -184,6 +184,7 @@
"cypress-each": "^1.13.3",
"cypress-multi-reporters": "^1.6.1",
"cypress-real-events": "^1.7.1",
"cypress-terminal-report": "^5.3.2",
"eslint": "8.43.0",
"eslint-config-google": "^0.14.0",
"eslint-config-prettier": "^8.5.0",
Expand Down
Loading

0 comments on commit 798e571

Please sign in to comment.