Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/services/WebExtensionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default class WebExtensionService {
}

private receive(event: { data: ExtensionResponse }): void {
if (!event.data?.action.startsWith("web-eid:")) return;
if (!event.data?.action?.startsWith("web-eid:")) return;

const message = event.data;
const suffix = ["success", "failure", "ack"].find((s) => message.action.endsWith(s));
Expand Down
29 changes: 29 additions & 0 deletions src/services/__tests__/WebExtensionService-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,35 @@ describe("WebExtensionService", () => {
jest.restoreAllMocks();
});

describe("receive", () => {
it("should ignore messages with data but no action property", async () => {
jest.spyOn(console, "warn").mockImplementation();

window.postMessage({ someOtherProperty: "value" }, "*");
await new Promise((resolve) => setTimeout(resolve));

expect(console.warn).not.toHaveBeenCalled();
});

it("should ignore messages with null data", async () => {
jest.spyOn(console, "warn").mockImplementation();

window.postMessage(null, "*");
await new Promise((resolve) => setTimeout(resolve));

expect(console.warn).not.toHaveBeenCalled();
});

it("should ignore messages with undefined data", async () => {
jest.spyOn(console, "warn").mockImplementation();

window.postMessage(undefined, "*");
await new Promise((resolve) => setTimeout(resolve));

expect(console.warn).not.toHaveBeenCalled();
});
});

describe("action web-eid:warning", () => {
it("should log a warning from web-eid:warning message", async () => {
jest.spyOn(console, "warn").mockImplementation();
Expand Down