From 8348a7b9a30c84aeb4e0da85cd2202ba028ac3f1 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Wed, 4 Sep 2024 18:47:25 +0200 Subject: [PATCH 1/2] Also update IWireMockMiddlewareOptions when settings are updated via admin interface (#1166) * Also update IWireMockMiddlewareOptions when settings are updated via admin interface * ci --- azure-pipelines-ci.yml | 7 ++++- .../Owin/WireMockMiddlewareOptionsHelper.cs | 27 ++++++++++++----- .../Server/WireMockServer.Admin.cs | 29 +++++++++---------- src/WireMock.Net/Server/WireMockServer.cs | 10 +++---- 4 files changed, 44 insertions(+), 29 deletions(-) diff --git a/azure-pipelines-ci.yml b/azure-pipelines-ci.yml index 27398efb..834ef5b2 100644 --- a/azure-pipelines-ci.yml +++ b/azure-pipelines-ci.yml @@ -53,8 +53,13 @@ jobs: inputs: 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" + 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" - displayName: 'Execute Unit Tests with Coverage' + displayName: 'Execute WireMock.Net.Aspire.Tests with Coverage' - task: CmdLine@2 displayName: 'Merge coverage files' diff --git a/src/WireMock.Net/Owin/WireMockMiddlewareOptionsHelper.cs b/src/WireMock.Net/Owin/WireMockMiddlewareOptionsHelper.cs index 9a084d88..7ba92b5f 100644 --- a/src/WireMock.Net/Owin/WireMockMiddlewareOptionsHelper.cs +++ b/src/WireMock.Net/Owin/WireMockMiddlewareOptionsHelper.cs @@ -1,5 +1,6 @@ // Copyright © WireMock.Net +using System; using Stef.Validation; using WireMock.Settings; @@ -7,21 +8,31 @@ namespace WireMock.Owin; internal static class WireMockMiddlewareOptionsHelper { - public static IWireMockMiddlewareOptions InitFromSettings(WireMockServerSettings settings, IWireMockMiddlewareOptions? options = null) + public static IWireMockMiddlewareOptions InitFromSettings( + WireMockServerSettings settings, + IWireMockMiddlewareOptions? options = null, + Action? postConfigure = null + ) { Guard.NotNull(settings); options ??= new WireMockMiddlewareOptions(); - options.FileSystemHandler = settings.FileSystemHandler; - options.PreWireMockMiddlewareInit = settings.PreWireMockMiddlewareInit; - options.PostWireMockMiddlewareInit = settings.PostWireMockMiddlewareInit; - options.Logger = settings.Logger; + options.AllowBodyForAllHttpMethods = settings.AllowBodyForAllHttpMethods; + options.AllowOnlyDefinedHttpStatusCodeInResponse = settings.AllowOnlyDefinedHttpStatusCodeInResponse; + options.AllowPartialMapping = settings.AllowPartialMapping; options.DisableJsonBodyParsing = settings.DisableJsonBodyParsing; - options.HandleRequestsSynchronously = settings.HandleRequestsSynchronously; - options.SaveUnmatchedRequests = settings.SaveUnmatchedRequests; + options.DisableRequestBodyDecompressing = settings.DisableRequestBodyDecompressing; 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.RequestLogExpirationDuration = settings.RequestLogExpirationDuration; + options.SaveUnmatchedRequests = settings.SaveUnmatchedRequests; if (settings.CustomCertificateDefined) { @@ -32,6 +43,8 @@ public static IWireMockMiddlewareOptions InitFromSettings(WireMockServerSettings options.X509CertificatePassword = settings.CertificateSettings.X509CertificatePassword; } + postConfigure?.Invoke(options); + return options; } } \ No newline at end of file diff --git a/src/WireMock.Net/Server/WireMockServer.Admin.cs b/src/WireMock.Net/Server/WireMockServer.Admin.cs index 324ac065..7ffe78e9 100644 --- a/src/WireMock.Net/Server/WireMockServer.Admin.cs +++ b/src/WireMock.Net/Server/WireMockServer.Admin.cs @@ -18,6 +18,7 @@ using WireMock.Logging; using WireMock.Matchers; using WireMock.Matchers.Request; +using WireMock.Owin; using WireMock.RequestBuilders; using WireMock.ResponseProviders; using WireMock.Serialization; @@ -321,28 +322,26 @@ private IResponseMessage SettingsUpdate(IRequestMessage requestMessage) 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 (Enum.TryParse(settings.CorsPolicyOptions, true, out var corsPolicyOptions)) { _settings.CorsPolicyOptions = corsPolicyOptions; - _options.CorsPolicyOptions = corsPolicyOptions; } +#endif + + WireMockMiddlewareOptionsHelper.InitFromSettings(_settings, _options, o => + { + if (settings.GlobalProcessingDelay != null) + { + o.RequestProcessingDelay = TimeSpan.FromMilliseconds(settings.GlobalProcessingDelay.Value); + } - _options.ClientCertificateMode = _settings.ClientCertificateMode; - _options.AcceptAnyClientCertificate = _settings.AcceptAnyClientCertificate; +#if USE_ASPNETCORE + o.CorsPolicyOptions = corsPolicyOptions; + o.ClientCertificateMode = _settings.ClientCertificateMode; + o.AcceptAnyClientCertificate = _settings.AcceptAnyClientCertificate; #endif + }); return ResponseMessageBuilder.Create(200, "Settings updated"); } diff --git a/src/WireMock.Net/Server/WireMockServer.cs b/src/WireMock.Net/Server/WireMockServer.cs index a9963c9a..3079c52b 100644 --- a/src/WireMock.Net/Server/WireMockServer.cs +++ b/src/WireMock.Net/Server/WireMockServer.cs @@ -20,7 +20,6 @@ using WireMock.Handlers; using WireMock.Http; using WireMock.Logging; -using WireMock.Matchers.Request; using WireMock.Models; using WireMock.Owin; using WireMock.RequestBuilders; @@ -369,9 +368,10 @@ protected WireMockServer(WireMockServerSettings settings) } } - WireMockMiddlewareOptionsHelper.InitFromSettings(settings, _options); - - _options.LogEntries.CollectionChanged += LogEntries_CollectionChanged; + WireMockMiddlewareOptionsHelper.InitFromSettings(settings, _options, o => + { + o.LogEntries.CollectionChanged += LogEntries_CollectionChanged; + }); _matcherMapper = new MatcherMapper(_settings); _mappingConverter = new MappingConverter(_matcherMapper); @@ -649,13 +649,11 @@ private void InitSettings(WireMockServerSettings settings) { if (settings.AllowBodyForAllHttpMethods == true) { - _options.AllowBodyForAllHttpMethods = _settings.AllowBodyForAllHttpMethods; _settings.Logger.Info("AllowBodyForAllHttpMethods is set to True"); } if (settings.AllowOnlyDefinedHttpStatusCodeInResponse == true) { - _options.AllowOnlyDefinedHttpStatusCodeInResponse = _settings.AllowOnlyDefinedHttpStatusCodeInResponse; _settings.Logger.Info("AllowOnlyDefinedHttpStatusCodeInResponse is set to True"); } From 07c9aebf44a462cbf787ef72ec9240af055d67b2 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Wed, 4 Sep 2024 18:50:59 +0200 Subject: [PATCH 2/2] 1.6.2 --- CHANGELOG.md | 7 +++++++ Directory.Build.props | 2 +- Generate-ReleaseNotes.cmd | 2 +- PackageReleaseNotes.txt | 9 ++++++--- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad94b3af..2d567d66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# 1.6.2 (04 September 2024) +- [#1152](https://github.com/WireMock-Net/WireMock.Net/pull/1152) - Update MappingConverter to correctly write the Matcher as C# code [bug] contributed by [StefH](https://github.com/StefH) +- [#1163](https://github.com/WireMock-Net/WireMock.Net/pull/1163) - Upgrade Aspire to version 8.2.0 [feature] contributed by [StefH](https://github.com/StefH) +- [#1166](https://github.com/WireMock-Net/WireMock.Net/pull/1166) - Also update IWireMockMiddlewareOptions when settings are updated via admin interface [bug] contributed by [StefH](https://github.com/StefH) +- [#1151](https://github.com/WireMock-Net/WireMock.Net/issues/1151) - MappingsToCSharpCode should use RegexMatcher when specified [bug] +- [#1164](https://github.com/WireMock-Net/WireMock.Net/issues/1164) - WithParam not working. [bug] + # 1.6.1 (22 August 2024) - [#1160](https://github.com/WireMock-Net/WireMock.Net/pull/1160) - Use default timeout for Regex [bug] contributed by [StefH](https://github.com/StefH) - [#1159](https://github.com/WireMock-Net/WireMock.Net/issues/1159) - RegexMatchTimeoutException when trying to parse HTTP version [bug] diff --git a/Directory.Build.props b/Directory.Build.props index c40ac679..6ac74555 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -4,7 +4,7 @@ - 1.6.1 + 1.6.2 WireMock.Net-Logo.png https://github.com/WireMock-Net/WireMock.Net Apache-2.0 diff --git a/Generate-ReleaseNotes.cmd b/Generate-ReleaseNotes.cmd index 3c8bd871..8bce4728 100644 --- a/Generate-ReleaseNotes.cmd +++ b/Generate-ReleaseNotes.cmd @@ -1,6 +1,6 @@ rem https://github.com/StefH/GitHubReleaseNotes -SET version=1.6.1 +SET version=1.6.2 GitHubReleaseNotes --output CHANGELOG.md --skip-empty-releases --exclude-labels question invalid doc duplicate example environment --version %version% --token %GH_TOKEN% diff --git a/PackageReleaseNotes.txt b/PackageReleaseNotes.txt index b0df0ecc..1e9868e8 100644 --- a/PackageReleaseNotes.txt +++ b/PackageReleaseNotes.txt @@ -1,5 +1,8 @@ -# 1.6.1 (22 August 2024) -- #1160 Use default timeout for Regex [bug] -- #1159 RegexMatchTimeoutException when trying to parse HTTP version [bug] +# 1.6.2 (04 September 2024) +- #1152 Update MappingConverter to correctly write the Matcher as C# code [bug] +- #1163 Upgrade Aspire to version 8.2.0 [feature] +- #1166 Also update IWireMockMiddlewareOptions when settings are updated via admin interface [bug] +- #1151 MappingsToCSharpCode should use RegexMatcher when specified [bug] +- #1164 WithParam not working. [bug] The full release notes can be found here: https://github.com/WireMock-Net/WireMock.Net/blob/master/CHANGELOG.md \ No newline at end of file