mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-19 09:39:08 +00:00
The JWT `permissions` claim is an array of numeric seqids at runtime (see authentication.guard.ts / authentication.decorator.ts), not claim strings. deriveOrchestIdentity previously matched claim strings against this numeric array, so roles[]/modules[] were always empty for every real user. - deriveOrchestIdentity now takes number[] | undefined and matches seqids sourced from PERMISSIONS_GROUPS (permissions.enum.ts) instead of hand-copied literals. - permissions is translated back to claim strings via a full seqid->claim catalog built once from PERMISSIONS_GROUPS; unknown seqids are dropped (auth-server ignores permissions[] in v1). - auth.controller.ts's api-key branch literal is now annotated `: UserDTO` so tsc enforces the three fields there. - Both spec files re-fixtured with numeric seqid inputs, including a mixed admin+module case and an exact claim-string translation assertion. Co-Authored-By: WOZCODE <contact@withwoz.com>
45 lines
1.5 KiB
TypeScript
45 lines
1.5 KiB
TypeScript
import { deriveOrchestIdentity } from './orchest-identity';
|
|
|
|
// JWT permissions claim carries numeric seqids (not claim strings) — see
|
|
// src/decorators/authentication.decorator.ts and
|
|
// src/authentication/authentication.guard.ts. 34 = users:admin,
|
|
// 31 = intelligence:open, 43 = process:open.
|
|
describe('deriveOrchestIdentity', () => {
|
|
it('translates seqids to claim strings in permissions', () => {
|
|
expect(deriveOrchestIdentity([31]).permissions).toEqual([
|
|
'intelligence:open',
|
|
]);
|
|
});
|
|
|
|
it('marks super-admin from the users:admin seqid (34)', () => {
|
|
expect(deriveOrchestIdentity([34]).roles).toContain('super-admin');
|
|
});
|
|
|
|
it('omits super-admin when the admin seqid is absent', () => {
|
|
expect(deriveOrchestIdentity([31]).roles).not.toContain('super-admin');
|
|
});
|
|
|
|
it('maps intelligence and process seqids to module keys', () => {
|
|
const { modules } = deriveOrchestIdentity([31, 43]);
|
|
expect(modules.sort()).toEqual(['intelligence', 'process']);
|
|
});
|
|
|
|
it('ignores non-module seqids in modules', () => {
|
|
expect(deriveOrchestIdentity([34]).modules).toEqual([]);
|
|
});
|
|
|
|
it('handles a mixed real-shape seqid array (admin + intelligence)', () => {
|
|
const { roles, modules } = deriveOrchestIdentity([34, 31]);
|
|
expect(roles).toEqual(['super-admin']);
|
|
expect(modules).toEqual(['intelligence']);
|
|
});
|
|
|
|
it('handles undefined/empty permissions', () => {
|
|
expect(deriveOrchestIdentity(undefined)).toEqual({
|
|
permissions: [],
|
|
roles: [],
|
|
modules: [],
|
|
});
|
|
});
|
|
});
|