2cbd99ed4f
用户点名:青果 Authpwd 是 •••••••• 且没有任何查看手段,填错只能靠猜。抽 useSecretVisibility(单槽)与 useKeyedSecretVisibility(循环卡用),眼睛按钮件沿用 登录页那对 svg 命名——登录页的 inline 是第一遍抄,这是第二遍,之后只改一处。 按键隔离不是细节:外观专利与货源查询共用同一段循环模板,共用一个布尔会变成 "我核对我手里这把"顺手把用户没打算看的另一把也摊在屏幕上。 射程按用户拍板"一起补":Authpwd、jikip 套餐 key、两张 LLM 密钥卡;弹窗外的 Aliprice 密码不在本面板、未动。三条红线:默认掩码、状态不落 localStorage 不进日志 上报、保存成功/重读配置/切供应商/卸载四处一律收回掩码。 判据:tests/密钥显隐状态机.test.ts 8 支(含"面板里不许再出现没挂眼睛的裸密码框" 这条防复发的尺子)+ tests/mount/密钥面板authpwd显隐.mount.test.ts 6 支。 本面 node --test 994/994、vitest 9 文件 55 例、vue-tsc rc=0。
112 lines
5.1 KiB
TypeScript
112 lines
5.1 KiB
TypeScript
import { test } from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { readFileSync } from 'node:fs'
|
|
import { fileURLToPath } from 'node:url'
|
|
import { resolve, dirname } from 'node:path'
|
|
import { useKeyedSecretVisibility, useSecretVisibility } from '../src/shared/composables/useSecretVisibility.ts'
|
|
|
|
const here = dirname(fileURLToPath(import.meta.url))
|
|
const repoRoot = resolve(here, '..')
|
|
|
|
/** 去掉注释再扫出口:注释里写「不落 localStorage」是说明,不是真的存储调用。 */
|
|
function stripComments(source: string): string {
|
|
return source.replace(/\/\*[\s\S]*?\*\//g, '').replace(/^\s*\/\/.*$/gm, '')
|
|
}
|
|
|
|
/**
|
|
* 密钥输入框「眼睛」的状态机(2026-11-02 用户点名:青果 Authpwd 是 •••••••• 且没有查看手段)。
|
|
* 判的是这台状态本身的形状;它落到界面上的行为在 tests/mount/密钥面板authpwd显隐.mount.test.ts。
|
|
*/
|
|
test('默认掩码,点一次眼睛变明文,再点一次回掩码', () => {
|
|
const visibility = useSecretVisibility()
|
|
const seen: string[] = []
|
|
for (let i = 0; i < 3; i += 1) {
|
|
seen.push(visibility.inputType.value)
|
|
visibility.toggle()
|
|
}
|
|
assert.deepEqual(seen, ['password', 'text', 'password'], '眼睛必须是自复位的两态开关,不能越点越亮')
|
|
})
|
|
|
|
test('reset 一律回到掩码(换号/重读配置/保存成功都走它),且重复调用不改变语义', () => {
|
|
const visibility = useSecretVisibility()
|
|
assert.equal(visibility.inputType.value, 'password')
|
|
visibility.toggle()
|
|
assert.equal(visibility.inputType.value, 'text')
|
|
visibility.reset()
|
|
assert.equal(visibility.inputType.value, 'password', 'reset 后必须掩码')
|
|
visibility.reset()
|
|
assert.equal(visibility.inputType.value, 'password', 'reset 幂等:不能把掩码翻成明文')
|
|
// 复位后眼睛仍可用(下一次点击还是明文,不是卡死在掩码)
|
|
visibility.toggle()
|
|
assert.equal(visibility.inputType.value, 'text')
|
|
})
|
|
|
|
test('状态机只交出可见性,不交出任何能带走密钥原文的口子', () => {
|
|
const visibility = useSecretVisibility()
|
|
assert.deepEqual(
|
|
Object.keys(visibility).sort(),
|
|
['inputType', 'reset', 'toggle', 'visible'],
|
|
'成员集固定:多一个口子就多一条把原文带进日志/上报的路',
|
|
)
|
|
visibility.toggle()
|
|
assert.equal(typeof visibility.visible.value, 'boolean')
|
|
assert.ok(visibility.inputType.value === 'text' || visibility.inputType.value === 'password')
|
|
})
|
|
|
|
test('显隐状态不落本机存储、不进日志、不发上报', () => {
|
|
const source = stripComments(readFileSync(
|
|
resolve(repoRoot, 'src/shared/composables/useSecretVisibility.ts'),
|
|
'utf-8',
|
|
))
|
|
for (const outlet of [
|
|
'localStorage', 'sessionStorage', 'indexedDB', 'document.cookie', 'caches',
|
|
'console.', 'fetch(', 'XMLHttpRequest', 'sendBeacon', 'WebSocket',
|
|
]) {
|
|
assert.ok(!source.includes(outlet), `状态机里不该出现出口 ${outlet}:把「用户点了显示密码」变成持久态或事件是没必要的隐私面`)
|
|
}
|
|
})
|
|
|
|
test('眼睛按钮件自己也不留第二条持久化/上报出口', () => {
|
|
const source = stripComments(readFileSync(
|
|
resolve(repoRoot, 'src/shared/components/SecretVisibilityToggle.vue'),
|
|
'utf-8',
|
|
))
|
|
for (const outlet of ['localStorage', 'sessionStorage', 'console.', 'fetch(', 'sendBeacon']) {
|
|
assert.ok(!source.includes(outlet), `眼睛按钮不该出现出口 ${outlet}:它只 emit('toggle')`)
|
|
}
|
|
assert.match(source, /\$emit\('toggle'\)|emit\('toggle'\)/, '唯一的对外动作就是 toggle')
|
|
})
|
|
test('按键显隐:点一张卡的眼睛不许把另一张也摊成明文', () => {
|
|
const keyed = useKeyedSecretVisibility()
|
|
assert.equal(keyed.inputTypeOf('appearance-patent'), 'password', '未知键必须默认掩码')
|
|
keyed.toggle('appearance-patent')
|
|
assert.equal(keyed.inputTypeOf('appearance-patent'), 'text')
|
|
assert.equal(keyed.visibleOf('appearance-patent'), true)
|
|
assert.equal(keyed.inputTypeOf('goods-source'), 'password', '隔壁那张卡不许跟着亮')
|
|
assert.equal(keyed.visibleOf('goods-source'), false)
|
|
})
|
|
|
|
test('resetAll 把所有键一次收回掩码(保存成功/重读配置/卸载都走它)', () => {
|
|
const keyed = useKeyedSecretVisibility()
|
|
keyed.toggle('appearance-patent')
|
|
keyed.toggle('goods-source')
|
|
keyed.resetAll()
|
|
assert.deepEqual(
|
|
[keyed.inputTypeOf('appearance-patent'), keyed.inputTypeOf('goods-source')],
|
|
['password', 'password'],
|
|
)
|
|
keyed.resetAll()
|
|
assert.equal(keyed.inputTypeOf('appearance-patent'), 'password', '重复 resetAll 不许翻转成明文')
|
|
})
|
|
|
|
test('面板里不许再出现没挂眼睛的裸密码框', () => {
|
|
const source = stripComments(readFileSync(
|
|
resolve(repoRoot, 'src/shared/components/ApiSecretSettingsPanel.vue'),
|
|
'utf-8',
|
|
))
|
|
assert.ok(!/type="password"/.test(source),
|
|
'又留下一个 •••• 且没有查看手段的字段(本会话用户点名的就是这个形状)⇒ 新密码框必须走 useSecretVisibility / useKeyedSecretVisibility')
|
|
const toggles = (source.match(/<SecretVisibilityToggle/g) || []).length
|
|
assert.ok(toggles >= 3, `面板里 Authpwd/套餐 key/LLM 循环都该有眼睛,实际只数到 ${toggles} 个`)
|
|
})
|