1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Add missing safety checks in unit tests for structured clone issues

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2022-12-01 11:00:29 -05:00
parent 33e6771da3
commit 31eef46630
2 changed files with 14 additions and 0 deletions

View File

@ -3,6 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { DiContainer } from "@ogre-tools/injectable"; import type { DiContainer } from "@ogre-tools/injectable";
import { deserialize, serialize } from "v8";
import type { MessageChannel, MessageChannelListener } from "../../common/utils/channel/message-channel-listener-injection-token"; import type { MessageChannel, MessageChannelListener } from "../../common/utils/channel/message-channel-listener-injection-token";
import enlistMessageChannelListenerInjectableInMain from "../../main/utils/channel/channel-listeners/enlist-message-channel-listener.injectable"; import enlistMessageChannelListenerInjectableInMain from "../../main/utils/channel/channel-listeners/enlist-message-channel-listener.injectable";
import { getOrInsertSet } from "../../renderer/utils"; import { getOrInsertSet } from "../../renderer/utils";
@ -40,6 +41,12 @@ export const overrideMessagingFromWindowToMain = (mainDi: DiContainer) => {
); );
} }
try {
message = deserialize(serialize(message));
} catch (error) {
throw new Error(`Tried to send a message to channel "${channelId}" that is not compatible with StructuredClone: ${error}`);
}
listeners.forEach((listener) => listener.handler(message)); listeners.forEach((listener) => listener.handler(message));
}); });
}; };

View File

@ -3,6 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { DiContainer } from "@ogre-tools/injectable"; import type { DiContainer } from "@ogre-tools/injectable";
import { deserialize, serialize } from "v8";
import type { RequestChannel } from "../../common/utils/channel/request-channel-listener-injection-token"; import type { RequestChannel } from "../../common/utils/channel/request-channel-listener-injection-token";
import type { RequestFromChannel } from "../../common/utils/channel/request-from-channel-injection-token"; import type { RequestFromChannel } from "../../common/utils/channel/request-from-channel-injection-token";
import enlistRequestChannelListenerInjectableInMain from "../../main/utils/channel/channel-listeners/enlist-request-channel-listener.injectable"; import enlistRequestChannelListenerInjectableInMain from "../../main/utils/channel/channel-listeners/enlist-request-channel-listener.injectable";
@ -46,6 +47,12 @@ export const overrideRequestingFromWindowToMain = (mainDi: DiContainer) => {
); );
} }
try {
request = deserialize(serialize(request));
} catch (error) {
throw new Error(`Tried to request from channel "${channel.id}" with data that is not compatible with StructuredClone: ${error}`);
}
return requestListener.handler(request); return requestListener.handler(request);
}) as RequestFromChannel, }) as RequestFromChannel,
); );