修改认证中心对接方式

This commit is contained in:
2026-06-04 12:02:53 +08:00
parent fb0229ba06
commit ce358df201
13 changed files with 195 additions and 24 deletions

View File

@@ -2,19 +2,26 @@ import { describe, expect, it } from "vitest";
import vm from "node:vm";
import { randomUUIDPolyfillScript } from "@/lib/client/random-uuid-polyfill";
type RandomUUIDContext = {
crypto?: {
randomUUID?: () => string;
getRandomValues?: (bytes: Uint8Array) => Uint8Array;
};
};
describe("client randomUUID polyfill", () => {
it("defines crypto.randomUUID when crypto is missing", () => {
const context = {};
const context: RandomUUIDContext = {};
vm.runInNewContext(randomUUIDPolyfillScript, context);
expect(context.crypto.randomUUID()).toMatch(
expect(context.crypto?.randomUUID?.()).toMatch(
/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/
);
});
it("defines crypto.randomUUID when only getRandomValues is available", () => {
const context = {
const context: RandomUUIDContext = {
crypto: {
getRandomValues(bytes: Uint8Array) {
for (let index = 0; index < bytes.length; index += 1) bytes[index] = index;
@@ -25,7 +32,7 @@ describe("client randomUUID polyfill", () => {
vm.runInNewContext(randomUUIDPolyfillScript, context);
expect(context.crypto.randomUUID()).toMatch(
expect(context.crypto?.randomUUID?.()).toMatch(
/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/
);
});