|
@@ -0,0 +1,93 @@
|
|
|
|
|
+/**
|
|
|
|
|
+ * ================================================================
|
|
|
|
|
+ * 匿名访问鉴权门禁 · 供应链库存端点守卫(本轮新增)· TC-AU-U81 ~ TC-AU-U101
|
|
|
|
|
+ * ================================================================
|
|
|
|
|
+ * 契约溯源:docs/superpowers/api/API_REFERENCE.md
|
|
|
|
|
+ * §4.62.2 库存管理(AdminInventoryController /api/admin/inventory,15 端点)
|
|
|
|
|
+ * §4.62.2 库存管理(SupplierProductController /api/admin/supplier/product,6 端点)
|
|
|
|
|
+ * 共 21 个 @PostMapping,逐条与源码 Mapping 核对一致;JwtInterceptor
|
|
|
|
|
+ * LOGIN_REQUIRED_PATHS 含 "/api/admin/" 整族,匿名(无 token)必须由拦截器拒绝。
|
|
|
|
|
+ *
|
|
|
|
|
+ * 覆盖盘点(B 类 20 分档):
|
|
|
|
|
+ * - tests/** 下 *.spec.js 对 /api/admin/inventory 与 /api/admin/supplier/product
|
|
|
|
|
+ * 鉴权守卫 0 命中(源码控制器存在,E2E 无守卫);
|
|
|
|
|
+ * - TC-AU-U01~U12(12 匿名点位)、U13~U15(已登记私有端点)、U16~U19(SC-A-04 字典)、
|
|
|
|
|
+ * U20~U31(food-rule)、U32~U42(file-record/supply-team)、U43~U58(org)、
|
|
|
|
|
+ * U59~U65(配置中心)、U66~U80(coupon/log/audit)与本文件 21 端点不重叠;
|
|
|
|
|
+ * - 本文件只补权限流/异常流,不重复造正常流业务断言。
|
|
|
|
|
+ *
|
|
|
|
|
+ * 契约取证(忽略型探针,无凭据空体 {},本轮实测 21/21 逐位一致):
|
|
|
|
|
+ * HTTP 401 / {"code":401,"message":"请先登录","data":null}
|
|
|
|
|
+ * 探针只发空体,不写业务数据、不触碰 create/confirm/delete/shelve 真实写入
|
|
|
|
|
+ * (匿名即被拦截,未穿透);未发现新增越权面、未发现匿名私有接口可达。
|
|
|
|
|
+ * 断言据此写,不臆造非 200。
|
|
|
|
|
+ *
|
|
|
|
|
+ * 三流口径:
|
|
|
|
|
+ * - 权限流:JWT 缺失必须被 JwtInterceptor 拒绝,不得放行到控制器/业务层(21 例);
|
|
|
|
|
+ * - 异常流:匿名空体不得返回业务成功码或任何业务数据(同 21 例内联合断言);
|
|
|
|
|
+ * - 正常流:admin/供应商角色库存 CRUD、入库确认、盘点、上/下架需真实 JWT 与有效业务体,
|
|
|
|
|
+ * 本档未注入凭据、禁臆造断言,交有凭据档承接。
|
|
|
|
|
+ *
|
|
|
|
|
+ * 运行:cd tests && npx playwright test -c playwright.config.api.js --project=desktop \
|
|
|
|
|
+ * e2e/api/auth-guard-admin-inventory-supplier-product.spec.js
|
|
|
|
|
+ * ================================================================
|
|
|
|
|
+ */
|
|
|
|
|
+const { test, expect } = require('@playwright/test');
|
|
|
|
|
+
|
|
|
|
|
+const API = process.env.LIVE_API_BASE || 'http://cfc.iwintrue.com';
|
|
|
|
|
+
|
|
|
|
|
+// [用例编号, 完整路径, API_REFERENCE §4.62.2 接口说明]
|
|
|
|
|
+const ENDPOINTS = [
|
|
|
|
|
+ ['TC-AU-U81', '/api/admin/inventory/inbound/create', '§4.62.2 入库单创建(写入口)'],
|
|
|
|
|
+ ['TC-AU-U82', '/api/admin/inventory/inbound/list', '§4.62.2 入库单列表(只读)'],
|
|
|
|
|
+ ['TC-AU-U83', '/api/admin/inventory/inbound/detail', '§4.62.2 入库单详情(只读)'],
|
|
|
|
|
+ ['TC-AU-U84', '/api/admin/inventory/inbound/confirm', '§4.62.2 入库确认(写入口)'],
|
|
|
|
|
+ ['TC-AU-U85', '/api/admin/inventory/inbound/cancel', '§4.62.2 入库取消(写入口)'],
|
|
|
|
|
+ ['TC-AU-U86', '/api/admin/inventory/outbound/create', '§4.62.2 出库单创建(写入口)'],
|
|
|
|
|
+ ['TC-AU-U87', '/api/admin/inventory/outbound/list', '§4.62.2 出库单列表(只读)'],
|
|
|
|
|
+ ['TC-AU-U88', '/api/admin/inventory/transactions/list', '§4.62.2 库存流水列表(只读)'],
|
|
|
|
|
+ ['TC-AU-U89', '/api/admin/inventory/counting/create', '§4.62.2 盘点单创建(写入口)'],
|
|
|
|
|
+ ['TC-AU-U90', '/api/admin/inventory/counting/confirm', '§4.62.2 盘点确认(写入口)'],
|
|
|
|
|
+ ['TC-AU-U91', '/api/admin/inventory/counting/list', '§4.62.2 盘点单列表(只读)'],
|
|
|
|
|
+ ['TC-AU-U92', '/api/admin/inventory/alert/list', '§4.62.2 库存告警列表(只读)'],
|
|
|
|
|
+ ['TC-AU-U93', '/api/admin/inventory/product/stock', '§4.62.2 商品库存查询(只读)'],
|
|
|
|
|
+ ['TC-AU-U94', '/api/admin/inventory/combo/items', '§4.62.2 组合商品项(只读)'],
|
|
|
|
|
+ ['TC-AU-U95', '/api/admin/inventory/combo/items/list', '§4.62.2 组合商品项列表(只读)'],
|
|
|
|
|
+ ['TC-AU-U96', '/api/admin/supplier/product/list', '§4.62.2 服务商商品列表(只读)'],
|
|
|
|
|
+ ['TC-AU-U97', '/api/admin/supplier/product/create', '§4.62.2 服务商商品创建(写入口)'],
|
|
|
|
|
+ ['TC-AU-U98', '/api/admin/supplier/product/update', '§4.62.2 服务商商品更新(写入口)'],
|
|
|
|
|
+ ['TC-AU-U99', '/api/admin/supplier/product/detail', '§4.62.2 服务商商品详情(只读)'],
|
|
|
|
|
+ ['TC-AU-U100', '/api/admin/supplier/product/delete', '§4.62.2 服务商商品删除(写入口)'],
|
|
|
|
|
+ ['TC-AU-U101', '/api/admin/supplier/product/shelve', '§4.62.2 服务商商品上/下架(写入口)'],
|
|
|
|
|
+];
|
|
|
|
|
+
|
|
|
|
|
+test.describe('匿名访问鉴权门禁 · 供应链库存二十一端点(§4.62.2 权限/异常流)', () => {
|
|
|
|
|
+ for (const [tc, path, desc] of ENDPOINTS) {
|
|
|
|
|
+ test(`${tc} [权限流+异常流] POST ${path} 匿名空体应被拒且无业务数据 · ${desc}`, async ({ request }) => {
|
|
|
|
|
+ const resp = await request.post(`${API}${path}`, {
|
|
|
|
|
+ data: {},
|
|
|
|
|
+ timeout: 20000,
|
|
|
|
|
+ failOnStatusCode: false,
|
|
|
|
|
+ });
|
|
|
|
|
+ const status = resp.status();
|
|
|
|
|
+ let body = {};
|
|
|
|
|
+ try { body = await resp.json(); } catch (e) { body = {}; }
|
|
|
|
|
+ console.log(`[${tc}] POST ${path} -> HTTP ${status} code=${body.code}`);
|
|
|
|
|
+
|
|
|
|
|
+ // 权限流:JWT 缺失必须由拦截器拒绝,不得放行到控制器/业务层
|
|
|
|
|
+ expect(
|
|
|
|
|
+ [401, 403],
|
|
|
|
|
+ `${tc} ${path} 匿名返回 HTTP ${status},期望 401/403(200 直通=库存/商品数据失守)`
|
|
|
|
|
+ ).toContain(status);
|
|
|
|
|
+ expect(
|
|
|
|
|
+ [401, 403],
|
|
|
|
|
+ `${tc} ${path} 匿名业务码 ${body.code},期望 401/403`
|
|
|
|
|
+ ).toContain(body.code);
|
|
|
|
|
+ expect(String(body.message || '')).toContain('登录');
|
|
|
|
|
+
|
|
|
|
|
+ // 异常流:空体探测不得返回业务成功码或任何业务数据
|
|
|
|
|
+ expect(body.code === 200, `${tc} 匿名空体不应得到业务成功码 200`).toBe(false);
|
|
|
|
|
+ expect(body.data == null, `${tc} 匿名空体不应返回业务数据(HTTP ${status} code=${body.code})`).toBe(true);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+});
|