Files
dth/openspec/changes/chg_0010_federated_risk_control/testcases.md
T
xstudio agentandClaude Code fadd9e46d0 chg_0010: federated_risk_control 提案 — 3 银行联合反欺诈场景(5 件套,无新代码,纯算子组合)
场景:3 银行(BankA/BankB/BankC)联合反欺诈,不泄露 PII,6 步流程
  1. DID 建立 + TDS 合约匹配 (did-identity + tds-connector)
  2. PSI 黑名单交集 (psi)
  3. Paillier 跨行特征聚合 (paillier-he)
  4. Threshold 2-of-3 风险签名 (threshold-sig)
  5. ABAC 风险分析师访问控制 (abac-policy)
  6. 数据水印嵌入 (data-watermark) + 审计链 HMAC (compliance-audit)

12 case e2e (S1-S12) 覆盖 8/10 chg_0009 算子 + 1 chg_0008 算子
4 不变性断言:PSI 正确 / PSI 不泄露 / Paillier 同态 / 水印 roundtrip

约束:
- 不改 backend 代码(10 算子已齐备,0 新依赖,0 新接口)
- 不加前端(backend-only e2e)
- 复用既有 /experiment/runs 一个一个跑算子
- admin token 全程,per-bank 标签在 input 里传

gate: PROJECT_ROOT=. bash openspec/scripts/check_spec_coverage.sh → PASS (gap=0, 9 archived + 1 active)

handoff §2 优先级 2 闭环。
实施待 sandbox dispatch(T1 architect → T5 pm)。

Co-Authored-By: Claude Code <[email protected]>
2026-09-28 21:49:33 +08:00

4.4 KiB
Raw Blame History

C1_3bank_did_setup_tds_match

  • Scenario: S1
  • Type: e2e
  • Priority: P0
  • Given: backend running on 30000, admin token, 3 bank private keys
  • When: POST /experiment/runs × 3 with operator=did-identity (per-bank), then POST with operator=tds-connector (matching contract_hash)
  • Then: 3 DIDs created + tds match=true + token non-empty (3-part JWT)
  • And: schema_version=v2
  • Automated: true
  • Bound Task: T2

C2_did_verify_loop_tamper_detect

  • Scenario: S2
  • Type: e2e
  • Priority: P0
  • Given: 3 DIDs from C1
  • When: verify each DID, then mutate one DID's publicKey and re-verify
  • Then: original 3 verify returns valid=true; mutated DID verify returns valid=false
  • Automated: true
  • Bound Task: T2

C3_tds_mismatch_abort

  • Scenario: S3
  • Type: e2e
  • Priority: P1
  • Given: contract_hash_a ≠ contract_hash_b
  • When: POST /experiment/runs with operator=tds-connector
  • Then: response.match=false, error="contract-mismatch"
  • And: FRC flow aborts (no PSI / aggregation steps executed)
  • Automated: true
  • Bound Task: T2

C4_psi_intersection_correct

  • Scenario: S4
  • Type: e2e
  • Priority: P0
  • Given: 3 blacklists A=[f01,f02,f03,f04] / B=[f02,f03,f05] / C=[f01,f03,f06,f07]
  • When: POST /experiment/runs with operator=psi
  • Then: response.intersection=[f01,f02,f03] (sorted, deduped)
  • And: intersection_size=3
  • And: schema_version=v2
  • Automated: true
  • Bound Task: T2

C5_psi_no_leak_non_intersection

  • Scenario: S5
  • Type: e2e
  • Priority: P0 (privacy invariant)
  • Given: blacklists from C4
  • When: inspect full PSI response (all keys + values)
  • Then: output NEVER contains f04/f05/f06/f07 (non-intersection)
  • And: output size ≤ min(4,3,4)=3
  • And: no per-bank blacklist size or membership info in output
  • Automated: true
  • Bound Task: T2

C6_paillier_cross_bank_sum_invariant

  • Scenario: S6
  • Type: e2e
  • Priority: P0
  • Given: paillier public key, 3 features (100/200/300)
  • When: POST /experiment/runs with operator=paillier-he, input={action: "homomorphic_sum", values: [100,200,300]}
  • Then: decrypted sum === 600 (mod n)
  • And: homomorphic_invariant passes (Enc(a)·Enc(b) mod n² === Enc(a+b))
  • And: schema_version=v2
  • Automated: true
  • Bound Task: T2

C7_threshold_sig_2shares_reconstruct

  • Scenario: S7
  • Type: e2e
  • Priority: P0
  • Given: 3-of-3 Shamir shares, payload
  • When: POST /experiment/runs with operator=threshold-sig, input={shares: [s1,s2,s3], threshold: 2}
  • Then: 2-share Lagrange reconstruction recovers secret
  • And: verify_code=0 (signature valid)
  • And: recovered payload === original payload
  • Automated: true
  • Bound Task: T2

C8_threshold_sig_1share_fails

  • Scenario: S8
  • Type: e2e
  • Priority: P1
  • Given: 3 shares from C7
  • When: POST with shares=[s1] only
  • Then: verify_code≠0
  • And: error code="insufficient-shares" or equivalent
  • Automated: true
  • Bound Task: T2

C9_abac_policy_decision_matrix

  • Scenario: S9
  • Type: e2e
  • Priority: P0
  • Given: abac policy requiring role=risk-analyst AND region∈[BJ,SH,GZ] AND time∈[09:00,18:00]
  • When: 4 POSTs with combinations (allow / 3× deny)
  • Then: allow for {role:risk-analyst,region:BJ,time:10:00}
  • And: deny "role-deny" for {role:guest}
  • And: deny "region-deny" for {region:NY}
  • And: deny "timewindow-deny" for {time:20:00}
  • Automated: true
  • Bound Task: T2

C10_data_watermark_roundtrip

  • Scenario: S10
  • Type: e2e
  • Priority: P0
  • Given: report text, watermark payload="FRC|2026-09-28|bankA,bankB,bankC"
  • When: POST with operator=data-watermark (embed), then POST same text (extract)
  • Then: report length unchanged after embed (zero-width chars)
  • And: extract returns exact payload string
  • And: schema_version=v2
  • Automated: true
  • Bound Task: T2

C11_audit_chain_hmac_valid

  • Scenario: S11
  • Type: e2e
  • Priority: P1
  • Given: 8 FRC step entries (S1-S10 condensed: did×3 / tds / psi / paillier / threshold / abac / watermark = ~9 audit entries)
  • When: POST with operator=compliance-audit, action=verify_chain
  • Then: chain length ≥ 8
  • And: each entry has prev_hash link
  • And: chainValid=true
  • Automated: true
  • Bound Task: T2

C12_e2e_full_flow_8_steps

  • Scenario: S12
  • Type: e2e
  • Priority: P0
  • Given: canonical 3-bank fixture (BankA/BankC blacklists + features + shares + ABAC subject + report)
  • When: 1 shell run executes all 11 steps in sequence (C1-C11 in order)
  • Then: pass=12 fail=0 (12 main cases)
  • And: total wall-clock < 60s
  • And: no operator-not-found or 500 errors in any substep
  • Automated: true
  • Bound Task: T3 (E2E orchestration test)