Compare commits

..

3 Commits

Author SHA1 Message Date
Stef Heyenrath
7033d85e3a 1.2.10 2020-05-17 20:01:30 +02:00
Stef Heyenrath
7d873611ee Limits (#457) 2020-05-17 19:55:36 +02:00
Stef Heyenrath
f26bf62a13 Include Handlebars.Net.Helpers project (#456)
* wip

* h 100

* rename

* csproj
2020-05-17 19:55:06 +02:00
19 changed files with 159 additions and 70 deletions

View File

@@ -1,3 +1,8 @@
# 1.2.10.0 (17 May 2020)
- [#456](https://github.com/WireMock-Net/WireMock.Net/pull/456) - Include Handlebars.Net.Helpers project [feature] contributed by [StefH](https://github.com/StefH)
- [#457](https://github.com/WireMock-Net/WireMock.Net/pull/457) - Kestrel Options Limits [bug] contributed by [StefH](https://github.com/StefH)
- [#455](https://github.com/WireMock-Net/WireMock.Net/issues/455) - There is no option to increase body size while proxying [bug]
# 1.2.9.0 (14 May 2020)
- [#465](https://github.com/WireMock-Net/WireMock.Net/pull/465) - Fix method ResetMappingsAsync in the RestEase-AdminApi [bug] contributed by [StefH](https://github.com/StefH)
- [#464](https://github.com/WireMock-Net/WireMock.Net/issues/464) - RestClient Admin API Metadata Base Path Duplication [bug]

View File

@@ -4,7 +4,7 @@
</PropertyGroup>
<PropertyGroup>
<VersionPrefix>1.2.9</VersionPrefix>
<VersionPrefix>1.2.10</VersionPrefix>
<PackageReleaseNotes>See CHANGELOG.md</PackageReleaseNotes>
<PackageIconUrl>https://raw.githubusercontent.com/WireMock-Net/WireMock.Net/master/WireMock.Net-Logo.png</PackageIconUrl>
<PackageProjectUrl>https://github.com/WireMock-Net/WireMock.Net</PackageProjectUrl>

View File

@@ -1,3 +1,3 @@
https://github.com/StefH/GitHubReleaseNotes
GitHubReleaseNotes.exe --output CHANGELOG.md --skip-empty-releases --exclude-labels question invalid doc --version 1.2.9.0
GitHubReleaseNotes.exe --output CHANGELOG.md --skip-empty-releases --exclude-labels question invalid doc --version 1.2.10.0

View File

@@ -28,7 +28,7 @@
<ItemGroup>
<ProjectReference Include="..\..\src\WireMock.Net\WireMock.Net.csproj" />
<PackageReference Include="Handlebars.Net" Version="1.9.5" />
<PackageReference Include="Handlebars.Net.Helpers" Version="0.0.3" />
<PackageReference Include="log4net" Version="2.0.8" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<!--<PackageReference Include="Microsoft.CodeAnalysis.Scripting.Common" Version="3.4.0" />-->

View File

@@ -0,0 +1,40 @@
#if USE_ASPNETCORE && !NETSTANDARD1_3
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Server.Kestrel.Core;
namespace WireMock.Owin
{
internal partial class AspNetCoreSelfHost
{
private static void SetKestrelOptionsLimits(KestrelServerOptions options)
{
options.Limits.KeepAliveTimeout = TimeSpan.MaxValue;
options.Limits.MaxRequestBodySize = null; // https://stackoverflow.com/questions/46738364/increase-upload-request-length-limit-in-kestrel
options.Limits.MaxRequestBufferSize = null;
options.Limits.MaxRequestHeaderCount = 100;
options.Limits.MaxResponseBufferSize = null;
options.Limits.RequestHeadersTimeout = TimeSpan.MaxValue;
}
private static void SetHttpsAndUrls(KestrelServerOptions options, ICollection<(string Url, int Port)> urlDetails)
{
foreach (var detail in urlDetails)
{
if (detail.Url.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
{
options.Listen(System.Net.IPAddress.Any, detail.Port, listenOptions =>
{
listenOptions.UseHttps();
});
}
else
{
options.Listen(System.Net.IPAddress.Any, detail.Port);
}
}
}
}
}
#endif

View File

@@ -0,0 +1,32 @@
#if USE_ASPNETCORE && NETSTANDARD1_3
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Server.Kestrel;
using WireMock.HttpsCertificate;
namespace WireMock.Owin
{
internal partial class AspNetCoreSelfHost
{
private static void SetKestrelOptionsLimits(KestrelServerOptions options)
{
options.Limits.KeepAliveTimeout = TimeSpan.MaxValue;
options.Limits.MaxRequestBufferSize = null;
options.Limits.MaxRequestHeaderCount = 100;
options.Limits.MaxResponseBufferSize = null;
options.Limits.RequestHeadersTimeout = TimeSpan.MaxValue;
}
private static void SetHttpsAndUrls(KestrelServerOptions options, ICollection<(string Url, int Port)> urlDetails)
{
var urls = urlDetails.Select(u => u.Url);
if (urls.Any(u => u.StartsWith("https://", StringComparison.OrdinalIgnoreCase)))
{
options.UseHttps(PublicCertificateHelper.GetX509Certificate2());
}
}
}
}
#endif

View File

@@ -8,7 +8,6 @@ using JetBrains.Annotations;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using WireMock.HttpsCertificate;
using WireMock.Logging;
using WireMock.Owin.Mappers;
using WireMock.Util;
@@ -16,7 +15,7 @@ using WireMock.Validation;
namespace WireMock.Owin
{
internal class AspNetCoreSelfHost : IOwinSelfHost
internal partial class AspNetCoreSelfHost : IOwinSelfHost
{
private readonly CancellationTokenSource _cts = new CancellationTokenSource();
private readonly IWireMockMiddlewareOptions _options;
@@ -78,31 +77,9 @@ namespace WireMock.Owin
})
.UseKestrel(options =>
{
var urlDetails = _urlOptions.GetDetails();
SetKestrelOptionsLimits(options);
#if NETSTANDARD1_3
var urls = urlDetails.Select(u => u.Url);
if (urls.Any(u => u.StartsWith("https://", StringComparison.OrdinalIgnoreCase)))
{
options.UseHttps(PublicCertificateHelper.GetX509Certificate2());
}
#else
foreach (var detail in urlDetails)
{
if (detail.Url.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
{
options.Listen(System.Net.IPAddress.Any, detail.Port, listenOptions =>
{
listenOptions.UseHttps(); // PublicCertificateHelper.GetX509Certificate2()
});
}
else
{
options.Listen(System.Net.IPAddress.Any, detail.Port);
}
}
#endif
SetHttpsAndUrls(options, _urlOptions.GetDetails());
})
#if NETSTANDARD1_3
@@ -144,6 +121,7 @@ namespace WireMock.Owin
#elif NET46
_logger.Info("WireMock.Net server using .net 4.6.1 or higher");
#endif
#if NETSTANDARD1_3
return Task.Run(() =>
{

View File

@@ -5,7 +5,7 @@ using WireMock.Validation;
namespace WireMock.Transformers
{
internal static class HandleBarsFile
internal static class HandlebarsFile
{
public static void Register(IHandlebars handlebarsContext, IFileSystemHandler fileSystemHandler)
{

View File

@@ -1,25 +0,0 @@
using HandlebarsDotNet;
using WireMock.Handlers;
namespace WireMock.Transformers
{
internal static class HandlebarsHelpers
{
public static void Register(IHandlebars handlebarsContext, IFileSystemHandler fileSystemHandler)
{
HandleBarsRegex.Register(handlebarsContext);
HandleBarsJsonPath.Register(handlebarsContext);
HandleBarsLinq.Register(handlebarsContext);
HandleBarsRandom.Register(handlebarsContext);
HandleBarsXeger.Register(handlebarsContext);
HandleBarsXPath.Register(handlebarsContext);
HandleBarsFile.Register(handlebarsContext, fileSystemHandler);
}
}
}

View File

@@ -9,7 +9,7 @@ using WireMock.Validation;
namespace WireMock.Transformers
{
internal static class HandleBarsJsonPath
internal static class HandlebarsJsonPath
{
public static void Register(IHandlebars handlebarsContext)
{

View File

@@ -9,7 +9,7 @@ using WireMock.Validation;
namespace WireMock.Transformers
{
internal static class HandleBarsLinq
internal static class HandlebarsLinq
{
public static void Register(IHandlebars handlebarsContext)
{

View File

@@ -11,7 +11,7 @@ using WireMock.Validation;
namespace WireMock.Transformers
{
internal static class HandleBarsRandom
internal static class HandlebarsRandom
{
public static void Register(IHandlebars handlebarsContext)
{

View File

@@ -7,7 +7,7 @@ using WireMock.Validation;
namespace WireMock.Transformers
{
internal static class HandleBarsRegex
internal static class HandlebarsRegex
{
public static void Register(IHandlebars handlebarsContext)
{

View File

@@ -10,7 +10,7 @@ using Wmhelp.XPath2;
namespace WireMock.Transformers
{
internal static class HandleBarsXPath
internal static class HandlebarsXPath
{
public static void Register(IHandlebars handlebarsContext)
{

View File

@@ -5,7 +5,7 @@ using WireMock.Validation;
namespace WireMock.Transformers
{
internal static class HandleBarsXeger
internal static class HandlebarsXeger
{
public static void Register(IHandlebars handlebarsContext)
{

View File

@@ -24,7 +24,7 @@ namespace WireMock.Transformers
{
var handlebars = Handlebars.Create(HandlebarsConfiguration);
HandlebarsHelpers.Register(handlebars, _fileSystemHandler);
WireMockHandlebarsHelpers.Register(handlebars, _fileSystemHandler);
_action?.Invoke(handlebars, _fileSystemHandler);

View File

@@ -0,0 +1,30 @@
using HandlebarsDotNet;
using HandlebarsDotNet.Helpers;
using WireMock.Handlers;
namespace WireMock.Transformers
{
internal static class WireMockHandlebarsHelpers
{
public static void Register(IHandlebars handlebarsContext, IFileSystemHandler fileSystemHandler)
{
// Register https://github.com/StefH/Handlebars.Net.Helpers
HandlebarsHelpers.Register(handlebarsContext);
// Register WireMock.Net specific helpers
HandlebarsRegex.Register(handlebarsContext);
HandlebarsJsonPath.Register(handlebarsContext);
HandlebarsLinq.Register(handlebarsContext);
HandlebarsRandom.Register(handlebarsContext);
HandlebarsXeger.Register(handlebarsContext);
HandlebarsXPath.Register(handlebarsContext);
HandlebarsFile.Register(handlebarsContext, fileSystemHandler);
}
}
}

View File

@@ -58,6 +58,7 @@
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.0.12" />
<PackageReference Include="RandomDataGenerator.Net" Version="1.0.10" />
<PackageReference Include="JmesPath.Net" Version="1.0.125" />
<PackageReference Include="Handlebars.Net.Helpers" Version="1.0.0" />
</ItemGroup>
<ItemGroup Condition="'$(Configuration)' == 'Debug - Sonar'">
@@ -67,14 +68,6 @@
</PackageReference>
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net451' ">
<PackageReference Include="Handlebars.Net" Version="[1.9.0]" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' != 'net451' ">
<PackageReference Include="Handlebars.Net" Version="1.9.5" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' != 'netstandard1.3' ">
<PackageReference Include="XPath2.Extensions" Version="1.0.6.1" />
</ItemGroup>

View File

@@ -0,0 +1,36 @@
using System.Threading.Tasks;
using NFluent;
using WireMock.Models;
using WireMock.ResponseBuilders;
using WireMock.Settings;
using WireMock.Types;
using WireMock.Util;
using Xunit;
namespace WireMock.Net.Tests.ResponseBuilders
{
public class ResponseWithHandlebarsHelpersTests
{
private readonly WireMockServerSettings _settings = new WireMockServerSettings();
private const string ClientIp = "::1";
[Fact]
public async Task Response_ProvideResponseAsync_HandlebarsHelpers_String_Uppercase()
{
// Assign
var body = new BodyData { BodyAsString = "abc", DetectedBodyType = BodyType.String };
var request = new RequestMessage(new UrlDetails("http://localhost:1234"), "POST", ClientIp, body);
var response = Response.Create()
.WithBody("{{String.Uppercase request.body}}")
.WithTransformer();
// Act
var responseMessage = await response.ProvideResponseAsync(request, _settings);
// assert
Check.That(responseMessage.BodyData.BodyAsString).Equals("ABC");
}
}
}