diff --git a/backend/src/app.module.ts b/backend/src/app.module.ts index 8f8bf7f7..00e26595 100644 --- a/backend/src/app.module.ts +++ b/backend/src/app.module.ts @@ -1,5 +1,5 @@ import { RouterUsageModule } from './router-usage/router-usage.module'; -import { HermesManagementModule } from './hermes-management/hermes-management.module'; +import { runtimeReadRegistration } from './hermes-management/runtime-read.registration'; import { TasksModule } from './common/services/tasks.module'; import { Module, NestModule, MiddlewareConsumer } from "@nestjs/common"; import { PrismaModule } from "./prisma/prisma.module"; @@ -47,7 +47,7 @@ import { Request, Response, NextFunction } from "express"; imports: [ RouterUsageModule, // Deny-all registration: no request identity or runtime credentials are accepted yet. - HermesManagementModule.register({origin:'http://canina-hermes:9119',token:async()=>''}), + runtimeReadRegistration(), OrchestrationModule, SupportChatModule, RevalidationModule, diff --git a/backend/src/hermes-management/runtime-read.registration.spec.ts b/backend/src/hermes-management/runtime-read.registration.spec.ts new file mode 100644 index 00000000..50bd30db --- /dev/null +++ b/backend/src/hermes-management/runtime-read.registration.spec.ts @@ -0,0 +1,16 @@ +import { runtimeReadRegistration } from './runtime-read.registration'; +import { RuntimeReadModule } from './runtime-read.module'; +describe('application runtime registration',()=>{ + afterEach(()=>jest.restoreAllMocks()); + it('registers denied routes without reading files when not explicitly enabled',async()=>{ + const file=jest.spyOn(RuntimeReadModule,'registerFromFile'); + const register=jest.spyOn(RuntimeReadModule,'register'); + await runtimeReadRegistration({}); + expect(file).not.toHaveBeenCalled();expect(register).toHaveBeenCalledWith({}); + }); + it('uses only the fixed reviewed grants mount when enabled',async()=>{ + const file=jest.spyOn(RuntimeReadModule,'registerFromFile').mockResolvedValue({module:RuntimeReadModule}); + await runtimeReadRegistration({CANINA_RUNTIME_READ_ENABLED:'true'}); + expect(file).toHaveBeenCalledWith('/run/secrets/hermes_runtime_grants'); + }); +}); diff --git a/backend/src/hermes-management/runtime-read.registration.ts b/backend/src/hermes-management/runtime-read.registration.ts new file mode 100644 index 00000000..57aa0b54 --- /dev/null +++ b/backend/src/hermes-management/runtime-read.registration.ts @@ -0,0 +1,6 @@ +import { RuntimeReadModule } from './runtime-read.module'; +export function runtimeReadRegistration(env:Record=process.env) { + return env.CANINA_RUNTIME_READ_ENABLED === 'true' + ? RuntimeReadModule.registerFromFile('/run/secrets/hermes_runtime_grants') + : RuntimeReadModule.register({}); +}