mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-29 13:52:08 +02:00
Also update IWireMockMiddlewareOptions when settings are updated via admin interface (#1166)
* Also update IWireMockMiddlewareOptions when settings are updated via admin interface * ci
This commit is contained in:
@@ -53,8 +53,13 @@ jobs:
|
|||||||
inputs:
|
inputs:
|
||||||
script: |
|
script: |
|
||||||
dotnet-coverage collect "dotnet test ./test/WireMock.Net.Tests/WireMock.Net.Tests.csproj --configuration Debug --no-build --framework net8.0" -f xml -o "wiremock-coverage-1.xml"
|
dotnet-coverage collect "dotnet test ./test/WireMock.Net.Tests/WireMock.Net.Tests.csproj --configuration Debug --no-build --framework net8.0" -f xml -o "wiremock-coverage-1.xml"
|
||||||
|
displayName: 'Execute WireMock.Net.Tests with Coverage'
|
||||||
|
|
||||||
|
- task: CmdLine@2
|
||||||
|
inputs:
|
||||||
|
script: |
|
||||||
dotnet-coverage collect "dotnet test ./test/WireMock.Net.Aspire.Tests/WireMock.Net.Aspire.Tests.csproj --configuration Debug --no-build" -f xml -o "wiremock-coverage-2.xml"
|
dotnet-coverage collect "dotnet test ./test/WireMock.Net.Aspire.Tests/WireMock.Net.Aspire.Tests.csproj --configuration Debug --no-build" -f xml -o "wiremock-coverage-2.xml"
|
||||||
displayName: 'Execute Unit Tests with Coverage'
|
displayName: 'Execute WireMock.Net.Aspire.Tests with Coverage'
|
||||||
|
|
||||||
- task: CmdLine@2
|
- task: CmdLine@2
|
||||||
displayName: 'Merge coverage files'
|
displayName: 'Merge coverage files'
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
// Copyright © WireMock.Net
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
|
using System;
|
||||||
using Stef.Validation;
|
using Stef.Validation;
|
||||||
using WireMock.Settings;
|
using WireMock.Settings;
|
||||||
|
|
||||||
@@ -7,21 +8,31 @@ namespace WireMock.Owin;
|
|||||||
|
|
||||||
internal static class WireMockMiddlewareOptionsHelper
|
internal static class WireMockMiddlewareOptionsHelper
|
||||||
{
|
{
|
||||||
public static IWireMockMiddlewareOptions InitFromSettings(WireMockServerSettings settings, IWireMockMiddlewareOptions? options = null)
|
public static IWireMockMiddlewareOptions InitFromSettings(
|
||||||
|
WireMockServerSettings settings,
|
||||||
|
IWireMockMiddlewareOptions? options = null,
|
||||||
|
Action<IWireMockMiddlewareOptions>? postConfigure = null
|
||||||
|
)
|
||||||
{
|
{
|
||||||
Guard.NotNull(settings);
|
Guard.NotNull(settings);
|
||||||
|
|
||||||
options ??= new WireMockMiddlewareOptions();
|
options ??= new WireMockMiddlewareOptions();
|
||||||
|
|
||||||
options.FileSystemHandler = settings.FileSystemHandler;
|
options.AllowBodyForAllHttpMethods = settings.AllowBodyForAllHttpMethods;
|
||||||
options.PreWireMockMiddlewareInit = settings.PreWireMockMiddlewareInit;
|
options.AllowOnlyDefinedHttpStatusCodeInResponse = settings.AllowOnlyDefinedHttpStatusCodeInResponse;
|
||||||
options.PostWireMockMiddlewareInit = settings.PostWireMockMiddlewareInit;
|
options.AllowPartialMapping = settings.AllowPartialMapping;
|
||||||
options.Logger = settings.Logger;
|
|
||||||
options.DisableJsonBodyParsing = settings.DisableJsonBodyParsing;
|
options.DisableJsonBodyParsing = settings.DisableJsonBodyParsing;
|
||||||
options.HandleRequestsSynchronously = settings.HandleRequestsSynchronously;
|
options.DisableRequestBodyDecompressing = settings.DisableRequestBodyDecompressing;
|
||||||
options.SaveUnmatchedRequests = settings.SaveUnmatchedRequests;
|
|
||||||
options.DoNotSaveDynamicResponseInLogEntry = settings.DoNotSaveDynamicResponseInLogEntry;
|
options.DoNotSaveDynamicResponseInLogEntry = settings.DoNotSaveDynamicResponseInLogEntry;
|
||||||
|
options.FileSystemHandler = settings.FileSystemHandler;
|
||||||
|
options.HandleRequestsSynchronously = settings.HandleRequestsSynchronously;
|
||||||
|
options.Logger = settings.Logger;
|
||||||
|
options.MaxRequestLogCount = settings.MaxRequestLogCount;
|
||||||
|
options.PostWireMockMiddlewareInit = settings.PostWireMockMiddlewareInit;
|
||||||
|
options.PreWireMockMiddlewareInit = settings.PreWireMockMiddlewareInit;
|
||||||
options.QueryParameterMultipleValueSupport = settings.QueryParameterMultipleValueSupport;
|
options.QueryParameterMultipleValueSupport = settings.QueryParameterMultipleValueSupport;
|
||||||
|
options.RequestLogExpirationDuration = settings.RequestLogExpirationDuration;
|
||||||
|
options.SaveUnmatchedRequests = settings.SaveUnmatchedRequests;
|
||||||
|
|
||||||
if (settings.CustomCertificateDefined)
|
if (settings.CustomCertificateDefined)
|
||||||
{
|
{
|
||||||
@@ -32,6 +43,8 @@ internal static class WireMockMiddlewareOptionsHelper
|
|||||||
options.X509CertificatePassword = settings.CertificateSettings.X509CertificatePassword;
|
options.X509CertificatePassword = settings.CertificateSettings.X509CertificatePassword;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
postConfigure?.Invoke(options);
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -18,6 +18,7 @@ using WireMock.Http;
|
|||||||
using WireMock.Logging;
|
using WireMock.Logging;
|
||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
using WireMock.Matchers.Request;
|
using WireMock.Matchers.Request;
|
||||||
|
using WireMock.Owin;
|
||||||
using WireMock.RequestBuilders;
|
using WireMock.RequestBuilders;
|
||||||
using WireMock.ResponseProviders;
|
using WireMock.ResponseProviders;
|
||||||
using WireMock.Serialization;
|
using WireMock.Serialization;
|
||||||
@@ -321,29 +322,27 @@ public partial class WireMockServer
|
|||||||
|
|
||||||
InitSettings(_settings);
|
InitSettings(_settings);
|
||||||
|
|
||||||
// _options
|
|
||||||
if (settings.GlobalProcessingDelay != null)
|
|
||||||
{
|
|
||||||
_options.RequestProcessingDelay = TimeSpan.FromMilliseconds(settings.GlobalProcessingDelay.Value);
|
|
||||||
}
|
|
||||||
_options.AllowBodyForAllHttpMethods = settings.AllowBodyForAllHttpMethods;
|
|
||||||
_options.AllowPartialMapping = settings.AllowPartialMapping;
|
|
||||||
_options.HandleRequestsSynchronously = settings.HandleRequestsSynchronously;
|
|
||||||
_options.MaxRequestLogCount = settings.MaxRequestLogCount;
|
|
||||||
_options.RequestLogExpirationDuration = settings.RequestLogExpirationDuration;
|
|
||||||
|
|
||||||
// _settings & _options
|
|
||||||
#if USE_ASPNETCORE
|
#if USE_ASPNETCORE
|
||||||
if (Enum.TryParse<CorsPolicyOptions>(settings.CorsPolicyOptions, true, out var corsPolicyOptions))
|
if (Enum.TryParse<CorsPolicyOptions>(settings.CorsPolicyOptions, true, out var corsPolicyOptions))
|
||||||
{
|
{
|
||||||
_settings.CorsPolicyOptions = corsPolicyOptions;
|
_settings.CorsPolicyOptions = corsPolicyOptions;
|
||||||
_options.CorsPolicyOptions = corsPolicyOptions;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_options.ClientCertificateMode = _settings.ClientCertificateMode;
|
|
||||||
_options.AcceptAnyClientCertificate = _settings.AcceptAnyClientCertificate;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
WireMockMiddlewareOptionsHelper.InitFromSettings(_settings, _options, o =>
|
||||||
|
{
|
||||||
|
if (settings.GlobalProcessingDelay != null)
|
||||||
|
{
|
||||||
|
o.RequestProcessingDelay = TimeSpan.FromMilliseconds(settings.GlobalProcessingDelay.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if USE_ASPNETCORE
|
||||||
|
o.CorsPolicyOptions = corsPolicyOptions;
|
||||||
|
o.ClientCertificateMode = _settings.ClientCertificateMode;
|
||||||
|
o.AcceptAnyClientCertificate = _settings.AcceptAnyClientCertificate;
|
||||||
|
#endif
|
||||||
|
});
|
||||||
|
|
||||||
return ResponseMessageBuilder.Create(200, "Settings updated");
|
return ResponseMessageBuilder.Create(200, "Settings updated");
|
||||||
}
|
}
|
||||||
#endregion Settings
|
#endregion Settings
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ using WireMock.Exceptions;
|
|||||||
using WireMock.Handlers;
|
using WireMock.Handlers;
|
||||||
using WireMock.Http;
|
using WireMock.Http;
|
||||||
using WireMock.Logging;
|
using WireMock.Logging;
|
||||||
using WireMock.Matchers.Request;
|
|
||||||
using WireMock.Models;
|
using WireMock.Models;
|
||||||
using WireMock.Owin;
|
using WireMock.Owin;
|
||||||
using WireMock.RequestBuilders;
|
using WireMock.RequestBuilders;
|
||||||
@@ -369,9 +368,10 @@ public partial class WireMockServer : IWireMockServer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WireMockMiddlewareOptionsHelper.InitFromSettings(settings, _options);
|
WireMockMiddlewareOptionsHelper.InitFromSettings(settings, _options, o =>
|
||||||
|
{
|
||||||
_options.LogEntries.CollectionChanged += LogEntries_CollectionChanged;
|
o.LogEntries.CollectionChanged += LogEntries_CollectionChanged;
|
||||||
|
});
|
||||||
|
|
||||||
_matcherMapper = new MatcherMapper(_settings);
|
_matcherMapper = new MatcherMapper(_settings);
|
||||||
_mappingConverter = new MappingConverter(_matcherMapper);
|
_mappingConverter = new MappingConverter(_matcherMapper);
|
||||||
@@ -649,13 +649,11 @@ public partial class WireMockServer : IWireMockServer
|
|||||||
{
|
{
|
||||||
if (settings.AllowBodyForAllHttpMethods == true)
|
if (settings.AllowBodyForAllHttpMethods == true)
|
||||||
{
|
{
|
||||||
_options.AllowBodyForAllHttpMethods = _settings.AllowBodyForAllHttpMethods;
|
|
||||||
_settings.Logger.Info("AllowBodyForAllHttpMethods is set to True");
|
_settings.Logger.Info("AllowBodyForAllHttpMethods is set to True");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (settings.AllowOnlyDefinedHttpStatusCodeInResponse == true)
|
if (settings.AllowOnlyDefinedHttpStatusCodeInResponse == true)
|
||||||
{
|
{
|
||||||
_options.AllowOnlyDefinedHttpStatusCodeInResponse = _settings.AllowOnlyDefinedHttpStatusCodeInResponse;
|
|
||||||
_settings.Logger.Info("AllowOnlyDefinedHttpStatusCodeInResponse is set to True");
|
_settings.Logger.Info("AllowOnlyDefinedHttpStatusCodeInResponse is set to True");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user