58 lines
2.7 KiB
JavaScript
58 lines
2.7 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 = ''/)
|
|
})
|
|
|
|
test('新增客户端使用原生表单提交且保留防重复提交保护', () => {
|
|
const source = read('js')
|
|
const template = read('vue')
|
|
assert.match(template, /<el-form\s+id="client-credential-create-form"\s+@submit\.prevent="submitCreateClient"/)
|
|
assert.match(template, /native-type="submit"\s+form="client-credential-create-form"/)
|
|
assert.doesNotMatch(template, /@click="submitCreateClient"|@key(?:down|up)\.enter[^=]*="submitCreateClient"/)
|
|
assert.match(source, /const submitCreateClient = async \(\) => \{\s+if \(createLoading\.value\) return/)
|
|
})
|