feat(P1/P2): 完成TDD开发及P1/P2设计文档
## 设计文档 - multi_role_permission_design: 多角色权限设计 (CONDITIONAL GO) - audit_log_enhancement_design: 审计日志增强 (CONDITIONAL GO) - routing_strategy_template_design: 路由策略模板 (CONDITIONAL GO) - sso_saml_technical_research: SSO/SAML调研 (CONDITIONAL GO) - compliance_capability_package_design: 合规能力包设计 (CONDITIONAL GO) ## TDD开发成果 - IAM模块: supply-api/internal/iam/ (111个测试) - 审计日志模块: supply-api/internal/audit/ (40+测试) - 路由策略模块: gateway/internal/router/ (33+测试) - 合规能力包: gateway/internal/compliance/ + scripts/ci/compliance/ ## 规范文档 - parallel_agent_output_quality_standards: 并行Agent产出质量规范 - project_experience_summary: 项目经验总结 (v2) - 2026-04-02-p1-p2-tdd-execution-plan: TDD执行计划 ## 评审报告 - 5个CONDITIONAL GO设计文档评审报告 - fix_verification_report: 修复验证报告 - full_verification_report: 全面质量验证报告 - tdd_module_quality_verification: TDD模块质量验证 - tdd_execution_summary: TDD执行总结 依据: Superpowers执行框架 + TDD规范
This commit is contained in:
131
supply-api/internal/audit/events/security_events_test.go
Normal file
131
supply-api/internal/audit/events/security_events_test.go
Normal file
@@ -0,0 +1,131 @@
|
||||
package events
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestSECURITYEvents_InvariantViolation(t *testing.T) {
|
||||
// 测试 invariant_violation 事件
|
||||
events := GetSECURITYEvents()
|
||||
|
||||
// INV-PKG-001: 供应方资质过期
|
||||
assert.Contains(t, events, "INV-PKG-001", "Should contain INV-PKG-001")
|
||||
|
||||
// INV-SET-001: processing/completed 不可撤销
|
||||
assert.Contains(t, events, "INV-SET-001", "Should contain INV-SET-001")
|
||||
}
|
||||
|
||||
func TestSECURITYEvents_AllEvents(t *testing.T) {
|
||||
// 测试所有SECURITY事件
|
||||
events := GetSECURITYEvents()
|
||||
|
||||
// 验证不变量违反事件
|
||||
invariantEvents := GetInvariantViolationEvents()
|
||||
for _, event := range invariantEvents {
|
||||
assert.Contains(t, events, event, "SECURITY events should contain %s", event)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSECURITYEvents_GetInvariantViolationEvents(t *testing.T) {
|
||||
events := GetInvariantViolationEvents()
|
||||
|
||||
// INV-PKG-001: 供应方资质过期
|
||||
assert.Contains(t, events, "INV-PKG-001")
|
||||
|
||||
// INV-PKG-002: 供应方余额为负
|
||||
assert.Contains(t, events, "INV-PKG-002")
|
||||
|
||||
// INV-PKG-003: 售价不得低于保护价
|
||||
assert.Contains(t, events, "INV-PKG-003")
|
||||
|
||||
// INV-SET-001: processing/completed 不可撤销
|
||||
assert.Contains(t, events, "INV-SET-001")
|
||||
|
||||
// INV-SET-002: 提现金额不得超过可提现余额
|
||||
assert.Contains(t, events, "INV-SET-002")
|
||||
|
||||
// INV-SET-003: 结算单金额与余额流水必须平衡
|
||||
assert.Contains(t, events, "INV-SET-003")
|
||||
}
|
||||
|
||||
func TestSECURITYEvents_GetSecurityAlertEvents(t *testing.T) {
|
||||
events := GetSecurityAlertEvents()
|
||||
|
||||
// 安全告警事件应该存在
|
||||
assert.NotEmpty(t, events)
|
||||
}
|
||||
|
||||
func TestSECURITYEvents_GetSecurityBreachEvents(t *testing.T) {
|
||||
events := GetSecurityBreachEvents()
|
||||
|
||||
// 安全突破事件应该存在
|
||||
assert.NotEmpty(t, events)
|
||||
}
|
||||
|
||||
func TestSECURITYEvents_GetEventCategory(t *testing.T) {
|
||||
// 所有SECURITY事件的类别应该是SECURITY
|
||||
events := GetSECURITYEvents()
|
||||
for _, eventName := range events {
|
||||
category := GetEventCategory(eventName)
|
||||
assert.Equal(t, "SECURITY", category, "Event %s should have category SECURITY", eventName)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSECURITYEvents_GetResultCode(t *testing.T) {
|
||||
// 测试不变量违反事件的结果码映射
|
||||
testCases := []struct {
|
||||
eventName string
|
||||
expectedCode string
|
||||
}{
|
||||
{"INV-PKG-001", "SEC_INV_PKG_001"},
|
||||
{"INV-PKG-002", "SEC_INV_PKG_002"},
|
||||
{"INV-PKG-003", "SEC_INV_PKG_003"},
|
||||
{"INV-SET-001", "SEC_INV_SET_001"},
|
||||
{"INV-SET-002", "SEC_INV_SET_002"},
|
||||
{"INV-SET-003", "SEC_INV_SET_003"},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.eventName, func(t *testing.T) {
|
||||
code := GetResultCode(tc.eventName)
|
||||
assert.Equal(t, tc.expectedCode, code, "Result code mismatch for %s", tc.eventName)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSECURITYEvents_GetEventDescription(t *testing.T) {
|
||||
// 测试事件描述
|
||||
desc := GetEventDescription("INV-PKG-001")
|
||||
assert.NotEmpty(t, desc)
|
||||
assert.Contains(t, desc, "供应方资质", "Description should contain 供应方资质")
|
||||
}
|
||||
|
||||
func TestSECURITYEvents_IsValidEvent(t *testing.T) {
|
||||
// 测试有效事件验证
|
||||
assert.True(t, IsValidEvent("INV-PKG-001"))
|
||||
assert.True(t, IsValidEvent("INV-SET-001"))
|
||||
assert.False(t, IsValidEvent("INVALID-EVENT"))
|
||||
assert.False(t, IsValidEvent(""))
|
||||
}
|
||||
|
||||
func TestSECURITYEvents_GetEventSubCategory(t *testing.T) {
|
||||
// SECURITY事件的子类别应该是VIOLATION/ALERT/BREACH
|
||||
testCases := []struct {
|
||||
eventName string
|
||||
expectedSubCategory string
|
||||
}{
|
||||
{"INV-PKG-001", "VIOLATION"},
|
||||
{"INV-SET-001", "VIOLATION"},
|
||||
{"SEC-BREACH-001", "BREACH"},
|
||||
{"SEC-ALERT-001", "ALERT"},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.eventName, func(t *testing.T) {
|
||||
subCategory := GetEventSubCategory(tc.eventName)
|
||||
assert.Equal(t, tc.expectedSubCategory, subCategory)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user