Files
ssw-platform/scripts/perm-smoke-jnpf.sh
T
admin acf076df5a refactor: 内核瘦身 —— 示例搬成业务包 + 装配/测试各归其位
- 内核只有 lib:启动装配 → crates/sspf-admin(bin sspf-admin);37 个集成测试 → crates/tests(package sspf-tests)。
- demo/shop/books 的 spec/菜单/DDL/面 B 路由搬进 packs/{demo,shop,books};内核 modules/*.rs 只剩「面 A 适配器 + pub use」⇒ 内核零业务知识,示例可整目录搬走。面 A 与前端零改动。
- 示例表 DDL 按平台规则补 f_tenant_id + 复合主键(spec 不加 ⇒ JSON 键与响应逐字不变)。
- 修 is_builtin_table 只认 schema.sql 的漏洞:包表(含 asset_data_resource)此前可被建模页删除/改;现为「平台 DDL ∪ 包表」。
- sspf-compat-online_dev → onlinedev(包名/模块/文件/路由别名同步);6 个 5 行转发壳合并为 forward.rs。
- 新增 AR16 闸门 + lib.rs「30 秒地图」+ src/backend/README.md;pack-sync 补两处判据(module_key=None 的 urlAddress、apiFile 查存在性)。
- 回归:704 tests / 6 道静态闸门全绿;health 181 表;四个包面 A/面 B 运行时全部 200。
2026-11-04 14:46:12 +08:00

715 lines
32 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# ssw-platform —— 【面 B:官方 JNPF 契约面】冒烟脚本(23 条断言)
#
# 这是**第二把尺子**。第一把是 scripts/perm-smoke.sh(32 条,测面 A = ssw 契约)。
# 本脚本测**官方形状**:同一个后端进程,按官方请求头 + 官方路径 + 官方响应形状断言。
#
# 用法:
# bash scripts/perm-smoke-jnpf.sh
# B=http://127.0.0.1:30010 bash scripts/perm-smoke-jnpf.sh
# ENC_BIN=/path/to/ssw-platform bash scripts/perm-smoke-jnpf.sh
# JQ_BIN="" bash scripts/perm-smoke-jnpf.sh # 强制走 python3 兜底路径(两条路径判据一致)
#
# 前置:后端已启动,且处于**初始种子状态**(admin / 123456)。
# 退出码:0 = 全绿(面 B 覆盖 23/23) / 1 = 有 FAIL 或有 SKIP(未全覆盖) / 2 = 前置错误
#
# 🔴 **面 B 的判别规则**(见 JNPF_COMPAT_SURFACE.md §2.2):
# 请求头带 `Vue-Version: 3` ⇒ 走官方形状;否则走面 A。
# 官方前端**必然**带这三个头(jnpf-web-apps-main/src/api/request.ts:109-112),
# 但本仓 React 前端**也发** `App-Code` 与 `Jnpf-Origin: pc`(同款),
# **只有 `Vue-Version` 不发** ⇒ 判别只能用它 ⇒ 零歧义、零配置。
#
# 🔴 **本脚本不假装全过**:面 B 尚未落地的能力记 **SKIP**(计入"未覆盖",不算 PASS)。
# 结尾打印 **面 B 覆盖 N/M**(M = 23)。
# 判定规则:**整组未落地**(路由 404 / 共享路由仍是面 A 形状)⇒ 该组逐条记 SKIP;
# **整组已落地但细节不对** ⇒ 该组逐条 FAIL。
#
# 🔴 不依赖 node:cipher 用后端 `--enc` 自证;JSON 取值用 jq(无则 python3 兜底)。
# 🔴 所有 curl 都带 `--noproxy '*'`(本机 curl 走系统代理,不加会打不通 loopback)与 `--max-time 10`。
# 🔴 所有含中文的变量引用一律写 `${VAR}`(变量名后紧跟中文时,bash 会把中文并进变量名 ⇒ set -u 下 unbound variable)。
set -u
if [ "${1:-}" = "-h" ] || [ "${1:-}" = "--help" ]; then
sed -n '2,26p' "$0" | sed 's/^# \{0,1\}//'
exit 0
fi
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
# 🔴 记住「B 是不是用户显式给的」—— 显式给了就不自起隔离后端(尊重外部后端)
B_RAW="${B:-}"
B="${B:-http://127.0.0.1:30010}"
ENC_BIN="${ENC_BIN:-$ROOT/target/release/sspf-admin}"
TMP="$(mktemp -d)"
# 🔴 退出时先停掉**自起的**隔离后端,再删临时目录(助手提供 kill;没自起就是空操作)
trap 'smoke_backend_kill 2>/dev/null || true; rm -rf "$TMP"' EXIT
# 隔离后端自启动助手(被 source;提供 ensure / kill)
# shellcheck source=scripts/smoke_backend.sh
. "${ROOT}/scripts/smoke_backend.sh"
# 🔴 JQ_BIN / PY_BIN **允许从环境覆盖**(与面 A 尺子同形):
# 用 `${VAR-default}`(只在未设置时取默认)⇒ `JQ_BIN="" bash …` 能强制走 python3 路径。
JQ_BIN="${JQ_BIN-$(command -v jq 2>/dev/null || true)}"
PY_BIN="${PY_BIN-$(command -v python3 2>/dev/null || true)}"
pre_fail() {
echo "❌ 前置错误:${1}"
exit 2
}
# ---- 契约期望值(唯一真源:docs/contract.md 附录 A)----
# 🔴 本尺子的**期望条数**从契约读 ⇒ 契约改了尺子不用改;
# 尺子被改弱(条数对不上)⇒ 结尾的自证会失败。
CE_PY="$ROOT/scripts/contract_expect.py"
if [ ! -f "$CE_PY" ]; then
pre_fail "找不到 ${CE_PY}(契约期望值读取器)。"
fi
if ! command -v python3 >/dev/null 2>&1; then
pre_fail "找不到 python3(读契约期望值用)。"
fi
CE_EXP_ASSERTIONS="$(python3 "${CE_PY}" ruler perm-smoke-jnpf.sh 2>/dev/null)" || CE_EXP_ASSERTIONS=""
if [ -z "${CE_EXP_ASSERTIONS}" ]; then
pre_fail "读契约的 [RULER] 区段失败(perm-smoke-jnpf.sh 的期望条数)。"
fi
# ---- 前置 1:JSON 取值工具(jq 优先,python3 兜底;两个都没有 ⇒ 退 2)----
if [ -z "$JQ_BIN" ] && [ -z "$PY_BIN" ]; then
pre_fail "jq 与 python3 都没装,无法解析 JSON。"
fi
# ---- 前置 2:cipher 自证二进制(--enc 必须在,脚本不依赖 node)----
if [ ! -x "$ENC_BIN" ]; then
pre_fail "找不到可执行的 ${ENC_BIN}(先 cargo build --release,或用 ENC_BIN= 指定)。"
fi
ENC_PROBE="$("$ENC_BIN" --enc '123456' 2>/dev/null || true)"
if [ -z "$ENC_PROBE" ]; then
pre_fail "${ENC_BIN} --enc 自证失败(无输出)。"
fi
if ! printf '%s' "$ENC_PROBE" | grep -Eq '^[0-9a-fA-F]+$'; then
pre_fail "${ENC_BIN} --enc 输出不是 hex。"
fi
# ---- python3 兜底的取值小工具(jq 在时不用它)----
# 🔴 本文件每个 mode 的 **jq 表达式与 python 实现必须给出同一个判据**,
# 否则 `JQ_BIN=""` 会跑出与 jq 路径不同的结论。改一处必须改两处。
PY_HELPER="$TMP/jget.py"
cat >"$PY_HELPER" <<'PYEOF'
import json
import sys
CUR_KEYS5 = ["menuList", "permissionList", "userInfo", "currentSystemId", "sysConfigInfo"]
CUR_KEYS2 = ["userInfo", "menuList"]
PL_KEYS = ["pagination", "list"]
PAG_KEYS = ["currentPage", "pageSize", "total"]
MENU_KEYS = [
"id", "fullName", "enCode", "parentId", "icon", "hasChildren",
"urlAddress", "pageAddress", "linkTarget", "children", "type",
"propertyJson", "sortCode", "systemId", "isData",
]
def out(v):
if v is None:
print("null")
elif v is True:
print("true")
elif v is False:
print("false")
elif isinstance(v, str):
print(v)
else:
print(json.dumps(v, ensure_ascii=False))
def d_obj(d):
v = d.get("data")
return v if isinstance(v, dict) else {}
def d_list(d):
v = d_obj(d).get("list")
return v if isinstance(v, list) else None
def jtype(v):
if v is None:
return "null"
if isinstance(v, bool):
return "boolean"
if isinstance(v, (int, float)):
return "number"
if isinstance(v, str):
return "string"
if isinstance(v, list):
return "array"
if isinstance(v, dict):
return "object"
return "other"
def count_present(container, keys):
if not isinstance(container, dict):
return 0
return sum(1 for k in keys if k in container)
def adm_type(d):
items = d_list(d)
if items is None or not items or not isinstance(items[0], dict):
return "missing"
if "isAdministrator" not in items[0]:
return "missing"
v = items[0]["isAdministrator"]
if v is None:
return "null"
if isinstance(v, bool):
return "boolean"
if isinstance(v, (int, float)):
return "number"
return "string"
def secret_leak(d):
items = d_list(d) or []
n = 0
for it in items:
if not isinstance(it, dict):
continue
for k in ("password", "secretkey", "f_password", "f_secretkey"):
if k in it:
n += 1
break
return n
def menu_keys_ok(d):
ml = d_obj(d).get("menuList")
if not isinstance(ml, list) or not ml or not isinstance(ml[0], dict):
return "missing"
miss = [k for k in MENU_KEYS if k not in ml[0]]
if not miss:
return "ok"
return "missing:" + ",".join(miss)
def perm_list_type(d):
obj = d_obj(d)
if "permissionList" not in obj:
return "missing"
return jtype(obj.get("permissionList"))
def str_array(d):
v = d.get("data")
if not isinstance(v, list):
return ""
return ",".join(str(x) for x in v if isinstance(x, str))
# 🔴 单条详情(**不是** PageListVO):`data` 直接是对象 ⇒ 不能复用 list 系的助手。
def data_id(d):
v = d_obj(d).get("id")
return "" if v is None else str(v)
def secret_leak_detail(d):
obj = d_obj(d)
for k in ("password", "secretkey", "f_password", "f_secretkey"):
if k in obj:
return "leak"
return "clean"
def detail_str(d, key):
v = d_obj(d).get(key)
return "" if v is None else str(v)
def main():
mode = sys.argv[1]
raw = sys.stdin.read()
try:
d = json.loads(raw)
except Exception:
print("ERR")
return
if not isinstance(d, dict):
print("ERR")
return
try:
if mode == "code":
out(d.get("code"))
elif mode == "msg":
out(d.get("msg"))
elif mode == "token":
v = d_obj(d).get("token")
print("" if v is None else v)
elif mode == "sysid":
# 🔴 多应用(面 B 口径):`currentSystemId` 在信封 data 内(官方 PcUserVO 的兄弟键)
v = d_obj(d).get("currentSystemId")
print("" if v is None else v)
elif mode == "dkeys5":
out(count_present(d_obj(d), CUR_KEYS5))
elif mode == "dkeys2":
out(count_present(d_obj(d), CUR_KEYS2))
elif mode == "dkeys_pl":
out(count_present(d_obj(d), PL_KEYS))
elif mode == "pkeys3":
out(count_present(d_obj(d).get("pagination"), PAG_KEYS))
elif mode == "listlen":
items = d_list(d)
out(0 if items is None else len(items))
elif mode == "total_ge_list":
p = d_obj(d).get("pagination")
total = p.get("total") if isinstance(p, dict) else None
items = d_list(d)
n = 0 if items is None else len(items)
if not isinstance(total, (int, float)) or isinstance(total, bool):
print("no")
else:
print("yes" if total >= n else "no")
elif mode == "admtype":
print(adm_type(d))
elif mode == "secretleak":
out(secret_leak(d))
elif mode == "menutkeys":
print(menu_keys_ok(d))
elif mode == "permlisttype":
print(perm_list_type(d))
elif mode == "datatype":
print(jtype(d.get("data")))
elif mode == "listisarray":
items = d_list(d)
print("yes" if isinstance(items, list) else "no")
elif mode == "strarray":
print(str_array(d))
elif mode == "dataid":
print(data_id(d))
elif mode == "pwdleak":
out(secret_leak_detail(d))
elif mode == "dranks":
out(detail_str(d, "ranks"))
elif mode == "denabled":
out(detail_str(d, "enabledMark"))
else:
print("ERR")
except Exception:
print("ERR")
main()
PYEOF
# ---- 取值小工具:json_get <模式> <JSON 文本> ----
json_get() {
local mode="${1}" body="${2}" expr=""
case "$mode" in
code) expr='.code' ;;
msg) expr='.msg' ;;
token) expr='(.data // {}) | .token // ""' ;;
# 🔴 多应用(面 B 口径):当前应用 id 由 `App-Code` 头解析,位置 = 信封 data 内
sysid) expr='(.data // {}) | .currentSystemId // ""' ;;
dkeys5) expr='(.data // {}) as $d | ["menuList","permissionList","userInfo","currentSystemId","sysConfigInfo"] | map(. as $k | select($d|has($k))) | length' ;;
dkeys2) expr='(.data // {}) as $d | ["userInfo","menuList"] | map(. as $k | select($d|has($k))) | length' ;;
dkeys_pl) expr='(.data // {}) as $d | ["pagination","list"] | map(. as $k | select($d|has($k))) | length' ;;
pkeys3) expr='(.data.pagination // {}) as $p | ["currentPage","pageSize","total"] | map(. as $k | select($p|has($k))) | length' ;;
listlen) expr='(.data.list // []) | length' ;;
total_ge_list) expr='(.data.pagination.total // 0) as $t | (.data.list // []) as $l | (($t|type)=="number" and $t >= ($l|length)) | if . then "yes" else "no" end' ;;
admtype) expr='(.data.list // []) as $l | (if ($l|length)>0 and ($l[0]|type)=="object" then $l[0] else null end) as $it | if $it == null then "missing" elif ($it|has("isAdministrator")|not) then "missing" else ($it.isAdministrator | if . == null then "null" else type end) end' ;;
secretleak) expr='[(.data.list // [])[] | select(type=="object") | select(has("password") or has("secretkey") or has("f_password") or has("f_secretkey"))] | length' ;;
menutkeys) expr='(.data.menuList // []) as $m | (if ($m|length)>0 and ($m[0]|type)=="object" then $m[0] else null end) as $it | if $it == null then "missing" else (["id","fullName","enCode","parentId","icon","hasChildren","urlAddress","pageAddress","linkTarget","children","type","propertyJson","sortCode","systemId","isData"] as $need | ($need - ($it|keys)) as $miss | if ($miss|length)==0 then "ok" else "missing:"+($miss|join(",")) end) end' ;;
permlisttype) expr='(.data // {}) as $d | if ($d|has("permissionList")) then ($d.permissionList|type) else "missing" end' ;;
datatype) expr='.data | type' ;;
listisarray) expr='(.data.list // null) | if . == null then "no" else (type == "array" | if . then "yes" else "no" end) end' ;;
strarray) expr='(.data // []) as $d | if ($d|type)=="array" then ($d|map(select(type=="string"))|join(",")) else "" end' ;;
# ---- 单条详情(data 是对象,不是 PageListVO)----
dataid) expr='(.data // {}) | .id // ""' ;;
# 🔴 `a|has(x) or b|has(y)` 在 jq 里会被 `|` 抢走结合 ⇒ **必须**先把候选键筛出来再判空。
pwdleak) expr='(.data // {}) | [keys[] | select(. == "password" or . == "f_password" or . == "secretkey" or . == "f_secretkey")] | if length > 0 then "leak" else "clean" end' ;;
dranks) expr='(.data // {}) | .ranks // ""' ;;
denabled) expr='(.data // {}) | .enabledMark // "" | tostring' ;;
*) echo "ERR"; return 0 ;;
esac
if [ -n "$JQ_BIN" ]; then
printf '%s' "$body" | "$JQ_BIN" -r "$expr" 2>/dev/null || echo 'ERR'
else
printf '%s' "$body" | "$PY_BIN" "$PY_HELPER" "$mode" 2>/dev/null || echo 'ERR'
fi
}
PASS=0
FAIL=0
SKIP=0
ok() {
echo " ✅ ${1}"
PASS=$((PASS + 1))
}
bad() {
echo " ❌ ${1}"
FAIL=$((FAIL + 1))
}
skipped() {
echo " ⏭ ${1} —— 面 B 未落地(不计入 PASS)"
SKIP=$((SKIP + 1))
}
# assert1 <说明> <0|1 判定结果> <细节>
assert1() {
local desc="${1}" good="${2}" detail="${3}"
if [ "$good" -eq 1 ]; then
ok "${desc}(${detail})"
else
bad "${desc} 实际=${detail}"
fi
}
# check <期望> <实际> <说明>(支持 ">=N" 数值比较)
check() {
local exp="${1}" act="${2}" desc="${3}" good=0
case "$exp" in
'>='*)
local num="${exp#>=}"
if printf '%s' "$act" | grep -Eq '^[0-9]+$' && [ "$act" -ge "$num" ]; then
good=1
fi
;;
*)
if [ "$exp" = "$act" ]; then
good=1
fi
;;
esac
if [ "$good" -eq 1 ]; then
ok "${desc}(实际=${act})"
else
bad "${desc} 期望=${exp} 实际=${act}"
fi
}
# skip_group "<描述1>|<描述2>|…" —— 整组未落地 ⇒ 逐条记 SKIP
skip_group() {
local descs="${1}" d
local IFS='|'
for d in ${descs}; do
skipped "${d}"
done
}
# 端点是否"未落地":HTTP 404 或 body code=404(本仓的未知路由兜底)
route_missing() {
local http="${1}" body="${2}"
if [ "$http" = "404" ]; then
return 0
fi
local c
c="$(json_get code "$body")"
if [ "$c" = "404" ]; then
return 0
fi
return 1
}
# 官方形状的请求头(官方前端必带的三个头;**判面 B 的依据是 `Vue-Version: 3`**)
HDR_B=(-H 'Jnpf-Origin: pc' -H 'Vue-Version: 3' -H 'App-Code: ssw-platform')
# cipher 自证:enc <明文> ⇒ hex 密文
enc() {
"$ENC_BIN" --enc "${1}"
}
# 登录一次,输出 body 到 stdout
login() {
curl --noproxy '*' -s --max-time 10 -X POST "$B/api/oauth/Login" \
"$@" \
-H 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode "account=admin" \
--data-urlencode "password=$(enc '123456')" \
--data-urlencode "grant_type=password"
}
echo "== ssw-platform 面 B(官方 JNPF 契约面)冒烟(目标 ${B})=="
# ---- 前置 3:后端可达且确实是本仓后端(不通 ⇒ 退 2,不是逐条假失败)----
# 🔴 **后端不可达时自动自起一个隔离实例**(独立数据目录 + 空闲端口)⇒
# ① 不用先手工起服务(CI 可跑)② 跑完不留脏数据 ③ 两把尺子互不污染。
# 但**用户显式给了 B** ⇒ 不自起(那个后端是用户自己的,不该替他关)。
smoke_backend_ensure "${ENC_BIN}" "${B_RAW}"
if [ "${BACKEND_ISOLATED}" = "1" ]; then
echo "ℹ️ 已自起隔离后端:${B}(数据目录 ${BACKEND_TMP}/pg,跑完即删)"
fi
# 判据:无 token 打 /api/oauth/CurrentUser ⇒ 本仓恒返回 {code:600}。
PROBE_BODY="$(curl --noproxy '*' -s --max-time 10 "$B/api/oauth/CurrentUser" 2>/dev/null || true)"
PROBE_CODE="$(json_get code "$PROBE_BODY")"
if [ "$PROBE_CODE" != "600" ]; then
pre_fail "后端不可达或不是 ssw-platform(${B} 返回 code=${PROBE_CODE:-无},期望 600=未登录)。先起服务,或用 B=<url> 指定目标后重试。"
fi
# =====================================================================
# G0 · 面 A 未被面 B 破坏(断言 1–2)—— 恒可跑
# =====================================================================
A_LOGIN="$(login)"
A_TOKEN="$(json_get token "$A_LOGIN")"
A_AUTH="Authorization: bearer ${A_TOKEN}"
A_CU="$(curl --noproxy '*' -s --max-time 10 "$B/api/oauth/CurrentUser" -H "$A_AUTH")"
A_K2="$(json_get dkeys2 "$A_CU")"
A_PERM="$(json_get permlisttype "$A_CU")"
if [ "$A_K2" = "2" ] && [ "$A_PERM" = "missing" ]; then
assert1 "断言 1 · 面 A CurrentUser 仍是 2 字段形状(userInfo + menuList,无 permissionList)" 1 "keys=${A_K2}, permissionList=${A_PERM}"
else
assert1 "断言 1 · 面 A CurrentUser 仍是 2 字段形状(userInfo + menuList,无 permissionList)" 0 "keys=${A_K2}, permissionList=${A_PERM}"
fi
A_CODE="$(json_get code "$A_LOGIN")"
if [ "$A_CODE" = "200" ] && [ -n "$A_TOKEN" ]; then
assert1 "断言 2 · 面 A 登录(无 Vue-Version 头)仍通" 1 "code=${A_CODE}, token 长度=${#A_TOKEN}"
else
assert1 "断言 2 · 面 A 登录(无 Vue-Version 头)仍通" 0 "code=${A_CODE}, token 长度=${#A_TOKEN}"
fi
# =====================================================================
# G1 · 面 B 登录(断言 3)—— 共用路由,恒可跑
# =====================================================================
B_LOGIN="$(login "${HDR_B[@]}")"
B_TOKEN="$(json_get token "$B_LOGIN")"
B_AUTH="Authorization: bearer ${B_TOKEN}"
B_CODE="$(json_get code "$B_LOGIN")"
if [ "$B_CODE" = "200" ] && [ -n "$B_TOKEN" ]; then
assert1 "断言 3 · 面 B 登录(带 Vue-Version: 3)⇒ code=200 且拿到 token" 1 "code=${B_CODE}, token 长度=${#B_TOKEN}"
else
assert1 "断言 3 · 面 B 登录(带 Vue-Version: 3)⇒ code=200 且拿到 token" 0 "code=${B_CODE}, token 长度=${#B_TOKEN}"
fi
# =====================================================================
# G2 · 面 B CurrentUser 形状(断言 4–6)—— 共用路由;仍是面 A 形状 ⇒ 整组 SKIP
# =====================================================================
B_CU="$(curl --noproxy '*' -s --max-time 10 "$B/api/oauth/CurrentUser" "${HDR_B[@]}" -H "$B_AUTH")"
B_K5="$(json_get dkeys5 "$B_CU")"
if [ "$B_K5" != "5" ]; then
skip_group "断言 4 · 面 B CurrentUser 顶层 5 字段齐全|断言 5 · 面 B menuList 节点是 AllMenuSelectVO 形状|断言 6 · 面 B permissionList 是数组(不能 null)"
else
assert1 "断言 4 · 面 B CurrentUser 顶层 5 字段齐全" 1 "命中 5/5"
MK="$(json_get menutkeys "$B_CU")"
if [ "$MK" = "ok" ]; then
assert1 "断言 5 · 面 B menuList 节点是 AllMenuSelectVO 形状(15 字段)" 1 "15/15 齐全"
else
assert1 "断言 5 · 面 B menuList 节点是 AllMenuSelectVO 形状(15 字段)" 0 "${MK}"
fi
PL="$(json_get permlisttype "$B_CU")"
if [ "$PL" = "array" ]; then
assert1 "断言 6 · 面 B permissionList 是数组(不能是 null)" 1 "type=array"
else
assert1 "断言 6 · 面 B permissionList 是数组(不能是 null)" 0 "type=${PL}"
fi
fi
# =====================================================================
# G3 · 面 B 鉴权码 602 + 未知路由 404(断言 7–8)
# =====================================================================
UNAUTH_HTTP="$(curl --noproxy '*' -s --max-time 10 -o "$TMP/unauth.json" -w '%{http_code}' \
"$B/api/permission/Users" "${HDR_B[@]}")"
UNAUTH_BODY="$(cat "$TMP/unauth.json" 2>/dev/null || true)"
if route_missing "$UNAUTH_HTTP" "$UNAUTH_BODY"; then
skipped "断言 7 · 面 B 无 token ⇒ 返 602(token 失效),不是 600/401"
else
check 602 "$(json_get code "$UNAUTH_BODY")" "断言 7 · 面 B 无 token ⇒ 返 602(token 失效),不是 600/401"
fi
check 404 "$(curl --noproxy '*' -s --max-time 10 -o /dev/null -w '%{http_code}' \
"$B/api/permission/NotExistJnpfRoute" "${HDR_B[@]}")" \
"断言 8 · 面 B 未知路由 HTTP 404 不被吞掉"
# =====================================================================
# G4 · 面 B 用户列表 = PageListVO(断言 9–13)
# =====================================================================
U_HTTP="$(curl --noproxy '*' -s --max-time 10 -o "$TMP/ulist.json" -w '%{http_code}' \
"$B/api/permission/Users?pageSize=20&currentPage=1" "${HDR_B[@]}" -H "$B_AUTH")"
U_BODY="$(cat "$TMP/ulist.json" 2>/dev/null || true)"
if route_missing "$U_HTTP" "$U_BODY"; then
skip_group "断言 9 · 面 B 用户列表 data 是 PageListVO(含 pagination + list)|断言 10 · 面 B pagination 三字段齐全|断言 11 · 面 B pagination.total 是总条数|断言 12 · 面 B 列表项不含 password/secretkey|断言 13 · 面 B 列表项 isAdministrator 是数字(0/1,不是布尔)"
else
check 2 "$(json_get dkeys_pl "$U_BODY")" "断言 9 · 面 B 用户列表 data 是 PageListVO(含 pagination + list)"
check 3 "$(json_get pkeys3 "$U_BODY")" "断言 10 · 面 B pagination 三字段齐全(currentPage/pageSize/total)"
check "yes" "$(json_get total_ge_list "$U_BODY")" "断言 11 · 面 B pagination.total 是总条数(≥ list 长度)"
check 0 "$(json_get secretleak "$U_BODY")" "断言 12 · 面 B 列表项不含 password/secretkey"
check "number" "$(json_get admtype "$U_BODY")" "断言 13 · 面 B 列表项 isAdministrator 是数字(0/1,不是布尔)"
fi
# =====================================================================
# G5 · 面 B 角色列表 = PageListVO(断言 14)
# =====================================================================
R_HTTP="$(curl --noproxy '*' -s --max-time 10 -o "$TMP/rlist.json" -w '%{http_code}' \
"$B/api/permission/Role?pageSize=20&currentPage=1" "${HDR_B[@]}" -H "$B_AUTH")"
R_BODY="$(cat "$TMP/rlist.json" 2>/dev/null || true)"
if route_missing "$R_HTTP" "$R_BODY"; then
skipped "断言 14 · 面 B 角色列表 data 是 PageListVO"
else
check 2 "$(json_get dkeys_pl "$R_BODY")" "断言 14 · 面 B 角色列表 data 是 PageListVO"
fi
# =====================================================================
# G6 · 面 B 组织列表支持 AsyncList/{id}(断言 15)
# =====================================================================
O_HTTP="$(curl --noproxy '*' -s --max-time 10 -o "$TMP/olist.json" -w '%{http_code}' \
"$B/api/permission/Organize/AsyncList/0" "${HDR_B[@]}" -H "$B_AUTH")"
O_BODY="$(cat "$TMP/olist.json" 2>/dev/null || true)"
if route_missing "$O_HTTP" "$O_BODY"; then
skipped "断言 15 · 面 B 组织列表支持 AsyncList/{id}(根节点 id=0 取一级组织)"
else
check 2 "$(json_get dkeys_pl "$O_BODY")" "断言 15 · 面 B 组织列表支持 AsyncList/{id}(根节点 id=0 取一级组织)"
fi
# =====================================================================
# G7 · 面 B 菜单 ModuleBySystem(断言 16)
# 官方返回 ActionResult<ListVO<MenuListVO>> ⇒ data = {list:[...]}(**不是裸数组**)
# =====================================================================
M_HTTP="$(curl --noproxy '*' -s --max-time 10 -o "$TMP/mlist.json" -w '%{http_code}' \
"$B/api/system/Menu/ModuleBySystem" "${HDR_B[@]}" -H "$B_AUTH")"
M_BODY="$(cat "$TMP/mlist.json" 2>/dev/null || true)"
if route_missing "$M_HTTP" "$M_BODY"; then
skipped "断言 16 · 面 B 菜单 ModuleBySystem 可达且 data.list 是数组"
else
M_CODE="$(json_get code "$M_BODY")"
M_LA="$(json_get listisarray "$M_BODY")"
if [ "$M_CODE" = "200" ] && [ "$M_LA" = "yes" ]; then
assert1 "断言 16 · 面 B 菜单 ModuleBySystem 可达且 data.list 是数组" 1 "code=200, data.list=array"
else
assert1 "断言 16 · 面 B 菜单 ModuleBySystem 可达且 data.list 是数组" 0 "code=${M_CODE}, data.list=${M_LA}"
fi
fi
# =====================================================================
# G8 · 授权:官方 body 超集(断言 17)+ 官方读用 POST(断言 18)
# =====================================================================
# 🔴 写入用的角色 = role_user,写入内容与面 A 尺子**完全相同**(module=["m_demo"])⇒ 幂等、互不干扰。
AUTH_WRITE="$(curl --noproxy '*' -s --max-time 10 -X PUT "$B/api/permission/Authority/Data/role_user" \
"${HDR_B[@]}" -H "$B_AUTH" -H 'Content-Type: application/json' \
-d '{"objectType":"role","module":["m_demo"],"button":[],"column":[],"resource":[],"form":[],"systemIds":[]}')"
AW_CODE="$(json_get code "$AUTH_WRITE")"
# 回读:走面 A 的只读端点(两把尺子共用一份数据 ⇒ 这才是真回读)
ROLE_MODS="$(curl --noproxy '*' -s --max-time 10 "$B/api/ssw/sys/Role/Modules?roleId=role_user" -H "$A_AUTH")"
ROLE_MOD_IDS="$(json_get strarray "$ROLE_MODS")"
if [ "$AW_CODE" = "200" ] && printf '%s' "$ROLE_MOD_IDS" | tr ',' '\n' | grep -qx 'm_demo'; then
assert1 "断言 17 · 授权写:官方完整 body(含 button/column/resource/form/systemIds)⇒ code=200 且 module 真落库" 1 "code=200, 回读含 m_demo"
else
assert1 "断言 17 · 授权写:官方完整 body(含 button/column/resource/form/systemIds)⇒ code=200 且 module 真落库" 0 "code=${AW_CODE}, 回读=${ROLE_MOD_IDS:-空}"
fi
# 官方读授权用 **POST**(AuthorizeController.java:100-101),body = DataValuesQuery{type, moduleIds(String), objectType}
AV_HTTP="$(curl --noproxy '*' -s --max-time 10 -o "$TMP/aval.json" -w '%{http_code}' \
-X POST "$B/api/permission/Authority/Data/role_user/Values" "${HDR_B[@]}" -H "$B_AUTH" \
-H 'Content-Type: application/json' \
-d '{"type":"module","moduleIds":"","objectType":"role"}')"
AV_BODY="$(cat "$TMP/aval.json" 2>/dev/null || true)"
if route_missing "$AV_HTTP" "$AV_BODY"; then
skipped "断言 18 · 授权读是 POST(POST .../Data/{id}/Values)⇒ code=200"
else
check 200 "$(json_get code "$AV_BODY")" "断言 18 · 授权读是 POST(POST .../Data/{id}/Values)⇒ code=200"
fi
# =====================================================================
# G9 · 多应用:`App-Code` 决定当前应用(断言 19)—— 面 B 与面 A **同一口径**
# =====================================================================
# 🔴 只改 `App-Code`(`Vue-Version: 3` 保持不动)⇒ 仍走面 B,但 currentSystemId 必须跟着变。
# 这钉住的是「头 → 系统解析」这条链路,不是形状(形状由断言 4/5 管)。
B_CU_APPB="$(curl --noproxy '*' -s --max-time 10 "$B/api/oauth/CurrentUser" \
-H 'Jnpf-Origin: pc' -H 'Vue-Version: 3' -H 'App-Code: app-b' -H "$B_AUTH")"
check "app-b" "$(json_get sysid "$B_CU_APPB")" \
"断言 19 · 多应用:App-Code: app-b ⇒ currentSystemId = app-b(面 B 同一口径)"
# =====================================================================
# G10 · 用户 CRUD(断言 20~23)—— 官方 `permission/Users` 那一族
# =====================================================================
# 🔴 用**独立账号** `smoke_jnpf_u1`,跑完**软删**(不硬删)⇒ 库里留一行 `f_delete_mark=1`,
# 下一次跑仍然能重建(查重只看 `f_delete_mark = 0`)⇒ **可重复**。
# 🔴 断言 22 钉的是「**只 SET body 里出现的键**」:创建时给 `ranks=P5`,
# 更新时**只发 realName** ⇒ 回读的 `ranks` 必须还在(少写一个 COALESCE 就会变空,
# 而且前端「编辑用户」一保存就把半个档案清空、**不报错**)。
SU_ACC="smoke_jnpf_u1"
SU_CREATE="$(curl --noproxy '*' -s --max-time 10 -X POST "$B/api/permission/Users" \
"${HDR_B[@]}" -H "$B_AUTH" -H 'Content-Type: application/json' \
-d "{\"account\":\"${SU_ACC}\",\"realName\":\"面B探针\",\"gender\":\"1\",\"mobilePhone\":\"13800009999\",\"ranks\":\"P5\",\"sortCode\":9,\"enabledMark\":1}")"
SU_NEW_ID="$(json_get dataid "$SU_CREATE")"
if [ "$(json_get code "$SU_CREATE")" = "200" ] && [ -n "$SU_NEW_ID" ]; then
assert1 "断言 20 · 用户建档是 POST /api/permission/Users(JSON body)⇒ code=200 且返回新 id" 1 "code=200, id=${SU_NEW_ID:0:8}…"
else
assert1 "断言 20 · 用户建档是 POST /api/permission/Users(JSON body)⇒ code=200 且返回新 id" 0 "code=$(json_get code "$SU_CREATE"), id=${SU_NEW_ID:-空}"
fi
if [ -n "$SU_NEW_ID" ]; then
SU_INFO="$(curl --noproxy '*' -s --max-time 10 "$B/api/permission/Users/${SU_NEW_ID}" "${HDR_B[@]}" -H "$B_AUTH")"
if [ "$(json_get code "$SU_INFO")" = "200" ] && [ "$(json_get pwdleak "$SU_INFO")" = "clean" ]; then
assert1 "断言 21 · 用户详情 GET /{id} ⇒ code=200 且**不含** password / secretkey" 1 "code=200, 口令列未外泄"
else
assert1 "断言 21 · 用户详情 GET /{id} ⇒ code=200 且**不含** password / secretkey" 0 "code=$(json_get code "$SU_INFO"), 口令=$(json_get pwdleak "$SU_INFO")"
fi
SU_UPD="$(curl --noproxy '*' -s --max-time 10 -X PUT "$B/api/permission/Users/${SU_NEW_ID}" \
"${HDR_B[@]}" -H "$B_AUTH" -H 'Content-Type: application/json' \
-d '{"realName":"面B探针改"}')"
SU_AFTER="$(curl --noproxy '*' -s --max-time 10 "$B/api/permission/Users/${SU_NEW_ID}" "${HDR_B[@]}" -H "$B_AUTH")"
if [ "$(json_get code "$SU_UPD")" = "200" ] && [ "$(json_get dranks "$SU_AFTER")" = "P5" ]; then
assert1 "断言 22 · 用户改档是 PUT /{id},且**只 SET body 里出现的键**(未发的 ranks 保持 P5)" 1 "code=200, ranks=P5 未被清空"
else
assert1 "断言 22 · 用户改档是 PUT /{id},且**只 SET body 里出现的键**(未发的 ranks 保持 P5)" 0 "code=$(json_get code "$SU_UPD"), ranks=$(json_get dranks "$SU_AFTER")"
fi
SU_BS="$(curl --noproxy '*' -s --max-time 10 -X POST "$B/api/permission/Users/BatchUpdateState" \
"${HDR_B[@]}" -H "$B_AUTH" -H 'Content-Type: application/json' \
-d "{\"ids\":[\"${SU_NEW_ID}\"],\"enabledMark\":2}")"
SU_DEL="$(curl --noproxy '*' -s --max-time 10 -X DELETE "$B/api/permission/Users/${SU_NEW_ID}" "${HDR_B[@]}" -H "$B_AUTH")"
SU_GONE="$(curl --noproxy '*' -s --max-time 10 "$B/api/permission/Users/${SU_NEW_ID}" "${HDR_B[@]}" -H "$B_AUTH")"
if [ "$(json_get code "$SU_BS")" = "200" ] && [ "$(json_get code "$SU_DEL")" = "200" ] \
&& [ "$(json_get code "$SU_GONE")" = "400" ]; then
assert1 "断言 23 · 批量启停 + 软删:BatchUpdateState / DELETE 都 code=200,删后详情 code=400" 1 "启停=200, 删=200, 删后=400"
else
assert1 "断言 23 · 批量启停 + 软删:BatchUpdateState / DELETE 都 code=200,删后详情 code=400" 0 "启停=$(json_get code "$SU_BS"), 删=$(json_get code "$SU_DEL"), 删后=$(json_get code "$SU_GONE")"
fi
else
skip_group "断言 21 · 用户详情 GET /{id} ⇒ code=200 且**不含** password / secretkey|断言 22 · 用户改档是 PUT /{id},且**只 SET body 里出现的键**(未发的 ranks 保持 P5)|断言 23 · 批量启停 + 软删:BatchUpdateState / DELETE 都 code=200,删后详情 code=400"
fi
# =====================================================================
# 汇总
# =====================================================================
TOTAL=$((PASS + FAIL + SKIP))
echo
echo "--------------------"
# 🔴 **尺子自证**:断言总条数(PASS+FAIL+SKIP)必须等于**契约**登记的条数。
# 少了 ⇒ 有人删了断言(尺子被改弱);多了 ⇒ 契约没同步。
# 自证本身**不计入** PASS/FAIL/SKIP(它是元断言,不是业务断言)。
if [ "${TOTAL}" -eq "${CE_EXP_ASSERTIONS}" ]; then
echo "✅ 尺子自证:本尺子跑了 ${TOTAL} 条断言 = 契约登记的 ${CE_EXP_ASSERTIONS} 条"
else
echo "❌ 尺子自证:本尺子跑了 ${TOTAL} 条断言,契约登记 ${CE_EXP_ASSERTIONS} 条 ⇒ 尺子被改弱了(少了/多了断言)"
FAIL=$((FAIL + 1))
fi
echo "PASS=${PASS} FAIL=${FAIL} SKIP=${SKIP} / 共 ${TOTAL} 条"
echo "面 B 覆盖 ${PASS}/${CE_EXP_ASSERTIONS}"
if [ "$FAIL" -eq 0 ] && [ "$SKIP" -eq 0 ]; then
echo "全绿 ✅(面 B 已达标)"
exit 0
fi
if [ "$FAIL" -eq 0 ]; then
echo "无失败,但面 B 尚未全覆盖 ⚠️(${SKIP} 条未落地)"
exit 1
fi
echo "有失败 ❌"
exit 1