Skip to content

Commit

Permalink
Autoapprove Element Call oidc requests (#11209)
Browse files Browse the repository at this point in the history
* autoapprove Element Call oidc requests

Signed-off-by: Timo K <toger5@hotmail.de>

* update comment

Signed-off-by: Timo K <toger5@hotmail.de>

* add tests for oidc element-call

Signed-off-by: Timo K <toger5@hotmail.de>

* fix ES lint

Signed-off-by: Timo K <toger5@hotmail.de>

---------

Signed-off-by: Timo K <toger5@hotmail.de>
  • Loading branch information
toger5 committed Jul 10, 2023
1 parent ab972dd commit 58710d1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/stores/widgets/StopGapWidgetDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@ export class StopGapWidgetDriver extends WidgetDriver {
WidgetEventCapability.forToDeviceEvent(EventDirection.Receive, eventType).raw,
);
}

// To always allow OIDC requests for element call, the widgetPermissionStore is used:
SdkContextClass.instance.widgetPermissionStore.setOIDCState(
forWidget,
forWidgetKind,
inRoomId,
OIDCState.Allowed,
);
}
}

Expand Down
15 changes: 14 additions & 1 deletion test/stores/widgets/WidgetPermissionStore-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ 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";
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");

Expand All @@ -38,6 +39,12 @@ describe("WidgetPermissionStore", () => {
type: "m.custom",
url: "https://invalid.address.here",
});
const elementCallWidget = new Widget({
id: "group_call",
creatorUserId: "@alice:example.org",
type: MatrixWidgetType.Custom,
url: "https://call.element.io",
});
let settings: Record<string, any> = {}; // key value store

beforeEach(() => {
Expand Down Expand Up @@ -92,4 +99,10 @@ describe("WidgetPermissionStore", () => {
const store2 = context.widgetPermissionStore;
expect(store2).toStrictEqual(store);
});
it("auto-approves OIDC requests for element-call", async () => {
new StopGapWidgetDriver([], elementCallWidget, WidgetKind.Room, true, roomId);
expect(widgetPermissionStore.getOIDCState(elementCallWidget, WidgetKind.Room, roomId)).toEqual(
OIDCState.Allowed,
);
});
});

0 comments on commit 58710d1

Please sign in to comment.