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