Skip to content

Commit e6a3f8c

Browse files
authored
fix: replace crypto.randomUUID to allow insecure environments (fix #9… (#9339)
1 parent acfbe8a commit e6a3f8c

File tree

5 files changed

+40
-1
lines changed

5 files changed

+40
-1
lines changed

packages/browser/src/client/public/esm-client-injector.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
}
1010

1111
const { evaluatedModules } = __vitest_worker__
12-
const moduleId = crypto.randomUUID()
12+
const moduleId = `${Math.random()}`
1313
const viteModule = evaluatedModules.ensureModule(moduleId, moduleId)
1414

1515
viteModule.evaluated = false
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { expect, test } from "vitest";
2+
3+
test("basic", async () => {
4+
expect(window.isSecureContext).toBe(false);
5+
expect(1).toBe((await import("./dynamic-import")).default);
6+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default 1;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { fileURLToPath } from "node:url";
2+
import os from "node:os";
3+
import { defineConfig } from "vitest/config";
4+
import { instances, provider } from "../../settings";
5+
6+
export default defineConfig({
7+
cacheDir: fileURLToPath(new URL("./node_modules/.vite", import.meta.url)),
8+
test: {
9+
browser: {
10+
enabled: true,
11+
headless: true,
12+
provider,
13+
instances,
14+
},
15+
},
16+
server: {
17+
host: os.hostname(), // To force an insecure-context, a host which is not 127.0.0.1 or localhost is needed
18+
},
19+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import os from 'node:os'
2+
import { expect, test } from 'vitest'
3+
import { instances, runBrowserTests } from './utils'
4+
5+
// server.host = os.hostname // doesnt work on mac, therefore the test is only run on linux
6+
test.runIf(os.platform() === 'linux')('server-host check dynamic import at insecure context', async () => {
7+
const { stdout, stderr } = await runBrowserTests({
8+
root: './fixtures/insecure-context',
9+
})
10+
11+
expect(stderr).toBe('')
12+
expect(stdout).toReportSummaryTestFiles({ passed: instances.length })
13+
})

0 commit comments

Comments
 (0)