Mark BlacklistedHeaders and BlacklistedCookies as obsolete (#492)

* #489

* .

* FluentMockServerSettings
This commit is contained in:
Stef Heyenrath
2020-07-27 17:24:24 +02:00
committed by GitHub
parent 9491280fd2
commit 9a532108b8
9 changed files with 39 additions and 29 deletions

View File

@@ -13,9 +13,9 @@ namespace WireMock.Net.StandAlone
public static class StandAloneApp public static class StandAloneApp
{ {
/// <summary> /// <summary>
/// Start WireMock.Net standalone Server based on the FluentMockServerSettings. /// Start WireMock.Net standalone Server based on the IWireMockServerSettings.
/// </summary> /// </summary>
/// <param name="settings">The FluentMockServerSettings</param> /// <param name="settings">The IWireMockServerSettings</param>
[PublicAPI] [PublicAPI]
public static WireMockServer Start([NotNull] IWireMockServerSettings settings) public static WireMockServer Start([NotNull] IWireMockServerSettings settings)
{ {

View File

@@ -1,7 +1,9 @@
using WireMock.Settings; using System;
using WireMock.Settings;
namespace WireMock.Server namespace WireMock.Server
{ {
[Obsolete("Use WireMockServer. This will removed in next version (1.3.x)")]
public class FluentMockServer : WireMockServer public class FluentMockServer : WireMockServer
{ {
public FluentMockServer(IFluentMockServerSettings settings) : base((IWireMockServerSettings) settings) public FluentMockServer(IFluentMockServerSettings settings) : base((IWireMockServerSettings) settings)

View File

@@ -290,7 +290,7 @@ namespace WireMock.Server
return responseMessage; return responseMessage;
} }
private IMapping ToMapping(RequestMessage requestMessage, ResponseMessage responseMessage, string[] blacklistedHeaders, string[] blacklistedCookies) private IMapping ToMapping(RequestMessage requestMessage, ResponseMessage responseMessage, string[] excludedHeaders, string[] excludedCookies)
{ {
var request = Request.Create(); var request = Request.Create();
request.WithPath(requestMessage.Path); request.WithPath(requestMessage.Path);
@@ -299,16 +299,16 @@ namespace WireMock.Server
requestMessage.Query.Loop((key, value) => request.WithParam(key, false, value.ToArray())); requestMessage.Query.Loop((key, value) => request.WithParam(key, false, value.ToArray()));
requestMessage.Cookies.Loop((key, value) => requestMessage.Cookies.Loop((key, value) =>
{ {
if (!blacklistedCookies.Contains(key, StringComparer.OrdinalIgnoreCase)) if (!excludedCookies.Contains(key, StringComparer.OrdinalIgnoreCase))
{ {
request.WithCookie(key, value); request.WithCookie(key, value);
} }
}); });
var allBlackListedHeaders = new List<string>(blacklistedHeaders) { "Cookie" }; var allExcludedHeaders = new List<string>(excludedHeaders) { "Cookie" };
requestMessage.Headers.Loop((key, value) => requestMessage.Headers.Loop((key, value) =>
{ {
if (!allBlackListedHeaders.Contains(key, StringComparer.OrdinalIgnoreCase)) if (!allExcludedHeaders.Contains(key, StringComparer.OrdinalIgnoreCase))
{ {
request.WithHeader(key, value.ToArray()); request.WithHeader(key, value.ToArray());
} }

View File

@@ -1,8 +1,11 @@
namespace WireMock.Settings using System;
namespace WireMock.Settings
{ {
/// <summary> /// <summary>
/// FluentMockServerSettings /// FluentMockServerSettings
/// </summary> /// </summary>
[Obsolete("Use WireMockServerSettings. This will removed in next version (1.3.x)")]
public class FluentMockServerSettings : WireMockServerSettings public class FluentMockServerSettings : WireMockServerSettings
{ {
} }

View File

@@ -1,8 +1,11 @@
namespace WireMock.Settings using System;
namespace WireMock.Settings
{ {
/// <summary> /// <summary>
/// IFluentMockServerSettings /// IFluentMockServerSettings
/// </summary> /// </summary>
[Obsolete("Use IWireMockServerSettings. This will removed in next version (1.3.x)")]
public interface IFluentMockServerSettings : IWireMockServerSettings public interface IFluentMockServerSettings : IWireMockServerSettings
{ {
} }

View File

@@ -1,4 +1,5 @@
using JetBrains.Annotations; using System;
using JetBrains.Annotations;
namespace WireMock.Settings namespace WireMock.Settings
{ {
@@ -38,11 +39,13 @@ namespace WireMock.Settings
/// <summary> /// <summary>
/// Defines a list from headers which will excluded from the saved mappings. /// Defines a list from headers which will excluded from the saved mappings.
/// </summary> /// </summary>
[Obsolete("Will be renamed to ExcludedHeaders in next version (1.3.x)")]
string[] BlackListedHeaders { get; set; } string[] BlackListedHeaders { get; set; }
/// <summary> /// <summary>
/// Defines a list of cookies which will excluded from the saved mappings. /// Defines a list of cookies which will excluded from the saved mappings.
/// </summary> /// </summary>
[Obsolete("Will be renamed to ExcludedCookies in next version (1.3.x)")]
string[] BlackListedCookies { get; set; } string[] BlackListedCookies { get; set; }
/// <summary> /// <summary>

View File

@@ -1,4 +1,5 @@
using JetBrains.Annotations; using System;
using JetBrains.Annotations;
namespace WireMock.Settings namespace WireMock.Settings
{ {
@@ -39,16 +40,14 @@ namespace WireMock.Settings
[PublicAPI] [PublicAPI]
public string ClientX509Certificate2ThumbprintOrSubjectName { get; set; } public string ClientX509Certificate2ThumbprintOrSubjectName { get; set; }
/// <summary> /// <inheritdoc cref="IProxyAndRecordSettings.BlackListedHeaders"/>
/// Defines a list from headers which will excluded from the saved mappings.
/// </summary>
[PublicAPI] [PublicAPI]
[Obsolete("Will be renamed to ExcludedHeaders in next version (1.3.x)")]
public string[] BlackListedHeaders { get; set; } public string[] BlackListedHeaders { get; set; }
/// <summary> /// <inheritdoc cref="IProxyAndRecordSettings.BlackListedCookies"/>
/// Defines a list of cookies which will excluded from the saved mappings.
/// </summary>
[PublicAPI] [PublicAPI]
[Obsolete("Will be renamed to ExcludedCookies in next version (1.3.x)")]
public string[] BlackListedCookies { get; set; } public string[] BlackListedCookies { get; set; }
/// <inheritdoc cref="IProxyAndRecordSettings.WebProxySettings"/> /// <inheritdoc cref="IProxyAndRecordSettings.WebProxySettings"/>

View File

@@ -11,7 +11,7 @@ namespace WireMock.Net.Tests.ResponseBuilders
{ {
public class ResponseWithStatusCodeTests public class ResponseWithStatusCodeTests
{ {
private readonly Mock<IFluentMockServerSettings> _settingsMock = new Mock<IFluentMockServerSettings>(); private readonly Mock<IWireMockServerSettings> _settingsMock = new Mock<IWireMockServerSettings>();
private const string ClientIp = "::1"; private const string ClientIp = "::1";
[Theory] [Theory]

View File

@@ -33,9 +33,9 @@ namespace WireMock.Net.Tests
SaveMappingToFile = false SaveMappingToFile = false
} }
}; };
var server = WireMockServer.Start(settings); var server = WireMockServer.Start(settings);
// Act // Act
var requestMessage = new HttpRequestMessage var requestMessage = new HttpRequestMessage
{ {
Method = HttpMethod.Get, Method = HttpMethod.Get,
@@ -47,8 +47,8 @@ namespace WireMock.Net.Tests
// Assert // Assert
Check.That(server.Mappings).HasSize(2); Check.That(server.Mappings).HasSize(2);
Check.That(server.LogEntries).HasSize(1); Check.That(server.LogEntries).HasSize(1);
} }
[Fact] [Fact]
public async Task WireMockServer_Proxy_Should_proxy_responses() public async Task WireMockServer_Proxy_Should_proxy_responses()
{ {
@@ -123,7 +123,7 @@ namespace WireMock.Net.Tests
} }
[Fact] [Fact]
public async Task WireMockServer_Proxy_Should_exclude_blacklisted_content_header_in_mapping() public async Task WireMockServer_Proxy_Should_exclude_ExcludedHeaders_in_mapping()
{ {
// Assign // Assign
string path = $"/prx_{Guid.NewGuid()}"; string path = $"/prx_{Guid.NewGuid()}";
@@ -139,7 +139,7 @@ namespace WireMock.Net.Tests
Url = serverForProxyForwarding.Urls[0], Url = serverForProxyForwarding.Urls[0],
SaveMapping = true, SaveMapping = true,
SaveMappingToFile = false, SaveMappingToFile = false,
BlackListedHeaders = new[] { "blacklisted" } BlackListedHeaders = new[] { "excluded-header-X" }
} }
}; };
var server = WireMockServer.Start(settings); var server = WireMockServer.Start(settings);
@@ -152,7 +152,7 @@ namespace WireMock.Net.Tests
RequestUri = new Uri($"{server.Urls[0]}{path}"), RequestUri = new Uri($"{server.Urls[0]}{path}"),
Content = new StringContent("stringContent") Content = new StringContent("stringContent")
}; };
requestMessage.Headers.Add("blacklisted", "exact_match"); requestMessage.Headers.Add("foobar", "exact_match");
requestMessage.Headers.Add("ok", "ok-value"); requestMessage.Headers.Add("ok", "ok-value");
await new HttpClient().SendAsync(requestMessage); await new HttpClient().SendAsync(requestMessage);
@@ -160,12 +160,12 @@ namespace WireMock.Net.Tests
var mapping = server.Mappings.FirstOrDefault(m => m.Guid != defaultMapping.Guid); var mapping = server.Mappings.FirstOrDefault(m => m.Guid != defaultMapping.Guid);
Check.That(mapping).IsNotNull(); Check.That(mapping).IsNotNull();
var matchers = ((Request)mapping.RequestMatcher).GetRequestMessageMatchers<RequestMessageHeaderMatcher>().Select(m => m.Name).ToList(); var matchers = ((Request)mapping.RequestMatcher).GetRequestMessageMatchers<RequestMessageHeaderMatcher>().Select(m => m.Name).ToList();
Check.That(matchers).Not.Contains("blacklisted"); Check.That(matchers).Not.Contains("excluded-header-X");
Check.That(matchers).Contains("ok"); Check.That(matchers).Contains("ok");
} }
[Fact] [Fact]
public async Task WireMockServer_Proxy_Should_exclude_blacklisted_cookies_in_mapping() public async Task WireMockServer_Proxy_Should_exclude_ExcludedCookies_in_mapping()
{ {
// Assign // Assign
string path = $"/prx_{Guid.NewGuid()}"; string path = $"/prx_{Guid.NewGuid()}";
@@ -515,7 +515,7 @@ namespace WireMock.Net.Tests
content.Should().Contain("known"); // On Linux it's "Name or service not known". On Windows it's "No such host is known.". content.Should().Contain("known"); // On Linux it's "Name or service not known". On Windows it's "No such host is known.".
server.LogEntries.Should().HaveCount(1); server.LogEntries.Should().HaveCount(1);
((StatusModel) server.LogEntries.First().ResponseMessage.BodyData.BodyAsJson).Status.Should().Contain("known"); ((StatusModel)server.LogEntries.First().ResponseMessage.BodyData.BodyAsJson).Status.Should().Contain("known");
} }
} }
} }