From 8892cfe061145c0f69918e56cdbdde0bb93606e4 Mon Sep 17 00:00:00 2001 From: rare-magma Date: Sat, 19 Oct 2024 16:09:56 +0200 Subject: [PATCH] fix: crypto.randomUUID validation for secure context Signed-off-by: rare-magma --- src/guitos/domain/uuid.ts | 5 +++++ src/setupTests.ts | 1 + 2 files changed, 6 insertions(+) diff --git a/src/guitos/domain/uuid.ts b/src/guitos/domain/uuid.ts index 8a29159..0969040 100644 --- a/src/guitos/domain/uuid.ts +++ b/src/guitos/domain/uuid.ts @@ -23,5 +23,10 @@ export class Uuid { `<${this.constructor.name}> does not allow the value <${id}>`, ); } + if (!window.isSecureContext) { + throw new Error( + `<${this.constructor.name}> is not available in a non-secure context`, + ); + } } } diff --git a/src/setupTests.ts b/src/setupTests.ts index e18a310..404eb88 100644 --- a/src/setupTests.ts +++ b/src/setupTests.ts @@ -12,6 +12,7 @@ import * as AppBudgetContext from "./guitos/context/BudgetContext"; import { BudgetMother } from "./guitos/domain/budget.mother"; window.crypto.randomUUID = randomUUID; +window.isSecureContext = true; global.URL.createObjectURL = vi.fn(); vi.mock("crypto", () => ({