这是第一次基于http域名成功的部署版本0718v1,修改了http与https都兼容的认证方式

This commit is contained in:
baozaotumao2025
2026-07-18 23:18:16 +08:00
parent 1b90e552a5
commit 789d4fc4e9
11 changed files with 62 additions and 20 deletions
+26
View File
@@ -0,0 +1,26 @@
import { afterEach, describe, expect, it, vi } from 'vitest'
import { createIdempotencyKey } from '../../src/idempotencyKey'
afterEach(() => vi.unstubAllGlobals())
describe('createIdempotencyKey', () => {
it('prefers the native UUID implementation', () => {
const randomUUID = vi.fn(() => 'native-uuid')
vi.stubGlobal('crypto', { randomUUID, getRandomValues: vi.fn() })
expect(createIdempotencyKey()).toBe('native-uuid')
expect(randomUUID).toHaveBeenCalledOnce()
})
it('generates an RFC 4122 UUID v4 when randomUUID is unavailable', () => {
vi.stubGlobal('crypto', { getRandomValues: (bytes: Uint8Array) => bytes.map((_, index) => index) })
expect(createIdempotencyKey()).toBe('00010203-0405-4607-8809-0a0b0c0d0e0f')
})
it('fails explicitly when no secure random source exists', () => {
vi.stubGlobal('crypto', {})
expect(() => createIdempotencyKey()).toThrow('当前浏览器不支持安全随机数')
})
})