Files
ssw-mvp/docs/e2e/cases/TC-DELIVERY_API-002.mjs
T
admin 3247e9fd15 init: ssw-mvp initial commit
- boot/ (Java/Maven, JNPF 7.0) — 移除旧的 boot/.git,源码直接纳入仓库
- web/ (Vue 3 + Vite + Ant Design Vue, pnpm)
- docs/, scard/, nax/
- refs/INDEX.md + refs/国标/(其余 refs/* 开源子仓库不纳入)
- 已忽略: connector_data/, jweb/, log/, web/{dist,node_modules,.pnpm}, boot/*/target/, .DS_Store, .idea, .vscode
2026-08-05 18:29:12 +08:00

109 lines
5.2 KiB
JavaScript
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.
/**
* TC-DELIVERY_API-002 · 条件不满足时不能办理数据传输
* REQ-066 数据传输 / FL 12.2 反向/状态迁移 P0
*
* 前置:1. 通过已认证的调用方连接器调用"数据传输"接口可以正常打开
* 2. 已准备无权限账号或错误数据
* 步骤:1. 打开通过已认证的调用方连接器调用"数据传输"接口
* 2. 使用无权限账号或错误数据办理数据传输
* 3. 点击提交,查看提示和数据
* 预期:系统不允许办理数据传输,并说明原因。原有数据和状态不变。
*/
export const meta = {
tc: 'TC-DELIVERY_API-002',
req: 'REQ-066',
title: '条件不满足时不能办理数据传输',
type: '反向/状态迁移',
priority: 'P0',
route: '',
needs: ['be']
}
export async function run(t) {
let baselineLogs = 0
let baselineCall = 0
await t.step('前置:登录', async () => {
await t.login()
})
await t.step('前置:记录基线消费日志条数 / callCount', async () => {
const logs = await t.api('GET', '/api/ssw/tdc/ApiConsumeLog?currentPage=1&pageSize=1')
baselineLogs = logs.data?.pagination?.total ?? 0
t.assert(true, `基线消费日志数 ${baselineLogs}`)
})
await t.step('反向 1:缺 X-App-Id 被拒(TC_DEL_003)', async () => {
const r = await t.api('POST', '/api/ssw/tdc/Gateway/Invoke', { appKey: 'k', xOrderCode: 'o' })
t.assert(r.code !== 200, `缺 X-App-Id 被拒(${r.code})`)
t.assert(/X-App-Id|缺少/i.test(r.msg || ''), `提示说明缺 X-App-Id(实际「${r.msg}」)`)
})
await t.step('反向 2:缺 X-App-Key 被拒', async () => {
const r = await t.api('POST', '/api/ssw/tdc/Gateway/Invoke', { appId: 'a', xOrderCode: 'o' })
t.assert(r.code !== 200, `缺 X-App-Key 被拒(${r.code})`)
t.assert(/X-App-Key|缺少/i.test(r.msg || ''), `提示说明缺 X-App-Key`)
})
await t.step('反向 3:缺 X-Order-Code 被拒', async () => {
const r = await t.api('POST', '/api/ssw/tdc/Gateway/Invoke', { appId: 'a', appKey: 'k' })
t.assert(r.code !== 200, `缺 X-Order-Code 被拒(${r.code})`)
t.assert(/X-Order-Code|缺少/i.test(r.msg || ''), `提示说明缺 X-Order-Code`)
})
await t.step('反向 4:X-Order-Code 无效被拒', async () => {
const r = await t.api('POST', '/api/ssw/tdc/Gateway/Invoke', {
appId: 'app_x',
appKey: 'k',
xOrderCode: 'INVALID_xxx_yyy_zzz'
})
t.assert(r.code !== 200, `无效 xOrderCode 被拒(${r.code} msg=${r.msg})`)
t.assert(/X-Order-Code|无效/i.test(r.msg || ''), `提示说明原因`)
})
await t.step('反向 5:appId 与任务 ID 不匹配被拒', async () => {
const r = await fetch('http://localhost:30000/api/ssw/tdc/DeliveryTask?currentPage=1&pageSize=1&deliveryType=API', {
headers: { Authorization: t.token, 'App-Code': 'sswflow', 'Jnpf-Origin': 'pc', 'Vue-Version': '3' }
})
const j = await r.json()
const target = (j.data?.list || []).find((x) => x.taskCode)
if (!target) t.skip('库中没有 API 任务,跳过 appId 校验')
const wrongAppId = 'app_WRONG_' + target.id.substring(0, 4)
const r2 = await t.api('POST', '/api/ssw/tdc/Gateway/Invoke', {
appId: wrongAppId, appKey: 'k', xOrderCode: target.taskCode
})
t.assert(r2.code !== 200, `appId 不匹配被拒(${r2.code} msg=${r2.msg})`)
t.assert(/AppId|不匹配|认证/i.test(r2.msg || ''), `提示说明原因`)
})
await t.step('反向 6:超过使用次数限制被拒(TC_DEL_004)', async () => {
// 找一条带 useTimesLimit 且已到上限的任务
const r = await fetch('http://localhost:30000/api/ssw/tdc/DeliveryTask?currentPage=1&pageSize=50&deliveryType=API', {
headers: { Authorization: t.token, 'App-Code': 'sswflow', 'Jnpf-Origin': 'pc', 'Vue-Version': '3' }
})
const j = await r.json()
const exhausted = (j.data?.list || []).find(
(x) => typeof x.useTimesLimit === 'number' && x.useTimesLimit >= 0 && (x.callCount ?? 0) >= x.useTimesLimit
)
if (!exhausted) {
t.assert(true, '库中没有 useTimesLimit 已到上限的任务,跳过次数上限断言')
} else {
const expectAppId = 'app_' + exhausted.id.substring(0, Math.min(8, exhausted.id.length))
const r2 = await t.api('POST', '/api/ssw/tdc/Gateway/Invoke', {
appId: expectAppId, appKey: 'k', xOrderCode: exhausted.taskCode
})
t.assert(r2.code !== 200, `达上限被拒(${r2.code} msg=${r2.msg})`)
t.assert(/次数|限制|拒绝/i.test(r2.msg || ''), `提示说明次数限制(实际「${r2.msg}」)`)
}
})
await t.step('核对:基线消费日志条数变化只来自「认证失败/策略拒绝」的 DENY 留痕', async () => {
const r = await t.api('GET', '/api/ssw/tdc/ApiConsumeLog?currentPage=1&pageSize=1')
const after = r.data?.pagination?.total ?? 0
t.assert(after >= baselineLogs, `日志条数不减(${baselineLogs} → ${after})`)
// 抽几条最近的 DENY 看是否有本次请求的痕迹
const recent = await t.api('GET', '/api/ssw/tdc/ApiConsumeLog?currentPage=1&pageSize=20&status=DENY')
const list = recent.data?.list || []
t.assert(list.length > 0, `DENY 留痕非空(${list.length})`)
})
}