2026-08-10 12:22:29 +08:00
|
|
|
const MODULE = 'phase3-warehouse-rbac'
|
|
|
|
|
const OPTIONS = { scenario: 'warehouse-role-boundary', deploymentBlocker: true }
|
|
|
|
|
|
|
|
|
|
function id(value) { return value == null ? '' : String(value) }
|
|
|
|
|
|
|
|
|
|
export async function run(context) {
|
|
|
|
|
const permissionsResponse = await context.request('GET', '/api/platform/v1/iam/permissions')
|
|
|
|
|
const permissions = context.apiSuccess(MODULE, '查询平台权限资源', permissionsResponse, '', OPTIONS)
|
|
|
|
|
const permissionById = new Map((Array.isArray(permissions) ? permissions : [])
|
|
|
|
|
.map((item) => [id(item.id), item.permissionCode]))
|
|
|
|
|
|
|
|
|
|
const controllerCodes = ['platform:firstleg:pda:view', 'platform:firstleg:pda:assign',
|
|
|
|
|
'platform:firstleg:pda:work', 'platform:firstleg:pda:review',
|
|
|
|
|
'platform:firstleg:inbound:loading:view', 'platform:firstleg:inbound:loading:edit',
|
|
|
|
|
'platform:firstleg:inbound:loading:complete']
|
|
|
|
|
const controllerPermissions = (Array.isArray(permissions) ? permissions : [])
|
|
|
|
|
.filter((item) => controllerCodes.includes(item.permissionCode))
|
|
|
|
|
context.assert(MODULE, 'PDA和装柜证据Controller权限资源完整', permissionsResponse,
|
|
|
|
|
controllerPermissions.length === controllerCodes.length
|
|
|
|
|
&& controllerPermissions.every((item) => item.builtIn === true && item.status === 'ACTIVE'),
|
|
|
|
|
`matched=${controllerPermissions.length}/${controllerCodes.length}`, OPTIONS)
|
|
|
|
|
|
|
|
|
|
const rolesResponse = await context.request('GET', '/api/platform/v1/iam/roles')
|
|
|
|
|
const roles = context.apiSuccess(MODULE, '查询三期仓库内置角色', rolesResponse, '', OPTIONS)
|
|
|
|
|
const warehouseRoles = new Map((Array.isArray(roles) ? roles : [])
|
|
|
|
|
.filter((item) => ['WAREHOUSE_OPERATOR', 'WAREHOUSE_PICKER', 'WAREHOUSE_TALLY'].includes(item.roleCode))
|
|
|
|
|
.map((item) => [item.roleCode, item]))
|
|
|
|
|
context.assert(MODULE, '操作员、拣货员、理货员三个系统角色已启用', rolesResponse,
|
|
|
|
|
warehouseRoles.size === 3 && [...warehouseRoles.values()]
|
|
|
|
|
.every((role) => role.roleType === 'SYSTEM' && role.status === 'ACTIVE'),
|
|
|
|
|
`roles=${[...warehouseRoles.keys()].join(',')}`, OPTIONS)
|
|
|
|
|
|
|
|
|
|
const roleCodes = (roleCode) => new Set((warehouseRoles.get(roleCode)?.permissionIds || [])
|
|
|
|
|
.map((permissionId) => permissionById.get(id(permissionId))).filter(Boolean))
|
|
|
|
|
const pickerCodes = roleCodes('WAREHOUSE_PICKER')
|
2026-08-24 21:00:22 +08:00
|
|
|
context.assert(MODULE, '拣货员只具备国内PDA查询作业与海外PDA入仓操作权限', rolesResponse,
|
|
|
|
|
pickerCodes.size === 3
|
2026-08-10 12:22:29 +08:00
|
|
|
&& pickerCodes.has('platform:firstleg:pda:view')
|
2026-08-24 21:00:22 +08:00
|
|
|
&& pickerCodes.has('platform:firstleg:pda:work')
|
|
|
|
|
&& pickerCodes.has('lastleg:pda:operate'),
|
2026-08-10 12:22:29 +08:00
|
|
|
`permissions=${[...pickerCodes].sort().join(',')}`, OPTIONS)
|
|
|
|
|
|
|
|
|
|
const operatorCodes = roleCodes('WAREHOUSE_OPERATOR')
|
|
|
|
|
context.assert(MODULE, '操作员仅具备入仓查看和后台证据维护权限', rolesResponse,
|
|
|
|
|
operatorCodes.has('platform:firstleg:inbound:loading:view')
|
|
|
|
|
&& operatorCodes.has('platform:firstleg:inbound:loading:edit')
|
|
|
|
|
&& operatorCodes.size === 5
|
|
|
|
|
&& !operatorCodes.has('platform:firstleg:inbound:loading:complete')
|
|
|
|
|
&& !operatorCodes.has('platform:firstleg:pda:assign')
|
|
|
|
|
&& !operatorCodes.has('platform:firstleg:outbound-dispatch:confirm')
|
|
|
|
|
&& !operatorCodes.has('platform:firstleg:outbound-dispatch:reverse'),
|
|
|
|
|
`permissionCount=${operatorCodes.size}`, OPTIONS)
|
|
|
|
|
|
|
|
|
|
const tallyCodes = roleCodes('WAREHOUSE_TALLY')
|
|
|
|
|
context.assert(MODULE, '理货员可后台维护证据和复核但不能完成装柜', rolesResponse,
|
|
|
|
|
tallyCodes.has('platform:firstleg:inbound:loading:view')
|
|
|
|
|
&& tallyCodes.has('platform:firstleg:inbound:loading:edit')
|
|
|
|
|
&& tallyCodes.has('platform:firstleg:pda:review')
|
|
|
|
|
&& !tallyCodes.has('platform:firstleg:inbound:loading:complete')
|
|
|
|
|
&& !tallyCodes.has('platform:firstleg:outbound-dispatch:confirm'),
|
|
|
|
|
`permissionCount=${tallyCodes.size}`, OPTIONS)
|
|
|
|
|
|
|
|
|
|
context.assert(MODULE, '仓库系统角色不包含任何客户侧权限', rolesResponse,
|
2026-08-24 21:46:19 +08:00
|
|
|
[...operatorCodes, ...pickerCodes, ...tallyCodes]
|
|
|
|
|
.every((code) => code.startsWith('platform:') || code === 'lastleg:pda:operate'),
|
|
|
|
|
'warehouse roles may use platform:* plus the single overseas service authority lastleg:pda:operate', OPTIONS)
|
2026-08-10 12:22:29 +08:00
|
|
|
|
|
|
|
|
const unauthorized = await context.request('GET',
|
2026-08-14 16:06:27 +08:00
|
|
|
'/api/platform/v1/first-leg/pda-loading/tasks?cabinetNo=UNAUTHORIZED&warehouseId=1', undefined, '')
|
2026-08-10 12:22:29 +08:00
|
|
|
context.addStep(MODULE, '未登录访问仓库PDA任务被拒绝', unauthorized,
|
|
|
|
|
[401, 403].includes(unauthorized.http)
|
|
|
|
|
|| (unauthorized.http === 200 && ['A0401', 'A0403', '401', '403'].includes(String(unauthorized.body?.code))),
|
|
|
|
|
`HTTP=${unauthorized.http}, code=${unauthorized.body?.code ?? 'missing'}`, OPTIONS)
|
|
|
|
|
}
|