/** * TC-CONTROL_API-002 · 条件不满足时不能办理控制策略下发 * REQ-058 [FL-6.9] 反向/状态迁移 P0 * * 前置:1. 通过已认证的调用方连接器调用「控制策略下发」接口可以正常打开 * 2. 已准备无权限账号或错误数据 * 步骤:1. 打开通过已认证的调用方连接器调用「控制策略下发」接口 * 2. 使用无权限账号或错误数据办理控制策略下发 * 3. 点击提交,查看提示和数据 * 预期:系统不允许办理控制策略下发,并说明原因。原有数据和状态不变。 * * 实现说明: * 控制策略下发(PolicyConflict/Check)的合法响应是 { pass, conflicts[] }。 * 「不能办理」的判定条件是 pass=false 且 conflicts 非空。 * 用例构造同一资源/执行点上既有 ALLOW 又有 DENY 的策略集合, * 验证后端能正确识别冲突并拒绝通过。 */ export const meta = { tc: 'TC-CONTROL_API-002', req: 'REQ-058', title: '条件不满足时不能办理控制策略下发', type: '反向/状态迁移', priority: 'P0', route: '', needs: ['be'] } export async function run(t) { await t.login() const productId = t.uid('E2E-POL-CONFLICT') await t.step('反向 1:同一资源同时 ALLOW 与 DENY → pass=false,conflicts 非空', async () => { const policy = JSON.stringify([ { policyCode: 'USE_COUNT_LIMIT', action: 'ALLOW', resource: 'table.user', enforcePoint: 'DELIVERY' }, { policyCode: 'USE_COUNT_LIMIT', action: 'DENY', resource: 'table.user', enforcePoint: 'DELIVERY' } ]) const r = await t.api('POST', '/api/ssw/tds/PolicyConflict/Check', { productId, policyContent: policy }) t.assert(r.code === 200, `接口返回成功但应判定为冲突(code=${r.code})`) const data = r.data ?? {} t.assert(data.pass === false, `判定为冲突 pass=false(实际 ${data.pass})`) t.assert(Array.isArray(data.conflicts) && data.conflicts.length > 0, `conflicts 非空(${JSON.stringify(data.conflicts)})`) t.assert(data.conflicts.some((c) => /ALLOW|DENY|资源|执行点/.test(c)), `冲突说明描述具体冲突维度(首条:${data.conflicts[0]})`) }) await t.step('反向 2:同一执行点同时 ALLOW 与 DENY → pass=false', async () => { const policy = JSON.stringify([ { policyCode: 'TIME_WINDOW', action: 'ALLOW', resource: 'table.a', enforcePoint: 'EXPORT' }, { policyCode: 'IP_WHITELIST', action: 'DENY', resource: 'table.b', enforcePoint: 'EXPORT' } ]) 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 === false, `执行点冲突 pass=false(实际 ${r.data?.pass})`) t.assert(r.data?.conflicts?.length > 0, `conflicts 非空(${JSON.stringify(r.data?.conflicts)})`) }) await t.step('反向 3:策略 JSON 格式异常 → 不抛异常,pass=false 并说明无法解析', async () => { const r = await t.api('POST', '/api/ssw/tds/PolicyConflict/Check', { productId, policyContent: 'this-is-not-json' }) t.assert(r.code === 200, `接口返回成功(code=${r.code})`) t.assert(r.data?.pass === false, `解析失败 pass=false(实际 ${r.data?.pass})`) t.assert((r.data?.conflicts || []).some((c) => /解析|无法|format/i.test(c)), `冲突说明指出解析失败(首条:${r.data?.conflicts?.[0]})`) }) await t.step('核对原有数据未被脏写:再次以正确策略检测仍可通过', async () => { const policy = JSON.stringify([ { policyCode: 'TIME_WINDOW', action: 'ALLOW', resource: 'table.user', enforcePoint: 'DELIVERY' } ]) const r = await t.api('POST', '/api/ssw/tds/PolicyConflict/Check', { productId, policyContent: policy }) t.assert(r.code === 200 && r.data?.pass === true, `合法策略重新检测 pass=true(实际 ${r.data?.pass})`) }) }