mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 22:30:41 +01:00
Update ProxyUrlReplaceSettingsModel with TransformTemplate property (#1362)
* Update ProxyUrlReplaceSettingsModel with TransformTemplate property + parse settings correctly * oldValue nullable * <Version>1.14.0-preview-01</Version>
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<Version>1.13.0</Version>
|
||||
<Version>1.14.0-preview-01</Version>
|
||||
<PackageIcon>WireMock.Net-Logo.png</PackageIcon>
|
||||
<PackageProjectUrl>https://github.com/wiremock/WireMock.Net</PackageProjectUrl>
|
||||
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using WireMock.Types;
|
||||
|
||||
namespace WireMock.Admin.Settings;
|
||||
|
||||
/// <summary>
|
||||
@@ -11,15 +13,25 @@ public class ProxyUrlReplaceSettingsModel
|
||||
/// <summary>
|
||||
/// The old path value to be replaced by the new path value
|
||||
/// </summary>
|
||||
public string OldValue { get; set; } = null!;
|
||||
public string? OldValue { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The new path value to replace the old value with
|
||||
/// </summary>
|
||||
public string NewValue { get; set; } = null!;
|
||||
public string? NewValue { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Defines if the case should be ignore when replacing.
|
||||
/// Defines if the case should be ignored when replacing.
|
||||
/// </summary>
|
||||
public bool IgnoreCase { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Holds the transformation template.
|
||||
/// </summary>
|
||||
public string? TransformTemplate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The transformer type.
|
||||
/// </summary>
|
||||
public TransformerType TransformerType { get; set; } = TransformerType.Handlebars;
|
||||
}
|
||||
@@ -202,14 +202,27 @@ public static class WireMockServerSettingsParser
|
||||
|
||||
private static void ParseProxyUrlReplaceSettings(ProxyAndRecordSettings settings, SimpleSettingsParser parser)
|
||||
{
|
||||
var proxyUrlReplaceOldValue = parser.GetStringValue("ProxyUrlReplaceOldValue");
|
||||
var proxyUrlReplaceNewValue = parser.GetStringValue("ProxyUrlReplaceNewValue");
|
||||
const string prefix = "ProxyUrlReplace";
|
||||
var proxyUrlReplaceOldValue = parser.GetStringValue($"{prefix}OldValue");
|
||||
var proxyUrlReplaceNewValue = parser.GetStringValue($"{prefix}NewValue");
|
||||
if (!string.IsNullOrEmpty(proxyUrlReplaceOldValue) && proxyUrlReplaceNewValue != null)
|
||||
{
|
||||
settings.ReplaceSettings = new ProxyUrlReplaceSettings
|
||||
{
|
||||
OldValue = proxyUrlReplaceOldValue!,
|
||||
NewValue = proxyUrlReplaceNewValue
|
||||
OldValue = proxyUrlReplaceOldValue,
|
||||
NewValue = proxyUrlReplaceNewValue,
|
||||
IgnoreCase = parser.GetBoolValue($"{prefix}IgnoreCase")
|
||||
};
|
||||
return;
|
||||
}
|
||||
|
||||
var transformTemplate = parser.GetStringValue($"{prefix}TransformTemplate");
|
||||
if (!string.IsNullOrEmpty(transformTemplate))
|
||||
{
|
||||
settings.ReplaceSettings = new ProxyUrlReplaceSettings
|
||||
{
|
||||
TransformTemplate = transformTemplate,
|
||||
TransformerType = parser.GetEnumValue($"{prefix}TransformerType", TransformerType.Handlebars)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
{
|
||||
Guid: 90356dba-b36c-469a-a17e-669cd84f1f06,
|
||||
UpdatedAt: DateTime_1,
|
||||
Request: {
|
||||
Path: {
|
||||
Matchers: [
|
||||
{
|
||||
Name: WildcardMatcher,
|
||||
Pattern: /1,
|
||||
IgnoreCase: false
|
||||
}
|
||||
]
|
||||
},
|
||||
Body: {
|
||||
Matcher: {
|
||||
Name: RegexMatcher,
|
||||
Pattern: hello,
|
||||
IgnoreCase: true
|
||||
}
|
||||
}
|
||||
},
|
||||
Response: {
|
||||
ProxyUrl: https://my-proxy.com,
|
||||
ProxyUrlReplaceSettings: {
|
||||
IgnoreCase: false,
|
||||
TransformTemplate: x{{this}}y
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -450,6 +450,55 @@ public partial class WireMockAdminApiTests
|
||||
server.Stop();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task IWireMockAdminApi_GetMappingAsync_WithProxy_And_ProxyUrlReplaceSettings_And_TransformTemplate()
|
||||
{
|
||||
// Arrange
|
||||
var guid = Guid.Parse("90356dba-b36c-469a-a17e-669cd84f1f06");
|
||||
var server = WireMockServer.StartWithAdminInterface();
|
||||
var api = RestClient.For<IWireMockAdminApi>(server.Url);
|
||||
|
||||
// Act
|
||||
var model = new MappingModel
|
||||
{
|
||||
Guid = guid,
|
||||
Request = new RequestModel
|
||||
{
|
||||
Path = "/1",
|
||||
Body = new BodyModel
|
||||
{
|
||||
Matcher = new MatcherModel
|
||||
{
|
||||
Name = "RegexMatcher",
|
||||
Pattern = "hello",
|
||||
IgnoreCase = true
|
||||
}
|
||||
}
|
||||
},
|
||||
Response = new ResponseModel
|
||||
{
|
||||
ProxyUrl = "https://my-proxy.com",
|
||||
ProxyUrlReplaceSettings = new ProxyUrlReplaceSettingsModel
|
||||
{
|
||||
TransformTemplate = "x{{this}}y"
|
||||
}
|
||||
}
|
||||
};
|
||||
var postMappingResult = await api.PostMappingAsync(model).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
postMappingResult.Should().NotBeNull();
|
||||
|
||||
var mapping = server.Mappings.FirstOrDefault(m => m.Guid == guid);
|
||||
mapping.Should().NotBeNull();
|
||||
|
||||
var getMappingResult = await api.GetMappingAsync(guid).ConfigureAwait(false);
|
||||
|
||||
await Verifier.Verify(getMappingResult, VerifySettings).DontScrubGuids();
|
||||
|
||||
server.Stop();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task IWireMockAdminApi_GetRequestsAsync_Json()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user