fix: 登录页访问不再记成「登录成功」——认证端点只记录 POST,登录成败以响应确认为准
现场反馈:审计列表「没有失败,全是成功,登录失败也显示成功」。在 Halo 2.26.1 上 复现(afda8d0 构建):GET /login、GET /login?authentication_required 只是打开登录页 (HTTP 200),却被记成「未知用户 · 登录 200」,列表里看起来全是登录成功;POST /login 本身的成败判定是对的,但被这些记录淹没。 - 捕获:AuthEndpointAuditWebFilter 只记录 POST /login(登录尝试)与 POST /logout (登出);登录/登出页面的 GET 访问(打开登录页、被弹回登录页、失败回显、登出 确认页)原样透传不记录(CaptureRule.isAuthOperation) - 判定:LoginOutcome 只有响应明确确认才算成功——302 跳回登录页(含 error 参数或 路径即 /login)、缺失 Location、4xx/5xx 一律判失败;移除失败回显页判定 - 结果语义:新增 AuditResult(成功 / 失败 / 页面访问),结果筛选、CSV 导出与前端 resultBadge 共用同一规则;登录成功显示「成功」,与「失败」对称 - 历史数据:升级前落库的登录页访问记录(GET,标注 login/logout)展示与导出为 「访问登录页/登出页」且不计成败,结果筛选与「登录/登出」语义动作筛选均排除; 落库标注不改写 - demo 同步同一套规则;README 与设计/技术文档同步 测试:后端 286、UI 74、demo 61 全过;真实 Halo 2.26.1 升级场景联调记录见测试报告
This commit is contained in:
@@ -39,3 +39,18 @@ describe('AuditLogDetail 字段变更区块', () => {
|
||||
expect(sfc).not.toContain('删除变更')
|
||||
})
|
||||
})
|
||||
|
||||
describe('AuditLogDetail 结果语义', () => {
|
||||
it('结果与列表徽标、结果筛选、CSV 导出共用同一规则(resultOutcome)', () => {
|
||||
// 登录失败靠语义动作标注识别(HTTP 状态码可能是 302/200),不能在组件里按状态码另判一套
|
||||
expect(sfc).toContain('resultOutcome(props.log.spec)')
|
||||
expect(sfc).not.toContain('isSuccessful(')
|
||||
})
|
||||
|
||||
it('结果三态:成功 / 失败 / 页面访问(中性灰,不计成败)', () => {
|
||||
// 升级前落库的登录页访问记录原先显示「成功 · 200」,误读为未知用户登录成功
|
||||
expect(sfc).toContain("'page-visit': '页面访问'")
|
||||
expect(sfc).toContain("'page-visit': 'status-na'")
|
||||
expect(sfc).toContain('.status-na {')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -8,9 +8,8 @@ import {
|
||||
describeOperation,
|
||||
displayUsername,
|
||||
formatTime,
|
||||
isLoginFailure,
|
||||
isSuccessful,
|
||||
methodBadgeClass,
|
||||
resultOutcome,
|
||||
} from '@/utils/audit'
|
||||
|
||||
const props = defineProps<{
|
||||
@@ -24,27 +23,26 @@ const emit = defineEmits<{
|
||||
|
||||
const close = () => emit('update:visible', false)
|
||||
|
||||
// 结果语义:登录失败记录(HTTP 状态码可能为 200/302)显示「登录失败」,
|
||||
// 其余按 HTTP 状态码判定成败
|
||||
const resultText = computed(() => {
|
||||
if (!props.log) {
|
||||
return '-'
|
||||
}
|
||||
if (isLoginFailure(props.log.spec)) {
|
||||
return '登录失败'
|
||||
}
|
||||
return isSuccessful(props.log.spec.statusCode) ? '成功' : '失败'
|
||||
})
|
||||
const RESULT_TEXT = {
|
||||
success: '成功',
|
||||
failure: '失败',
|
||||
// 认证端点的页面访问(升级前落库的 GET 记录):不是操作,不计成败
|
||||
'page-visit': '页面访问',
|
||||
} as const
|
||||
|
||||
const resultBadgeClass = computed(() => {
|
||||
if (!props.log) {
|
||||
return 'status-fail'
|
||||
}
|
||||
if (isLoginFailure(props.log.spec)) {
|
||||
return 'status-fail'
|
||||
}
|
||||
return isSuccessful(props.log.spec.statusCode) ? 'status-ok' : 'status-fail'
|
||||
})
|
||||
const RESULT_CLASS = {
|
||||
success: 'status-ok',
|
||||
failure: 'status-fail',
|
||||
'page-visit': 'status-na',
|
||||
} as const
|
||||
|
||||
// 结果语义(与列表徽标、结果筛选、CSV 导出同一规则):登录失败靠语义动作标注识别
|
||||
// (HTTP 状态码可能是 302/200),页面访问不计成败,其余按 HTTP 状态码判定
|
||||
const outcome = computed(() => (props.log ? resultOutcome(props.log.spec) : 'failure'))
|
||||
|
||||
const resultText = computed(() => RESULT_TEXT[outcome.value])
|
||||
|
||||
const resultBadgeClass = computed(() => RESULT_CLASS[outcome.value])
|
||||
|
||||
/** 字段级变更(字段级变更 diff,产品设计 V2);历史记录缺失。 */
|
||||
const changes = computed(() => props.log?.spec.changes ?? [])
|
||||
@@ -347,6 +345,8 @@ const rawJson = computed(() =>
|
||||
}
|
||||
.status-ok { color: #0f766e; background: rgba(76, 203, 160, 0.15); }
|
||||
.status-fail { color: #d71d1d; background: rgba(215, 29, 29, 0.12); }
|
||||
/* 页面访问(登录页/登出页的 GET,不计成败):中性灰 */
|
||||
.status-na { color: #6b7280; background: rgba(107, 114, 128, 0.12); }
|
||||
.raw-json {
|
||||
margin-top: 1rem;
|
||||
font-size: 0.75rem;
|
||||
|
||||
@@ -110,4 +110,11 @@ describe('AuditLogList 页面外观', () => {
|
||||
expect(descIdx).toBeGreaterThan(resourceIdx)
|
||||
expect(statusIdx).toBeGreaterThan(descIdx)
|
||||
})
|
||||
|
||||
it('结果徽标有中性灰样式:页面访问(登录页/登出页的 GET)不计成败', () => {
|
||||
// 升级前落库的登录页访问记录原先显示绿色 200,误读为未知用户登录成功;
|
||||
// resultBadge 现判为 page-visit,需有既非成功色也非失败色的样式承接
|
||||
expect(sfc).toContain("resultBadge(log.spec)")
|
||||
expect(styleRule('.status-na')).toMatch(/color:\s*#6b7280/)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -387,8 +387,9 @@ onMounted(fetchLogs)
|
||||
</VEntityField>
|
||||
</template>
|
||||
<template #end>
|
||||
<!-- 结果列:登录失败记录(HTTP 200/302 也可能是失败,语义动作已标注)
|
||||
显示红色「失败」,避免绿色 200/302 误读为登录成功;
|
||||
<!-- 结果列:登录失败显示红色「失败」(表单登录失败是 302,裸状态码是绿的),
|
||||
登录成功显示「成功」;升级前落库的登录页访问(GET,HTTP 200)显示
|
||||
灰色「—」——只是打开过登录页,不计成败,不再以绿色 200 误读为登录成功;
|
||||
徽标经 #title 插槽渲染(当前版本组件在无 title 时不渲染 #extra,
|
||||
原先徽标实际不可见) -->
|
||||
<VEntityField width="4rem">
|
||||
@@ -590,6 +591,8 @@ onMounted(fetchLogs)
|
||||
}
|
||||
.status-ok { color: #0f766e; background: rgba(76, 203, 160, 0.15); }
|
||||
.status-fail { color: var(--audit-red); background: rgba(215, 29, 29, 0.12); }
|
||||
/* 页面访问(登录页/登出页的 GET,不计成败):中性灰,既不是成功色也不是失败色 */
|
||||
.status-na { color: #6b7280; background: rgba(107, 114, 128, 0.12); }
|
||||
.audit-pagination {
|
||||
/* 在白卡内铺满整行:白底与上方列表左右对齐;上下各留 1rem,
|
||||
文字的垂直位置与原分页条一致;上边缘 1px 分隔线同控制台卡片 footer 观感 */
|
||||
|
||||
Reference in New Issue
Block a user