Skip to content

Commit

Permalink
Prepare for switch to testcontainers in playwright (#28880)
Browse files Browse the repository at this point in the history
* Remove access to homeserver.config.baseUrl field in favour of homeserver.baseUrl

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Use sane default_server_config and specify server.invalid in the specific tests which demand it

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* break cycle

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Iterate

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* typo

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Iterate

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Iterate

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

---------

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
  • Loading branch information
t3chguy authored Jan 7, 2025
1 parent 1e758ca commit a73faff
Show file tree
Hide file tree
Showing 22 changed files with 102 additions and 88 deletions.
7 changes: 0 additions & 7 deletions playwright/e2e/app-loading/guest-registration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ import { expect, test } from "../../element-web-test";

test.use({
startHomeserverOpts: "guest-enabled",
config: async ({ homeserver }, use) => {
await use({
default_server_config: {
"m.homeserver": { base_url: homeserver.config.baseUrl },
},
});
},
});

test("Shows the welcome page by default", async ({ page }) => {
Expand Down
4 changes: 2 additions & 2 deletions playwright/e2e/crypto/complete-security.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ test.describe("Complete security", () => {
homeserver,
credentials,
}) => {
await logIntoElement(page, homeserver, credentials);
await logIntoElement(page, credentials);
await expect(page.getByText("Welcome Jeff", { exact: true })).toBeVisible();
});

// see also "Verify device during login with SAS" in `verifiction.spec.ts`.
// see also "Verify device during login with SAS" in `verification.spec.ts`.
});
4 changes: 2 additions & 2 deletions playwright/e2e/crypto/decryption-failure-messages.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ test.describe("Cryptography", function () {
await logOutOfElement(page, true);

// Log in again, and see how the message looks.
await logIntoElement(page, homeserver, credentials);
await logIntoElement(page, credentials);
await app.viewRoomByName("Test room");
const lastTile = page.locator(".mx_EventTile").last();
await expect(lastTile).toContainText("Historical messages are not available on this device");
Expand All @@ -62,7 +62,7 @@ test.describe("Cryptography", function () {

// Finally, log out again, and back in, skipping verification for now, and see what we see.
await logOutOfElement(page);
await logIntoElement(page, homeserver, credentials);
await logIntoElement(page, credentials);
await page.locator(".mx_AuthPage").getByRole("button", { name: "Skip verification for now" }).click();
await page.locator(".mx_AuthPage").getByRole("button", { name: "I'll verify later" }).click();
await app.viewRoomByName("Test room");
Expand Down
10 changes: 3 additions & 7 deletions playwright/e2e/crypto/dehydration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,17 @@ const test = base.extend<Fixtures>({
startHomeserverOpts: async ({}, use) => {
await use("dehydration");
},
config: async ({ homeserver, context }, use) => {
config: async ({ config, context }, use) => {
const wellKnown = {
"m.homeserver": {
base_url: homeserver.config.baseUrl,
},
...config.default_server_config,
"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,
});
await use(config);
},
});

Expand Down
10 changes: 5 additions & 5 deletions playwright/e2e/crypto/device-verification.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ test.describe("Device verification", { tag: "@no-webkit" }, () => {
}

test("Verify device with SAS during login", async ({ page, app, credentials, homeserver }) => {
await logIntoElement(page, homeserver, credentials);
await logIntoElement(page, credentials);

// Launch the verification request between alice and the bot
const verificationRequest = await initiateAliceVerificationRequest(page);
Expand All @@ -93,7 +93,7 @@ test.describe("Device verification", { tag: "@no-webkit" }, () => {

test("Verify device with QR code during login", async ({ page, app, credentials, homeserver }) => {
// A mode 0x02 verification: "self-verifying in which the current device does not yet trust the master key"
await logIntoElement(page, homeserver, credentials);
await logIntoElement(page, credentials);

// Launch the verification request between alice and the bot
const verificationRequest = await initiateAliceVerificationRequest(page);
Expand Down Expand Up @@ -137,7 +137,7 @@ test.describe("Device verification", { tag: "@no-webkit" }, () => {
});

test("Verify device with Security Phrase during login", async ({ page, app, credentials, homeserver }) => {
await logIntoElement(page, homeserver, credentials);
await logIntoElement(page, credentials);

// Select the security phrase
await page.locator(".mx_AuthPage").getByRole("button", { name: "Verify with Security Key or Phrase" }).click();
Expand All @@ -158,7 +158,7 @@ test.describe("Device verification", { tag: "@no-webkit" }, () => {
});

test("Verify device with Security Key during login", async ({ page, app, credentials, homeserver }) => {
await logIntoElement(page, homeserver, credentials);
await logIntoElement(page, credentials);

// Select the security phrase
await page.locator(".mx_AuthPage").getByRole("button", { name: "Verify with Security Key or Phrase" }).click();
Expand All @@ -181,7 +181,7 @@ test.describe("Device verification", { tag: "@no-webkit" }, () => {
});

test("Handle incoming verification request with SAS", async ({ page, credentials, homeserver, toasts }) => {
await logIntoElement(page, homeserver, credentials);
await logIntoElement(page, credentials);

/* Dismiss "Verify this device" */
const authPage = page.locator(".mx_AuthPage");
Expand Down
2 changes: 1 addition & 1 deletion playwright/e2e/crypto/event-shields.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ test.describe("Cryptography", function () {
window.localStorage.clear();
});
await page.reload();
await logIntoElement(page, homeserver, aliceCredentials, securityKey);
await logIntoElement(page, aliceCredentials, securityKey);

/* go back to the test room and find Bob's message again */
await app.viewRoomById(testRoomId);
Expand Down
2 changes: 1 addition & 1 deletion playwright/e2e/crypto/logout.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { createRoom, enableKeyBackup, logIntoElement, sendMessageInCurrentRoom }

test.describe("Logout tests", () => {
test.beforeEach(async ({ page, homeserver, credentials }) => {
await logIntoElement(page, homeserver, credentials);
await logIntoElement(page, credentials);
});

test("Ask to set up recovery on logout if not setup", async ({ page, app }) => {
Expand Down
15 changes: 1 addition & 14 deletions playwright/e2e/crypto/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,22 +138,9 @@ export async function checkDeviceIsConnectedKeyBackup(
*
* If a `securityKey` is given, verifies the new device using the key.
*/
export async function logIntoElement(
page: Page,
homeserver: HomeserverInstance,
credentials: Credentials,
securityKey?: string,
) {
export async function logIntoElement(page: Page, credentials: Credentials, securityKey?: string) {
await page.goto("/#/login");

// select homeserver
await page.getByRole("button", { name: "Edit" }).click();
await page.getByRole("textbox", { name: "Other homeserver" }).fill(homeserver.config.baseUrl);
await page.getByRole("button", { name: "Continue", exact: true }).click();

// wait for the dialog to go away
await expect(page.locator(".mx_ServerPickerDialog")).not.toBeVisible();

await page.getByRole("textbox", { name: "Username" }).fill(credentials.userId);
await page.getByPlaceholder("Password").fill(credentials.password);
await page.getByRole("button", { name: "Sign in" }).click();
Expand Down
4 changes: 2 additions & 2 deletions playwright/e2e/csAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class TestClientServerAPI {
) {}

public async getCurrentBackupInfo(): Promise<KeyBackupInfo | null> {
const res = await this.request.get(`${this.homeserver.config.baseUrl}/_matrix/client/v3/room_keys/version`, {
const res = await this.request.get(`${this.homeserver.baseUrl}/_matrix/client/v3/room_keys/version`, {
headers: { Authorization: `Bearer ${this.accessToken}` },
});

Expand All @@ -35,7 +35,7 @@ export class TestClientServerAPI {
*/
public async deleteBackupVersion(version: string): Promise<void> {
const res = await this.request.delete(
`${this.homeserver.config.baseUrl}/_matrix/client/v3/room_keys/version/${version}`,
`${this.homeserver.baseUrl}/_matrix/client/v3/room_keys/version/${version}`,
{
headers: { Authorization: `Bearer ${this.accessToken}` },
},
Expand Down
13 changes: 11 additions & 2 deletions playwright/e2e/forgot-password/forgot-password.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ const email = "user@nowhere.dummy";

test.describe("Forgot Password", () => {
test.use({
config: {
// The only thing that we really *need* (otherwise Element refuses to load) is a default homeserver.
// We point that to a guaranteed-invalid domain.
default_server_config: {
"m.homeserver": {
base_url: "https://server.invalid",
},
},
},
startHomeserverOpts: ({ mailhog }, use) =>
use({
template: "email",
Expand All @@ -32,7 +41,7 @@ test.describe("Forgot Password", () => {
await page.getByRole("link", { name: "Sign in" }).click();

// need to select a homeserver at this stage, before entering the forgot password flow
await selectHomeserver(page, homeserver.config.baseUrl);
await selectHomeserver(page, homeserver.baseUrl);

await page.getByRole("button", { name: "Forgot password?" }).click();

Expand All @@ -47,7 +56,7 @@ test.describe("Forgot Password", () => {
await page.goto("/");

await page.getByRole("link", { name: "Sign in" }).click();
await selectHomeserver(page, homeserver.config.baseUrl);
await selectHomeserver(page, homeserver.baseUrl);

await page.getByRole("button", { name: "Forgot password?" }).click();

Expand Down
30 changes: 21 additions & 9 deletions playwright/e2e/login/login.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,26 @@ const DEVICE_SIGNING_KEYS_BODY = {

async function login(page: Page, homeserver: HomeserverInstance) {
await page.getByRole("link", { name: "Sign in" }).click();
await selectHomeserver(page, homeserver.config.baseUrl);
await selectHomeserver(page, homeserver.baseUrl);

await page.getByRole("textbox", { name: "Username" }).fill(username);
await page.getByPlaceholder("Password").fill(password);
await page.getByRole("button", { name: "Sign in" }).click();
}

test.describe("Login", () => {
test.use({
config: {
// The only thing that we really *need* (otherwise Element refuses to load) is a default homeserver.
// We point that to a guaranteed-invalid domain.
default_server_config: {
"m.homeserver": {
base_url: "https://server.invalid",
},
},
},
});

test.describe("Password login", () => {
test.use({ startHomeserverOpts: "consent" });

Expand All @@ -101,7 +113,7 @@ test.describe("Login", () => {
await page.getByRole("link", { name: "Sign in" }).click();

// first pick the homeserver, as otherwise the user picker won't be visible
await selectHomeserver(page, homeserver.config.baseUrl);
await selectHomeserver(page, homeserver.baseUrl);

await page.getByRole("button", { name: "Edit" }).click();

Expand All @@ -114,7 +126,7 @@ test.describe("Login", () => {
await expect(page.locator(".mx_ServerPicker_server")).toHaveText("server.invalid");

// switch back to the custom homeserver
await selectHomeserver(page, homeserver.config.baseUrl);
await selectHomeserver(page, homeserver.baseUrl);

await expect(page.getByRole("textbox", { name: "Username" })).toBeVisible();
// Disabled because flaky - see https://github.com/vector-im/element-web/issues/24688
Expand Down Expand Up @@ -142,10 +154,10 @@ test.describe("Login", () => {
homeserver,
request,
}) => {
const res = await request.post(
`${homeserver.config.baseUrl}/_matrix/client/v3/keys/device_signing/upload`,
{ headers: { Authorization: `Bearer ${creds.accessToken}` }, data: DEVICE_SIGNING_KEYS_BODY },
);
const res = await request.post(`${homeserver.baseUrl}/_matrix/client/v3/keys/device_signing/upload`, {
headers: { Authorization: `Bearer ${creds.accessToken}` },
data: DEVICE_SIGNING_KEYS_BODY,
});
if (res.status() / 100 !== 2) {
console.log("Uploading dummy keys failed", await res.json());
}
Expand All @@ -172,7 +184,7 @@ test.describe("Login", () => {
request,
}) => {
const res = await request.post(
`${homeserver.config.baseUrl}/_matrix/client/v3/keys/device_signing/upload`,
`${homeserver.baseUrl}/_matrix/client/v3/keys/device_signing/upload`,
{ headers: { Authorization: `Bearer ${creds.accessToken}` }, data: DEVICE_SIGNING_KEYS_BODY },
);
if (res.status() / 100 !== 2) {
Expand Down Expand Up @@ -203,7 +215,7 @@ test.describe("Login", () => {
}) => {
console.log(`uid ${creds.userId} body`, DEVICE_SIGNING_KEYS_BODY);
const res = await request.post(
`${homeserver.config.baseUrl}/_matrix/client/v3/keys/device_signing/upload`,
`${homeserver.baseUrl}/_matrix/client/v3/keys/device_signing/upload`,
{ headers: { Authorization: `Bearer ${creds.accessToken}` }, data: DEVICE_SIGNING_KEYS_BODY },
);
if (res.status() / 100 !== 2) {
Expand Down
4 changes: 2 additions & 2 deletions playwright/e2e/login/overwrite_login.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test.describe("Overwrite login action", () => {
// This seems terminally flakey: https://github.com/element-hq/element-web/issues/27363
// I tried verious things to try & deflake it, to no avail: https://github.com/matrix-org/matrix-react-sdk/pull/12506
test.skip("Try replace existing login with new one", async ({ page, app, credentials, homeserver }) => {
await logIntoElement(page, homeserver, credentials);
await logIntoElement(page, credentials);

const userMenu = await app.openUserMenu();
await expect(userMenu.getByText(credentials.userId)).toBeVisible();
Expand All @@ -24,7 +24,7 @@ test.describe("Overwrite login action", () => {
expect(credentials.userId).not.toBe(bobRegister.userId);

const clientCredentials /* IMatrixClientCreds */ = {
homeserverUrl: homeserver.config.baseUrl,
homeserverUrl: homeserver.baseUrl,
...bobRegister,
};

Expand Down
9 changes: 9 additions & 0 deletions playwright/e2e/login/soft_logout.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ import { isDendrite } from "../../plugins/homeserver/dendrite";
test.describe("Soft logout", () => {
test.use({
displayName: "Alice",
config: {
// The only thing that we really *need* (otherwise Element refuses to load) is a default homeserver.
// We point that to a guaranteed-invalid domain.
default_server_config: {
"m.homeserver": {
base_url: "https://server.invalid",
},
},
},
startHomeserverOpts: ({ oAuthServer }, use) =>
use({
template: "default",
Expand Down
2 changes: 1 addition & 1 deletion playwright/e2e/login/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export async function doTokenRegistration(
await page.goto("/#/login");

await page.getByRole("button", { name: "Edit" }).click();
await page.getByRole("textbox", { name: "Other homeserver" }).fill(homeserver.config.baseUrl);
await page.getByRole("textbox", { name: "Other homeserver" }).fill(homeserver.baseUrl);
await page.getByRole("button", { name: "Continue" }).click();
// wait for the dialog to go away
await expect(page.locator(".mx_ServerPickerDialog")).toHaveCount(0);
Expand Down
10 changes: 3 additions & 7 deletions playwright/e2e/oidc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,10 @@ export const test = base.extend<{
},
});
},
config: async ({ homeserver, startHomeserverOpts, context }, use) => {
config: async ({ config, startHomeserverOpts, context }, use) => {
const issuer = `http://localhost:${(startHomeserverOpts as StartHomeserverOpts).variables["MAS_PORT"]}/`;
const wellKnown = {
"m.homeserver": {
base_url: homeserver.config.baseUrl,
},
...config.default_server_config,
"org.matrix.msc2965.authentication": {
issuer,
account: `${issuer}account`,
Expand All @@ -57,9 +55,7 @@ export const test = base.extend<{
await route.fulfill({ json: wellKnown });
});

await use({
default_server_config: wellKnown,
});
await use(config);
},
});

Expand Down
9 changes: 4 additions & 5 deletions playwright/e2e/register/email.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,19 @@ test.describe("Email Registration", async () => {
SMTP_PORT: mailhog.instance.smtpPort,
},
}),
config: ({ homeserver }, use) =>
config: ({ config }, use) =>
use({
...config,
default_server_config: {
"m.homeserver": {
base_url: homeserver.config.baseUrl,
},
...config.default_server_config,
"m.identity_server": {
base_url: "https://server.invalid",
},
},
}),
});

test.beforeEach(async ({ page }) => {
test.beforeEach(async ({ homeserver, page }) => {
await page.goto("/#/register");
});

Expand Down
Loading

0 comments on commit a73faff

Please sign in to comment.