| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- import assert from 'node:assert/strict'
- import test from 'node:test'
- import {
- auditEventHeaders,
- categoryPresentation,
- coveragePresentation,
- defaultAuditWindow,
- formatAuditTime,
- integrityPresentation,
- shortDigest,
- statusPresentation,
- toAuditWindow
- } from '../src/views/systemManage/governanceAudit/governanceAuditModel.js'
- test('presents the six fixed governance audit categories', () => {
- const labels = [
- 'authentication',
- 'ingestion',
- 'entity_resolution',
- 'publication',
- 'remediation',
- 'knowledge_query'
- ].map(code => categoryPresentation(code).label)
- assert.deepEqual(labels, [
- '登录认证',
- '数据采集',
- '实体合并与回滚',
- '语义与质量发布',
- '质量整改',
- '知识问答'
- ])
- })
- test('keeps no records distinct and presents seal integrity explicitly', () => {
- assert.deepEqual(coveragePresentation({ count: 0 }), {
- label: '暂无记录',
- color: 'blue-grey'
- })
- assert.deepEqual(coveragePresentation({ count: 2 }), {
- label: '有记录',
- color: 'success'
- })
- assert.equal(integrityPresentation('intact').label, '校验完整')
- assert.equal(integrityPresentation('tampered').label, '检测到变更')
- assert.equal(
- integrityPresentation('invalid_signature').label,
- '封存签名无效'
- )
- })
- test('formats only bounded safe event fields', () => {
- const values = auditEventHeaders().map(item => item.value)
- assert.deepEqual(values, [
- 'occurred_at',
- 'category',
- 'action',
- 'status',
- 'actor_uid',
- 'resource'
- ])
- for (const forbidden of [
- 'password',
- 'query',
- 'evidence',
- 'ip_address',
- 'user_agent',
- 'note',
- 'payload'
- ]) {
- assert.ok(!values.includes(forbidden))
- }
- assert.equal(statusPresentation('failed').color, 'error')
- assert.equal(formatAuditTime(null), '-')
- assert.match(formatAuditTime('2026-07-30T00:00:00Z'), /2026/)
- })
- test('shortens hashes without mistaking empty values for evidence', () => {
- assert.equal(shortDigest(null), '-')
- assert.equal(shortDigest('a'.repeat(64)), 'aaaaaaaaaaaa…aaaaaaaa')
- })
- test('uses local calendar dates and never seals a future window', () => {
- const now = new Date(2026, 6, 30, 1, 30, 0, 0)
- assert.deepEqual(defaultAuditWindow(now), {
- startDate: '2026-06-30',
- endDate: '2026-07-30'
- })
- assert.deepEqual(toAuditWindow('2026-07-01', '2026-07-30', now), {
- period_start: new Date(2026, 6, 1, 0, 0, 0, 0).toISOString(),
- period_end: now.toISOString()
- })
- assert.equal(
- toAuditWindow('2026-07-01', '2026-07-29', now).period_end,
- new Date(2026, 6, 29, 23, 59, 59, 999).toISOString()
- )
- })
|