fix(security): P0 安全修复 — Access Token 吊销 + OpenAPI 保护 + RLS 补齐 + CI 加固 + 测试修复

P0-5: Access Token 吊销机制
- 新增内存 DashMap 黑名单(token_hash → exp),支持单 token 吊销
- 密码修改/登出时自动清除用户权限缓存,强制重新认证
- 惰性清理过期条目,防止内存无限增长

P0-6: OpenAPI 端点安全
- 生产构建返回 404,仅 cfg(debug_assertions) 模式可用
- 防止 385+ API 端点 schema 对外暴露

P0-4: RLS 策略补充迁移 (m000169)
- 幂等遍历所有含 tenant_id 的表,补齐缺失的 RLS 策略
- 覆盖 m000088 之后创建的约 20 张新表

P0-3: CI 安全加固
- 移除 CI 中硬编码密码 123123,改用 postgres
- 保持 cargo audit / npm-audit 严格门禁

P0-7: AI prompt 集成测试修复
- get_active_prompt 改按 analysis_type 查找而非 name
- list_prompts 过滤参数从 category 改为 analysis_type
- 167 集成测试全部通过(原 164 passed / 3 failed)
This commit is contained in:
iven
2026-05-29 11:38:38 +08:00
parent 9a67bf80c1
commit aa6d93129d
8 changed files with 160 additions and 22 deletions

View File

@@ -83,7 +83,11 @@ async fn prompt_list_with_category_filter() {
let tenant_id = uuid::Uuid::new_v4();
let user_id = uuid::Uuid::new_v4();
for (name, cat) in [("p1", "analysis"), ("p2", "summary"), ("p3", "analysis")] {
for (name, cat, at) in [
("p1", "analysis", "lab_report"),
("p2", "summary", "trends"),
("p3", "analysis", "report_summary"),
] {
svc.create_prompt(
tenant_id,
user_id,
@@ -92,16 +96,17 @@ async fn prompt_list_with_category_filter() {
"usr".into(),
serde_json::json!({}),
cat.into(),
"lab_report".into(),
at.into(),
)
.await
.expect("创建应成功");
}
// list_prompts 现在按 analysis_type 过滤
let (items, total) = svc
.list_prompts(
tenant_id,
Some("analysis".into()),
Some("lab_report".into()),
&Pagination {
page: Some(1),
page_size: Some(10),
@@ -110,8 +115,9 @@ async fn prompt_list_with_category_filter() {
.await
.expect("查询应成功");
assert_eq!(total, 2);
assert_eq!(items.len(), 2);
assert_eq!(total, 1);
assert_eq!(items.len(), 1);
assert_eq!(items[0].name, "p1");
}
#[tokio::test]
@@ -150,9 +156,9 @@ async fn prompt_activate_switches_version() {
assert_eq!(v2.version, 2);
// v1 仍然激活update 继承 is_active
// v1 仍然激活update 继承 is_active,按 analysis_type 查找
let active_before = svc
.get_active_prompt(tenant_id, "my_prompt")
.get_active_prompt(tenant_id, "lab_report")
.await
.expect("active");
assert_eq!(active_before.system_prompt, "sys_v1");
@@ -163,7 +169,7 @@ async fn prompt_activate_switches_version() {
.expect("activate");
let active_after = svc
.get_active_prompt(tenant_id, "my_prompt")
.get_active_prompt(tenant_id, "lab_report")
.await
.expect("active");
assert_eq!(active_after.id, v2.id);
@@ -218,7 +224,7 @@ async fn prompt_rollback_equals_activate() {
.expect("rollback");
let active = svc
.get_active_prompt(tenant_id, "rb_test")
.get_active_prompt(tenant_id, "lab_report")
.await
.expect("active");
assert_eq!(active.id, v1.id);