From e4463cb4dc165bc0f22a8faaf25b8710f29296bc Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Fri, 6 Feb 2026 17:06:00 -0700 Subject: [PATCH] Make a basic test --- ...oles-permissions-room-settings-tab.spec.ts | 42 +++++++++++++++++++ .../views/settings/PolicyServerConfig.tsx | 11 ++++- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/playwright/e2e/settings/room-settings/roles-permissions-room-settings-tab.spec.ts b/playwright/e2e/settings/room-settings/roles-permissions-room-settings-tab.spec.ts index d287234af5..2895c1502c 100644 --- a/playwright/e2e/settings/room-settings/roles-permissions-room-settings-tab.spec.ts +++ b/playwright/e2e/settings/room-settings/roles-permissions-room-settings-tab.spec.ts @@ -56,4 +56,46 @@ test.describe("Roles & Permissions room settings tab", () => { combobox = privilegedUserSection.getByRole("combobox", { name: user.userId }); await expect(combobox).toHaveValue("50"); }); + + test("should not see policy server configuration by default", async () => { + const section = settings.locator(".mx_SettingsFieldset_legend").first(); + await expect(section).not.toHaveText("Policy server"); + }); + + test("should be able to set policy server with labs flag enabled", async ({ app, page, room }) => { + // Back out of the room settings dialog from beforeEach and enable the labs flag + await app.settings.closeDialog(); + const labs = await app.settings.openUserSettings("Labs"); + await labs.getByLabel("Enable options to set up Policy Servers in rooms").check(); + await app.settings.closeDialog(); + + // Go back to the room settings and verify our new options are there + settings = await app.settings.openRoomSettings("Roles & Permissions"); + const section = settings.locator(".mx_SettingsFieldset_legend").first(); + await expect(section).toHaveText("Policy server"); + + // Prepare to serve a valid policy server config + await page.route("**/.well-known/matrix/org.matrix.msc4284.policy_server", async (route) => { + await route.fulfill({ + status: 200, + json: { + public_key: "not_a_real_key", + }, + }); + }); + + // Intercept our request to set the policy server + await page.route("**/_matrix/client/*/rooms/*/state/org.matrix.msc4284.policy", async (route) => { + expect(route.request().postDataJSON()).toEqual({ + via: "localhost:1111", + public_key: "not_a_real_key", + }); + await route.fulfill({ status: 200 }); + }); + + // Find the text box and choose a server which hits that route + await section.locator("input").fill("http://localhost:1111"); + await section.locator(".mx_AccessibleButton").click(); + await expect(section.locator(".error")).not.toBeVisible(); + }); }); diff --git a/src/components/views/settings/PolicyServerConfig.tsx b/src/components/views/settings/PolicyServerConfig.tsx index 2423c1af7e..d727895a9d 100644 --- a/src/components/views/settings/PolicyServerConfig.tsx +++ b/src/components/views/settings/PolicyServerConfig.tsx @@ -60,15 +60,22 @@ export const PolicyServerConfig: React.FC = ({ room }) try { if (serverName.trim().length > 0) { + // We force HTTPS on non-localhost environments + let hostname = serverName.trim(); + let urlBase = `https://${hostname}`; + if (hostname.startsWith("http://localhost:")) { + urlBase = serverName.trim(); + hostname = hostname.substring("http://".length); + } const res = await ( - await fetch(`https://${serverName.trim()}/.well-known/matrix/org.matrix.msc4284.policy_server`) + await fetch(`${urlBase}/.well-known/matrix/org.matrix.msc4284.policy_server`) ).json(); if (!!res["public_key"] && typeof res["public_key"] === "string") { await client.sendStateEvent( room.roomId, EventType.RoomPolicy, { - via: serverName, + via: hostname, public_key: res["public_key"], }, "",