Make a basic test

This commit is contained in:
Travis Ralston 2026-02-06 17:06:00 -07:00
parent fdea9d7128
commit e4463cb4dc
2 changed files with 51 additions and 2 deletions

View File

@ -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();
});
});

View File

@ -60,15 +60,22 @@ export const PolicyServerConfig: React.FC<PolicyServerConfigProps> = ({ 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"],
},
"",