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

Commit 6af4786

Browse files
authored
Merge branch 'develop' into alunturner/mentions-for-plain-text-editor
2 parents 7948fa7 + be5928c commit 6af4786

File tree

103 files changed

+2077
-800
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+2077
-800
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
Copyright 2023 The Matrix.org Foundation C.I.C.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import type { VerificationRequest } from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
18+
import { HomeserverInstance } from "../../plugins/utils/homeserver";
19+
import { handleVerificationRequest, waitForVerificationRequest } from "./utils";
20+
import { CypressBot } from "../../support/bot";
21+
22+
describe("Complete security", () => {
23+
let homeserver: HomeserverInstance;
24+
25+
beforeEach(() => {
26+
cy.startHomeserver("default").then((data) => {
27+
homeserver = data;
28+
});
29+
// visit the login page of the app, to load the matrix sdk
30+
cy.visit("/#/login");
31+
32+
// wait for the page to load
33+
cy.window({ log: false }).should("have.property", "matrixcs");
34+
});
35+
36+
afterEach(() => {
37+
cy.stopHomeserver(homeserver);
38+
});
39+
40+
it("should go straight to the welcome screen if we have no signed device", () => {
41+
const username = Cypress._.uniqueId("user_");
42+
const password = "supersecret";
43+
cy.registerUser(homeserver, username, password, "Jeff");
44+
logIntoElement(homeserver.baseUrl, username, password);
45+
cy.findByText("Welcome Jeff");
46+
});
47+
48+
it("should walk through device verification if we have a signed device", () => {
49+
// create a new user, and have it bootstrap cross-signing
50+
let botClient: CypressBot;
51+
cy.getBot(homeserver, { displayName: "Jeff" })
52+
.then(async (bot) => {
53+
botClient = bot;
54+
await bot.bootstrapCrossSigning({});
55+
})
56+
.then(() => {
57+
// now log in, in Element. We go in through the login page because otherwise the device setup flow
58+
// doesn't get triggered
59+
console.log("%cAccount set up; logging in user", "font-weight: bold; font-size:x-large");
60+
logIntoElement(homeserver.baseUrl, botClient.getSafeUserId(), botClient.__cypress_password);
61+
62+
// we should see a prompt for a device verification
63+
cy.findByRole("heading", { name: "Verify this device" });
64+
const botVerificationRequestPromise = waitForVerificationRequest(botClient);
65+
cy.findByRole("button", { name: "Verify with another device" }).click();
66+
67+
// accept the verification request on the "bot" side
68+
cy.wrap(botVerificationRequestPromise).then(async (verificationRequest: VerificationRequest) => {
69+
await verificationRequest.accept();
70+
await handleVerificationRequest(verificationRequest);
71+
});
72+
73+
// confirm that the emojis match
74+
cy.findByRole("button", { name: "They match" }).click();
75+
76+
// we should get the confirmation box
77+
cy.findByText(/You've successfully verified/);
78+
79+
cy.findByRole("button", { name: "Got it" }).click();
80+
});
81+
});
82+
});
83+
84+
/**
85+
* Fill in the login form in element with the given creds
86+
*/
87+
function logIntoElement(homeserverUrl: string, username: string, password: string) {
88+
cy.visit("/#/login");
89+
90+
// select homeserver
91+
cy.findByRole("button", { name: "Edit" }).click();
92+
cy.findByRole("textbox", { name: "Other homeserver" }).type(homeserverUrl);
93+
cy.findByRole("button", { name: "Continue" }).click();
94+
95+
// wait for the dialog to go away
96+
cy.get(".mx_ServerPickerDialog").should("not.exist");
97+
98+
cy.findByRole("textbox", { name: "Username" }).type(username);
99+
cy.findByPlaceholderText("Password").type(password);
100+
cy.findByRole("button", { name: "Sign in" }).click();
101+
}

cypress/e2e/crypto/crypto.spec.ts

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

1717
import type { ISendEventResponse, MatrixClient, Room } from "matrix-js-sdk/src/matrix";
1818
import type { VerificationRequest } from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
19-
import type { ISasEvent } from "matrix-js-sdk/src/crypto/verification/SAS";
2019
import type { CypressBot } from "../../support/bot";
2120
import { HomeserverInstance } from "../../plugins/utils/homeserver";
22-
import Chainable = Cypress.Chainable;
2321
import { UserCredentials } from "../../support/login";
22+
import { EmojiMapping, handleVerificationRequest, waitForVerificationRequest } from "./utils";
2423

25-
type EmojiMapping = [emoji: string, name: string];
2624
interface CryptoTestContext extends Mocha.Context {
2725
homeserver: HomeserverInstance;
2826
bob: CypressBot;
2927
}
3028

31-
const waitForVerificationRequest = (cli: MatrixClient): Promise<VerificationRequest> => {
32-
return new Promise<VerificationRequest>((resolve) => {
33-
const onVerificationRequestEvent = (request: VerificationRequest) => {
34-
// @ts-ignore CryptoEvent is not exported to window.matrixcs; using the string value here
35-
cli.off("crypto.verification.request", onVerificationRequestEvent);
36-
resolve(request);
37-
};
38-
// @ts-ignore
39-
cli.on("crypto.verification.request", onVerificationRequestEvent);
40-
});
41-
};
42-
4329
const openRoomInfo = () => {
4430
cy.get(".mx_RightPanel_roomSummaryButton").click();
4531
return cy.get(".mx_RightPanel");
@@ -117,23 +103,6 @@ function autoJoin(client: MatrixClient) {
117103
});
118104
}
119105

