Skip to content

Commit

Permalink
Wire up basics of dendriteHomeserver
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Telatynski <[email protected]>
  • Loading branch information
t3chguy committed Jan 6, 2025
1 parent fd44732 commit 0410574
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 40 deletions.
59 changes: 26 additions & 33 deletions playwright/plugins/homeserver/dendrite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,32 @@ 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.
*/

// export const dendriteHomeserver: Fixtures<BaseFixtures, {}, BaseFixtures> & Fixtures<Services, {}, Services> = {
// _homeserver: async ({ request }, use) => {
// const container = new SynapseContainer(request);
// await use(container);
//
// container.withConfig({
// oidc_providers: [
// {
// idp_id: "test",
// idp_name: "OAuth test",
// issuer: `http://localhost:${port}/oauth`,
// authorization_endpoint: `http://localhost:${port}/oauth/auth.html`,
// // the token endpoint receives requests from synapse,
// // rather than the webapp, so needs to escape the docker container.
// token_endpoint: `http://host.testcontainers.internal:${port}/oauth/token`,
// userinfo_endpoint: `http://host.testcontainers.internal:${port}/oauth/userinfo`,
// client_id: "synapse",
// discover: false,
// scopes: ["profile"],
// skip_verification: true,
// client_auth_method: "none",
// user_mapping_provider: {
// config: {
// display_name_template: "{{ user.name }}",
// },
// },
// },
// ],
// });
// await use(container);
// server.stop();
// },
// };
import { Fixtures, PlaywrightTestArgs } from "@playwright/test";

import { Fixtures as BaseFixtures } from "../../../element-web-test.ts";
import { DendriteContainer, PineconeContainer } from "../../../testcontainers/dendrite.ts";
import { Services } from "../../../services.ts";

type Fixture = PlaywrightTestArgs & Services & BaseFixtures;
export const dendriteHomeserver: Fixtures<Fixture, {}, Fixture> = {
_homeserver: async ({ request }, use) => {
const container =
process.env["PLAYWRIGHT_HOMESERVER"] === "dendrite"
? new DendriteContainer(request)
: new PineconeContainer(request);
await use(container);
},
homeserver: async ({ logger, network, _homeserver: homeserver }, use) => {
const container = await homeserver
.withNetwork(network)
.withNetworkAliases("homeserver")
.withLogConsumer(logger.getConsumer("dendrite"))
.start();

await use(container);
await container.stop();
},
};

export function isDendrite(): boolean {
return process.env["PLAYWRIGHT_HOMESERVER"] === "dendrite" || process.env["PLAYWRIGHT_HOMESERVER"] === "pinecone";
Expand Down
7 changes: 4 additions & 3 deletions playwright/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import mailhog from "mailhog";
import { GenericContainer, Network, StartedNetwork, StartedTestContainer, Wait } from "testcontainers";
import { PostgreSqlContainer, StartedPostgreSqlContainer } from "@testcontainers/postgresql";

import { StartedSynapseContainer, SynapseConfigOptions, SynapseContainer } from "./testcontainers/synapse.ts";
import { SynapseConfigOptions, SynapseContainer } from "./testcontainers/synapse.ts";
import { ContainerLogger } from "./testcontainers/utils.ts";
import { StartedMatrixAuthenticationServiceContainer } from "./testcontainers/mas.ts";
import { HomeserverContainer, StartedHomeserverContainer } from "./testcontainers/HomeserverContainer.ts";

export interface Services {
logger: ContainerLogger;
Expand All @@ -24,8 +25,8 @@ export interface Services {
mailhogClient: mailhog.API;

synapseConfigOptions: SynapseConfigOptions;
_homeserver: SynapseContainer;
homeserver: StartedSynapseContainer;
_homeserver: HomeserverContainer<any>;
homeserver: StartedHomeserverContainer;
mas?: StartedMatrixAuthenticationServiceContainer;
}

Expand Down
19 changes: 19 additions & 0 deletions playwright/testcontainers/HomeserverContainer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
Copyright 2024 New Vector Ltd.
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE files in the repository root for full details.
*/

import { AbstractStartedContainer, GenericContainer } from "testcontainers";

import { StartedSynapseContainer } from "./synapse.ts";
import { HomeserverInstance } from "../plugins/homeserver";

export interface HomeserverContainer<Config> extends GenericContainer {
withConfigField(key: string, value: any): this;
withConfig(config: Partial<Config>): this;
start(): Promise<StartedSynapseContainer>;
}

export interface StartedHomeserverContainer extends AbstractStartedContainer, HomeserverInstance {}
3 changes: 2 additions & 1 deletion playwright/testcontainers/dendrite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { set } from "lodash";
import { randB64Bytes } from "../plugins/utils/rand.ts";
import { StartedSynapseContainer } from "./synapse.ts";
import { deepCopy } from "../plugins/utils/object.ts";
import { HomeserverContainer } from "./HomeserverContainer.ts";

const DEFAULT_CONFIG = {
version: 2,
Expand Down Expand Up @@ -204,7 +205,7 @@ const DEFAULT_CONFIG = {
],
};

export class DendriteContainer extends GenericContainer {
export class DendriteContainer extends GenericContainer implements HomeserverContainer<typeof DEFAULT_CONFIG> {
private config: typeof DEFAULT_CONFIG;

constructor(
Expand Down
7 changes: 4 additions & 3 deletions playwright/testcontainers/synapse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import { set } from "lodash";

import { getFreePort } from "../plugins/utils/port.ts";
import { randB64Bytes } from "../plugins/utils/rand.ts";
import { Credentials, HomeserverInstance } from "../plugins/homeserver";
import { Credentials } from "../plugins/homeserver";
import { deepCopy } from "../plugins/utils/object.ts";
import { HomeserverContainer, StartedHomeserverContainer } from "./HomeserverContainer.ts";

const TAG = "develop@sha256:17cc0a301447430624afb860276e5c13270ddeb99a3f6d1c6d519a20b1a8f650";

Expand Down Expand Up @@ -137,7 +138,7 @@ const DEFAULT_CONFIG = {

export type SynapseConfigOptions = Partial<typeof DEFAULT_CONFIG>;

export class SynapseContainer extends GenericContainer {
export class SynapseContainer extends GenericContainer implements HomeserverContainer<typeof DEFAULT_CONFIG> {
private config: typeof DEFAULT_CONFIG;

constructor(private readonly request: APIRequestContext) {
Expand Down Expand Up @@ -225,7 +226,7 @@ export class SynapseContainer extends GenericContainer {
}
}

export class StartedSynapseContainer extends AbstractStartedContainer implements HomeserverInstance {
export class StartedSynapseContainer extends AbstractStartedContainer implements StartedHomeserverContainer {
private adminToken?: string;

constructor(
Expand Down

0 comments on commit 0410574

Please sign in to comment.