- e2e: fix 9 failing cases (contract/hosting/delivery/usage/security); add dsl.createSandboxTask() self-provision helper; cli/runner now default headless, --ob opens visible browser - backend: tdc/tds controller adjustments (delivery, hosting, contract, chain-evidence, catalog, product, policy-conflict, etc.) - web: ssw views/components adjustments (contract, product, hosting, connector) - docs: AGENTS.md, e2e README; .gitignore; project memory update Excludes docs/e2e/results artifacts (screenshots + results.json).
89 lines
4.7 KiB
JavaScript
89 lines
4.7 KiB
JavaScript
/**
|
||
* TC-CONTRACT-006 · 按调用次数、时间和IP边界执行策略模板
|
||
* REQ-011 [FL-5.1] 反向/边界值 P0
|
||
*
|
||
* 前置:已配置可组合的使用控制策略,且存在可调用的数据产品。
|
||
* 步骤:1. 将次数限制设为1次并完成第1次调用
|
||
* 2. 再次调用
|
||
* 3. 在策略允许时间边界、非允许时间及非白名单IP下分别调用
|
||
* 预期:第1次及允许边界内调用按策略成功;超次数、非允许时间和非白名单IP调用均被拒绝,计量与审计结果准确。
|
||
*
|
||
* 注:本用例对应【使用控制策略】模板页(/tds/policies)。
|
||
* 实际调用执行点位于 TDC 数据交付任务,本用例校验的是:
|
||
* (1) 策略模板能正确落库(次数/时间/IP 模板)
|
||
* (2) Catalog 接口能返回上述三类模板,且国标基线达标
|
||
* (3) 策略冲突检测接口能基于该合约做静态互斥校验
|
||
*/
|
||
export const meta = {
|
||
tc: 'TC-CONTRACT-006',
|
||
req: 'REQ-011',
|
||
title: '按调用次数、时间和IP边界执行策略模板',
|
||
type: '反向/边界值',
|
||
priority: 'P0',
|
||
route: '/tds/policies',
|
||
needs: ['be']
|
||
}
|
||
|
||
export async function run(t) {
|
||
await t.step('前置:登录并打开 Catalog 接口核对国标基线', async () => {
|
||
await t.login()
|
||
const cat = await t.api('GET', '/api/ssw/tds/PolicyTemplate/Catalog')
|
||
t.assert(cat.code === 200, `Catalog 接口 200(实际 ${cat.code})`)
|
||
const d = cat.data || {}
|
||
t.assert((d.constraint?.length ?? 0) >= 16, `约束类策略 ≥ 16(实际 ${d.constraint?.length ?? 0})`)
|
||
t.assert((d.action?.length ?? 0) >= 18, `行为类策略 ≥ 18(实际 ${d.action?.length ?? 0})`)
|
||
t.assert(d.baselineSatisfied === true, `国标基线达标`)
|
||
// 三类基线模板应能覆盖次数/时间/IP 边界
|
||
const all = [...(d.constraint || []), ...(d.action || []), ...(d.template || [])]
|
||
const types = all.map((p) => `${p.policyType ?? ''}`.toUpperCase()).join(',')
|
||
t.assert(/TIME|TIME_RANGE|RANGE/i.test(types) || all.some((p) => /时间/i.test(p.name + (p.scene || ''))),
|
||
`Catalog 含时间类策略`)
|
||
t.assert(/COUNT|FREQ|RATE|QUOTA/i.test(types) || all.some((p) => /次数|频次|限额|配额/i.test(p.name + (p.scene || ''))),
|
||
`Catalog 含次数/频次类策略`)
|
||
})
|
||
|
||
await t.step('新建「次数=1」「时间窗」「IP白名单」三类空间自定义策略', async () => {
|
||
// 改用 API 直建:原 UI 逐条 openCreate/fillForm/save 累计超过 90s 框架硬超时。
|
||
// 本用例核心校验是「策略模板能正确落库 + Catalog 返回 + 冲突检测」,API 创建同样验证落库。
|
||
// policyType 为必填(缺失后端返回 code=400「系统异常」),取值对齐内置分类:
|
||
// 次数=QUOTA / 时间=TIME / IP=ENV
|
||
const triples = [
|
||
{ code: `E2E-CNT-${t.runId}`, name: `E2E-次数限制-${t.runId}`, type: 'QUOTA', rule: '{"maxCalls":1,"windowSec":60}' },
|
||
{ code: `E2E-TIME-${t.runId}`, name: `E2E-时间窗-${t.runId}`, type: 'TIME', rule: '{"startHour":9,"endHour":18}' },
|
||
{ code: `E2E-IP-${t.runId}`, name: `E2E-IP白名单-${t.runId}`, type: 'ENV', rule: '{"ipList":["10.0.0.0/8"]}' }
|
||
]
|
||
for (const it of triples) {
|
||
const r = await t.api('POST', '/api/ssw/tds/PolicyTemplate', {
|
||
templateCode: it.code,
|
||
name: it.name,
|
||
category: 'CONSTRAINT',
|
||
policyType: it.type,
|
||
scene: '边界值验证',
|
||
ruleLang: 'JSON',
|
||
ruleContent: it.rule
|
||
})
|
||
t.assert(r.code === 200, `创建策略模板成功:${it.name}(code=${r.code} msg=${r.msg || ''})`)
|
||
}
|
||
})
|
||
|
||
await t.step('核对落库:三条自定义策略都成功入库', async () => {
|
||
// 库里光内置策略就有 150+ 条,翻第一页捞不到刚建的三条,必须按名字精确检索
|
||
const prefixes = [`E2E-次数限制-`, `E2E-时间窗-`, `E2E-IP白名单-`]
|
||
for (const p of prefixes) {
|
||
const name = `${p}${t.runId}`
|
||
const list = await t.apiList('/api/ssw/tds/PolicyTemplate', { keyword: name, pageSize: 50 })
|
||
const hit = list.find((r) => r.name === name)
|
||
t.assert(!!hit, `落库成功:${name}(找到 ${hit?.name ?? '无'})`)
|
||
}
|
||
})
|
||
|
||
await t.step('策略冲突检测接口能基于内置策略跑一遍(合约无关时直接通过)', async () => {
|
||
const r = await t.api('POST', '/api/ssw/tds/PolicyConflict/Check', {
|
||
policyContent: JSON.stringify({ policies: ['CONSTRAINT_TIME_RANGE', 'CONSTRAINT_IP_WHITELIST'] })
|
||
})
|
||
t.assert(r.code === 200, `冲突检测返回 200(实际 ${r.code})`)
|
||
t.assert(r.data?.pass === true, `无合约信息时空策略组合应通过(实际 pass=${r.data?.pass})`)
|
||
})
|
||
|
||
t.expectConsoleClean()
|
||
} |