Fix orchestration actor role normalization at HTTP boundary
This commit is contained in:
1 parent
ba0aa5ee4e
commit
c46f0909f3
2 files changed
+41
-2
No files matched your search
@@ -97,13 +97,20 @@ export class OrchestrationController {
|
|||||||
) {}
|
) {}
|
||||||
private actor(req: any): WorkflowIdentity {
|
private actor(req: any): WorkflowIdentity {
|
||||||
const id = req?.user?.id ?? req?.user?.sub;
|
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 (
|
if (
|
||||||
typeof id !== 'string' ||
|
typeof id !== 'string' ||
|
||||||
!id ||
|
!id ||
|
||||||
!['Admin', 'SUPER_ADMIN'].includes(req?.user?.role)
|
!role
|
||||||
)
|
)
|
||||||
throw new ForbiddenException('Authenticated workflow identity required');
|
throw new ForbiddenException('Authenticated workflow identity required');
|
||||||
return { id, role: req.user.role };
|
return { id, role };
|
||||||
}
|
}
|
||||||
private safe(row: any, req: any) {
|
private safe(row: any, req: any) {
|
||||||
const view = project(row);
|
const view = project(row);
|
||||||
|
|||||||
@@ -68,6 +68,38 @@ describe('bounded workflow HTTP contracts', () => {
|
|||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
await app.close();
|
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 () => {
|
it('accepts existing proposal DTO, derives actor from JWT sub and returns projected task', async () => {
|
||||||
const dto = {
|
const dto = {
|
||||||
key: 'k',
|
key: 'k',
|
||||||
|
|||||||
Reference in new issue
Block a user