所有后台账号可在左上角修改本人密码:校验原密码、新密码至少 12 位, 成功后该账号所有既有会话立即失效需重新登录。会话校验新增密码哈希比对。 后端 615 项、前端 7 项测试全部通过。
96 lines
4.5 KiB
JavaScript
96 lines
4.5 KiB
JavaScript
import { readFile } from 'node:fs/promises'
|
|
import test from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
|
|
test('prototype interactions expose stable test ids', async () => {
|
|
const source = await readFile(new URL('../src/App.vue', import.meta.url), 'utf8')
|
|
const required = [
|
|
'admin-input-account',
|
|
'admin-input-password',
|
|
'admin-btn-login',
|
|
'admin-menu-tokens',
|
|
'admin-menu-clients',
|
|
'admin-menu-tools',
|
|
'admin-menu-scopes',
|
|
'admin-menu-audit',
|
|
'admin-menu-accounts',
|
|
'admin-btn-new-account',
|
|
'admin-table-accounts',
|
|
'admin-account-account',
|
|
'admin-account-name',
|
|
'admin-account-password',
|
|
'admin-account-status',
|
|
'admin-account-save',
|
|
'admin-input-user-search',
|
|
'admin-btn-issue-token',
|
|
'admin-btn-new-client',
|
|
'admin-table-clients',
|
|
'admin-issued-client-key',
|
|
'admin-table-tools',
|
|
'admin-tool-pager',
|
|
'admin-btn-new-scope',
|
|
'admin-table-scopes',
|
|
'admin-table-audit',
|
|
'admin-btn-logout'
|
|
]
|
|
for (const testId of required) {
|
|
assert.match(source, new RegExp(`data-testid=["']${testId}["']`), testId)
|
|
}
|
|
})
|
|
|
|
test('multi-tab navigation exposes tab bar and close controls', async () => {
|
|
const source = await readFile(new URL('../src/App.vue', import.meta.url), 'utf8')
|
|
assert.match(source, /data-testid=["']admin-tabbar["']/, 'admin-tabbar')
|
|
assert.match(source, /admin-tab-\$\{tab\.id\}/, 'admin-tab-*')
|
|
assert.match(source, /admin-tab-close-\$\{tab\.id\}/, 'admin-tab-close-*')
|
|
assert.match(source, /openTabs\.includes\('tokens'\)/, 'tokens panel gated by openTabs')
|
|
assert.match(source, /openTabs\.includes\('clients'\)/, 'clients panel gated by openTabs')
|
|
assert.match(source, /openTabs\.includes\('tools'\)/, 'tools panel gated by openTabs')
|
|
assert.match(source, /openTabs\.includes\('scopes'\)/, 'scopes panel gated by openTabs')
|
|
assert.match(source, /openTabs\.includes\('audit'\)/, 'audit panel gated by openTabs')
|
|
assert.match(source, /function closeTab\(/, 'closeTab handler')
|
|
assert.match(source, /openTabs\.includes\('accounts'\)/, 'accounts panel gated by openTabs')
|
|
})
|
|
|
|
test('token edit uses the same multi-scope selection as token issuing', async () => {
|
|
const source = await readFile(new URL('../src/App.vue', import.meta.url), 'utf8')
|
|
assert.match(source, /scopeIds: \[\.\.\.token\.scopeIds\]/, 'edit copies all current scopes')
|
|
assert.match(source, /const scopeIds = tokenForm\.scopeIds/, 'save uses one scope list for add and edit')
|
|
assert.doesNotMatch(source, /tokenForm\.scopeId\b/, 'legacy single-scope editor removed')
|
|
assert.doesNotMatch(source, /<el-radio-group v-if="tokenForm\.id"/, 'single-scope radio group removed')
|
|
})
|
|
|
|
test('account management uses CRUD endpoints and token rows expose issuer', async () => {
|
|
const source = await readFile(new URL('../src/App.vue', import.meta.url), 'utf8')
|
|
assert.match(source, /api\('\/accounts'\)/, 'account list')
|
|
assert.match(source, /api\('\/accounts', \{ method: 'POST'/, 'account create')
|
|
assert.match(source, /api\(`\/accounts\/\$\{accountForm\.id\}`, \{ method: 'PUT'/, 'account update')
|
|
assert.match(source, /api\(`\/accounts\/\$\{account\.id\}`, \{ method: 'DELETE'/, 'account delete')
|
|
assert.match(source, /row\.issuerAccount/, 'token issuer account column')
|
|
})
|
|
|
|
test('account management is only available to the admin account', async () => {
|
|
const source = await readFile(new URL('../src/App.vue', import.meta.url), 'utf8')
|
|
assert.match(source, /<button v-if="session\.account === 'admin'"[^>]*data-testid="admin-menu-accounts"/, 'admin-only menu')
|
|
assert.match(source, /v-if="session\.account === 'admin' && openTabs\.includes\('accounts'\)"/, 'admin-only panel')
|
|
assert.match(source, /if \(id === 'accounts' && session\.account !== 'admin'\) return/, 'admin-only navigation guard')
|
|
})
|
|
|
|
test('every current account can change its own password from the account area', async () => {
|
|
const source = await readFile(new URL('../src/App.vue', import.meta.url), 'utf8')
|
|
const required = [
|
|
'admin-btn-change-password',
|
|
'admin-password-old',
|
|
'admin-password-new',
|
|
'admin-password-confirm',
|
|
'admin-password-cancel',
|
|
'admin-password-save',
|
|
]
|
|
for (const testId of required) {
|
|
assert.match(source, new RegExp(`data-testid=["']${testId}["']`), testId)
|
|
}
|
|
assert.match(source, /api\('\/auth\/password', \{ method: 'PUT'/, 'self-service password endpoint')
|
|
assert.match(source, /newPassword: passwordForm\.newPassword/, 'only sends password fields, not another account id')
|
|
assert.match(source, /loggedIn\.value = false/, 'returns to login after changing password')
|
|
})
|