Compare commits

...
Author SHA1 Message Date
devops c46f0909f3 Fix orchestration actor role normalization at HTTP boundary 2026-10-24 04:01:18 +00:00
2 changed files with 41 additions and 2 deletions

No files matched your search

@@ -97,13 +97,20 @@ export class OrchestrationController {
) {}
private actor(req: any): WorkflowIdentity {
const id = req?.user?.id ?? req?.user?.sub;
// Match RolesGuard aliases without promoting an admin to a reviewer.
const normalized = typeof req?.user?.role === 'string'
? req.user.role.toLowerCase().replace(/[_-]/g, '')
: '';
const role = normalized === 'admin' ? 'Admin'
: ['superadmin', 'adminsuper'].includes(normalized) ? 'SUPER_ADMIN'
: undefined;
if (
typeof id !== 'string' ||
!id ||
!['Admin', 'SUPER_ADMIN'].includes(req?.user?.role)
!role
)
throw new ForbiddenException('Authenticated workflow identity required');
return { id, role: req.user.role };
return { id, role };
}
private safe(row: any, req: any) {
const view = project(row);
@@ -68,6 +68,38 @@ describe('bounded workflow HTTP contracts', () => {
afterAll(async () => {
await app.close();
});
it.each([
['ADMIN', 'Admin'],
['admin', 'Admin'],
['Admin', 'Admin'],
['SUPER_ADMIN', 'SUPER_ADMIN'],
['super-admin', 'SUPER_ADMIN'],
['SuperAdmin', 'SUPER_ADMIN'],
['ADMIN_SUPER', 'SUPER_ADMIN'],
])('canonicalizes guard-supported %s on task reads to %s', async (role, canonical) => {
for (const path of ['tasks', 'tasks/t']) {
workflow.project.mockClear();
const response = await request(app.getHttpServer())
.get('/admin/orchestration/' + path)
.set('Authorization', role)
.expect(200);
expect(workflow.project).toHaveBeenCalledWith(t, {
id: 'verified-subject', role: canonical,
});
const task = Array.isArray(response.body) ? response.body[0] : response.body;
expect(task.availableActions).toEqual(['SUBMIT_GATE1']);
}
});
it('denies ordinary users before workflow projection', async () => {
workflow.project.mockClear();
for (const path of ['tasks', 'tasks/t', 'overview']) {
await request(app.getHttpServer())
.get('/admin/orchestration/' + path)
.set('Authorization', 'User_PetOwner')
.expect(403);
}
expect(workflow.project).not.toHaveBeenCalled();
});
it('accepts existing proposal DTO, derives actor from JWT sub and returns projected task', async () => {
const dto = {
key: 'k',