Smail/test/review/protocol-frontend.test.mjs
smail e358396be5
Some checks are pending
Security Checks / security (push) Waiting to run
加固客户端凭据签发与撤销的本人密码验证
2026-10-02 20:46:24 +08:00

49 lines
2.2 KiB
JavaScript

import assert from 'node:assert/strict'
import test from 'node:test'
import { readFileSync } from 'node:fs'
import { createRequire } from 'node:module'
const require = createRequire(new URL('../../frontend/package.json', import.meta.url))
const Vue = require('vue')
const { parse, compileScript } = require('@vue/compiler-sfc')
const read = extension => readFileSync(new URL(`../../frontend/src/views/components/ThirdPartyAuthorization/ThirdPartyAuthorization.${extension}`, import.meta.url), 'utf8')
test('客户端授权码页面的 Vue 模板和脚本可编译', () => {
const { descriptor, errors } = parse(read('vue'))
assert.deepEqual(errors, [])
assert.doesNotThrow(() => compileScript(descriptor, { id: 'audit-protocol', inlineTemplate: true }))
})
test('客户端授权码接口与界面能力保持一致', () => {
const source = read('js')
const template = read('vue')
for (const path of [
'/api/v1/security/credentials/clients',
'/api/v1/security/credentials/clients/create',
'/api/v1/security/credentials/clients/regenerate',
'/api/v1/security/credentials/clients/revoke',
'/api/v1/security/credentials/clients/reveal',
]) {
assert.match(source, new RegExp(path.replaceAll('/', '\\/')))
}
assert.match(template, /安全验证查看明文/)
assert.match(source, /startRevealCountdown\(60\)/)
assert.match(template, /自动隐藏/)
assert.match(template, /撤销删除/)
})
test('客户端凭据操作验证本人密码且保留密码空白字符', () => {
const source = read('js')
const template = read('vue')
assert.match(template, /v-model="createPassword"/)
assert.match(template, /验证并生成/)
assert.match(source, /const password = createPassword\.value/)
assert.match(source, /const password = verifyPassword\.value/)
assert.doesNotMatch(source, /(?:createPassword|verifyPassword)\.value\.trim\(/)
assert.match(source, /client_name: name,\s+password,/)
assert.match(source, /openActionVerification\('regenerate', client\)/)
assert.match(source, /openActionVerification\('revoke', client\)/)
assert.match(source, /if \(verifyLoading\.value\) return/)
assert.match(source, /finally \{\s+verifyPassword\.value = ''/)
})