参考 boot/ 仓库结构初始化, 同步到 gitea:3000/ssw/dacli (private). 包括: - src/ 8 父命令 (form/menu/dm/dict/di/apis/doc/workflow + login/status) + core (client/crypto/help/log/types/config) - src/schema/ FieldBuilder (从 JNPF web 源码提取, 避免 53 个手写 builder) - tests/ vitest 单元 + playwright E2E (含 workSystem/developSystem baseline regression) - scripts/ extract-all.mjs (从 jnpf-web 源码生成 schema) + seed-tds-baseline.ts - doc/ architecture/plan/api/extractors/baseline/RESUME/help-system + v0.6/v0.7 changelog - .claude/skills/dacli-ts/ Claude 集成 skill (SKILL.md + 5 references + 7 examples + 3 baseline) - CLAUDE.md (项目说明) + README.md + prompt.md (开发任务说明书) - 配置文件: package.json/lock, tsconfig, vitest.config, playwright.config
47 lines
1.4 KiB
TypeScript
47 lines
1.4 KiB
TypeScript
/**
|
|
* crypto.test.ts — 加密 1:1 一致性验证
|
|
*
|
|
* 关键: '123456' + 默认密钥 'EY8WePvjM5GGwQzn' → 96 字符 hex
|
|
*/
|
|
import { describe, it, expect, beforeAll } from 'vitest'
|
|
import { encryptByMd5, encryptPassword, isEncrypted } from '../../src/core/crypto.ts'
|
|
|
|
describe('crypto', () => {
|
|
beforeAll(() => {
|
|
// 强制用固定 key, 避免 .env 漂移
|
|
process.env.VITE_CIPHER_KEY = 'EY8WePvjM5GGwQzn'
|
|
})
|
|
|
|
it('encryptByMd5 输出 32 字符 hex', () => {
|
|
const r = encryptByMd5('123456')
|
|
expect(r).toMatch(/^[0-9a-f]{32}$/)
|
|
expect(r).toBe('e10adc3949ba59abbe56e057f20f883e') // 知名 md5
|
|
})
|
|
|
|
it('encryptPassword 输出 96 字符 hex (与 web cipher.ts 一致)', () => {
|
|
const r = encryptPassword('123456')
|
|
expect(r).toMatch(/^[0-9a-f]+$/)
|
|
expect(r).toHaveLength(96)
|
|
})
|
|
|
|
it('encryptPassword 同输入同输出 (ECB 无 IV)', () => {
|
|
const a = encryptPassword('123456')
|
|
const b = encryptPassword('123456')
|
|
expect(a).toBe(b)
|
|
})
|
|
|
|
it('encryptPassword 不同输入不同输出', () => {
|
|
const a = encryptPassword('123456')
|
|
const b = encryptPassword('abcdef')
|
|
expect(a).not.toBe(b)
|
|
})
|
|
|
|
it('isEncrypted 判定', () => {
|
|
expect(isEncrypted('123456')).toBe(false)
|
|
expect(isEncrypted(encryptPassword('123456'))).toBe(true)
|
|
expect(isEncrypted('')).toBe(false)
|
|
expect(isEncrypted(null)).toBe(false)
|
|
expect(isEncrypted('z'.repeat(96))).toBe(false) // 'z' 不是 hex 字符
|
|
})
|
|
})
|