Skip to content

Commit 50ac509

Browse files
authored
Use homeserver in a worker-scoped fixture (#28848)
* Use homeserver in a worker-scoped fixture Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> * Switch to TestContainers for manging services in Playwright Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> * Flip fixture dependency order Signed-off-by: Michael Telatynski <[email protected]> * Remove mas dep Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> * Update matrix-authentication-service in Playwright tests Signed-off-by: Michael Telatynski <[email protected]> * delint Signed-off-by: Michael Telatynski <[email protected]> * Fix SMTP port Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> * Comments Signed-off-by: Michael Telatynski <[email protected]> * Strip ansi from playwright logs to make them more readable Signed-off-by: Michael Telatynski <[email protected]> * Actually do the update Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> * Remove access to homeserver.config.baseUrl field in favour of homeserver.baseUrl Signed-off-by: Michael Telatynski <[email protected]> * Use sane default_server_config and specify server.invalid in the specific tests which demand it Signed-off-by: Michael Telatynski <[email protected]> * Fix mas run Signed-off-by: Michael Telatynski <[email protected]> * break cycle Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> * typo Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> * prettier Signed-off-by: Michael Telatynski <[email protected]> * Wire up basics of dendriteHomeserver Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> * Fix types Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> * Discard changes to playwright/e2e/settings/device-management.spec.ts * Iterate Signed-off-by: Michael Telatynski <[email protected]> * Fix bad merge Signed-off-by: Michael Telatynski <[email protected]> --------- Signed-off-by: Michael Telatynski <[email protected]>
1 parent 3e27a00 commit 50ac509

38 files changed

+854
-764
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
Copyright 2024 New Vector Ltd.
3+
Copyright 2023 The Matrix.org Foundation C.I.C.
4+
5+
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
6+
Please see LICENSE files in the repository root for full details.
7+
*/
8+
9+
import { test, expect } from "../../element-web-test";
10+
import { registerAccountMas } from "../oidc";
11+
import { isDendrite } from "../../plugins/homeserver/dendrite";
12+
import { TestClientServerAPI } from "../csAPI";
13+
import { masHomeserver } from "../../plugins/homeserver/synapse/masHomeserver.ts";
14+
15+
// These tests register an account with MAS because then we go through the "normal" registration flow
16+
// and crypto gets set up. Using the 'user' fixture create a a user an synthesizes an existing login,
17+
// which is faster but leaves us without crypto set up.
18+
test.use(masHomeserver);
19+
test.describe("Encryption state after registration", () => {
20+
test.skip(isDendrite, "does not yet support MAS");
21+
22+
test("Key backup is enabled by default", async ({ page, mailhogClient, app }) => {
23+
await page.goto("/#/login");
24+
await page.getByRole("button", { name: "Continue" }).click();
25+
await registerAccountMas(page, mailhogClient, "alice", "[email protected]", "Pa$sW0rD!");
26+
27+
await app.settings.openUserSettings("Security & Privacy");
28+
await expect(page.getByText("This session is backing up your keys.")).toBeVisible();
29+
});
30+
31+
test("user is prompted to set up recovery", async ({ page, mailhogClient, app }) => {
32+
await page.goto("/#/login");
33+
await page.getByRole("button", { name: "Continue" }).click();
34+
await registerAccountMas(page, mailhogClient, "alice", "[email protected]", "Pa$sW0rD!");
35+
36+
await page.getByRole("button", { name: "Add room" }).click();
37+
await page.getByRole("menuitem", { name: "New room" }).click();
38+
await page.getByRole("textbox", { name: "Name" }).fill("test room");
39+
await page.getByRole("button", { name: "Create room" }).click();
40+
41+
await expect(page.getByRole("heading", { name: "Set up recovery" })).toBeVisible();
42+
});
43+
});
44+
45+
test.describe("Key backup reset from elsewhere", () => {
46+
test.skip(isDendrite, "does not yet support MAS");
47+
48+
test("Key backup is disabled when reset from elsewhere", async ({ page, mailhogClient, request, homeserver }) => {
49+
const testUsername = "alice";
50+
const testPassword = "Pa$sW0rD!";
51+
52+
// there's a delay before keys are uploaded so the error doesn't appear immediately: use a fake
53+
// clock so we can skip the delay
54+
await page.clock.install();
55+
56+
await page.goto("/#/login");
57+
await page.getByRole("button", { name: "Continue" }).click();
58+
await registerAccountMas(page, mailhogClient, testUsername, "[email protected]", testPassword);
59+
60+
await page.getByRole("button", { name: "Add room" }).click();
61+
await page.getByRole("menuitem", { name: "New room" }).click();
62+
await page.getByRole("textbox", { name: "Name" }).fill("test room");
63+
await page.getByRole("button", { name: "Create room" }).click();
64+
65+
// @ts-ignore - this runs in the browser scope where mxMatrixClientPeg is a thing. Here, it is not.
66+
const accessToken = await page.evaluate(() => mxMatrixClientPeg.get().getAccessToken());
67+
68+
const csAPI = new TestClientServerAPI(request, homeserver, accessToken);
69+
70+
const backupInfo = await csAPI.getCurrentBackupInfo();
71+
72+
await csAPI.deleteBackupVersion(backupInfo.version);
73+
74+
await page.getByRole("textbox", { name: "Send an encrypted message…" }).fill("/discardsession");
75+
await page.getByRole("button", { name: "Send message" }).click();
76+
77+
await page.getByRole("textbox", { name: "Send an encrypted message…" }).fill("Message with broken key backup");
78+
await page.getByRole("button", { name: "Send message" }).click();
79+
80+
// Should be the message we sent plus the room creation event
81+
await expect(page.locator(".mx_EventTile")).toHaveCount(2);
82+
await expect(
83+
page.locator(".mx_RoomView_MessageList > .mx_EventTile_last .mx_EventTile_receiptSent"),
84+
).toBeVisible();
85+
86+
// Wait for it to try uploading the key
87+
await page.clock.fastForward(20000);
88+
89+
await expect(page.getByRole("heading", { level: 1, name: "New Recovery Method" })).toBeVisible();
90+
});
91+
});

playwright/e2e/crypto/backups.spec.ts

Lines changed: 0 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ Please see LICENSE files in the repository root for full details.
99
import { type Page } from "@playwright/test";
1010

1111
import { test, expect } from "../../element-web-test";
12-
import { registerAccountMas } from "../oidc";
13-
import { isDendrite } from "../../plugins/homeserver/dendrite";
14-
import { TestClientServerAPI } from "../csAPI";
15-
import { masHomeserver } from "../../plugins/homeserver/synapse/masHomeserver.ts";
1612

1713
async function expectBackupVersionToBe(page: Page, version: string) {
1814
await expect(page.locator(".mx_SecureBackupPanel_statusList tr:nth-child(5) td")).toHaveText(
@@ -22,85 +18,6 @@ async function expectBackupVersionToBe(page: Page, version: string) {
2218
await expect(page.locator(".mx_SecureBackupPanel_statusList tr:nth-child(6) td")).toHaveText(version);
2319
}
2420

25-
// These tests register an account with MAS because then we go through the "normal" registration flow
26-
// and crypto gets set up. Using the 'user' fixture create a a user an synthesizes an existing login,
27-
// which is faster but leaves us without crypto set up.
28-
test.describe("Encryption state after registration", () => {
29-
test.use(masHomeserver);
30-
test.skip(isDendrite, "does not yet support MAS");
31-
32-
test("Key backup is enabled by default", async ({ page, mailhogClient, app }) => {
33-
await page.goto("/#/login");
34-
await page.getByRole("button", { name: "Continue" }).click();
35-
await registerAccountMas(page, mailhogClient, "alice", "[email protected]", "Pa$sW0rD!");
36-
37-
await app.settings.openUserSettings("Security & Privacy");
38-
await expect(page.getByText("This session is backing up your keys.")).toBeVisible();
39-
});
40-
41-
test("user is prompted to set up recovery", async ({ page, mailhogClient, app }) => {
42-
await page.goto("/#/login");
43-
await page.getByRole("button", { name: "Continue" }).click();
44-
await registerAccountMas(page, mailhogClient, "alice", "[email protected]", "Pa$sW0rD!");
45-
46-
await page.getByRole("button", { name: "Add room" }).click();
47-
await page.getByRole("menuitem", { name: "New room" }).click();
48-
await page.getByRole("textbox", { name: "Name" }).fill("test room");
49-
await page.getByRole("button", { name: "Create room" }).click();
50-
51-
await expect(page.getByRole("heading", { name: "Set up recovery" })).toBeVisible();
52-
});
53-
});
54-
55-
test.describe("Key backup reset from elsewhere", () => {
56-
test.use(masHomeserver);
57-
test.skip(isDendrite, "does not yet support MAS");
58-
59-
test("Key backup is disabled when reset from elsewhere", async ({ page, mailhogClient, request, homeserver }) => {
60-
const testUsername = "alice";
61-
const testPassword = "Pa$sW0rD!";
62-
63-
// there's a delay before keys are uploaded so the error doesn't appear immediately: use a fake
64-
// clock so we can skip the delay
65-
await page.clock.install();
66-
67-
await page.goto("/#/login");
68-
await page.getByRole("button", { name: "Continue" }).click();
69-
await registerAccountMas(page, mailhogClient, testUsername, "[email protected]", testPassword);
70-
71-
await page.getByRole("button", { name: "Add room" }).click();
72-
await page.getByRole("menuitem", { name: "New room" }).click();
73-
await page.getByRole("textbox", { name: "Name" }).fill("test room");
74-
await page.getByRole("button", { name: "Create room" }).click();
75-
76-
// @ts-ignore - this runs in the browser scope where mxMatrixClientPeg is a thing. Here, it is not.
77-
const accessToken = await page.evaluate(() => mxMatrixClientPeg.get().getAccessToken());
78-
79-
const csAPI = new TestClientServerAPI(request, homeserver, accessToken);
80-
81-
const backupInfo = await csAPI.getCurrentBackupInfo();
82-
83-
await csAPI.deleteBackupVersion(backupInfo.version);
84-
85-
await page.getByRole("textbox", { name: "Send an encrypted message…" }).fill("/discardsession");
86-
await page.getByRole("button", { name: "Send message" }).click();
87-
88-
await page.getByRole("textbox", { name: "Send an encrypted message…" }).fill("Message with broken key backup");
89-
await page.getByRole("button", { name: "Send message" }).click();
90-
91-
// Should be the message we sent plus the room creation event
92-
await expect(page.locator(".mx_EventTile")).toHaveCount(2);
93-
await expect(
94-
page.locator(".mx_RoomView_MessageList > .mx_EventTile_last .mx_EventTile_receiptSent"),
95-
).toBeVisible();
96-
97-
// Wait for it to try uploading the key
98-
await page.clock.fastForward(20000);
99-
100-
await expect(page.getByRole("heading", { level: 1, name: "New Recovery Method" })).toBeVisible();
101-
});
102-
});
103-
10421
test.describe("Backups", () => {
10522
test.use({
10623
displayName: "Hanako",

playwright/e2e/crypto/dehydration.spec.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,30 @@ function getMemberTileByName(page: Page, name: string): Locator {
1919
return page.locator(`.mx_EntityTile, [title="${name}"]`);
2020
}
2121

22-
test.describe("Dehydration", () => {
23-
test.skip(isDendrite, "does not yet support dehydration v2");
24-
25-
test.use({
26-
displayName: NAME,
27-
synapseConfigOptions: {
28-
experimental_features: {
29-
msc2697_enabled: false,
30-
msc3814_enabled: true,
31-
},
22+
test.use({
23+
displayName: NAME,
24+
synapseConfigOptions: {
25+
experimental_features: {
26+
msc2697_enabled: false,
27+
msc3814_enabled: true,
3228
},
33-
config: async ({ config, context }, use) => {
34-
const wellKnown = {
35-
...config.default_server_config,
36-
"org.matrix.msc3814": true,
37-
};
38-
39-
await context.route("https://localhost/.well-known/matrix/client", async (route) => {
40-
await route.fulfill({ json: wellKnown });
41-
});
29+
},
30+
config: async ({ config, context }, use) => {
31+
const wellKnown = {
32+
...config.default_server_config,
33+
"org.matrix.msc3814": true,
34+
};
35+
36+
await context.route("https://localhost/.well-known/matrix/client", async (route) => {
37+
await route.fulfill({ json: wellKnown });
38+
});
39+
40+
await use(config);
41+
},
42+
});
4243

43-
await use(config);
44-
},
45-
});
44+
test.describe("Dehydration", () => {
45+
test.skip(isDendrite, "does not yet support dehydration v2");
4646

4747
test("Create dehydrated device", async ({ page, user, app }, workerInfo) => {
4848
// Create a backup (which will create SSSS, and dehydrated device)

playwright/e2e/forgot-password/forgot-password.spec.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,21 @@ const username = "user1234";
1616
const password = "oETo7MPf0o";
1717
const email = "[email protected]";
1818

19-
test.describe("Forgot Password", () => {
20-
test.skip(isDendrite, "not yet wired up");
21-
test.use(emailHomeserver);
22-
test.use({
23-
config: {
24-
// The only thing that we really *need* (otherwise Element refuses to load) is a default homeserver.
25-
// We point that to a guaranteed-invalid domain.
26-
default_server_config: {
27-
"m.homeserver": {
28-
base_url: "https://server.invalid",
29-
},
19+
test.use(emailHomeserver);
20+
test.use({
21+
config: {
22+
// The only thing that we really *need* (otherwise Element refuses to load) is a default homeserver.
23+
// We point that to a guaranteed-invalid domain.
24+
default_server_config: {
25+
"m.homeserver": {
26+
base_url: "https://server.invalid",
3027
},
3128
},
32-
});
29+
},
30+
});
31+
32+
test.describe("Forgot Password", () => {
33+
test.skip(isDendrite, "not yet wired up");
3334

3435
test("renders properly", { tag: "@screenshot" }, async ({ page, homeserver }) => {
3536
await page.goto("/");

playwright/e2e/login/consent.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ Please see LICENSE files in the repository root for full details.
99
import { test, expect } from "../../element-web-test";
1010
import { consentHomeserver } from "../../plugins/homeserver/synapse/consentHomeserver.ts";
1111

12-
test.describe("Consent", () => {
13-
test.use(consentHomeserver);
14-
test.use({
15-
displayName: "Bob",
16-
});
12+
test.use(consentHomeserver);
13+
test.use({
14+
displayName: "Bob",
15+
});
1716

17+
test.describe("Consent", () => {
1818
test("should prompt the user to consent to terms when server deems it necessary", async ({
1919
context,
2020
page,

0 commit comments

Comments
 (0)