Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

62 lines
2.3 KiB
TypeScript
Raw Permalink Normal View History

/*
Copyright 2024 New Vector Ltd.
Copyright 2023 The Matrix.org Foundation C.I.C.
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 { TestContainers } from "testcontainers";
import { OAuthServer } from "../../oauth_server";
2025-02-05 13:25:06 +00:00
import { type Fixtures } from "../../../element-web-test.ts";
2025-01-14 08:58:06 +00:00
export const legacyOAuthHomeserver: Fixtures = {
2025-01-13 17:43:28 +00:00
oAuthServer: [
async ({}, use) => {
const server = new OAuthServer();
2025-01-13 17:43:28 +00:00
await use(server);
server.stop();
},
{ scope: "worker" },
],
context: async ({ homeserverType, context, oAuthServer }, use, testInfo) => {
testInfo.skip(homeserverType !== "synapse", "does not yet support OIDC");
oAuthServer!.onTestStarted(testInfo);
2025-01-13 17:43:28 +00:00
await use(context);
},
_homeserver: [
async ({ oAuthServer, _homeserver: homeserver }, use) => {
const port = oAuthServer!.start();
await TestContainers.exposeHostPorts(port);
2025-01-13 17:43:28 +00:00
homeserver.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 }}",
},
},
},
],
});
2025-01-13 17:43:28 +00:00
await use(homeserver);
},
{ scope: "worker" },
],
};