From 63e855e0c4f8f092848377e77c4a207f640f38a6 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 6 Jan 2025 15:25:40 +0000 Subject: [PATCH] Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- playwright/e2e/crypto/dehydration.spec.ts | 49 +++++++++++------------ playwright/e2e/crypto/migration.spec.ts | 32 +++++++-------- playwright/testcontainers/dendrite.ts | 14 +++---- playwright/testcontainers/mas.ts | 1 + playwright/testcontainers/synapse.ts | 1 + 5 files changed, 46 insertions(+), 51 deletions(-) diff --git a/playwright/e2e/crypto/dehydration.spec.ts b/playwright/e2e/crypto/dehydration.spec.ts index 64d0c4888c..fe0aad51b9 100644 --- a/playwright/e2e/crypto/dehydration.spec.ts +++ b/playwright/e2e/crypto/dehydration.spec.ts @@ -8,35 +8,10 @@ Please see LICENSE files in the repository root for full details. import { Locator, type Page } from "@playwright/test"; -import { test as base, expect, Fixtures } from "../../element-web-test"; +import { test, expect } from "../../element-web-test"; import { viewRoomSummaryByName } from "../right-panel/utils"; import { isDendrite } from "../../plugins/homeserver/dendrite"; -const test = base.extend({ - synapseConfigOptions: { - experimental_features: { - msc2697_enabled: false, - msc3814_enabled: true, - }, - }, - config: async ({ homeserver, context }, use) => { - const wellKnown = { - "m.homeserver": { - base_url: homeserver.baseUrl, - }, - "org.matrix.msc3814": true, - }; - - await context.route("https://localhost/.well-known/matrix/client", async (route) => { - await route.fulfill({ json: wellKnown }); - }); - - await use({ - default_server_config: wellKnown, - }); - }, -}); - const ROOM_NAME = "Test room"; const NAME = "Alice"; @@ -49,6 +24,28 @@ test.describe("Dehydration", () => { test.use({ displayName: NAME, + synapseConfigOptions: { + experimental_features: { + msc2697_enabled: false, + msc3814_enabled: true, + }, + }, + config: async ({ homeserver, context }, use) => { + const wellKnown = { + "m.homeserver": { + base_url: homeserver.baseUrl, + }, + "org.matrix.msc3814": true, + }; + + await context.route("https://localhost/.well-known/matrix/client", async (route) => { + await route.fulfill({ json: wellKnown }); + }); + + await use({ + default_server_config: wellKnown, + }); + }, }); test("Create dehydrated device", async ({ page, user, app }, workerInfo) => { diff --git a/playwright/e2e/crypto/migration.spec.ts b/playwright/e2e/crypto/migration.spec.ts index c36cf2997e..86072fccc0 100644 --- a/playwright/e2e/crypto/migration.spec.ts +++ b/playwright/e2e/crypto/migration.spec.ts @@ -9,24 +9,24 @@ Please see LICENSE files in the repository root for full details. import path from "path"; import { readFile } from "node:fs/promises"; -import { expect, Fixtures, test as base } from "../../element-web-test"; - -const test = base.extend({ - // Replace the `user` fixture with one which populates the indexeddb data before starting the app. - user: async ({ context, pageWithCredentials: page, credentials }, use) => { - await page.route(`/test_indexeddb_cryptostore_dump/*`, async (route, request) => { - const resourcePath = path.join(__dirname, new URL(request.url()).pathname); - const body = await readFile(resourcePath, { encoding: "utf-8" }); - await route.fulfill({ body }); - }); - await page.goto("/test_indexeddb_cryptostore_dump/index.html"); - - await use(credentials); - }, -}); +import { expect, test } from "../../element-web-test"; test.describe("migration", { tag: "@no-webkit" }, function () { - test.use({ displayName: "Alice" }); + test.use({ + displayName: "Alice", + + // Replace the `user` fixture with one which populates the indexeddb data before starting the app. + user: async ({ context, pageWithCredentials: page, credentials }, use) => { + await page.route(`/test_indexeddb_cryptostore_dump/*`, async (route, request) => { + const resourcePath = path.join(__dirname, new URL(request.url()).pathname); + const body = await readFile(resourcePath, { encoding: "utf-8" }); + await route.fulfill({ body }); + }); + await page.goto("/test_indexeddb_cryptostore_dump/index.html"); + + await use(credentials); + }, + }); test("Should support migration from legacy crypto", async ({ context, user, page }, workerInfo) => { test.slow(); diff --git a/playwright/testcontainers/dendrite.ts b/playwright/testcontainers/dendrite.ts index f066791e2b..141d96156b 100644 --- a/playwright/testcontainers/dendrite.ts +++ b/playwright/testcontainers/dendrite.ts @@ -10,7 +10,6 @@ import { APIRequestContext } from "@playwright/test"; import * as YAML from "yaml"; import { set } from "lodash"; -import { getFreePort } from "../plugins/utils/port.ts"; import { randB64Bytes } from "../plugins/utils/rand.ts"; import { StartedSynapseContainer } from "./synapse.ts"; import { deepCopy } from "../plugins/utils/object.ts"; @@ -223,6 +222,7 @@ export class DendriteContainer extends GenericContainer { "-c", `/usr/bin/generate-keys -private-key /etc/dendrite/matrix_key.pem && ${binary} --config /etc/dendrite/dendrite.yaml --really-enable-open-registration true run`, ]) + .withExposedPorts(8008) .withWaitStrategy(Wait.forHttp("/_matrix/client/versions", 8008)); } @@ -240,22 +240,18 @@ export class DendriteContainer extends GenericContainer { } public override async start(): Promise { - const port = await getFreePort(); - - this.withExposedPorts({ - container: 8008, - host: port, - }).withCopyContentToContainer([ + this.withCopyContentToContainer([ { target: "/etc/dendrite/dendrite.yaml", content: YAML.stringify(this.config), }, ]); + const container = await super.start(); // Surprisingly, Dendrite implements the same register user Admin API Synapse, so we can just extend it return new StartedSynapseContainer( - await super.start(), - `http://localhost:${port}`, + container, + `http://${container.getHost()}:${container.getMappedPort(8008)}`, this.config.client_api.registration_shared_secret, this.request, ); diff --git a/playwright/testcontainers/mas.ts b/playwright/testcontainers/mas.ts index 0c5dae89d0..d15f619dbc 100644 --- a/playwright/testcontainers/mas.ts +++ b/playwright/testcontainers/mas.ts @@ -194,6 +194,7 @@ export class MatrixAuthenticationServiceContainer extends GenericContainer { } public override async start(): Promise { + // MAS config issuer needs to know what URL it'll be accessed from, so we have to map the port manually const port = await getFreePort(); this.config.http.public_base = `http://localhost:${port}/`; diff --git a/playwright/testcontainers/synapse.ts b/playwright/testcontainers/synapse.ts index 4cc5c3e7d8..a04041437f 100644 --- a/playwright/testcontainers/synapse.ts +++ b/playwright/testcontainers/synapse.ts @@ -199,6 +199,7 @@ export class SynapseContainer extends GenericContainer { } public override async start(): Promise { + // Synapse config public_baseurl needs to know what URL it'll be accessed from, so we have to map the port manually const port = await getFreePort(); this.withExposedPorts({