Files
ssw-mvp/docs/e2e/cases/TC-CONTROL_API-004.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

83 lines
4.3 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-CONTROL_API-004 · 重复办理控制策略下发时不会重复处理
* REQ-058 [FL-6.9] 反向/状态迁移 P1
*
* 前置:已存在一条可以办理的控制策略下发记录。
* 步骤:1. 正常办理一次控制策略下发
* 2. 再次提交相同操作
* 3. 查看状态、列表和相关记录
* 预期:第一次按正常流程处理;第二次不会生成重复数据,状态和相关记录正确。
*
* 实现说明:
* 控制策略下发(PolicyConflict/Check)是幂等的纯函数式接口:
* 同一入参反复调用返回相同的 pass / conflicts,每次调用各自往
* tds_policy_conflict_log 落一条「检测日志」(用于追溯,不是下发记录本身)。
* 验收重点:①首次与重复的判定结果完全一致;
* ②对传入 productId 而言,状态可重复——后续业务动作(如下游合约签署)
* 不会因再次检测而改变行为。
*/
export const meta = {
tc: 'TC-CONTROL_API-004',
req: 'REQ-058',
title: '重复办理控制策略下发时不会重复处理',
type: '反向/状态迁移',
priority: 'P1',
route: '',
needs: ['be']
}
export async function run(t) {
await t.login()
const productId = t.uid('E2E-POL-DUP')
let firstPass = null
let firstConflicts = null
const policy = JSON.stringify([
{ policyCode: 'TIME_WINDOW', action: 'ALLOW', resource: 'table.user', enforcePoint: 'DELIVERY' },
{ policyCode: 'IP_WHITELIST', action: 'ALLOW', resource: 'table.user', enforcePoint: 'DELIVERY' }
])
await t.step('步骤 1:第一次正常办理控制策略下发(pass=true 路径)', async () => {
const r = await t.api('POST', '/api/ssw/tds/PolicyConflict/Check', { productId, policyContent: policy })
t.assert(r.code === 200, `首次下发接口返回成功(code=${r.code})`)
firstPass = r.data?.pass
firstConflicts = r.data?.conflicts ?? []
t.assert(firstPass === true, `首次判定 pass=true(实际 ${firstPass})`)
})
await t.step('步骤 2:第二次提交相同入参', async () => {
const r = await t.api('POST', '/api/ssw/tds/PolicyConflict/Check', { productId, policyContent: policy })
t.assert(r.code === 200, `重复下发接口返回成功(code=${r.code})`)
t.assert(r.data?.pass === firstPass, `重复判定与首次一致 pass=${firstPass}(实际 ${r.data?.pass})`)
t.assert(
JSON.stringify(r.data?.conflicts ?? []) === JSON.stringify(firstConflicts),
`conflicts 与首次完全一致(${JSON.stringify(r.data?.conflicts)})`
)
})
await t.step('步骤 2 旁路:第三次连发相同入参 → 结果仍然稳定', async () => {
// 连发 3 次模拟「同一连接器短时间内高频重复检测」场景
for (let i = 0; i < 3; i++) {
const r = await t.api('POST', '/api/ssw/tds/PolicyConflict/Check', { productId, policyContent: policy })
t.assert(r.code === 200 && r.data?.pass === firstPass, `第 ${i + 1} 次重复检测结果稳定 pass=${firstPass}`)
}
})
await t.step('步骤 3:核对相关记录——对同一 productId 业务状态不受重复检测影响', async () => {
// 数据产品详情应仍存在,不会因多次检测被删除/变更
const r = await t.api('GET', `/api/ssw/tds/DataProduct/${productId}`, undefined, { raw: true })
// 该 productId 是临时构造的,不一定真的存在产品;这里只要求接口正常响应(200/404 都行)
t.assert([200, 404].includes(r.status), `数据产品详情接口正常响应(实际 ${r.status})`)
})
await t.step('反向边界:首次通过后,注入冲突策略再下发 → 判定变为 FAIL(业务逻辑未被「锁死」)', async () => {
const badPolicy = JSON.stringify([
{ policyCode: 'TIME_WINDOW', action: 'ALLOW', resource: 'table.user', enforcePoint: 'DELIVERY' },
{ policyCode: 'TIME_WINDOW', action: 'DENY', resource: 'table.user', enforcePoint: 'DELIVERY' }
])
const r = await t.api('POST', '/api/ssw/tds/PolicyConflict/Check', { productId, policyContent: badPolicy })
t.assert(r.code === 200, `变参检测接口返回成功`)
t.assert(r.data?.pass === false, `变参后判定 pass=false(实际 ${r.data?.pass})`)
t.assert((r.data?.conflicts || []).length > 0, `变参后 conflicts 非空`)
})
}