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

Start adding Cypress tests for crypto #8577

Merged
merged 14 commits into from
May 30, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ limitations under the License.
import type { MatrixClient } from "matrix-js-sdk/src/matrix";
import { SynapseInstance } from "../../plugins/synapsedocker";

function waitForEvent(cli: MatrixClient, event: any, check: () => boolean, callback: () => void) {
if (check()) {
callback();
} else {
cli.once(event, () => waitForEvent(cli, event, check, callback));
}
function waitForEncryption(cli: MatrixClient, roomId: string, event: any, resolve: () => void) {
cli.crypto.cryptoStore.getEndToEndRooms(null, (result) => {
if (result[roomId]) {
resolve();
} else {
cli.once(event, () => waitForEncryption(cli, roomId, event, resolve));
}
});
duxovni marked this conversation as resolved.
Show resolved Hide resolved
}

describe("Cryptography", () => {
Expand Down Expand Up @@ -53,32 +55,29 @@ describe("Cryptography", () => {
],
}).as('roomId');

cy.get<MatrixClient>('@bot').then(bot =>
cy.get<string>('@roomId').then(roomId =>
cy.inviteUser(roomId, bot.getUserId())
.then(() => cy.visit("/#/room/" + roomId))
.then(() => cy.window().then(win => cy.wrap(
new Promise<void>(resolve =>
waitForEvent(
bot,
win.matrixcs.RoomStateEvent.Update,
// @ts-ignore - protected
() => bot.roomList.isRoomEncrypted(roomId),
resolve,
),
).then(() => bot.sendMessage(roomId, {
body: "Top secret message",
msgtype: "m.text",
})),
))),
),
);
cy.all([
cy.get<MatrixClient>('@bot'),
cy.get<string>('@roomId'),
cy.window(),
]).then(results => {
const [bot, roomId, win] = results;
duxovni marked this conversation as resolved.
Show resolved Hide resolved
cy.inviteUser(roomId, bot.getUserId());
cy.visit("/#/room/" + roomId);
cy.wrap(
new Promise<void>(resolve =>
waitForEncryption(bot, roomId, win.matrixcs.RoomStateEvent.Update, resolve),
).then(() => bot.sendMessage(roomId, {
body: "Top secret message",
msgtype: "m.text",
})),
);
});

cy.get(".mx_RoomView_body .mx_cryptoEvent").should("contain", "Encryption enabled");

cy.get(".mx_EventTile_body")
.contains("Top secret message")
.parent().parent()
.closest(".mx_EventTile_line")
.should("not.have.descendants", ".mx_EventTile_e2eIcon_warning");
});
});