From 9a87a7d6a4ff5efd0aba25b88fdf0cda0ae9044c Mon Sep 17 00:00:00 2001 From: Timo K Date: Mon, 10 Jul 2023 13:04:20 +0200 Subject: [PATCH 1/4] autoapprove Element Call oidc requests Signed-off-by: Timo K --- src/stores/widgets/StopGapWidgetDriver.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/stores/widgets/StopGapWidgetDriver.ts b/src/stores/widgets/StopGapWidgetDriver.ts index b0fe61deb77..0acbf5144ce 100644 --- a/src/stores/widgets/StopGapWidgetDriver.ts +++ b/src/stores/widgets/StopGapWidgetDriver.ts @@ -165,6 +165,14 @@ export class StopGapWidgetDriver extends WidgetDriver { WidgetEventCapability.forToDeviceEvent(EventDirection.Receive, eventType).raw, ); } + + // special case OIDC capabilities because they you the setting store to track that oidc request are always allowed: + SdkContextClass.instance.widgetPermissionStore.setOIDCState( + forWidget, + forWidgetKind, + inRoomId, + OIDCState.Allowed, + ); } } From 984f6f937e4f6098fa92577b3173af3e29ed997f Mon Sep 17 00:00:00 2001 From: Timo K Date: Mon, 10 Jul 2023 13:08:56 +0200 Subject: [PATCH 2/4] update comment Signed-off-by: Timo K --- src/stores/widgets/StopGapWidgetDriver.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stores/widgets/StopGapWidgetDriver.ts b/src/stores/widgets/StopGapWidgetDriver.ts index 0acbf5144ce..18c04cccccf 100644 --- a/src/stores/widgets/StopGapWidgetDriver.ts +++ b/src/stores/widgets/StopGapWidgetDriver.ts @@ -166,7 +166,7 @@ export class StopGapWidgetDriver extends WidgetDriver { ); } - // special case OIDC capabilities because they you the setting store to track that oidc request are always allowed: + // To always allow OIDC requests for element call, the widgetPermissionStore is used: SdkContextClass.instance.widgetPermissionStore.setOIDCState( forWidget, forWidgetKind, From 0d984ea85b793f482d22d5f37e970794c9675454 Mon Sep 17 00:00:00 2001 From: Timo K Date: Mon, 10 Jul 2023 15:39:10 +0200 Subject: [PATCH 3/4] add tests for oidc element-call Signed-off-by: Timo K --- test/stores/widgets/WidgetPermissionStore-test.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/test/stores/widgets/WidgetPermissionStore-test.ts b/test/stores/widgets/WidgetPermissionStore-test.ts index d9f1cbb8045..9310cd40130 100644 --- a/test/stores/widgets/WidgetPermissionStore-test.ts +++ b/test/stores/widgets/WidgetPermissionStore-test.ts @@ -16,7 +16,7 @@ limitations under the License. import { mocked } from "jest-mock"; import { MatrixClient } from "matrix-js-sdk/src/matrix"; -import { Widget, WidgetKind } from "matrix-widget-api"; +import { MatrixWidgetType, Widget, WidgetKind } from "matrix-widget-api"; import { OIDCState, WidgetPermissionStore } from "../../../src/stores/widgets/WidgetPermissionStore"; import SettingsStore from "../../../src/settings/SettingsStore"; @@ -24,6 +24,7 @@ import { TestSdkContext } from "../../TestSdkContext"; import { SettingLevel } from "../../../src/settings/SettingLevel"; import { SdkContextClass } from "../../../src/contexts/SDKContext"; import { stubClient } from "../../test-utils"; +import { StopGapWidgetDriver } from "../../../src/stores/widgets/StopGapWidgetDriver"; jest.mock("../../../src/settings/SettingsStore"); @@ -38,6 +39,12 @@ describe("WidgetPermissionStore", () => { type: "m.custom", url: "https://invalid.address.here", }); + const ec_w = new Widget({ + id: "group_call", + creatorUserId: "@alice:example.org", + type: MatrixWidgetType.Custom, + url: "https://call.element.io", + }); let settings: Record = {}; // key value store beforeEach(() => { @@ -92,4 +99,8 @@ describe("WidgetPermissionStore", () => { const store2 = context.widgetPermissionStore; expect(store2).toStrictEqual(store); }); + it("auto-approves OIDC requests for element-call", async () => { + new StopGapWidgetDriver([], ec_w, WidgetKind.Room, true, roomId); + expect(widgetPermissionStore.getOIDCState(ec_w, WidgetKind.Room, roomId)).toEqual(OIDCState.Allowed); + }); }); From 06ae34cc36f9a083b2bfb81b9351325203809bdf Mon Sep 17 00:00:00 2001 From: Timo K Date: Mon, 10 Jul 2023 16:27:46 +0200 Subject: [PATCH 4/4] fix ES lint Signed-off-by: Timo K --- test/stores/widgets/WidgetPermissionStore-test.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/stores/widgets/WidgetPermissionStore-test.ts b/test/stores/widgets/WidgetPermissionStore-test.ts index 9310cd40130..97a59834f98 100644 --- a/test/stores/widgets/WidgetPermissionStore-test.ts +++ b/test/stores/widgets/WidgetPermissionStore-test.ts @@ -39,7 +39,7 @@ describe("WidgetPermissionStore", () => { type: "m.custom", url: "https://invalid.address.here", }); - const ec_w = new Widget({ + const elementCallWidget = new Widget({ id: "group_call", creatorUserId: "@alice:example.org", type: MatrixWidgetType.Custom, @@ -100,7 +100,9 @@ describe("WidgetPermissionStore", () => { expect(store2).toStrictEqual(store); }); it("auto-approves OIDC requests for element-call", async () => { - new StopGapWidgetDriver([], ec_w, WidgetKind.Room, true, roomId); - expect(widgetPermissionStore.getOIDCState(ec_w, WidgetKind.Room, roomId)).toEqual(OIDCState.Allowed); + new StopGapWidgetDriver([], elementCallWidget, WidgetKind.Room, true, roomId); + expect(widgetPermissionStore.getOIDCState(elementCallWidget, WidgetKind.Room, roomId)).toEqual( + OIDCState.Allowed, + ); }); });