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

Commit a97656e

Browse files
author
Alun Turner
committed
Merge to fix package.json conflict
1 parent 7e2f37d commit a97656e

29 files changed

+674
-360
lines changed

.github/workflows/cypress.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ jobs:
174174
record: true
175175
parallel: true
176176
command-prefix: "yarn percy exec --parallel --"
177-
config: '{"reporter":"cypress-multi-reporters", "reporterOptions": { "configFile": "cypress-ci-reporter-config.json" } }'
177+
config: '{"reporter":"cypress-multi-reporters", "reporterOptions": { "configFile": "cypress-ci-reporter-config.json" }, "morgan": false }'
178178
ci-build-id: ${{ needs.prepare.outputs.uuid }}
179179
env:
180180
# pass the Dashboard record key as an environment variable

cypress.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,8 @@ export default defineConfig({
3838
runMode: 4,
3939
openMode: 0,
4040
},
41+
42+
// disable logging of HTTP requests made to the Cypress server. They are noisy and not very helpful.
43+
// @ts-ignore https://github.com/cypress-io/cypress/issues/26284
44+
morgan: false,
4145
});

cypress/e2e/crypto/verification.spec.ts

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ describe("Device verification", () => {
3636
cy.window({ log: false }).should("have.property", "matrixcs");
3737

3838
// Create a new device for alice
39-
cy.getBot(homeserver, { rustCrypto: true, bootstrapCrossSigning: true }).then((bot) => {
39+
cy.getBot(homeserver, {
40+
rustCrypto: true,
41+
bootstrapCrossSigning: true,
42+
bootstrapSecretStorage: true,
43+
}).then((bot) => {
4044
aliceBotClient = bot;
4145
});
4246
});
@@ -87,6 +91,51 @@ describe("Device verification", () => {
8791
checkDeviceIsCrossSigned();
8892
});
8993

94+
it("Verify device during login with Security Phrase", () => {
95+
logIntoElement(homeserver.baseUrl, aliceBotClient.getUserId(), aliceBotClient.__cypress_password);
96+
97+
// Select the security phrase
98+
cy.get(".mx_AuthPage").within(() => {
99+
cy.findByRole("button", { name: "Verify with Security Key or Phrase" }).click();
100+
});
101+
102+
// Fill the passphrase
103+
cy.get(".mx_Dialog").within(() => {
104+
cy.get("input").type("new passphrase");
105+
cy.contains(".mx_Dialog_primary:not([disabled])", "Continue").click();
106+
});
107+
108+
cy.get(".mx_AuthPage").within(() => {
109+
cy.findByRole("button", { name: "Done" }).click();
110+
});
111+
112+
// Check that our device is now cross-signed
113+
checkDeviceIsCrossSigned();
114+
});
115+
116+
it("Verify device during login with Security Key", () => {
117+
logIntoElement(homeserver.baseUrl, aliceBotClient.getUserId(), aliceBotClient.__cypress_password);
118+
119+
// Select the security phrase
120+
cy.get(".mx_AuthPage").within(() => {
121+
cy.findByRole("button", { name: "Verify with Security Key or Phrase" }).click();
122+
});
123+
124+
// Fill the security key
125+
cy.get(".mx_Dialog").within(() => {
126+
cy.findByRole("button", { name: "use your Security Key" }).click();
127+
cy.get("#mx_securityKey").type(aliceBotClient.__cypress_recovery_key.encodedPrivateKey);
128+
cy.contains(".mx_Dialog_primary:not([disabled])", "Continue").click();
129+
});
130+
131+
cy.get(".mx_AuthPage").within(() => {
132+
cy.findByRole("button", { name: "Done" }).click();
133+
});
134+
135+
// Check that our device is now cross-signed
136+
checkDeviceIsCrossSigned();
137+
});
138+
90139
it("Handle incoming verification request with SAS", () => {
91140
logIntoElement(homeserver.baseUrl, aliceBotClient.getUserId(), aliceBotClient.__cypress_password);
92141

cypress/plugins/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ limitations under the License.
1515
*/
1616

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

1920
import PluginEvents = Cypress.PluginEvents;
2021
import PluginConfigOptions = Cypress.PluginConfigOptions;
@@ -35,4 +36,7 @@ export default function (on: PluginEvents, config: PluginConfigOptions) {
3536
slidingSyncProxyDocker(on, config);
3637
webserver(on, config);
3738
log(on, config);
39+
installLogsPrinter(on, {
40+
// printLogsToConsole: "always",
41+
});
3842
}

cypress/support/bot.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
/// <reference types="cypress" />
1818

1919
import type { ISendEventResponse, MatrixClient, Room } from "matrix-js-sdk/src/matrix";
20+
import type { GeneratedSecretStorageKey } from "matrix-js-sdk/src/crypto-api";
21+
import type { AddSecretStorageKeyOpts } from "matrix-js-sdk/src/secret-storage";
2022
import { HomeserverInstance } from "../plugins/utils/homeserver";
2123
import { Credentials } from "./homeserver";
2224
import Chainable = Cypress.Chainable;
@@ -47,6 +49,10 @@ interface CreateBotOpts {
4749
* Whether to use the rust crypto impl. Defaults to false (for now!)
4850
*/
4951
rustCrypto?: boolean;
52+
/**
53+
* Whether or not to bootstrap the secret storage
54+
*/
55+
bootstrapSecretStorage?: boolean;
5056
}
5157

5258
const defaultCreateBotOptions = {
@@ -58,6 +64,7 @@ const defaultCreateBotOptions = {
5864

5965
export interface CypressBot extends MatrixClient {
6066
__cypress_password: string;
67+
__cypress_recovery_key: GeneratedSecretStorageKey;
6168
}
6269

6370
declare global {
@@ -143,6 +150,24 @@ function setupBotClient(
143150
Object.assign(keys, k);
144151
};
145152

153+
// Store the cached secret storage key and return it when `getSecretStorageKey` is called
154+
let cachedKey: { keyId: string; key: Uint8Array };
155+
const cacheSecretStorageKey = (keyId: string, keyInfo: AddSecretStorageKeyOpts, key: Uint8Array) => {
156+
cachedKey = {
157+
keyId,
158+
key,
159+
};
160+
};
161+
162+
const getSecretStorageKey = () => Promise.resolve<[string, Uint8Array]>([cachedKey.keyId, cachedKey.key]);
163+
164+
const cryptoCallbacks = {
165+
getCrossSigningKey,
166+
saveCrossSigningKeys,
167+
cacheSecretStorageKey,
168+
getSecretStorageKey,
169+
};
170+
146171
const cli = new win.matrixcs.MatrixClient({
147172
baseUrl: homeserver.baseUrl,
148173
userId: credentials.userId,
@@ -151,7 +176,7 @@ function setupBotClient(
151176
store: new win.matrixcs.MemoryStore(),
152177
scheduler: new win.matrixcs.MatrixScheduler(),
153178
cryptoStore: new win.matrixcs.MemoryCryptoStore(),
154-
cryptoCallbacks: { getCrossSigningKey, saveCrossSigningKeys },
179+
cryptoCallbacks,
155180
});
156181

157182
if (opts.autoAcceptInvites) {
@@ -192,6 +217,18 @@ function setupBotClient(
192217
},
193218
});
194219
}
220+
221+
if (opts.bootstrapSecretStorage) {
222+
const passphrase = "new passphrase";
223+
const recoveryKey = await cli.getCrypto().createRecoveryKeyFromPassphrase(passphrase);
224+
Object.assign(cli, { __cypress_recovery_key: recoveryKey });
225+
226+
await cli.getCrypto()!.bootstrapSecretStorage({
227+
setupNewSecretStorage: true,
228+
createSecretStorageKey: () => Promise.resolve(recoveryKey),
229+
});
230+
}
231+
195232
return cli;
196233
},
197234
);

cypress/support/e2e.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ limitations under the License.
1919
import "@percy/cypress";
2020
import "cypress-real-events";
2121
import "@testing-library/cypress/add-commands";
22+
import installLogsCollector from "cypress-terminal-report/src/installLogsCollector";
2223

2324
import "./config.json";
2425
import "./homeserver";
@@ -39,3 +40,20 @@ import "./network";
3940
import "./composer";
4041
import "./proxy";
4142
import "./axe";
43+
44+
installLogsCollector({
45+
// specify the types of logs to collect (and report to the node console at the end of the test)
46+
collectTypes: [
47+
"cons:log",
48+
"cons:info",
49+
"cons:warn",
50+
"cons:error",
51+
// "cons:debug",
52+
"cy:log",
53+
"cy:xhr",
54+
"cy:fetch",
55+
"cy:request",
56+
"cy:intercept",
57+
"cy:command",
58+
],
59+
});

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"@babel/runtime": "^7.12.5",
6363
"@matrix-org/analytics-events": "^0.5.0",
6464
"@matrix-org/matrix-wysiwyg": "^2.3.1",
65-
"@matrix-org/react-sdk-module-api": "^0.0.6",
65+
"@matrix-org/react-sdk-module-api": "^1.0.0",
6666
"@sentry/browser": "^7.0.0",
6767
"@sentry/tracing": "^7.0.0",
6868
"@testing-library/react-hooks": "^8.0.1",
@@ -184,6 +184,7 @@
184184
"cypress-each": "^1.13.3",
185185
"cypress-multi-reporters": "^1.6.1",
186186
"cypress-real-events": "^1.7.1",
187+
"cypress-terminal-report": "^5.3.2",
187188
"eslint": "8.43.0",
188189
"eslint-config-google": "^0.14.0",
189190
"eslint-config-prettier": "^8.5.0",

0 commit comments

Comments
 (0)