Skip to content

Commit 4b6e5d3

Browse files
authored
tests: use stable MAS integration in Synapse (#30473)
* tests: use stable MAS integration in Synapse * Automatically follow MAS main branch * Update the pinned Synapse container image to latest develop * Update element-web-playwright-common to 1.4.5 * Fix the typing of the MAS config * Update playwright-common to 1.4.6 * Use the modern MAS -> Synapse API * Relax MAS rate limiting * Revert using the modern API explicitly, it is now the default * Better adjust the MAS rate limits
1 parent 1f825f1 commit 4b6e5d3

File tree

6 files changed

+73
-60
lines changed

6 files changed

+73
-60
lines changed

.github/workflows/playwright-image-updates.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ jobs:
2121
env:
2222
IMAGE: ghcr.io/element-hq/synapse:develop
2323

24+
- name: Update MAS image
25+
run: |
26+
docker pull "$IMAGE"
27+
INSPECT=$(docker inspect --format='{{index .RepoDigests 0}}' "$IMAGE")
28+
DIGEST=${INSPECT#*@}
29+
sed -i "s/const TAG.*/const TAG = \"main@$DIGEST\";/" playwright/testcontainers/mas.ts
30+
env:
31+
IMAGE: ghcr.io/element-hq/matrix-authentication-service:main
32+
2433
- name: Create Pull Request
2534
id: cpr
2635
uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@
187187
"@babel/runtime": "^7.12.5",
188188
"@casualbot/jest-sonar-reporter": "2.2.7",
189189
"@element-hq/element-call-embedded": "0.14.1",
190-
"@element-hq/element-web-playwright-common": "^1.4.4",
190+
"@element-hq/element-web-playwright-common": "^1.4.6",
191191
"@peculiar/webcrypto": "^1.4.3",
192192
"@playwright/test": "^1.50.1",
193193
"@principalstudio/html-webpack-inject-preload": "^1.2.7",

playwright/e2e/oidc/oidc-native.spec.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,6 @@ test.describe("OIDC Native", { tag: ["@no-firefox", "@no-webkit"] }, () => {
9595
const result = await mas.manage("kill-sessions", userId);
9696
expect(result.output).toContain("Ended 1 active OAuth 2.0 session");
9797

98-
// Workaround for Synapse's 2 minute cache on MAS token validity
99-
// (https://github.com/element-hq/synapse/pull/18231)
100-
await homeserver.restart();
101-
10298
await page.goto("http://localhost:8080");
10399
await expect(
104100
page.getByText("For security, this session has been signed out. Please sign in again."),

playwright/plugins/homeserver/synapse/masHomeserver.ts

Lines changed: 33 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,60 @@
11
/*
2-
Copyright 2024 New Vector Ltd.
2+
Copyright 2024-2025 New Vector Ltd.
33
Copyright 2023 The Matrix.org Foundation C.I.C.
44
55
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
66
Please see LICENSE files in the repository root for full details.
77
*/
88

9-
import { MatrixAuthenticationServiceContainer } from "@element-hq/element-web-playwright-common/lib/testcontainers";
10-
9+
import { MatrixAuthenticationServiceContainer } from "../../../testcontainers/mas.ts";
1110
import { type Fixtures } from "../../../element-web-test.ts";
1211

1312
export const masHomeserver: Fixtures = {
1413
mas: [
1514
async ({ _homeserver: homeserver, logger, network, postgres, mailpit }, use) => {
16-
const config = {
17-
clients: [
18-
{
19-
client_id: "0000000000000000000SYNAPSE",
20-
client_auth_method: "client_secret_basic",
21-
client_secret: "SomeRandomSecret",
22-
},
23-
],
24-
matrix: {
25-
homeserver: "localhost",
26-
secret: "AnotherRandomSecret",
27-
endpoint: "http://homeserver:8008",
28-
},
29-
};
15+
const secret = "AnotherRandomSecret";
3016

17+
const limits = { burst: 10, per_second: 10 };
3118
const container = await new MatrixAuthenticationServiceContainer(postgres)
3219
.withNetwork(network)
3320
.withNetworkAliases("mas")
3421
.withLogConsumer(logger.getConsumer("mas"))
35-
.withConfig(config)
22+
.withConfig({
23+
matrix: {
24+
kind: "synapse",
25+
homeserver: "localhost",
26+
secret,
27+
endpoint: "http://homeserver:8008",
28+
},
29+
rate_limiting: {
30+
login: {
31+
per_ip: limits,
32+
per_account: limits,
33+
},
34+
registration: limits,
35+
email_authentication: {
36+
per_ip: limits,
37+
per_address: limits,
38+
emails_per_session: limits,
39+
attempt_per_session: limits,
40+
},
41+
account_recovery: {
42+
per_ip: limits,
43+
per_address: limits,
44+
},
45+
},
46+
})
3647
.start();
3748

3849
homeserver.withConfig({
3950
enable_registration: undefined,
4051
enable_registration_without_verification: undefined,
4152
disable_msisdn_registration: undefined,
4253
password_config: undefined,
43-
experimental_features: {
44-
msc3861: {
45-
enabled: true,
46-
issuer: `http://mas:8080/`,
47-
introspection_endpoint: "http://mas:8080/oauth2/introspect",
48-
client_id: config.clients[0].client_id,
49-
client_auth_method: config.clients[0].client_auth_method,
50-
client_secret: config.clients[0].client_secret,
51-
admin_token: config.matrix.secret,
52-
},
54+
matrix_authentication_service: {
55+
enabled: true,
56+
endpoint: "http://mas:8080/",
57+
secret,
5358
},
5459
});
5560

@@ -59,28 +64,6 @@ export const masHomeserver: Fixtures = {
5964
{ scope: "worker" },
6065
],
6166

62-
config: async ({ homeserver, context, mas }, use) => {
63-
const issuer = `${mas.baseUrl}/`;
64-
const wellKnown = {
65-
"m.homeserver": {
66-
base_url: homeserver.baseUrl,
67-
},
68-
"org.matrix.msc2965.authentication": {
69-
issuer,
70-
account: `${issuer}account`,
71-
},
72-
};
73-
74-
// Ensure org.matrix.msc2965.authentication is in well-known
75-
await context.route("https://localhost/.well-known/matrix/client", async (route) => {
76-
await route.fulfill({ json: wellKnown });
77-
});
78-
79-
await use({
80-
default_server_config: wellKnown,
81-
});
82-
},
83-
8467
context: async ({ homeserverType, context }, use, testInfo) => {
8568
testInfo.skip(homeserverType !== "synapse", "does not yet support MAS");
8669
await use(context);

playwright/testcontainers/mas.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
Copyright 2025 New Vector Ltd.
3+
4+
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
5+
Please see LICENSE files in the repository root for full details.
6+
*/
7+
8+
import {
9+
MatrixAuthenticationServiceContainer as BaseMatrixAuthenticationServiceContainer,
10+
type StartedPostgreSqlContainer,
11+
} from "@element-hq/element-web-playwright-common/lib/testcontainers";
12+
13+
const TAG = "main@sha256:ee8ce7523f6aeeee9abacb00021428f6f864347581ae23feb17303e55f633f13";
14+
15+
/**
16+
* MatrixAuthenticationServiceContainer which freezes the docker digest to
17+
* stabilise tests, updated periodically by the `playwright-image-updates.yaml`
18+
* workflow.
19+
*/
20+
export class MatrixAuthenticationServiceContainer extends BaseMatrixAuthenticationServiceContainer {
21+
public constructor(db: StartedPostgreSqlContainer) {
22+
super(db, `ghcr.io/element-hq/matrix-authentication-service:${TAG}`);
23+
}
24+
}

yarn.lock

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,10 +1726,10 @@
17261726
resolved "https://registry.yarnpkg.com/@element-hq/element-web-module-api/-/element-web-module-api-1.4.1.tgz#a46526d58985190f9989bf1686ea872687d3c6e1"
17271727
integrity sha512-A8yaQtX7QoKThzzZVU+VYOFhpiNyppEMuIQijK48RvhVp1nwmy0cTD6u/6Yn64saNwJjtna+Oy+Qzo/TfwwhxQ==
17281728

1729-
"@element-hq/element-web-playwright-common@^1.4.4":
1730-
version "1.4.4"
1731-
resolved "https://registry.yarnpkg.com/@element-hq/element-web-playwright-common/-/element-web-playwright-common-1.4.4.tgz#d58dba7b5b4198f2fc137e1bdd1ad82c2cee46fb"
1732-
integrity sha512-QnWz8dlRuQHZYZT9ewrcN++l7gQ0Kf+oZwMCi0k1TBf8Za40r5ibNrgZqZYyCoItBc8LGTVL3yOrUfzN4Dm2Qw==
1729+
"@element-hq/element-web-playwright-common@^1.4.6":
1730+
version "1.4.6"
1731+
resolved "https://registry.yarnpkg.com/@element-hq/element-web-playwright-common/-/element-web-playwright-common-1.4.6.tgz#a94d5d4ea94627aec430dd904c43f509a2e6c4b2"
1732+
integrity sha512-LJ4V6e6NrF2ikNCsxR93PFwDfcRUTY3b2reXwlFJeo44pj8vTYFxkuJwokibFx6+x1zkXWAIMh/0saTMRUXdSA==
17331733
dependencies:
17341734
"@axe-core/playwright" "^4.10.1"
17351735
"@testcontainers/postgresql" "^11.0.0"
@@ -4714,13 +4714,14 @@
47144714

47154715
"@vector-im/matrix-wysiwyg-wasm@link:../../../.cache/yarn/v6/npm-@vector-im-matrix-wysiwyg-2.39.0-a6238e517f23a2f3025d9c65445914771c63b163-integrity/node_modules/bindings/wysiwyg-wasm":
47164716
version "0.0.0"
4717+
uid ""
47174718

47184719
"@vector-im/[email protected]":
47194720
version "2.39.0"
47204721
resolved "https://registry.yarnpkg.com/@vector-im/matrix-wysiwyg/-/matrix-wysiwyg-2.39.0.tgz#a6238e517f23a2f3025d9c65445914771c63b163"
47214722
integrity sha512-OROXnzPcQWrCMoUpIrCKEC4FYU+9SsRomUgu+VbJwWtBDkCbfvLD4z6w/mgiADw3iTUpBPgmcWJoGxesFuB20Q==
47224723
dependencies:
4723-
"@vector-im/matrix-wysiwyg-wasm" "link:../../../.cache/yarn/v6/npm-@vector-im-matrix-wysiwyg-2.39.0-a6238e517f23a2f3025d9c65445914771c63b163-integrity/node_modules/bindings/wysiwyg-wasm"
4724+
"@vector-im/matrix-wysiwyg-wasm" "link:../../../Library/Caches/Yarn/v6/npm-@vector-im-matrix-wysiwyg-2.39.0-a6238e517f23a2f3025d9c65445914771c63b163-integrity/node_modules/bindings/wysiwyg-wasm"
47244725

47254726
47264727
version "3.2.4"

0 commit comments

Comments
 (0)