diff --git a/src/Trax.Scheduler/Services/RequestHandler/TraxRequestHandler.cs b/src/Trax.Scheduler/Services/RequestHandler/TraxRequestHandler.cs index b191ed2..00e97c7 100644 --- a/src/Trax.Scheduler/Services/RequestHandler/TraxRequestHandler.cs +++ b/src/Trax.Scheduler/Services/RequestHandler/TraxRequestHandler.cs @@ -3,6 +3,7 @@ using Trax.Core.Exceptions; using Trax.Effect.Utils; using Trax.Mediator.Services.TrainExecution; +using Trax.Mediator.Services.TrustedExecution; using Trax.Scheduler.Services.JobSubmitter; using Trax.Scheduler.Services.RunExecutor; using Trax.Scheduler.Trains.JobRunner; @@ -16,6 +17,7 @@ namespace Trax.Scheduler.Services.RequestHandler; internal class TraxRequestHandler( IJobRunnerTrain jobRunnerTrain, ITrainExecutionService executionService, + ITrustedExecutionScope trustedScope, ILogger logger ) : ITraxRequestHandler { @@ -51,6 +53,10 @@ public async Task RunTrainAsync( { try { + // Remote job submissions were already authorized at the original API + // submission point. Mark this execution as trusted so the mediator's + // authorization service skips the per-train check. + using var _ = trustedScope.BeginTrusted("scheduler.remote-run"); var result = await executionService.RunAsync(request.TrainName, request.InputJson, ct); string? outputJson = null; diff --git a/tests/Trax.Scheduler.Tests.Integration/IntegrationTests/RemoteRunExecutionTests.cs b/tests/Trax.Scheduler.Tests.Integration/IntegrationTests/RemoteRunExecutionTests.cs index 9bae512..658e9d4 100644 --- a/tests/Trax.Scheduler.Tests.Integration/IntegrationTests/RemoteRunExecutionTests.cs +++ b/tests/Trax.Scheduler.Tests.Integration/IntegrationTests/RemoteRunExecutionTests.cs @@ -124,7 +124,9 @@ public async Task RunAsync_UnknownTrain_ThrowsInvalidOperationException() var act = async () => await executionService.RunAsync("NonExistent.Train", "{}"); - await act.Should().ThrowAsync().WithMessage("*No train found*"); + await act.Should() + .ThrowAsync() + .WithMessage("*requested train was not found*"); } [Test] diff --git a/tests/Trax.Scheduler.Tests/UnitTests/TraxRequestHandlerTests.cs b/tests/Trax.Scheduler.Tests/UnitTests/TraxRequestHandlerTests.cs index 5d7f9fa..96fd59b 100644 --- a/tests/Trax.Scheduler.Tests/UnitTests/TraxRequestHandlerTests.cs +++ b/tests/Trax.Scheduler.Tests/UnitTests/TraxRequestHandlerTests.cs @@ -7,6 +7,7 @@ using Trax.Effect.Models.Metadata; using Trax.Effect.Utils; using Trax.Mediator.Services.TrainExecution; +using Trax.Mediator.Services.TrustedExecution; using Trax.Scheduler.Services.JobSubmitter; using Trax.Scheduler.Services.RequestHandler; using Trax.Scheduler.Services.RunExecutor; @@ -302,6 +303,7 @@ private static TraxRequestHandler CreateHandler( return new TraxRequestHandler( jobRunner ?? new FakeJobRunnerTrain(), executionService ?? new FakeTrainExecutionService(), + new TrustedExecutionScope(), NullLogger.Instance ); }