cmvr-wms/ruoyi-ui-vue3/tests/unit/business-assistant-private-input.test.mjs
lixiaolong a82258561b feat(auth): 添加认证cookie名称配置并优化表单布局
- 在 .env.production 中新增 VITE_AUTH_COOKIE_NAME 配置项用于设置认证cookie名称
- 将 AcceptanceException.vue 中的表单标签宽度从固定90px改为自动适配
- 在 ActionDialog.vue 中将多个表单项标记为必填项并调整标签宽度为自动适配
- 重构 ActionHistory.vue 中的按钮布局结构并添加表格列样式类名
- 更新 api-contract-audit.cjs 添加生产任务和BOM相关接口的契约测试
- 修改 auth.js 使用动态认证cookie键名替换硬编码的Admin-Token
- 调整系统角色授权用户页面的表单布局和表格样式类名
- 优化 ReceiptDialog Batch 组件的对话框尺寸、表单验证和分页功能
2026-10-16 15:30:10 +08:00

44 lines
3.2 KiB
JavaScript

import test from 'node:test'
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import { assistantContainsChatPassword, assistantPrivateRows, assistantPrivateValues } from '../../src/utils/assistant-private-input.js'
test('password entries cover only unexecuted rows and never mutate draft data', () => {
const draft = { rows: [{ _rowId: 'a', userName: 'one' }, { _rowId: 'b', userName: 'two' }], results: [{ rowId: 'a', status: 'SUCCEEDED' }] }
const before = structuredClone(draft)
const rows = assistantPrivateRows(draft)
assert.deepEqual(rows, [draft.rows[1]])
assert.equal(assistantPrivateValues(rows, {}), null)
assert.equal(assistantPrivateValues(rows, { b: { password: 'Sample12', repeat: 'Sample13' } }), null)
assert.equal(assistantPrivateValues(rows, { b: { password: 'short', repeat: 'short' } }), null)
assert.deepEqual(assistantPrivateValues(rows, { b: { password: 'Sample12', repeat: 'Sample12' } }), { b: 'Sample12' })
assert.deepEqual(draft, before)
})
test('secure input is transient and cleared on draft, account or visibility changes', () => {
const ui = readFileSync(new URL('../../src/components/BusinessAssistant/index.vue', import.meta.url), 'utf8')
assert.match(ui, /user.id, assistant.open, assistant.draft\?\.id, assistant.draft\?\.version/)
assert.match(ui, /finally \{ privateValues.value = null/)
assert.match(ui, /showPrivateInputs.value, user.token, visible.value/, 'Locking the screen, hiding the panel or changing login token must clear private inputs')
const secure = readFileSync(new URL('../../src/components/BusinessAssistant/AssistantSecureInputs.vue', import.meta.url), 'utf8')
assert.doesNotMatch(secure, /localStorage|sessionStorage|useBusinessAssistantStore/)
assert.match(secure, /type="password"/)
const api = readFileSync(new URL('../../src/api/warehouse/assistant.js', import.meta.url), 'utf8')
assert.match(api, /executeAssistantDraft[^\n]+headers: \{ repeatSubmit: false \}/, 'Password request must bypass the shared sessionStorage duplicate-body cache; server command lock provides idempotency')
})
test('system-initial-password creation visibly explains the policy without forcing per-row secret inputs', () => {
const ui = readFileSync(new URL('../../src/components/BusinessAssistant/index.vue', import.meta.url), 'utf8')
assert.match(ui, /currentAction\?\.passwordMode === 'SYSTEM_INITIAL'/)
assert.match(ui, /:title="currentAction.passwordNotice"/)
assert.match(ui, /currentAction.value\?\.requiresPassword/)
assert.doesNotMatch(ui, /privateValues.*123456|password:\s*['"]123456/)
})
test('explicit secrets in chat are rejected before creating an outgoing bubble or HTTP cache record', () => {
assert.equal(assistantContainsChatPassword('密码设置为Sample12'), true)
assert.equal(assistantContainsChatPassword('password: Sample12'), true)
assert.equal(assistantContainsChatPassword('帮张三重置密码'), false)
assert.equal(assistantContainsChatPassword('怎么重置密码?'), false)
const store = readFileSync(new URL('../../src/store/modules/businessAssistant.js', import.meta.url), 'utf8')
assert.ok(store.indexOf('if (assistantContainsChatPassword(text))') < store.indexOf('const payload = { sessionId, text'))
})