diff --git a/src/samples/aspnet/Elsa.Samples.MassTransitRabbitMq/Properties/launchSettings.json b/src/samples/aspnet/Elsa.Samples.MassTransitRabbitMq/Properties/launchSettings.json new file mode 100644 index 000000000..897350537 --- /dev/null +++ b/src/samples/aspnet/Elsa.Samples.MassTransitRabbitMq/Properties/launchSettings.json @@ -0,0 +1,27 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:59550/", + "sslPort": 44301 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "Elsa.Samples.MassTransitRabbitMq": { + "commandName": "Project", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "https://localhost:5001;http://localhost:5000" + } + } +} \ No newline at end of file diff --git a/src/scripting/Elsa.Scripting.Liquid/Handlers/ConfigureLiquidEngine.cs b/src/scripting/Elsa.Scripting.Liquid/Handlers/ConfigureLiquidEngine.cs index f5472f658..6b6142396 100644 --- a/src/scripting/Elsa.Scripting.Liquid/Handlers/ConfigureLiquidEngine.cs +++ b/src/scripting/Elsa.Scripting.Liquid/Handlers/ConfigureLiquidEngine.cs @@ -16,6 +16,7 @@ using Fluid; using Fluid.Values; using MediatR; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Options; using Newtonsoft.Json.Linq; namespace Elsa.Scripting.Liquid.Handlers @@ -26,11 +27,11 @@ namespace Elsa.Scripting.Liquid.Handlers private readonly IWorkflowStorageService _workflowStorageService; private readonly LiquidOptions _liquidOptions; - public ConfigureLiquidEngine(IConfiguration configuration, IWorkflowStorageService workflowStorageService, LiquidOptions liquidOptions) + public ConfigureLiquidEngine(IConfiguration configuration, IWorkflowStorageService workflowStorageService, IOptions liquidOptions) { _configuration = configuration; _workflowStorageService = workflowStorageService; - _liquidOptions = liquidOptions; + _liquidOptions = liquidOptions.Value; } public Task Handle(EvaluatingLiquidExpression notification, CancellationToken cancellationToken) diff --git a/test/integration/Elsa.Core.IntegrationTests/Scripting/Liquid/LiquidExpressionIntegrationTests.cs b/test/integration/Elsa.Core.IntegrationTests/Scripting/Liquid/LiquidExpressionIntegrationTests.cs new file mode 100644 index 000000000..511f1d534 --- /dev/null +++ b/test/integration/Elsa.Core.IntegrationTests/Scripting/Liquid/LiquidExpressionIntegrationTests.cs @@ -0,0 +1,97 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Elsa.ActivityResults; +using Elsa.Builders; +using Elsa.Expressions; +using Elsa.Scripting.Liquid.Extensions; +using Elsa.Services; +using Elsa.Services.Models; +using Elsa.Testing.Shared.Helpers; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Xunit; + +namespace Elsa.Core.IntegrationTests.Scripting.Liquid +{ + public class LiquidExpressionIntegrationTests + { + [Fact] + public async Task LiquidExpressionsCannotAccessConfigurationByDefault() + { + var services = new ServiceCollection() + .AddSingleton(_ => new ConfigurationBuilder() + .AddInMemoryCollection(new Dictionary + { + { "SomeSecret", "I am a secret" }, + }) + .Build()) + .AddSingleton() + .AddElsa(elsa => elsa + .AddActivity() + .AddWorkflow()) + .BuildServiceProvider(); + + var workflowStarter = services.GetRequiredService(); + var activityState = services.GetRequiredService(); + + await workflowStarter.BuildAndStartWorkflowAsync(); + + Assert.Single(activityState.Messages, "Config secret: "); + } + + [Fact] + public async Task ConfigureAccessCanBeEnabledForLiquidExpressions() + { + var services = new ServiceCollection() + .AddSingleton(_ => new ConfigurationBuilder() + .AddInMemoryCollection(new Dictionary + { + { "SomeSecret", "I am a secret" }, + }) + .Build()) + .AddSingleton() + .AddElsa(elsa => elsa + .AddActivity() + .AddWorkflow()) + .EnableLiquidConfigurationAccess() + .BuildServiceProvider(); + + var workflowStarter = services.GetRequiredService(); + var activityState = services.GetRequiredService(); + + await workflowStarter.BuildAndStartWorkflowAsync(); + + Assert.Single(activityState.Messages, "Config secret: I am a secret"); + } + + private class ConfigurationAccessWorkflow : IWorkflow + { + public void Build(IWorkflowBuilder builder) + { + builder.StartWith(); + } + } + + private class WriteConfigActivity : Activity + { + private IExpressionEvaluator _expressionEvaluator; + private AssertableActivityState _activityState; + + public WriteConfigActivity(IExpressionEvaluator evaluator, AssertableActivityState activityState) + { + _expressionEvaluator = evaluator; + _activityState = activityState; + } + + protected override async ValueTask OnExecuteAsync(ActivityExecutionContext context) + { + var liquidExpression = "{{Configuration.SomeSecret}}"; + var expressionResult = await _expressionEvaluator.TryEvaluateAsync(liquidExpression, "Liquid", context); + + _activityState.Messages.Add($"Config secret: {expressionResult.Value ?? ""}"); + + return Done(); + } + } + } +} \ No newline at end of file