feat(web): add lightweight workspace matching existing UI
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { browserUuid } from "../src/lib/browser-uuid.ts";
|
||||
|
||||
test("native UUID generation keeps the crypto receiver", () => {
|
||||
const source = {
|
||||
randomUUID() { assert.equal(this, source); return "native-id"; },
|
||||
getRandomValues() { assert.fail("native generation should be used"); },
|
||||
};
|
||||
assert.equal(browserUuid(source), "native-id");
|
||||
});
|
||||
|
||||
test("older browsers generate RFC 4122 version 4 UUIDs using secure random bytes", () => {
|
||||
const source = { getRandomValues(bytes) {
|
||||
assert.equal(this, source);
|
||||
assert.equal(bytes.length, 16);
|
||||
for (let i = 0; i < bytes.length; i++) bytes[i] = i;
|
||||
return bytes;
|
||||
} };
|
||||
assert.equal(browserUuid(source), "00010203-0405-4607-8809-0a0b0c0d0e0f");
|
||||
});
|
||||
|
||||
test("missing secure randomness never falls back to a guessable identifier", () => {
|
||||
assert.throws(() => browserUuid({}), /Secure browser identifiers are unavailable/);
|
||||
});
|
||||
Reference in New Issue
Block a user