1
0
mirror of https://github.com/matrix-org/matrix-react-sdk.git synced 2025-07-28 15:22:05 +03:00

Migrate remaining crypto tests from Cypress to Playwright (#12021)

* Fix bot MatrixClient being set up multiple times

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Migrate verification.spec.ts from Cypress to Playwright

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Migrate crypto.spec.ts from Cypress to Playwright

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* delint

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Add screenshot

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Record trace on-first-retry

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Iterate

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Don't start client when not needed

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Add bot log prefixing

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Turns out we need these

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Fix crypto tests in rust crypto

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

---------

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski
2023-12-12 08:55:29 +00:00
committed by GitHub
parent 0f42418b5c
commit 5104d53ddf
13 changed files with 1111 additions and 1259 deletions

View File

@ -27,6 +27,7 @@ import type {
ReceiptType,
IRoomDirectoryOptions,
} from "matrix-js-sdk/src/matrix";
import { Credentials } from "../plugins/homeserver";
export class Client {
protected client: JSHandle<MatrixClient>;
@ -100,7 +101,14 @@ export class Client {
* @param roomId ID of the room to send the message into
* @param content the event content to send
*/
public async sendMessage(roomId: string, content: IContent): Promise<ISendEventResponse> {
public async sendMessage(roomId: string, content: IContent | string): Promise<ISendEventResponse> {
if (typeof content === "string") {
content = {
body: content,
msgtype: "m.text",
};
}
const client = await this.prepareClient();
return client.evaluate(
(client, { roomId, content }) => {
@ -177,13 +185,14 @@ export class Client {
* Make this bot join a room by name
* @param roomName Name of the room to join
*/
public async joinRoomByName(roomName: string): Promise<void> {
public async joinRoomByName(roomName: string): Promise<string> {
const client = await this.prepareClient();
await client.evaluate(
(client, { roomName }) => {
return client.evaluate(
async (client, { roomName }) => {
const room = client.getRooms().find((r) => r.getDefaultRoomName(client.getUserId()) === roomName);
if (room) {
return client.joinRoom(room.roomId);
await client.joinRoom(room.roomId);
return room.roomId;
}
throw new Error(`Bot room join failed. Cannot find room '${roomName}'`);
},
@ -227,8 +236,29 @@ export class Client {
public async publicRooms(options?: IRoomDirectoryOptions): ReturnType<MatrixClient["publicRooms"]> {
const client = await this.prepareClient();
return await client.evaluate((client, options) => {
return client.evaluate((client, options) => {
return client.publicRooms(options);
}, options);
}
/**
* Boostraps cross-signing.
*/
public async bootstrapCrossSigning(credentials: Credentials): Promise<void> {
const client = await this.prepareClient();
return client.evaluate(async (client, credentials) => {
await client.getCrypto().bootstrapCrossSigning({
authUploadDeviceSigningKeys: async (func) => {
await func({
type: "m.login.password",
identifier: {
type: "m.id.user",
user: credentials.userId,
},
password: credentials.password,
});
},
});
}, credentials);
}
}