mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 12:02:50 +08:00
feat(skin): bridge trusted plugin actions
This commit is contained in:
1 parent
1aa29158ef
commit
35cb6ad6df
13 files changed
+276
-45
No files matched your search
@@ -19,6 +19,22 @@ const plugin = parseSkinRuntimePluginDocument({
|
||||
}],
|
||||
}).plugins[0];
|
||||
|
||||
const joinPlugin = parseSkinRuntimePluginDocument({
|
||||
schemaVersion: 1,
|
||||
plugins: [{
|
||||
id: "voice-join",
|
||||
name: "Voice join",
|
||||
version: "1.0.0",
|
||||
apiVersion: 1,
|
||||
runtime: "wasm",
|
||||
page: "voice",
|
||||
mode: "surface",
|
||||
entry: "plugins/voice-join/index.wasm",
|
||||
assets: [],
|
||||
permissions: ["ui.surface.replace", "session.channel.join"],
|
||||
}],
|
||||
}).plugins[0];
|
||||
|
||||
function output(page = "voice", count = 1): string {
|
||||
return JSON.stringify({
|
||||
schemaVersion: 5,
|
||||
@@ -33,6 +49,21 @@ function output(page = "voice", count = 1): string {
|
||||
});
|
||||
}
|
||||
|
||||
function joinOutput(request = false, eventName: "dblclick" | "input" = "dblclick"): string {
|
||||
return JSON.stringify({
|
||||
schemaVersion: 6,
|
||||
components: [{
|
||||
id: "voice-ui",
|
||||
name: "Voice UI",
|
||||
page: "voice",
|
||||
accessibleName: "Voice workspace",
|
||||
state: {},
|
||||
root: { tag: "button", events: { [eventName]: "join" }, children: [{ text: "Join" }] },
|
||||
}],
|
||||
...(request ? { request: { type: "voice.joinChannel", args: { channelId: "channel-1" } } } : {}),
|
||||
});
|
||||
}
|
||||
|
||||
function sessionWithOutput(value: string, onError: (error: Error) => void = () => undefined) {
|
||||
return createSkinRuntimePluginSession({
|
||||
plugin,
|
||||
@@ -67,3 +98,51 @@ test("runtime surface plugins cannot emit competing roots", async () => {
|
||||
assert.equal((errors[0] as SkinRuntimePluginSessionError).code, "SKIN_RUNTIME_PLUGIN_SURFACE_OUTPUT_INVALID");
|
||||
assert.equal(session.output, null);
|
||||
});
|
||||
|
||||
test("runtime host actions require an approved permission and a trusted explicit event", async () => {
|
||||
const actions: Array<{ type: string; args: Record<string, string | number | boolean> }> = [];
|
||||
const session = createSkinRuntimePluginSession({
|
||||
plugin: joinPlugin,
|
||||
createRun: (input) => ({ result: Promise.resolve({ uiOutput: joinOutput(Boolean(input.event)) }), close: () => undefined }),
|
||||
onAction: (action) => { actions.push({ type: action.type, args: { ...action.args } }); },
|
||||
});
|
||||
|
||||
assert.equal(await session.start(), true);
|
||||
assert.equal(await session.dispatch({
|
||||
schemaVersion: 1,
|
||||
state: {},
|
||||
event: { componentId: "voice-ui", handlerId: "join", eventName: "dblclick" },
|
||||
}), true);
|
||||
assert.deepEqual(actions, [{ type: "voice.joinChannel", args: { channelId: "channel-1" } }]);
|
||||
session.close();
|
||||
});
|
||||
|
||||
test("runtime host actions reject initial effects, typing events, and permissions absent from the manifest", async () => {
|
||||
const initialActions: unknown[] = [];
|
||||
const initial = createSkinRuntimePluginSession({
|
||||
plugin: joinPlugin,
|
||||
createRun: () => ({ result: Promise.resolve({ uiOutput: joinOutput(true) }), close: () => undefined }),
|
||||
onAction: (action) => { initialActions.push(action); },
|
||||
});
|
||||
assert.equal(await initial.start(), false);
|
||||
assert.deepEqual(initialActions, []);
|
||||
|
||||
const noJoinPermission = parseSkinRuntimePluginDocument({
|
||||
schemaVersion: 1,
|
||||
plugins: [{ ...joinPlugin, id: "voice-readonly", entry: "plugins/voice-readonly/index.wasm", permissions: ["ui.surface.replace"] }],
|
||||
}).plugins[0];
|
||||
const deniedActions: unknown[] = [];
|
||||
const denied = createSkinRuntimePluginSession({
|
||||
plugin: noJoinPermission,
|
||||
createRun: (input) => ({ result: Promise.resolve({ uiOutput: joinOutput(Boolean(input.event), "dblclick") }), close: () => undefined }),
|
||||
onAction: (action) => { deniedActions.push(action); },
|
||||
});
|
||||
assert.equal(await denied.start(), true);
|
||||
assert.equal(await denied.dispatch({
|
||||
schemaVersion: 1,
|
||||
state: {},
|
||||
event: { componentId: "voice-ui", handlerId: "join", eventName: "dblclick" },
|
||||
}), false);
|
||||
assert.deepEqual(deniedActions, []);
|
||||
denied.close();
|
||||
});
|
||||
Reference in new issue
Block a user