test(dth:frc): T3 12/0 PASS(2.4s)+ spec 输入修正(交集 [f01,f02,f03])
This commit is contained in:
1 parent
a3b1c7bb67
commit
a97c8bf111
3 files changed
+96
-51
No files matched your search
@@ -34,8 +34,8 @@ so that 业务方能用现有算子验证"数据不出域"的多方金融场景
|
||||
|
||||
- **WHEN** 3 banks submit private blacklists:
|
||||
- BankA = `[f01, f02, f03, f04]`
|
||||
- BankB = `[f02, f03, f05]`
|
||||
- BankC = `[f01, f03, f06, f07]`
|
||||
- BankB = `[f01, f02, f03, f05]`
|
||||
- BankC = `[f01, f02, f03, f06, f07]`
|
||||
- **THEN** PSI intersection output = `[f01, f02, f03]` (sorted, no duplicates, no extras)
|
||||
- **AND** output `intersection_size === 3`
|
||||
- **AND** schema_version = "v2"
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
- Scenario: S4
|
||||
- Type: e2e
|
||||
- Priority: P0
|
||||
- Given: 3 blacklists A=[f01,f02,f03,f04] / B=[f02,f03,f05] / C=[f01,f03,f06,f07]
|
||||
- Given: 3 blacklists A=[f01,f02,f03,f04] / B=[f01,f02,f03,f05] / C=[f01,f02,f03,f06,f07]
|
||||
- When: POST /experiment/runs with operator=psi
|
||||
- Then: response.intersection=[f01,f02,f03] (sorted, deduped)
|
||||
- And: intersection_size=3
|
||||
|
||||
+93
-48
@@ -57,6 +57,9 @@ ADMIN_BODY="$(login admin 123456)"
|
||||
ADMIN_TOKEN="$(json_get "['data']['token']" "$ADMIN_BODY")"
|
||||
assert "pre_admin_login" "[ -n '$ADMIN_TOKEN' ]" "admin token empty; body=$ADMIN_BODY"
|
||||
|
||||
# Export for python audit helpers (they read via os.environ).
|
||||
export ADMIN_TOKEN RUNS_URL
|
||||
|
||||
if [ -z "$ADMIN_TOKEN" ]; then
|
||||
echo "---"; echo "FATAL: admin login failed; aborting"
|
||||
exit 1
|
||||
@@ -157,23 +160,23 @@ assert "C3_tds_mismatch_no_token" "[ '$TDS_MISMATCH_TOKEN' = 'None' ]" "mismatch
|
||||
# psi operator 仅支持两两求交 → 分两步:(A∩B) ∩ C
|
||||
# ============================================================
|
||||
PSI_AB_BODY="$(curl -s -H "Authorization: Bearer $ADMIN_TOKEN" -H 'Content-Type: application/json' \
|
||||
-d '{"operator":"psi","input":{"set_a":["f01","f02","f03","f04"],"set_b":["f02","f03","f05"],"hash_key":"psi-frc"}}' "$RUNS_URL")"
|
||||
-d '{"operator":"psi","input":{"set_a":["f01","f02","f03","f04"],"set_b":["f01","f02","f03","f05"],"hash_key":"psi-frc"}}' "$RUNS_URL")"
|
||||
PSI_AB_ID="$(json_get "['data']['run_id']" "$PSI_AB_BODY")"
|
||||
PSI_AB_GET="$(curl -s -H "Authorization: Bearer $ADMIN_TOKEN" "$RUNS_URL/$PSI_AB_ID")"
|
||||
PSI_AB_INTERSECT="$(json_get "['data']['output_json']['psi']['intersection']" "$PSI_AB_GET")"
|
||||
PSI_AB_SIZE="$(json_get "['data']['output_json']['psi']['size']" "$PSI_AB_GET")"
|
||||
assert "C4_psi_AB_size_2" "[ '$PSI_AB_SIZE' = '2' ]" "A∩B size=$PSI_AB_SIZE; body=$PSI_AB_GET"
|
||||
# Convert ["f02","f03"] representation to comma list
|
||||
assert "C4_psi_AB_size_3" "[ '$PSI_AB_SIZE' = '3' ]" "A∩B size=$PSI_AB_SIZE; body=$PSI_AB_GET"
|
||||
# Convert intersection representation to comma list
|
||||
PSI_AB_INTERSECT_LIST="$(python3 -c "
|
||||
import json,sys
|
||||
d=json.loads(sys.argv[1])
|
||||
print(','.join(sorted(d['data']['output_json']['psi']['intersection'])))
|
||||
" "$PSI_AB_GET" 2>/dev/null)"
|
||||
assert "C4_psi_AB_intersection" "[ '$PSI_AB_INTERSECT_LIST' = 'f02,f03' ]" "A∩B=$PSI_AB_INTERSECT_LIST; raw=$PSI_AB_INTERSECT"
|
||||
assert "C4_psi_AB_intersection" "[ '$PSI_AB_INTERSECT_LIST' = 'f01,f02,f03' ]" "A∩B=$PSI_AB_INTERSECT_LIST; raw=$PSI_AB_INTERSECT"
|
||||
|
||||
# Pass (A∩B) into B-side for the next PSI: set_a = intersection, set_b = BankC blacklist
|
||||
PSI_ABC_BODY="$(curl -s -H "Authorization: Bearer $ADMIN_TOKEN" -H 'Content-Type: application/json' \
|
||||
-d '{"operator":"psi","input":{"set_a":["f02","f03"],"set_b":["f01","f03","f06","f07"],"hash_key":"psi-frc"}}' "$RUNS_URL")"
|
||||
-d '{"operator":"psi","input":{"set_a":["f01","f02","f03"],"set_b":["f01","f02","f03","f06","f07"],"hash_key":"psi-frc"}}' "$RUNS_URL")"
|
||||
PSI_ABC_ID="$(json_get "['data']['run_id']" "$PSI_ABC_BODY")"
|
||||
PSI_ABC_GET="$(curl -s -H "Authorization: Bearer $ADMIN_TOKEN" "$RUNS_URL/$PSI_ABC_ID")"
|
||||
PSI_ABC_INTERSECT_LIST="$(python3 -c "
|
||||
@@ -387,60 +390,102 @@ assert "C10_watermark_extract_roundtrip" "[ '$WM_EXT_OUT' = '$WM_PAYLOAD' ]" "wa
|
||||
# 8 条 entry 串行 append (frc 流程全步骤):did-A/B/C + tds + psi + paillier + threshold + abac
|
||||
# 然后 verify_chain → chainValid=true
|
||||
# ============================================================
|
||||
# Use python helper to serialize & chain entries via curl.
|
||||
AUD_ENTRIES_FILE="/tmp/dth_frc_audit_entries.json"
|
||||
> "$AUD_ENTRIES_FILE"
|
||||
AUD_OK=1
|
||||
AUD_DETAIL=""
|
||||
|
||||
append_audit() {
|
||||
local step_label="$1"
|
||||
local action="$2"
|
||||
local prior_json="$3" # JSON array string "[]" or "[entry1,entry2,...]"
|
||||
python3 <<PYEOF
|
||||
import json, subprocess
|
||||
prior=json.loads('''$prior_json''')
|
||||
req={
|
||||
# Write the python helper script once (file-based JSON load avoids heredoc interpolation issues).
|
||||
AUD_HELPER="/tmp/dth_frc_audit_helper.py"
|
||||
cat > "$AUD_HELPER" <<'PYEOF'
|
||||
import json, subprocess, os, sys
|
||||
prior_file = sys.argv[1]
|
||||
action = sys.argv[2]
|
||||
with open(prior_file) as f:
|
||||
prior = json.load(f)
|
||||
req = {
|
||||
"operator":"compliance-audit",
|
||||
"input":{
|
||||
"action":"$action",
|
||||
"actor":"frc-aggregator",
|
||||
"user":"frc-aggregator",
|
||||
"timestamp":"2026-09-29T12:00:00Z",
|
||||
"action": action,
|
||||
"actor": "frc-aggregator",
|
||||
"user": "frc-aggregator",
|
||||
"timestamp": "2026-09-29T12:00:00Z",
|
||||
"entries": prior,
|
||||
}
|
||||
}
|
||||
out=subprocess.run([
|
||||
'curl','-s','-H','Authorization: Bearer $ADMIN_TOKEN',
|
||||
'-H','Content-Type: application/json',
|
||||
'-d',json.dumps(req),
|
||||
'$RUNS_URL'
|
||||
], capture_output=True, text=True)
|
||||
d=json.loads(out.stdout)
|
||||
entry=d['data']['output_json']['audit']['entry']
|
||||
admin_token = os.environ["ADMIN_TOKEN"]
|
||||
runs_url = os.environ["RUNS_URL"] # POST endpoint
|
||||
auth_hdr = ["-H",f"Authorization: Bearer {admin_token}"]
|
||||
ct_hdr = ["-H","Content-Type: application/json"]
|
||||
|
||||
# Step 1: POST to enqueue + run
|
||||
post = subprocess.run(
|
||||
["curl","-s",*auth_hdr,*ct_hdr,"-d",json.dumps(req),runs_url],
|
||||
capture_output=True, text=True,
|
||||
)
|
||||
post_body = json.loads(post.stdout)
|
||||
run_id = post_body["data"]["run_id"]
|
||||
|
||||
# Step 2: GET /runs/:id to retrieve output_json
|
||||
get_url = f"{runs_url}/{run_id}"
|
||||
get = subprocess.run(
|
||||
["curl","-s",*auth_hdr,get_url],
|
||||
capture_output=True, text=True,
|
||||
)
|
||||
get_body = json.loads(get.stdout)
|
||||
entry = get_body["data"]["output_json"]["audit"]["entry"]
|
||||
print(json.dumps(entry))
|
||||
PYEOF
|
||||
|
||||
append_audit() {
|
||||
local action="$1"
|
||||
local prior_file="$2"
|
||||
python3 "$AUD_HELPER" "$prior_file" "$action"
|
||||
}
|
||||
|
||||
# 8 entry sequence (FRC 全流程审计):
|
||||
AUD_E1="$(append_audit "step1-did-bankA" "frc.did.bankA" '[]')"
|
||||
AUD_E2="$(append_audit "step2-did-bankB" "frc.did.bankB" "[$AUD_E1]")"
|
||||
AUD_E3="$(append_audit "step3-did-bankC" "frc.did.bankC" "[$AUD_E1,$AUD_E2]")"
|
||||
AUD_E4="$(append_audit "step4-tds-match" "frc.tds.match" "[$AUD_E1,$AUD_E2,$AUD_E3]")"
|
||||
AUD_E5="$(append_audit "step5-psi" "frc.psi" "[$AUD_E1,$AUD_E2,$AUD_E3,$AUD_E4]")"
|
||||
AUD_E6="$(append_audit "step6-paillier" "frc.paillier" "[$AUD_E1,$AUD_E2,$AUD_E3,$AUD_E4,$AUD_E5]")"
|
||||
AUD_E7="$(append_audit "step7-threshold" "frc.threshold" "[$AUD_E1,$AUD_E2,$AUD_E3,$AUD_E4,$AUD_E5,$AUD_E6]")"
|
||||
AUD_E8="$(append_audit "step8-abac" "frc.abac" "[$AUD_E1,$AUD_E2,$AUD_E3,$AUD_E4,$AUD_E5,$AUD_E6,$AUD_E7]")"
|
||||
# Each prior file is built from the prior entry JSON(s); this avoids heredoc interpolation issues.
|
||||
echo '[]' > /tmp/dth_frc_aud_prior_0.json
|
||||
AUD_E1="$(append_audit 'frc.did.bankA' /tmp/dth_frc_aud_prior_0.json)"
|
||||
|
||||
# Verify chain
|
||||
AUD_V_REQ_FILE="/tmp/dth_frc_audit_verify.json"
|
||||
python3 <<PYEOF > "$AUD_V_REQ_FILE"
|
||||
import json
|
||||
entries=[json.loads('''$AUD_E1'''),json.loads('''$AUD_E2'''),json.loads('''$AUD_E3'''),
|
||||
json.loads('''$AUD_E4'''),json.loads('''$AUD_E5'''),json.loads('''$AUD_E6'''),
|
||||
json.loads('''$AUD_E7'''),json.loads('''$AUD_E8''')]
|
||||
print(json.dumps({'operator':'compliance-audit','input':{'verify':True,'entries':entries}}))
|
||||
echo "[$AUD_E1]" > /tmp/dth_frc_aud_prior_1.json
|
||||
AUD_E2="$(append_audit 'frc.did.bankB' /tmp/dth_frc_aud_prior_1.json)"
|
||||
|
||||
echo "[$AUD_E1,$AUD_E2]" > /tmp/dth_frc_aud_prior_2.json
|
||||
AUD_E3="$(append_audit 'frc.did.bankC' /tmp/dth_frc_aud_prior_2.json)"
|
||||
|
||||
echo "[$AUD_E1,$AUD_E2,$AUD_E3]" > /tmp/dth_frc_aud_prior_3.json
|
||||
AUD_E4="$(append_audit 'frc.tds.match' /tmp/dth_frc_aud_prior_3.json)"
|
||||
|
||||
echo "[$AUD_E1,$AUD_E2,$AUD_E3,$AUD_E4]" > /tmp/dth_frc_aud_prior_4.json
|
||||
AUD_E5="$(append_audit 'frc.psi' /tmp/dth_frc_aud_prior_4.json)"
|
||||
|
||||
echo "[$AUD_E1,$AUD_E2,$AUD_E3,$AUD_E4,$AUD_E5]" > /tmp/dth_frc_aud_prior_5.json
|
||||
AUD_E6="$(append_audit 'frc.paillier' /tmp/dth_frc_aud_prior_5.json)"
|
||||
|
||||
echo "[$AUD_E1,$AUD_E2,$AUD_E3,$AUD_E4,$AUD_E5,$AUD_E6]" > /tmp/dth_frc_aud_prior_6.json
|
||||
AUD_E7="$(append_audit 'frc.threshold' /tmp/dth_frc_aud_prior_6.json)"
|
||||
|
||||
echo "[$AUD_E1,$AUD_E2,$AUD_E3,$AUD_E4,$AUD_E5,$AUD_E6,$AUD_E7]" > /tmp/dth_frc_aud_prior_7.json
|
||||
AUD_E8="$(append_audit 'frc.abac' /tmp/dth_frc_aud_prior_7.json)"
|
||||
|
||||
# Sanity: each AUD_E* must be non-empty JSON (otherwise chain construction failed).
|
||||
for VAR in AUD_E1 AUD_E2 AUD_E3 AUD_E4 AUD_E5 AUD_E6 AUD_E7 AUD_E8; do
|
||||
if [ -z "${!VAR}" ]; then
|
||||
echo "FATAL: $VAR empty — audit chain construction failed"
|
||||
fail=$((fail+1))
|
||||
fi
|
||||
done
|
||||
|
||||
# Verify chain via a second helper script (also file-based).
|
||||
AUD_V_HELPER="/tmp/dth_frc_audit_verify_helper.py"
|
||||
cat > "$AUD_V_HELPER" <<'PYEOF'
|
||||
import json, os, sys
|
||||
entries = []
|
||||
for v in ["AUD_E1","AUD_E2","AUD_E3","AUD_E4","AUD_E5","AUD_E6","AUD_E7","AUD_E8"]:
|
||||
s = os.environ.get(v, "")
|
||||
if not s: sys.exit(f"missing env var {v}")
|
||||
entries.append(json.loads(s))
|
||||
print(json.dumps({"operator":"compliance-audit","input":{"verify":True,"entries":entries}}))
|
||||
PYEOF
|
||||
AUD_V_REQ_FILE="/tmp/dth_frc_audit_verify.json"
|
||||
AUD_E1="$AUD_E1" AUD_E2="$AUD_E2" AUD_E3="$AUD_E3" AUD_E4="$AUD_E4" \
|
||||
AUD_E5="$AUD_E5" AUD_E6="$AUD_E6" AUD_E7="$AUD_E7" AUD_E8="$AUD_E8" \
|
||||
python3 "$AUD_V_HELPER" > "$AUD_V_REQ_FILE"
|
||||
AUD_V_BODY="$(curl -s -H "Authorization: Bearer $ADMIN_TOKEN" -H 'Content-Type: application/json' \
|
||||
--data-binary "@$AUD_V_REQ_FILE" "$RUNS_URL")"
|
||||
AUD_V_ID="$(json_get "['data']['run_id']" "$AUD_V_BODY")"
|
||||
|
||||
Reference in new issue
Block a user