You've already forked element-web
mirror of
https://github.com/element-hq/element-web.git
synced 2025-07-31 19:44:30 +03:00
Fix flaky playwright tests (#28984)
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
committed by
GitHub
parent
1a21b718d8
commit
540580504d
@ -19,19 +19,19 @@ test.use(masHomeserver);
|
|||||||
test.describe("Encryption state after registration", () => {
|
test.describe("Encryption state after registration", () => {
|
||||||
test.skip(isDendrite, "does not yet support MAS");
|
test.skip(isDendrite, "does not yet support MAS");
|
||||||
|
|
||||||
test("Key backup is enabled by default", async ({ page, mailhogClient, app }) => {
|
test("Key backup is enabled by default", async ({ page, mailhogClient, app }, testInfo) => {
|
||||||
await page.goto("/#/login");
|
await page.goto("/#/login");
|
||||||
await page.getByRole("button", { name: "Continue" }).click();
|
await page.getByRole("button", { name: "Continue" }).click();
|
||||||
await registerAccountMas(page, mailhogClient, "alice", "alice@email.com", "Pa$sW0rD!");
|
await registerAccountMas(page, mailhogClient, `alice_${testInfo.testId}`, "alice@email.com", "Pa$sW0rD!");
|
||||||
|
|
||||||
await app.settings.openUserSettings("Security & Privacy");
|
await app.settings.openUserSettings("Security & Privacy");
|
||||||
await expect(page.getByText("This session is backing up your keys.")).toBeVisible();
|
await expect(page.getByText("This session is backing up your keys.")).toBeVisible();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("user is prompted to set up recovery", async ({ page, mailhogClient, app }) => {
|
test("user is prompted to set up recovery", async ({ page, mailhogClient, app }, testInfo) => {
|
||||||
await page.goto("/#/login");
|
await page.goto("/#/login");
|
||||||
await page.getByRole("button", { name: "Continue" }).click();
|
await page.getByRole("button", { name: "Continue" }).click();
|
||||||
await registerAccountMas(page, mailhogClient, "alice", "alice@email.com", "Pa$sW0rD!");
|
await registerAccountMas(page, mailhogClient, `alice_${testInfo.testId}`, "alice@email.com", "Pa$sW0rD!");
|
||||||
|
|
||||||
await page.getByRole("button", { name: "Add room" }).click();
|
await page.getByRole("button", { name: "Add room" }).click();
|
||||||
await page.getByRole("menuitem", { name: "New room" }).click();
|
await page.getByRole("menuitem", { name: "New room" }).click();
|
||||||
@ -45,8 +45,13 @@ test.describe("Encryption state after registration", () => {
|
|||||||
test.describe("Key backup reset from elsewhere", () => {
|
test.describe("Key backup reset from elsewhere", () => {
|
||||||
test.skip(isDendrite, "does not yet support MAS");
|
test.skip(isDendrite, "does not yet support MAS");
|
||||||
|
|
||||||
test("Key backup is disabled when reset from elsewhere", async ({ page, mailhogClient, request, homeserver }) => {
|
test("Key backup is disabled when reset from elsewhere", async ({
|
||||||
const testUsername = "alice";
|
page,
|
||||||
|
mailhogClient,
|
||||||
|
request,
|
||||||
|
homeserver,
|
||||||
|
}, testInfo) => {
|
||||||
|
const testUsername = `alice_${testInfo.testId}`;
|
||||||
const testPassword = "Pa$sW0rD!";
|
const testPassword = "Pa$sW0rD!";
|
||||||
|
|
||||||
// there's a delay before keys are uploaded so the error doesn't appear immediately: use a fake
|
// there's a delay before keys are uploaded so the error doesn't appear immediately: use a fake
|
||||||
|
@ -17,13 +17,13 @@ test.use(legacyOAuthHomeserver);
|
|||||||
test.describe("SSO login", () => {
|
test.describe("SSO login", () => {
|
||||||
test.skip(isDendrite, "does not yet support SSO");
|
test.skip(isDendrite, "does not yet support SSO");
|
||||||
|
|
||||||
test("logs in with SSO and lands on the home screen", async ({ page, homeserver }) => {
|
test("logs in with SSO and lands on the home screen", async ({ page, homeserver }, testInfo) => {
|
||||||
// If this test fails with a screen showing "Timeout connecting to remote server", it is most likely due to
|
// If this test fails with a screen showing "Timeout connecting to remote server", it is most likely due to
|
||||||
// your firewall settings: Synapse is unable to reach the OIDC server.
|
// your firewall settings: Synapse is unable to reach the OIDC server.
|
||||||
//
|
//
|
||||||
// If you are using ufw, try something like:
|
// If you are using ufw, try something like:
|
||||||
// sudo ufw allow in on docker0
|
// sudo ufw allow in on docker0
|
||||||
//
|
//
|
||||||
await doTokenRegistration(page, homeserver);
|
await doTokenRegistration(page, homeserver, testInfo);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -26,8 +26,8 @@ test.use({
|
|||||||
test.use(legacyOAuthHomeserver);
|
test.use(legacyOAuthHomeserver);
|
||||||
test.describe("Soft logout with SSO user", () => {
|
test.describe("Soft logout with SSO user", () => {
|
||||||
test.use({
|
test.use({
|
||||||
user: async ({ page, homeserver }, use) => {
|
user: async ({ page, homeserver }, use, testInfo) => {
|
||||||
const user = await doTokenRegistration(page, homeserver);
|
const user = await doTokenRegistration(page, homeserver, testInfo);
|
||||||
|
|
||||||
// Eventually, we should end up at the home screen.
|
// Eventually, we should end up at the home screen.
|
||||||
await expect(page).toHaveURL(/\/#\/home$/);
|
await expect(page).toHaveURL(/\/#\/home$/);
|
||||||
|
@ -6,7 +6,7 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
|
|||||||
Please see LICENSE files in the repository root for full details.
|
Please see LICENSE files in the repository root for full details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Page, expect } from "@playwright/test";
|
import { Page, expect, TestInfo } from "@playwright/test";
|
||||||
|
|
||||||
import { Credentials, HomeserverInstance } from "../../plugins/homeserver";
|
import { Credentials, HomeserverInstance } from "../../plugins/homeserver";
|
||||||
|
|
||||||
@ -15,6 +15,7 @@ import { Credentials, HomeserverInstance } from "../../plugins/homeserver";
|
|||||||
export async function doTokenRegistration(
|
export async function doTokenRegistration(
|
||||||
page: Page,
|
page: Page,
|
||||||
homeserver: HomeserverInstance,
|
homeserver: HomeserverInstance,
|
||||||
|
testInfo: TestInfo,
|
||||||
): Promise<Credentials & { displayName: string }> {
|
): Promise<Credentials & { displayName: string }> {
|
||||||
await page.goto("/#/login");
|
await page.goto("/#/login");
|
||||||
|
|
||||||
@ -35,7 +36,7 @@ export async function doTokenRegistration(
|
|||||||
|
|
||||||
// Synapse prompts us to pick a user ID
|
// Synapse prompts us to pick a user ID
|
||||||
await expect(page.getByRole("heading", { name: "Create your account" })).toBeVisible();
|
await expect(page.getByRole("heading", { name: "Create your account" })).toBeVisible();
|
||||||
await page.getByRole("textbox", { name: "Username (required)" }).fill("alice");
|
await page.getByRole("textbox", { name: "Username (required)" }).fill(`alice_${testInfo.testId}`);
|
||||||
|
|
||||||
// wait for username validation to start, and complete
|
// wait for username validation to start, and complete
|
||||||
await expect(page.locator("#field-username-output")).toHaveText("");
|
await expect(page.locator("#field-username-output")).toHaveText("");
|
||||||
|
@ -6,20 +6,31 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
|
|||||||
Please see LICENSE files in the repository root for full details.
|
Please see LICENSE files in the repository root for full details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Fixtures } from "@playwright/test";
|
import { Fixtures, PlaywrightTestArgs } from "@playwright/test";
|
||||||
import { TestContainers } from "testcontainers";
|
import { TestContainers } from "testcontainers";
|
||||||
|
|
||||||
import { Services } from "../../../services.ts";
|
import { Services } from "../../../services.ts";
|
||||||
import { OAuthServer } from "../../oauth_server";
|
import { OAuthServer } from "../../oauth_server";
|
||||||
|
|
||||||
export const legacyOAuthHomeserver: Fixtures<{}, Services> = {
|
export const legacyOAuthHomeserver: Fixtures<PlaywrightTestArgs, Services, PlaywrightTestArgs> = {
|
||||||
_homeserver: [
|
oAuthServer: [
|
||||||
async ({ _homeserver: container }, use) => {
|
// eslint-disable-next-line no-empty-pattern
|
||||||
|
async ({}, use) => {
|
||||||
const server = new OAuthServer();
|
const server = new OAuthServer();
|
||||||
const port = server.start();
|
await use(server);
|
||||||
|
server.stop();
|
||||||
|
},
|
||||||
|
{ scope: "worker" },
|
||||||
|
],
|
||||||
|
context: async ({ context, oAuthServer }, use, testInfo) => {
|
||||||
|
oAuthServer.onTestStarted(testInfo);
|
||||||
|
await use(context);
|
||||||
|
},
|
||||||
|
_homeserver: [
|
||||||
|
async ({ oAuthServer, _homeserver: homeserver }, use) => {
|
||||||
|
const port = oAuthServer.start();
|
||||||
await TestContainers.exposeHostPorts(port);
|
await TestContainers.exposeHostPorts(port);
|
||||||
container.withConfig({
|
homeserver.withConfig({
|
||||||
oidc_providers: [
|
oidc_providers: [
|
||||||
{
|
{
|
||||||
idp_id: "test",
|
idp_id: "test",
|
||||||
@ -43,8 +54,8 @@ export const legacyOAuthHomeserver: Fixtures<{}, Services> = {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
await use(container);
|
|
||||||
server.stop();
|
await use(homeserver);
|
||||||
},
|
},
|
||||||
{ scope: "worker" },
|
{ scope: "worker" },
|
||||||
],
|
],
|
||||||
|
@ -9,12 +9,21 @@ Please see LICENSE files in the repository root for full details.
|
|||||||
import http from "http";
|
import http from "http";
|
||||||
import express from "express";
|
import express from "express";
|
||||||
import { AddressInfo } from "net";
|
import { AddressInfo } from "net";
|
||||||
|
import { TestInfo } from "@playwright/test";
|
||||||
|
|
||||||
|
import { randB64Bytes } from "../utils/rand.ts";
|
||||||
|
|
||||||
export class OAuthServer {
|
export class OAuthServer {
|
||||||
private server?: http.Server;
|
private server?: http.Server;
|
||||||
|
private sub?: string;
|
||||||
|
|
||||||
|
public onTestStarted(testInfo: TestInfo): void {
|
||||||
|
this.sub = testInfo.testId;
|
||||||
|
}
|
||||||
|
|
||||||
public start(): number {
|
public start(): number {
|
||||||
if (this.server) this.stop();
|
if (this.server) this.stop();
|
||||||
|
const token = randB64Bytes(16);
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
@ -28,7 +37,7 @@ export class OAuthServer {
|
|||||||
const code = req.body.code;
|
const code = req.body.code;
|
||||||
if (code === "valid_auth_code") {
|
if (code === "valid_auth_code") {
|
||||||
res.send({
|
res.send({
|
||||||
access_token: "oauth_access_token",
|
access_token: token,
|
||||||
token_type: "Bearer",
|
token_type: "Bearer",
|
||||||
expires_in: "3600",
|
expires_in: "3600",
|
||||||
});
|
});
|
||||||
@ -43,7 +52,7 @@ export class OAuthServer {
|
|||||||
|
|
||||||
// return an OAuth2 user info object
|
// return an OAuth2 user info object
|
||||||
res.send({
|
res.send({
|
||||||
sub: "alice",
|
sub: this.sub,
|
||||||
name: "Alice",
|
name: "Alice",
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -15,6 +15,7 @@ import { Logger } from "./logger.ts";
|
|||||||
import { StartedMatrixAuthenticationServiceContainer } from "./testcontainers/mas.ts";
|
import { StartedMatrixAuthenticationServiceContainer } from "./testcontainers/mas.ts";
|
||||||
import { HomeserverContainer, StartedHomeserverContainer } from "./testcontainers/HomeserverContainer.ts";
|
import { HomeserverContainer, StartedHomeserverContainer } from "./testcontainers/HomeserverContainer.ts";
|
||||||
import { MailhogContainer, StartedMailhogContainer } from "./testcontainers/mailhog.ts";
|
import { MailhogContainer, StartedMailhogContainer } from "./testcontainers/mailhog.ts";
|
||||||
|
import { OAuthServer } from "./plugins/oauth_server";
|
||||||
|
|
||||||
interface TestFixtures {
|
interface TestFixtures {
|
||||||
mailhogClient: mailhog.API;
|
mailhogClient: mailhog.API;
|
||||||
@ -30,7 +31,10 @@ export interface Services {
|
|||||||
synapseConfigOptions: SynapseConfigOptions;
|
synapseConfigOptions: SynapseConfigOptions;
|
||||||
_homeserver: HomeserverContainer<any>;
|
_homeserver: HomeserverContainer<any>;
|
||||||
homeserver: StartedHomeserverContainer;
|
homeserver: StartedHomeserverContainer;
|
||||||
|
// Set in masHomeserver only
|
||||||
mas?: StartedMatrixAuthenticationServiceContainer;
|
mas?: StartedMatrixAuthenticationServiceContainer;
|
||||||
|
// Set in legacyOAuthHomeserver only
|
||||||
|
oAuthServer?: OAuthServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const test = base.extend<TestFixtures, Services>({
|
export const test = base.extend<TestFixtures, Services>({
|
||||||
|
Reference in New Issue
Block a user