120-
const handleVerificationRequest = (request: VerificationRequest): Chainable<EmojiMapping[]> => {
121-
return cy.wrap(
122-
new Promise<EmojiMapping[]>((resolve) => {
123-
const onShowSas = (event: ISasEvent) => {
124-
verifier.off("show_sas", onShowSas);
125-
event.confirm();
126-
verifier.done();
127-
resolve(event.sas.emoji);
128-
};
129-
130-
const verifier = request.beginKeyVerification("m.sas.v1");
131-
verifier.on("show_sas", onShowSas);
132-
verifier.verify();
133-
}),
134-
);
135-
};
136-
137106
const verify = function (this: CryptoTestContext) {
138107
const bobsVerificationRequestPromise = waitForVerificationRequest(this.bob);
139108

@@ -150,7 +119,7 @@ const verify = function (this: CryptoTestContext) {
150119
.as("bobsVerificationRequest");
151120
cy.findByRole("button", { name: "Verify by emoji" }).click();
152121
cy.get<VerificationRequest>("@bobsVerificationRequest").then((request: VerificationRequest) => {
153-
return handleVerificationRequest(request).then((emojis: EmojiMapping[]) => {
122+
return cy.wrap(handleVerificationRequest(request)).then((emojis: EmojiMapping[]) => {
154123
cy.get(".mx_VerificationShowSas_emojiSas_block").then((emojiBlocks) => {
155124
emojis.forEach((emoji: EmojiMapping, index: number) => {
156125
expect(emojiBlocks[index].textContent.toLowerCase()).to.eq(emoji[0] + emoji[1]);

cypress/e2e/crypto/utils.ts

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
Copyright 2023 The Matrix.org Foundation C.I.C.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import type { ISasEvent } from "matrix-js-sdk/src/crypto/verification/SAS";
18+
import type { MatrixClient } from "matrix-js-sdk/src/matrix";
19+
import type { VerificationRequest } from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
20+
21+
export type EmojiMapping = [emoji: string, name: string];
22+
23+
/**
24+
* wait for the given client to receive an incoming verification request
25+
*
26+
* @param cli - matrix client we expect to receive a request
27+
*/
28+
export function waitForVerificationRequest(cli: MatrixClient): Promise<VerificationRequest> {
29+
return new Promise<VerificationRequest>((resolve) => {
30+
const onVerificationRequestEvent = (request: VerificationRequest) => {
31+
// @ts-ignore CryptoEvent is not exported to window.matrixcs; using the string value here
32+
cli.off("crypto.verification.request", onVerificationRequestEvent);
33+
resolve(request);
34+
};
35+
// @ts-ignore
36+
cli.on("crypto.verification.request", onVerificationRequestEvent);
37+
});
38+
}
39+
40+
/**
41+
* Handle an incoming verification request
42+
*
43+
* Starts the key verification process, and, once it is accepted on the other side, confirms that the
44+
* emojis match.
45+
*
46+
* Returns a promise that resolves, with the emoji list, once we confirm the emojis
47+
*
48+
* @param request - incoming verification request
49+
*/
50+
export function handleVerificationRequest(request: VerificationRequest) {
51+
return new Promise<EmojiMapping[]>((resolve) => {
52+
const onShowSas = (event: ISasEvent) => {
53+
verifier.off("show_sas", onShowSas);
54+
event.confirm();
55+
verifier.done();
56+
resolve(event.sas.emoji);
57+
};
58+
59+
const verifier = request.beginKeyVerification("m.sas.v1");
60+
verifier.on("show_sas", onShowSas);
61+
verifier.verify();
62+
});
63+
}

0 commit comments

Comments
 (0)