124 lines
6.5 KiB
Bash
Executable File
124 lines
6.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# s2-walkthrough.sh S2-D2/D3 用户人工走查脚本(2026-11-14)
|
|
#
|
|
# 用途:把 S2-D2(消耗日汇总)/S2-D3(充值审核流)的验收从「AI 自证」补正为
|
|
# 「用户本人走查」(七件套·本人走查项)。全程只读或可还原,跑完自动清理。
|
|
# 前置:① gateway 在跑(:8080,make gw-start) ② sg docker 可用(dev MySQL 13306)
|
|
# 用法:bash docs/acceptance/scripts/s2-walkthrough.sh 2>&1 | tee /tmp/s2-walk.log
|
|
# 走查后将 /tmp/s2-walk.log 全文交回,回填 s2-d2.md/s2-d3.md 走查记录。
|
|
set -u
|
|
GW=http://127.0.0.1:8080/api/v1
|
|
step() { echo; echo "===== $1 ====="; }
|
|
pass() { echo "[PASS] $1"; }
|
|
fail() { echo "[FAIL] $1 (预期 ${2:-?},见上行输出)"; }
|
|
|
|
# ---------- 步骤 0:签临时 JWT(dev secret,账号 1=admin) ----------
|
|
step "步骤0 签发临时 token(非侵入)"
|
|
TOK=$(python3 - <<'EOF'
|
|
import hmac, hashlib, base64, json, time, uuid
|
|
def b64(d): return base64.urlsafe_b64encode(d).rstrip(b'=')
|
|
now = int(time.time())
|
|
h = b64(json.dumps({'alg':'HS256','typ':'JWT'}).encode())
|
|
p = b64(json.dumps({'account_id':1,'username':'admin','roles':['admin'],
|
|
'permissions':[],'jti':uuid.uuid4().hex,'iss':'go-sms','sub':'1',
|
|
'exp':now+3600,'iat':now}).encode())
|
|
s = b64(hmac.new(b'dev-go-sms-secret', h+b'.'+p, hashlib.sha256).digest())
|
|
print((h+b'.'+p+b'.'+s).decode())
|
|
EOF
|
|
)
|
|
AUTH="Authorization: Bearer $TOK"
|
|
curl -s -m 3 -H "$AUTH" "$GW/billing/consume" | grep -q ISC:000 \
|
|
&& pass "token 有效(列表 200)" || fail "token 无效"
|
|
|
|
# ---------- D2 走查:消耗日汇总 ----------
|
|
step "D2-1 种两条测试明细(账号1 成功+未知,通道1)"
|
|
sg docker -c 'docker exec go-sms-mysql mysql -uroot -proot123 gosms -e "\
|
|
INSERT INTO message_detail (id,task_id,account_id,channel_id,mobile,content,status,business,fee,created_at) VALUES \
|
|
(9302401110000000001,810001,1,1,\"13000000001\",\"s2-walk\",2,\"sms\",1.5,NOW()),\
|
|
(9302401110000000002,810002,1,1,\"13000000002\",\"s2-walk\",4,\"sms\",2.5,NOW());"' >/dev/null 2>&1 \
|
|
&& pass "明细 2 条已插入" || fail "明细插入"
|
|
|
|
step "D2-2 手动触发今日汇总(应 account_rows=1/channel_rows=1)"
|
|
R=$(curl -s -m 5 -X POST -H "$AUTH" -H 'Content-Type: application/json' \
|
|
-d "{\"date\":\"$(date +%F)\"}" "$GW/ops/settle/aggregate")
|
|
echo "$R"
|
|
echo "$R" | grep -q '"account_rows":1' && echo "$R" | grep -q '"channel_rows":1' \
|
|
&& pass "落账行数 1/1" || fail "落账行数"
|
|
|
|
step "D2-3 查询消耗(admin 应见账号1:submit2/succ1/unk1/fee4.0)"
|
|
R=$(curl -s -m 5 -H "$AUTH" "$GW/billing/consume?account_id=1")
|
|
echo "$R"
|
|
echo "$R" | grep -q '"success_count":1' && echo "$R" | grep -q '"unknown_count":1' \
|
|
&& echo "$R" | grep -q '"fee_total":4' && pass "计数口径正确" || fail "计数口径"
|
|
|
|
step "D2-4 customer 视角收窄(以账号1 冒充 customer 应仍只见自己)"
|
|
TOKC=$(python3 - <<'EOF'
|
|
import hmac, hashlib, base64, json, time, uuid
|
|
def b64(d): return base64.urlsafe_b64encode(d).rstrip(b'=')
|
|
now = int(time.time())
|
|
h = b64(json.dumps({'alg':'HS256','typ':'JWT'}).encode())
|
|
p = b64(json.dumps({'account_id':1,'username':'admin','roles':['customer'],
|
|
'permissions':[],'jti':uuid.uuid4().hex,'iss':'go-sms','sub':'1',
|
|
'exp':now+3600,'iat':now}).encode())
|
|
s = b64(hmac.new(b'dev-go-sms-secret', h+b'.'+p, hashlib.sha256).digest())
|
|
print((h+b'.'+p+b'.'+s).decode())
|
|
EOF
|
|
)
|
|
R=$(curl -s -m 5 -H "Authorization: Bearer $TOKC" "$GW/billing/consume?account_id=999")
|
|
echo "$R"
|
|
echo "$R" | grep -q '"total":1' && pass "customer 越权带参被覆盖收窄(total=1)" || fail "customer 收窄"
|
|
|
|
step "D2-5 状态迁移收敛(未知→成功,重刷后 unknown 0/succ 2)"
|
|
sg docker -c 'docker exec go-sms-mysql mysql -uroot -proot123 gosms -e "\
|
|
UPDATE message_detail SET status=2 WHERE id=9302401110000000002;"' >/dev/null 2>&1
|
|
curl -s -m 5 -X POST -H "$AUTH" -H 'Content-Type: application/json' \
|
|
-d "{\"date\":\"$(date +%F)\"}" "$GW/ops/settle/aggregate" >/dev/null
|
|
R=$(curl -s -m 5 -H "$AUTH" "$GW/billing/consume?account_id=1")
|
|
echo "$R"
|
|
echo "$R" | grep -q '"success_count":2' && echo "$R" | grep -q '"unknown_count":0' \
|
|
&& pass "滚动重刷收敛(72h 回执窗语义)" || fail "收敛"
|
|
|
|
# ---------- D3 走查:充值订单 ----------
|
|
step "D3-1 创建订单(count=300,不动余额)"
|
|
B0=$(sg docker -c 'docker exec go-sms-mysql mysql -uroot -proot123 gosms -N -e "SELECT balance FROM account_user WHERE id=1;"' 2>/dev/null)
|
|
R=$(curl -s -m 5 -H "$AUTH" -H 'Content-Type: application/json' \
|
|
-d '{"account_id":1,"count":300,"amount":30.0,"pay_type":"bank","remark":"s2-walk"}' "$GW/billing/orders")
|
|
echo "$R"
|
|
ON=$(echo "$R" | grep -o '"order_no":"[^"]*"' | cut -d'"' -f4)
|
|
OID=$(echo "$R" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2)
|
|
B1=$(sg docker -c 'docker exec go-sms-mysql mysql -uroot -proot123 gosms -N -e "SELECT balance FROM account_user WHERE id=1;"' 2>/dev/null)
|
|
[ "$B0" = "$B1" ] && echo "$R" | grep -q '"pay_status":0' \
|
|
&& pass "创建后 pay_status=0 且余额未动($B0)" || fail "创建不动余额"
|
|
|
|
step "D3-2 confirm(余额应 +300)"
|
|
R=$(curl -s -m 5 -X POST -H "$AUTH" "$GW/billing/orders/$OID/confirm")
|
|
echo "$R"
|
|
echo "$R" | grep -q "\"balance\":$((B0+300))" && pass "confirm 余额 $B0→$((B0+300))" || fail "confirm 余额"
|
|
|
|
step "D3-3 重复 confirm(应 409 ISC:039)"
|
|
R=$(curl -s -w '\nHTTP=%{http_code}' -m 5 -X POST -H "$AUTH" "$GW/billing/orders/$OID/confirm")
|
|
echo "$R"
|
|
echo "$R" | grep -q 'HTTP=409' && echo "$R" | grep -q 'ISC:039' && pass "409+ISC:039" || fail "重复 confirm"
|
|
|
|
step "D3-4 真库核验流水(ref_id=order_no 双通道锚点)"
|
|
sg docker -c "docker exec go-sms-mysql mysql -uroot -proot123 gosms -e \
|
|
\"SELECT biz_type,amount,balance_after,ref_id FROM account_balance_log WHERE ref_id='$ON';\"" 2>/dev/null
|
|
|
|
step "D3-5 审计留痕(module=billing)"
|
|
sg docker -c 'docker exec go-sms-mysql mysql -uroot -proot123 gosms -e \
|
|
"SELECT module,action FROM system_operate_log WHERE module=\"billing\" ORDER BY id DESC LIMIT 3;"' 2>/dev/null
|
|
|
|
# ---------- 清理还原 ----------
|
|
step "清理(明细/汇总行/订单/流水还原;审计行保留为走查证据)"
|
|
sg docker -c 'docker exec go-sms-mysql mysql -uroot -proot123 gosms -e "\
|
|
DELETE FROM message_detail WHERE id IN (9302401110000000001,9302401110000000002);\
|
|
DELETE FROM billing_consume_log WHERE stat_date=CURDATE();\
|
|
DELETE FROM stats_channel_daily WHERE stat_date=CURDATE();\
|
|
DELETE FROM billing_order WHERE order_no=\"$ON\";\
|
|
DELETE FROM account_balance_log WHERE ref_id=\"$ON\";\
|
|
UPDATE account_user SET balance=$B0 WHERE id=1;"' >/dev/null 2>&1 \
|
|
&& pass "数据已还原" || fail "清理"
|
|
|
|
echo
|
|
echo "===== 走查完成:以上 [PASS] 全绿即 S2-D2/D3 用户走查通过;任一 [FAIL] 请连同整份日志交回 ====="
|