mirror of
https://github.com/vector-im/element-web.git
synced 2026-05-04 11:51:36 +02:00
Merge pull request #212 from element-hq/t3chguy/wat/382
This commit is contained in:
commit
134ffe3de2
@ -7,7 +7,7 @@ Please see LICENSE files in the repository root for full details.
|
||||
|
||||
import { type MailpitClient } from "mailpit-api";
|
||||
import { Network, type StartedNetwork } from "testcontainers";
|
||||
import { PostgreSqlContainer, type StartedPostgreSqlContainer } from "@testcontainers/postgresql";
|
||||
import { type StartedPostgreSqlContainer } from "@testcontainers/postgresql";
|
||||
|
||||
import {
|
||||
type SynapseConfig,
|
||||
@ -22,6 +22,7 @@ import { Logger } from "../utils/logger.js";
|
||||
// We want to avoid using `mergeTests` in index.ts because it drops useful type information about the fixtures. Instead,
|
||||
// we add `axe` into our fixture suite by using its `test` as a base, so that there is a linear hierarchy.
|
||||
import { test as base } from "./axe.js";
|
||||
import { makePostgres } from "../testcontainers/postgres.js";
|
||||
|
||||
/**
|
||||
* Test-scoped fixtures available in the test
|
||||
@ -101,27 +102,7 @@ export const test = base.extend<TestFixtures, WorkerOptions & Services>({
|
||||
],
|
||||
postgres: [
|
||||
async ({ logger, network }, use) => {
|
||||
const container = await new PostgreSqlContainer("postgres:13.3-alpine")
|
||||
.withNetwork(network)
|
||||
.withNetworkAliases("postgres")
|
||||
.withLogConsumer(logger.getConsumer("postgres"))
|
||||
.withTmpFs({
|
||||
"/dev/shm/pgdata/data": "",
|
||||
})
|
||||
.withEnvironment({
|
||||
PG_DATA: "/dev/shm/pgdata/data",
|
||||
})
|
||||
.withCommand([
|
||||
"-c",
|
||||
"shared_buffers=128MB",
|
||||
"-c",
|
||||
`fsync=off`,
|
||||
"-c",
|
||||
`synchronous_commit=off`,
|
||||
"-c",
|
||||
"full_page_writes=off",
|
||||
])
|
||||
.start();
|
||||
const container = await makePostgres(network, logger);
|
||||
await use(container);
|
||||
await container.stop();
|
||||
},
|
||||
|
||||
@ -11,6 +11,7 @@ import {
|
||||
type StartedTestContainer,
|
||||
Wait,
|
||||
type ExecResult,
|
||||
type StartedNetwork,
|
||||
} from "testcontainers";
|
||||
import { type StartedPostgreSqlContainer } from "@testcontainers/postgresql";
|
||||
import * as YAML from "yaml";
|
||||
@ -23,6 +24,7 @@ import { type Credentials } from "../utils/api.js";
|
||||
// curl -sL https://element-hq.github.io/matrix-authentication-service/config.schema.json \
|
||||
// | npx json-schema-to-typescript -o packages/element-web-playwright-common/src/testconainers/mas-config.ts
|
||||
import type { RootConfig as MasConfig } from "./mas-config.js";
|
||||
import type { Logger } from "../utils/logger.js";
|
||||
|
||||
export { type MasConfig };
|
||||
|
||||
@ -156,6 +158,7 @@ export class MatrixAuthenticationServiceContainer extends GenericContainer {
|
||||
super(image);
|
||||
|
||||
const initialConfig = deepCopy(DEFAULT_CONFIG);
|
||||
initialConfig.database.host = db.getHostname();
|
||||
initialConfig.database.username = db.getUsername();
|
||||
initialConfig.database.password = db.getPassword();
|
||||
|
||||
@ -205,6 +208,7 @@ export class MatrixAuthenticationServiceContainer extends GenericContainer {
|
||||
await super.start(),
|
||||
`http://localhost:${port}`,
|
||||
this.args,
|
||||
this.config.matrix.secret,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -219,6 +223,7 @@ export class StartedMatrixAuthenticationServiceContainer extends AbstractStarted
|
||||
container: StartedTestContainer,
|
||||
public readonly baseUrl: string,
|
||||
private readonly args: string[],
|
||||
public readonly sharedSecret: string,
|
||||
) {
|
||||
super(container);
|
||||
}
|
||||
@ -346,3 +351,19 @@ export class StartedMatrixAuthenticationServiceContainer extends AbstractStarted
|
||||
await this.manage("add-email", username, address);
|
||||
}
|
||||
}
|
||||
|
||||
export async function makeMas(
|
||||
postgres: StartedPostgreSqlContainer,
|
||||
network: StartedNetwork,
|
||||
logger: Logger,
|
||||
config: Partial<MasConfig>,
|
||||
name = "mas",
|
||||
): Promise<StartedMatrixAuthenticationServiceContainer> {
|
||||
const container = await new MatrixAuthenticationServiceContainer(postgres)
|
||||
.withNetwork(network)
|
||||
.withNetworkAliases(name)
|
||||
.withLogConsumer(logger.getConsumer(name))
|
||||
.withConfig(config)
|
||||
.start();
|
||||
return container;
|
||||
}
|
||||
|
||||
@ -0,0 +1,40 @@
|
||||
/*
|
||||
Copyright 2026 Element Creations Ltd.
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import { PostgreSqlContainer, type StartedPostgreSqlContainer } from "@testcontainers/postgresql";
|
||||
import { type StartedNetwork } from "testcontainers";
|
||||
|
||||
import { type Logger } from "../utils/logger.js";
|
||||
|
||||
export async function makePostgres(
|
||||
network: StartedNetwork,
|
||||
logger: Logger,
|
||||
name = "postgres",
|
||||
): Promise<StartedPostgreSqlContainer> {
|
||||
const container = await new PostgreSqlContainer("postgres:13.3-alpine")
|
||||
.withNetwork(network)
|
||||
.withNetworkAliases(name)
|
||||
.withLogConsumer(logger.getConsumer(name))
|
||||
.withTmpFs({
|
||||
"/dev/shm/pgdata/data": "",
|
||||
})
|
||||
.withEnvironment({
|
||||
PG_DATA: "/dev/shm/pgdata/data",
|
||||
})
|
||||
.withCommand([
|
||||
"-c",
|
||||
"shared_buffers=128MB",
|
||||
"-c",
|
||||
`fsync=off`,
|
||||
"-c",
|
||||
`synchronous_commit=off`,
|
||||
"-c",
|
||||
"full_page_writes=off",
|
||||
])
|
||||
.start();
|
||||
return container;
|
||||
}
|
||||
@ -184,6 +184,14 @@ const DEFAULT_CONFIG = {
|
||||
},
|
||||
room_list_publication_rules: [{ action: "allow" }],
|
||||
modules: [] as Array<{ module: string; config?: Record<string, unknown> }>,
|
||||
matrix_authentication_service: undefined as
|
||||
| undefined
|
||||
| {
|
||||
enabled?: boolean;
|
||||
endpoint?: string;
|
||||
secret?: string | null;
|
||||
secret_path?: string | null;
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
@ -278,7 +286,22 @@ export class SynapseContainer extends GenericContainer implements HomeserverCont
|
||||
}
|
||||
|
||||
public withMatrixAuthenticationService(mas?: StartedMatrixAuthenticationServiceContainer): this {
|
||||
this.mas = mas;
|
||||
if (mas) {
|
||||
this.mas = mas;
|
||||
this.withConfig({
|
||||
matrix_authentication_service: {
|
||||
enabled: true,
|
||||
endpoint: `http://${mas.getHostname()}:8080/`,
|
||||
secret: mas.sharedSecret,
|
||||
},
|
||||
// Must be disabled when using MAS.
|
||||
password_config: {
|
||||
enabled: false,
|
||||
},
|
||||
// Must be disabled when using MAS.
|
||||
enable_registration: false,
|
||||
});
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user