Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright © WireMock.Net

using WireMock.Types;

namespace WireMock.Admin.Settings;

/// <summary>
Expand All @@ -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;
}
21 changes: 17 additions & 4 deletions src/WireMock.Net.Minimal/Settings/WireMockServerSettingsParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,27 @@ private static void ParseWebProxyAddressSettings(ProxyAndRecordSettings settings

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)
};
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
}
}
49 changes: 49 additions & 0 deletions test/WireMock.Net.Tests/AdminApi/WireMockAdminApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,55 @@ public async Task IWireMockAdminApi_GetMappingAsync_WithProxy_And_ProxyUrlReplac
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()
{
Expand Down
Loading