mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 22:30:41 +01:00
Add ProxyUrlReplaceSettings to Response (#1026)
This commit is contained in:
@@ -325,6 +325,23 @@ namespace WireMock.Net.ConsoleApplication
|
||||
.WithHeader("Keep-Alive-Test", "stef")
|
||||
);
|
||||
|
||||
server
|
||||
.Given(Request.Create()
|
||||
.UsingGet()
|
||||
.WithPath("/proxy-replace")
|
||||
)
|
||||
.RespondWith(Response.Create()
|
||||
.WithProxy(new ProxyAndRecordSettings
|
||||
{
|
||||
Url = "http://localhost:9999",
|
||||
ReplaceSettings = new ProxyUrlReplaceSettings
|
||||
{
|
||||
OldValue = "old",
|
||||
NewValue = "new"
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
server
|
||||
.Given(Request.Create()
|
||||
.WithPath("/xpath").UsingPost()
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using WireMock.Admin.Settings;
|
||||
|
||||
namespace WireMock.Admin.Mappings;
|
||||
|
||||
@@ -103,6 +104,11 @@ public class ResponseModel
|
||||
/// </summary>
|
||||
public string? ProxyUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Defines the Proxy Url Replace Settings.
|
||||
/// </summary>
|
||||
public ProxyUrlReplaceSettingsModel? ProxyUrlReplaceSettings { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The client X509Certificate2 Thumbprint or SubjectName to use.
|
||||
/// </summary>
|
||||
|
||||
@@ -70,7 +70,7 @@ public class ProxyAndRecordSettingsModel
|
||||
public bool AppendGuidToSavedMappingFile { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Defines the Replace Settings
|
||||
/// Defines the Replace Settings.
|
||||
/// </summary>
|
||||
public ProxyUrlReplaceSettingsModel? ReplaceSettings { get; set; }
|
||||
}
|
||||
@@ -1,24 +1,23 @@
|
||||
namespace WireMock.Admin.Settings
|
||||
namespace WireMock.Admin.Settings;
|
||||
|
||||
/// <summary>
|
||||
/// WebProxySettings
|
||||
/// </summary>
|
||||
[FluentBuilder.AutoGenerateBuilder]
|
||||
public class WebProxySettingsModel
|
||||
{
|
||||
/// <summary>
|
||||
/// WebProxySettings
|
||||
/// A string instance that contains the address of the proxy server.
|
||||
/// </summary>
|
||||
[FluentBuilder.AutoGenerateBuilder]
|
||||
public class WebProxySettingsModel
|
||||
{
|
||||
/// <summary>
|
||||
/// A string instance that contains the address of the proxy server.
|
||||
/// </summary>
|
||||
public string Address { get; set; }
|
||||
public string Address { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// The user name associated with the credentials.
|
||||
/// </summary>
|
||||
public string? UserName { get; set; }
|
||||
/// <summary>
|
||||
/// The user name associated with the credentials.
|
||||
/// </summary>
|
||||
public string? UserName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The password for the user name associated with the credentials.
|
||||
/// </summary>
|
||||
public string? Password { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// The password for the user name associated with the credentials.
|
||||
/// </summary>
|
||||
public string? Password { get; set; }
|
||||
}
|
||||
@@ -373,9 +373,11 @@ internal class MappingConverter
|
||||
mappingModel.Response.UseTransformerForBodyAsFile = null;
|
||||
mappingModel.Response.TransformerReplaceNodeOptions = null;
|
||||
mappingModel.Response.BodyEncoding = null;
|
||||
mappingModel.Response.ProxyUrl = response.ProxyAndRecordSettings.Url;
|
||||
mappingModel.Response.Fault = null;
|
||||
mappingModel.Response.WebProxy = MapWebProxy(response.ProxyAndRecordSettings.WebProxySettings);
|
||||
|
||||
mappingModel.Response.WebProxy = TinyMapperUtils.Instance.Map(response.ProxyAndRecordSettings.WebProxySettings);
|
||||
mappingModel.Response.ProxyUrl = response.ProxyAndRecordSettings.Url;
|
||||
mappingModel.Response.ProxyUrlReplaceSettings = TinyMapperUtils.Instance.Map(response.ProxyAndRecordSettings.ReplaceSettings);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -509,16 +511,6 @@ internal class MappingConverter
|
||||
return values is { } ? string.Join(", ", values.Select(ToCSharpStringLiteral)) : ToCSharpStringLiteral(defaultValue);
|
||||
}
|
||||
|
||||
private static WebProxyModel? MapWebProxy(WebProxySettings? settings)
|
||||
{
|
||||
return settings != null ? new WebProxyModel
|
||||
{
|
||||
Address = settings.Address,
|
||||
UserName = settings.UserName,
|
||||
Password = settings.Password
|
||||
} : null;
|
||||
}
|
||||
|
||||
private static IDictionary<string, object> MapHeaders(IDictionary<string, WireMockList<string>> dictionary)
|
||||
{
|
||||
var newDictionary = new Dictionary<string, object>();
|
||||
|
||||
@@ -280,12 +280,8 @@ public partial class WireMockServer
|
||||
{
|
||||
Url = responseModel.ProxyUrl!,
|
||||
ClientX509Certificate2ThumbprintOrSubjectName = responseModel.X509Certificate2ThumbprintOrSubjectName,
|
||||
WebProxySettings = responseModel.WebProxy != null ? new WebProxySettings
|
||||
{
|
||||
Address = responseModel.WebProxy.Address,
|
||||
UserName = responseModel.WebProxy.UserName,
|
||||
Password = responseModel.WebProxy.Password
|
||||
} : null
|
||||
WebProxySettings = TinyMapperUtils.Instance.Map(responseModel.WebProxy),
|
||||
ReplaceSettings = TinyMapperUtils.Instance.Map(responseModel.ProxyUrlReplaceSettings)
|
||||
};
|
||||
|
||||
return responseBuilder.WithProxy(proxyAndRecordSettings);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Nelibur.ObjectMapper;
|
||||
using WireMock.Admin.Mappings;
|
||||
using WireMock.Admin.Settings;
|
||||
using WireMock.Settings;
|
||||
|
||||
@@ -12,10 +13,12 @@ internal sealed class TinyMapperUtils
|
||||
{
|
||||
TinyMapper.Bind<ProxyAndRecordSettings, ProxyAndRecordSettingsModel>();
|
||||
TinyMapper.Bind<WebProxySettings, WebProxySettingsModel>();
|
||||
TinyMapper.Bind<WebProxySettings, WebProxyModel>();
|
||||
TinyMapper.Bind<ProxyUrlReplaceSettings, ProxyUrlReplaceSettingsModel>();
|
||||
|
||||
TinyMapper.Bind<ProxyAndRecordSettingsModel, ProxyAndRecordSettings>();
|
||||
TinyMapper.Bind<WebProxySettingsModel, WebProxySettings>();
|
||||
TinyMapper.Bind<WebProxyModel, WebProxySettings>();
|
||||
TinyMapper.Bind<ProxyUrlReplaceSettingsModel, ProxyUrlReplaceSettings>();
|
||||
}
|
||||
|
||||
@@ -28,4 +31,24 @@ internal sealed class TinyMapperUtils
|
||||
{
|
||||
return model == null ? null : TinyMapper.Map<ProxyAndRecordSettings>(model);
|
||||
}
|
||||
|
||||
public ProxyUrlReplaceSettingsModel? Map(ProxyUrlReplaceSettings? instance)
|
||||
{
|
||||
return instance == null ? null : TinyMapper.Map<ProxyUrlReplaceSettingsModel>(instance);
|
||||
}
|
||||
|
||||
public ProxyUrlReplaceSettings? Map(ProxyUrlReplaceSettingsModel? model)
|
||||
{
|
||||
return model == null ? null : TinyMapper.Map<ProxyUrlReplaceSettings>(model);
|
||||
}
|
||||
|
||||
public WebProxyModel? Map(WebProxySettings? instance)
|
||||
{
|
||||
return instance == null ? null : TinyMapper.Map<WebProxyModel>(instance);
|
||||
}
|
||||
|
||||
public WebProxySettings? Map(WebProxyModel? model)
|
||||
{
|
||||
return model == null ? null : TinyMapper.Map<WebProxySettings>(model);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
{
|
||||
Guid: 90356dba-b36c-469a-a17e-669cd84f1f05,
|
||||
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: {
|
||||
OldValue: x,
|
||||
NewValue: y,
|
||||
IgnoreCase: true
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -351,6 +351,57 @@ public class WireMockAdminApiTests
|
||||
server.Stop();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task IWireMockAdminApi_GetMappingAsync_WithProxy_And_ProxyUrlReplaceSettings()
|
||||
{
|
||||
// Arrange
|
||||
var guid = Guid.Parse("90356dba-b36c-469a-a17e-669cd84f1f05");
|
||||
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
|
||||
{
|
||||
OldValue = "x",
|
||||
NewValue = "y",
|
||||
IgnoreCase = true
|
||||
}
|
||||
}
|
||||
};
|
||||
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