From 885e7c36d9eaaeb483016d9ca44ab9641a3052e7 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Fri, 3 Oct 2025 12:25:21 +0100 Subject: [PATCH] Add `homeserverBaseUrl` field to `Credentials` `Credentials` is used to record the access token etc once we log in a or register a user. An access token isn't much use to you unless you know where to send it, so this patch addes a new field, `homeserverUrl`, which contains the base public URL for the homeserver. --- .../src/testcontainers/mas.ts | 9 +++++++-- .../src/testcontainers/synapse.ts | 11 ++++++++--- .../element-web-playwright-common/src/utils/api.ts | 8 +++++++- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/packages/element-web-playwright-common/src/testcontainers/mas.ts b/packages/element-web-playwright-common/src/testcontainers/mas.ts index 6330897ada..294afb7343 100644 --- a/packages/element-web-playwright-common/src/testcontainers/mas.ts +++ b/packages/element-web-playwright-common/src/testcontainers/mas.ts @@ -302,7 +302,7 @@ export class StartedMatrixAuthenticationServiceContainer extends AbstractStarted password: string, displayName?: string, admin = false, - ): Promise { + ): Promise> { const userId = await this.manageRegisterUser(username, password, displayName, admin); const { deviceId, accessToken } = await this.manageIssueCompatibilityToken(username, admin); @@ -319,11 +319,16 @@ export class StartedMatrixAuthenticationServiceContainer extends AbstractStarted /** * Registers a user + * * @param username - the username of the user to register * @param password - the password of the user to register * @param displayName - optional display name to set on the newly registered user */ - public async registerUser(username: string, password: string, displayName?: string): Promise { + public async registerUser( + username: string, + password: string, + displayName?: string, + ): Promise> { return this.registerUserInternal(username, password, displayName, false); } diff --git a/packages/element-web-playwright-common/src/testcontainers/synapse.ts b/packages/element-web-playwright-common/src/testcontainers/synapse.ts index 84ac60957b..4662031473 100644 --- a/packages/element-web-playwright-common/src/testcontainers/synapse.ts +++ b/packages/element-web-playwright-common/src/testcontainers/synapse.ts @@ -389,6 +389,7 @@ export class StartedSynapseContainer extends AbstractStartedContainer implements return { homeServer: data.home_server || data.user_id.split(":").slice(1).join(":"), + homeserverBaseUrl: this.baseUrl, accessToken: data.access_token, userId: data.user_id, deviceId: data.device_id, @@ -433,7 +434,10 @@ export class StartedSynapseContainer extends AbstractStartedContainer implements * @param password - login password */ public async loginUser(userId: string, password: string): Promise { - return this.csApi.loginUser(userId, password); + return { + ...(await this.csApi.loginUser(userId, password)), + homeserverBaseUrl: this.baseUrl, + }; } /** @@ -480,8 +484,9 @@ export class StartedSynapseWithMasContainer extends StartedSynapseContainer { * @param password - the password of the user to register * @param displayName - optional display name to set on the newly registered user */ - public registerUser(username: string, password: string, displayName?: string): Promise { - return this.mas.registerUser(username, password, displayName); + public async registerUser(username: string, password: string, displayName?: string): Promise { + const registered = await this.mas.registerUser(username, password, displayName); + return { ...registered, homeserverBaseUrl: this.baseUrl }; } /** diff --git a/packages/element-web-playwright-common/src/utils/api.ts b/packages/element-web-playwright-common/src/utils/api.ts index 55258e7408..8ce6f2f5dc 100644 --- a/packages/element-web-playwright-common/src/utils/api.ts +++ b/packages/element-web-playwright-common/src/utils/api.ts @@ -64,10 +64,16 @@ export class Api { * Credentials for a user. */ export interface Credentials { + /** The base URL of the homeserver's CS API. */ + homeserverBaseUrl: string; + accessToken: string; userId: string; deviceId: string; + + /** The domain part of the user's matrix ID. */ homeServer: string; + password: string | null; // null for password-less users displayName?: string; username: string; // the localpart of the userId @@ -86,7 +92,7 @@ export class ClientServerApi extends Api { * @param userId - The user ID to register. * @param password - The password to use for the user. */ - public async loginUser(userId: string, password: string): Promise { + public async loginUser(userId: string, password: string): Promise> { const json = await this.request<{ access_token: string; user_id: string;