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

88 lines
4.1 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-001 · 正常办理控制策略下发
* REQ-058 [FL-6.9] 正向/场景法 P0
*
* 前置:1. 已绑定连接器的机构用户或已认证连接器
* 2. 通过已认证的调用方连接器调用「控制策略下发」接口可以正常打开
* 3. 已准备好测试数据
* 步骤:1. 打开通过已认证的调用方连接器调用「控制策略下发」接口
* 2. 按页面提示填写或选择正确的数据
* 3. 点击提交,查看办理结果
* 预期:控制策略下发办理成功,系统按要求完成处理,状态和记录正确。
*
* 实现说明:
* 控制策略下发的对外可见端点是 POST /api/ssw/tds/PolicyConflict/Check,
* 该接口会执行静态策略互斥检测(同资源/执行点 ALLOW 与 DENY 冲突),
* 并把检测结果写入 tds_policy_conflict_log。
* 「无冲突」即下发成功的判定条件:返回 pass=true,且冲突明细为空。
*/
export const meta = {
tc: 'TC-CONTROL_API-001',
req: 'REQ-058',
title: '正常办理控制策略下发',
type: '正向/场景法',
priority: 'P0',
route: '',
needs: ['be']
}
export async function run(t) {
await t.login()
const productId = t.uid('E2E-POL-PROD')
await t.step('前置:登录并取一个已存在的空间作为 spaceId', async () => {
const spaces = await t.apiList('/api/ssw/tds/Space', { pageSize: 5 })
if (!spaces.length) t.skip('库中没有任何可信数据空间,无法构造 spaceId')
t.assert(true, `取到空间 ${spaces.length} 个,使用 spaceId=${spaces[0].id}`)
})
await t.step('正向场景:仅含 ALLOW 的策略组合 → 检测通过 pass=true', async () => {
const policy = JSON.stringify([
{ policyCode: 'USE_COUNT_LIMIT', action: 'ALLOW', resource: 'table.user', enforcePoint: 'DELIVERY' },
{ 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, `控制策略下发接口返回成功(code=${r.code} msg=${r.msg})`)
const data = r.data ?? {}
t.assert(data.pass === true, `pass=true 视为下发成功(实际 ${data.pass})`)
t.assert(Array.isArray(data.conflicts) && data.conflicts.length === 0, `conflicts 为空数组(实际 ${JSON.stringify(data.conflicts)})`)
t.assert(data.contractId === undefined || data.contractId === null, `未关联合约时 contractId 为空(${data.contractId})`)
})
await t.step('正向场景:传 contractId 关联已有合约,policyContent 仍无冲突 → 通过', async () => {
const spaces = await t.apiList('/api/ssw/tds/Space', { pageSize: 5 })
const spaceId = spaces[0].id
const conns = await t.apiList('/api/ssw/tds/Connector', { pageSize: 50 })
const prods = await t.apiList('/api/ssw/tds/DataProduct', { pageSize: 50 })
const inSpace = (c) => prods.some((p) => p.spaceId === c.spaceId)
const usable = conns.filter(inSpace)
if (usable.length < 2) t.skip('同一空间下连接器不足 2 个,跳过合约关联场景')
const product = prods.find((p) => p.spaceId === usable[0].spaceId)
const code = t.uid('E2E-POL-CT')
const create = await t.api('POST', '/api/ssw/tds/Contract', {
contractCode: code,
name: `策略冲突检测-${t.runId}`,
spaceId: usable[0].spaceId,
productId: product.id,
providerConnectorId: usable[0].id,
consumerConnectorId: usable[1].id,
purpose: '联合建模',
policyContent: JSON.stringify([
{ policyCode: 'TIME_WINDOW', action: 'ALLOW', resource: 'table.user', enforcePoint: 'DELIVERY' }
])
})
t.assert(create.code === 200, `构造合约成功(id=${create.data})`)
const r = await t.api('POST', '/api/ssw/tds/PolicyConflict/Check', {
contractId: create.data,
spaceId
})
t.assert(r.code === 200, `关联合约场景返回成功`)
t.assert(r.data?.pass === true, `pass=true(实际 ${r.data?.pass})`)
t.assert(r.data?.contractId === create.data, `contractId 回填一致(${r.data?.contractId})`)
})
}