mirror of
https://github.com/vector-im/element-web.git
synced 2026-05-04 19:56:45 +02:00
Share code to silence SonarQube
This commit is contained in:
parent
0ecb4d18a8
commit
b7e63a48cd
@ -6,10 +6,13 @@
|
||||
*/
|
||||
|
||||
import { createNewInstance } from "@element-hq/element-web-playwright-common";
|
||||
import { type StartedHomeserverContainer } from "@element-hq/element-web-playwright-common/lib/testcontainers";
|
||||
import { type Page, type Browser, type TestInfo } from "@playwright/test";
|
||||
|
||||
import { test, expect } from "./index";
|
||||
import { ElementAppPage } from "../../../pages/ElementAppPage";
|
||||
import { createRoom, sendMessageInCurrentRoom, verifyApp } from "../../crypto/utils";
|
||||
import { type CredentialsOptionalAccessToken } from "../../../pages/bot";
|
||||
|
||||
test.describe("Other people's devices section in Encryption tab", () => {
|
||||
test.use({
|
||||
@ -23,23 +26,13 @@ test.describe("Other people's devices section in Encryption tab", () => {
|
||||
browser,
|
||||
user: aliceCredentials,
|
||||
}, testInfo) => {
|
||||
await aliceElementApp.client.bootstrapCrossSigning(aliceCredentials);
|
||||
await aliceElementApp.closeKeyStorageToast();
|
||||
await prepForEncryption(aliceElementApp, aliceCredentials);
|
||||
|
||||
// Create a second browser instance.
|
||||
const bobCredentials = await homeserver.registerUser(`user_${testInfo.testId}_bob`, "password", "bob");
|
||||
const bobPage = await createNewInstance(browser, bobCredentials, {});
|
||||
const bobElementApp = new ElementAppPage(bobPage);
|
||||
await bobElementApp.client.bootstrapCrossSigning(bobCredentials);
|
||||
await bobElementApp.closeKeyStorageToast();
|
||||
const { bobCredentials, bobPage } = await newBrowser(homeserver, testInfo, browser);
|
||||
|
||||
// Create the room and invite bob
|
||||
await createRoom(alicePage, "TestRoom", true);
|
||||
await aliceElementApp.inviteUserToCurrentRoom(bobCredentials.userId);
|
||||
|
||||
// Bob accepts the invite
|
||||
await bobPage.getByRole("option", { name: "TestRoom" }).click();
|
||||
await bobPage.getByRole("button", { name: "Accept" }).click();
|
||||
await inviteBobToNewRoom(alicePage, aliceElementApp, bobCredentials, bobPage);
|
||||
|
||||
// Alice sends a message, which Bob should be able to decrypt
|
||||
await sendMessageInCurrentRoom(alicePage, "Decryptable");
|
||||
@ -54,8 +47,7 @@ test.describe("Other people's devices section in Encryption tab", () => {
|
||||
user: aliceCredentials,
|
||||
util,
|
||||
}, testInfo) => {
|
||||
await aliceElementApp.client.bootstrapCrossSigning(aliceCredentials);
|
||||
await aliceElementApp.closeKeyStorageToast();
|
||||
await prepForEncryption(aliceElementApp, aliceCredentials);
|
||||
|
||||
// Enable blacklist toggle.
|
||||
const dialog = await util.openEncryptionTab();
|
||||
@ -68,19 +60,10 @@ test.describe("Other people's devices section in Encryption tab", () => {
|
||||
await aliceElementApp.settings.closeDialog();
|
||||
|
||||
// Create a second browser instance.
|
||||
const bobCredentials = await homeserver.registerUser(`user_${testInfo.testId}_bob`, "password", "bob");
|
||||
const bobPage = await createNewInstance(browser, bobCredentials, {});
|
||||
const bobElementApp = new ElementAppPage(bobPage);
|
||||
await bobElementApp.client.bootstrapCrossSigning(bobCredentials);
|
||||
await bobElementApp.closeKeyStorageToast();
|
||||
const { bobCredentials, bobPage } = await newBrowser(homeserver, testInfo, browser);
|
||||
|
||||
// Create the room and invite bob
|
||||
await createRoom(alicePage, "TestRoom", true);
|
||||
await aliceElementApp.inviteUserToCurrentRoom(bobCredentials.userId);
|
||||
|
||||
// Bob accepts the invite
|
||||
await bobPage.getByRole("option", { name: "TestRoom" }).click();
|
||||
await bobPage.getByRole("button", { name: "Accept" }).click();
|
||||
await inviteBobToNewRoom(alicePage, aliceElementApp, bobCredentials, bobPage);
|
||||
|
||||
// Alice sends a message, which Bob should not be able to decrypt
|
||||
await sendMessageInCurrentRoom(alicePage, "Undecryptable");
|
||||
@ -99,8 +82,7 @@ test.describe("Other people's devices section in Encryption tab", () => {
|
||||
user: aliceCredentials,
|
||||
util,
|
||||
}, testInfo) => {
|
||||
await aliceElementApp.client.bootstrapCrossSigning(aliceCredentials);
|
||||
await aliceElementApp.closeKeyStorageToast();
|
||||
await prepForEncryption(aliceElementApp, aliceCredentials);
|
||||
|
||||
// Enable blacklist toggle.
|
||||
const dialog = await util.openEncryptionTab();
|
||||
@ -113,19 +95,10 @@ test.describe("Other people's devices section in Encryption tab", () => {
|
||||
await aliceElementApp.settings.closeDialog();
|
||||
|
||||
// Create a second browser instance.
|
||||
const bobCredentials = await homeserver.registerUser(`user_${testInfo.testId}_bob`, "password", "bob");
|
||||
const bobPage = await createNewInstance(browser, bobCredentials, {});
|
||||
const bobElementApp = new ElementAppPage(bobPage);
|
||||
await bobElementApp.client.bootstrapCrossSigning(bobCredentials);
|
||||
await bobElementApp.closeKeyStorageToast();
|
||||
const { bobCredentials, bobPage, bobElementApp } = await newBrowser(homeserver, testInfo, browser);
|
||||
|
||||
// Create the room and invite bob
|
||||
await createRoom(alicePage, "TestRoom", true);
|
||||
await aliceElementApp.inviteUserToCurrentRoom(bobCredentials.userId);
|
||||
|
||||
// Bob accepts the invite and dismisses the warnings.
|
||||
await bobPage.getByRole("option", { name: "TestRoom" }).click();
|
||||
await bobPage.getByRole("button", { name: "Accept" }).click();
|
||||
await inviteBobToNewRoom(alicePage, aliceElementApp, bobCredentials, bobPage);
|
||||
await bobElementApp.closeNotificationToast();
|
||||
|
||||
// Perform verification.
|
||||
@ -143,23 +116,13 @@ test.describe("Other people's devices section in Encryption tab", () => {
|
||||
browser,
|
||||
user: aliceCredentials,
|
||||
}, testInfo) => {
|
||||
await aliceElementApp.client.bootstrapCrossSigning(aliceCredentials);
|
||||
await aliceElementApp.closeKeyStorageToast();
|
||||
await prepForEncryption(aliceElementApp, aliceCredentials);
|
||||
|
||||
// Create a second browser instance.
|
||||
const bobCredentials = await homeserver.registerUser(`user_${testInfo.testId}_bob`, "password", "bob");
|
||||
const bobPage = await createNewInstance(browser, bobCredentials, {});
|
||||
const bobElementApp = new ElementAppPage(bobPage);
|
||||
await bobElementApp.client.bootstrapCrossSigning(bobCredentials);
|
||||
await bobElementApp.closeKeyStorageToast();
|
||||
const { bobCredentials, bobPage } = await newBrowser(homeserver, testInfo, browser);
|
||||
|
||||
// Alice creates the room and invite Bob.
|
||||
await createRoom(alicePage, "TestRoom", true);
|
||||
await aliceElementApp.inviteUserToCurrentRoom(bobCredentials.userId);
|
||||
|
||||
// Bob accepts the invite.
|
||||
await bobPage.getByRole("option", { name: "TestRoom" }).click();
|
||||
await bobPage.getByRole("button", { name: "Accept" }).click();
|
||||
// Alice creates the room and invites Bob.
|
||||
await inviteBobToNewRoom(alicePage, aliceElementApp, bobCredentials, bobPage);
|
||||
|
||||
// Alice configures her client to blacklist unverified users in this room.
|
||||
const dialog = await aliceElementApp.settings.openRoomSettings("Security & Privacy");
|
||||
@ -196,8 +159,7 @@ test.describe("Other people's devices section in Encryption tab", () => {
|
||||
user: aliceCredentials,
|
||||
util,
|
||||
}, testInfo) => {
|
||||
await aliceElementApp.client.bootstrapCrossSigning(aliceCredentials);
|
||||
await aliceElementApp.closeKeyStorageToast();
|
||||
await prepForEncryption(aliceElementApp, aliceCredentials);
|
||||
|
||||
// Enable blacklist toggle.
|
||||
let dialog = await util.openEncryptionTab();
|
||||
@ -210,19 +172,10 @@ test.describe("Other people's devices section in Encryption tab", () => {
|
||||
await aliceElementApp.settings.closeDialog();
|
||||
|
||||
// Create a second browser instance.
|
||||
const bobCredentials = await homeserver.registerUser(`user_${testInfo.testId}_bob`, "password", "bob");
|
||||
const bobPage = await createNewInstance(browser, bobCredentials, {});
|
||||
const bobElementApp = new ElementAppPage(bobPage);
|
||||
await bobElementApp.client.bootstrapCrossSigning(bobCredentials);
|
||||
await bobElementApp.closeKeyStorageToast();
|
||||
const { bobCredentials, bobPage } = await newBrowser(homeserver, testInfo, browser);
|
||||
|
||||
// Alice creates the room and invite Bob.
|
||||
await createRoom(alicePage, "TestRoom", true);
|
||||
await aliceElementApp.inviteUserToCurrentRoom(bobCredentials.userId);
|
||||
|
||||
// Bob accepts the invite.
|
||||
await bobPage.getByRole("option", { name: "TestRoom" }).click();
|
||||
await bobPage.getByRole("button", { name: "Accept" }).click();
|
||||
// Alice creates the room and invites Bob.
|
||||
await inviteBobToNewRoom(alicePage, aliceElementApp, bobCredentials, bobPage);
|
||||
|
||||
// Alice configures her client to allow sending to unverified users in this room.
|
||||
dialog = await aliceElementApp.settings.openRoomSettings("Security & Privacy");
|
||||
@ -251,3 +204,32 @@ test.describe("Other people's devices section in Encryption tab", () => {
|
||||
).toBeVisible();
|
||||
});
|
||||
});
|
||||
|
||||
async function inviteBobToNewRoom(
|
||||
alicePage: Page,
|
||||
aliceElementApp: ElementAppPage,
|
||||
bobCredentials: CredentialsOptionalAccessToken,
|
||||
bobPage: Page,
|
||||
) {
|
||||
await createRoom(alicePage, "TestRoom", true);
|
||||
await aliceElementApp.inviteUserToCurrentRoom(bobCredentials.userId);
|
||||
await bobPage.getByRole("option", { name: "TestRoom" }).click();
|
||||
await bobPage.getByRole("button", { name: "Accept" }).click();
|
||||
}
|
||||
|
||||
async function newBrowser(
|
||||
homeserver: StartedHomeserverContainer,
|
||||
testInfo: TestInfo,
|
||||
browser: Browser,
|
||||
): Promise<{ bobCredentials: CredentialsOptionalAccessToken; bobPage: Page; bobElementApp: ElementAppPage }> {
|
||||
const bobCredentials = await homeserver.registerUser(`user_${testInfo.testId}_bob`, "password", "bob");
|
||||
const bobPage = await createNewInstance(browser, bobCredentials, {});
|
||||
const bobElementApp = new ElementAppPage(bobPage);
|
||||
await prepForEncryption(bobElementApp, bobCredentials);
|
||||
return { bobCredentials, bobPage, bobElementApp };
|
||||
}
|
||||
|
||||
async function prepForEncryption(app: ElementAppPage, credentials: CredentialsOptionalAccessToken): Promise<void> {
|
||||
await app.client.bootstrapCrossSigning(credentials);
|
||||
await app.closeKeyStorageToast();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user