You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

58 lines
2.8 KiB

# -*- coding: utf-8 -*-
"""Ticket 02 运行时冒烟:资源树 perms 三缺口加固(必填/全局唯一/编辑只读)。
五段式 A1/A2/A3/U/D,连接 verify profile 本地服务。perms 用 t02hp_ 前缀防撞远程库。
"""
import io
import sys
import requests
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
BASE = "http://localhost:8080"
PASS, FAIL = [], []
def check(name, ok, detail=""):
(PASS if ok else FAIL).append(name)
print(("PASS" if ok else "FAIL") + " | " + name + ((" | " + str(detail)) if detail else ""))
tr = requests.get(BASE + "/api/auth/debug/token", params={"userId": "739564171091247104"}, timeout=15).json()
assert tr.get("code") == 0, "debug token 失败: %s" % tr
H = {"Authorization": "Bearer " + tr["data"]}
# ── A1: 新增 catalog 无 perms -> 61009 ──
r = requests.post(BASE + "/api/resources/saveOrUpdate",
data={"name": "t02hp-目录-无perms", "type": "CATALOG"}, headers=H, timeout=10).json()
check("A1 新增catalog无perms拒绝", r.get("code") == 61009 and "perms" in str(r.get("message", "")), r)
# ── A2: 新增 catalog 带合法 perms -> 成功 ──
perms = "t02hp_catalog_perm"
r = requests.post(BASE + "/api/resources/saveOrUpdate",
data={"name": "t02hp-目录-带perms", "type": "CATALOG", "perms": perms}, headers=H, timeout=10).json()
saved = r.get("data") or {}
nid = saved.get("id")
check("A2 新增catalog带perms成功", r.get("code") == 0 and nid and saved.get("perms") == perms, r)
# ── A3: 新增另一节点 perms 重复(跨类型 menu 撞 catalog)-> 61009 ──
r = requests.post(BASE + "/api/resources/saveOrUpdate",
data={"name": "t02hp-菜单-撞perms", "type": "MENU", "route": "/t02hp-dup",
"perms": perms}, headers=H, timeout=10).json()
check("A3 新增跨类型撞perms拒绝", r.get("code") == 61009 and "已被其他资源使用" in str(r.get("message", "")), r)
# ── U: 编辑 A2 节点传不同 perms -> 保留原值 ──
r = requests.post(BASE + "/api/resources/saveOrUpdate",
data={"id": nid, "name": "t02hp-目录-改名字", "type": "CATALOG",
"perms": "t02hp_changed_perm"}, headers=H, timeout=10).json()
edited = r.get("data") or {}
check("U 编辑传不同perms保留原值", r.get("code") == 0 and edited.get("perms") == perms, r)
# ── D: 清理 A2 节点 -> 删除成功且 list 不再可见 ──
r = requests.post(BASE + "/api/resources/delete", params={"id": nid}, headers=H, timeout=10).json()
lst = requests.get(BASE + "/api/resources/list", headers=H, timeout=10).json()
gone = all(str(x.get("id")) != str(nid) for x in (lst.get("data") or []))
check("D 清理测试节点", r.get("code") == 0 and gone, r)
print("-" * 50)
print("TOTAL: %d pass, %d fail" % (len(PASS), len(FAIL)))
sys.exit(1 if FAIL else 0)