diff --git a/playwright/e2e/login/login-consent.spec.ts b/playwright/e2e/login/login-consent.spec.ts index d7d5861a02..31d0ccc652 100644 --- a/playwright/e2e/login/login-consent.spec.ts +++ b/playwright/e2e/login/login-consent.spec.ts @@ -92,6 +92,9 @@ test.use({ }, }, credentials: async ({ context, homeserver }, use) => { + // Restart the homeserver to wipe its in-memory db so we can reuse the same user ID without cross-signing prompts + await homeserver.restart(); + const displayName = "Dave"; const credentials = await homeserver.registerUser(username, password, displayName); console.log(`Registered test user @user:localhost with displayname ${displayName}`); @@ -100,9 +103,6 @@ test.use({ ...credentials, displayName, }); - - // Restart the homeserver to wipe its in-memory db so we can reuse the same user ID without cross-signing prompts - await homeserver.restart(); }, }); diff --git a/playwright/e2e/spotlight/spotlight.spec.ts b/playwright/e2e/spotlight/spotlight.spec.ts index da35ca57b3..22a3a41a81 100644 --- a/playwright/e2e/spotlight/spotlight.spec.ts +++ b/playwright/e2e/spotlight/spotlight.spec.ts @@ -81,6 +81,11 @@ const test = base.extend<{ }); await use({ name, roomId }); }, + credentials: async ({ credentials, homeserver }, use) => { + // Restart the homeserver to wipe its in-memory db so we can purge the user_directory of users + await homeserver.restart(); + await use(credentials); + }, }); test.describe("Spotlight", () => { diff --git a/playwright/plugins/homeserver/synapse/legacyOAuthHomeserver.ts b/playwright/plugins/homeserver/synapse/legacyOAuthHomeserver.ts index 246829e422..90737f94a4 100644 --- a/playwright/plugins/homeserver/synapse/legacyOAuthHomeserver.ts +++ b/playwright/plugins/homeserver/synapse/legacyOAuthHomeserver.ts @@ -9,11 +9,11 @@ Please see LICENSE files in the repository root for full details. import { Fixtures } from "@playwright/test"; import { TestContainers } from "testcontainers"; -import { Services } from "../../../services.ts"; +import { Services, TestFixtures } from "../../../services.ts"; import { OAuthServer } from "../../oauth_server"; -export const legacyOAuthHomeserver: Fixtures<{}, Services> = { - _homeserver: [ +export const legacyOAuthHomeserver: Fixtures = { + _oAuthServer: [ async ({ _homeserver: container }, use) => { const server = new OAuthServer(); const port = server.start(); @@ -43,9 +43,13 @@ export const legacyOAuthHomeserver: Fixtures<{}, Services> = { }, ], }); - await use(container); + await use(server); server.stop(); }, { scope: "worker" }, ], + oAuthServer: async ({ _oAuthServer }, use, testInfo) => { + _oAuthServer.onTestStarted(testInfo); + await use(_oAuthServer); + }, }; diff --git a/playwright/plugins/oauth_server/index.ts b/playwright/plugins/oauth_server/index.ts index 3f80dc11ca..df5ee0f461 100644 --- a/playwright/plugins/oauth_server/index.ts +++ b/playwright/plugins/oauth_server/index.ts @@ -9,12 +9,21 @@ Please see LICENSE files in the repository root for full details. import http from "http"; import express from "express"; import { AddressInfo } from "net"; +import { TestInfo } from "@playwright/test"; + +import { randB64Bytes } from "../utils/rand.ts"; export class OAuthServer { private server?: http.Server; + private sub?: string; + + public onTestStarted(testInfo: TestInfo): void { + this.sub = testInfo.testId; + } public start(): number { if (this.server) this.stop(); + const token = randB64Bytes(16); const app = express(); @@ -28,7 +37,7 @@ export class OAuthServer { const code = req.body.code; if (code === "valid_auth_code") { res.send({ - access_token: "oauth_access_token", + access_token: token, token_type: "Bearer", expires_in: "3600", }); @@ -43,7 +52,7 @@ export class OAuthServer { // return an OAuth2 user info object res.send({ - sub: "alice", + sub: this.sub, name: "Alice", }); }); diff --git a/playwright/services.ts b/playwright/services.ts index f275f63774..26ab25c5c6 100644 --- a/playwright/services.ts +++ b/playwright/services.ts @@ -15,9 +15,12 @@ import { ContainerLogger } from "./testcontainers/utils.ts"; import { StartedMatrixAuthenticationServiceContainer } from "./testcontainers/mas.ts"; import { HomeserverContainer, StartedHomeserverContainer } from "./testcontainers/HomeserverContainer.ts"; import { MailhogContainer, StartedMailhogContainer } from "./testcontainers/mailhog.ts"; +import { OAuthServer } from "./plugins/oauth_server"; -interface TestFixtures { +export interface TestFixtures { mailhogClient: mailhog.API; + // Set in legacyOAuthHomeserver only + oAuthServer?: OAuthServer; } export interface Services { @@ -31,6 +34,9 @@ export interface Services { _homeserver: HomeserverContainer; homeserver: StartedHomeserverContainer; mas?: StartedMatrixAuthenticationServiceContainer; + + // Set in legacyOAuthHomeserver only + _oAuthServer?: OAuthServer; } export const test = base.extend({ diff --git a/playwright/testcontainers/mas.ts b/playwright/testcontainers/mas.ts index 697ef374a1..6939789457 100644 --- a/playwright/testcontainers/mas.ts +++ b/playwright/testcontainers/mas.ts @@ -162,6 +162,14 @@ const DEFAULT_CONFIG = { access_token_ttl: 300, compat_token_ttl: 300, }, + rate_limiting: { + login: { + burst: 1000, + }, + registration: { + burst: 1000, + }, + }, }; export class MatrixAuthenticationServiceContainer extends GenericContainer {