mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-26 19:31:48 +01:00
Fix recorded requests skipped by request logger (#346)
* Fix recorded requests skipped request logger. - When proxy is enabled the recorded requests are mistaken (IMO) for admin requests and skipped * Add unit test * Use different solution * Introduce IsRecordedByProxy property on Mapping class * Cleanup empty lines * Refactored fix suggested way
This commit is contained in:
committed by
Stef Heyenrath
parent
e1798fbb8e
commit
feea64b328
@@ -79,6 +79,14 @@ namespace WireMock
|
|||||||
/// </value>
|
/// </value>
|
||||||
bool IsAdminInterface { get; }
|
bool IsAdminInterface { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether this mapping to be logged.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>
|
||||||
|
/// <c>true</c> if this mapping to be logged; otherwise, <c>false</c>.
|
||||||
|
/// </value>
|
||||||
|
bool LogMapping { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// ProvideResponseAsync
|
/// ProvideResponseAsync
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -48,6 +48,9 @@ namespace WireMock
|
|||||||
/// <inheritdoc cref="IMapping.IsAdminInterface" />
|
/// <inheritdoc cref="IMapping.IsAdminInterface" />
|
||||||
public bool IsAdminInterface => Provider is DynamicResponseProvider || Provider is DynamicAsyncResponseProvider || Provider is ProxyAsyncResponseProvider;
|
public bool IsAdminInterface => Provider is DynamicResponseProvider || Provider is DynamicAsyncResponseProvider || Provider is ProxyAsyncResponseProvider;
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IMapping.LogMapping" />
|
||||||
|
public bool LogMapping => !(Provider is DynamicResponseProvider || Provider is DynamicAsyncResponseProvider);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="Mapping"/> class.
|
/// Initializes a new instance of the <see cref="Mapping"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ using WireMock.Util;
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using WireMock.Http;
|
using WireMock.Http;
|
||||||
using WireMock.Owin.Mappers;
|
using WireMock.Owin.Mappers;
|
||||||
|
using WireMock.ResponseProviders;
|
||||||
using WireMock.Serialization;
|
using WireMock.Serialization;
|
||||||
using WireMock.Validation;
|
using WireMock.Validation;
|
||||||
#if !USE_ASPNETCORE
|
#if !USE_ASPNETCORE
|
||||||
@@ -99,7 +100,7 @@ namespace WireMock.Owin
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
logRequest = !targetMapping.IsAdminInterface;
|
logRequest = !targetMapping.IsAdminInterface || targetMapping.LogMapping;
|
||||||
|
|
||||||
if (targetMapping.IsAdminInterface && _options.AuthorizationMatcher != null)
|
if (targetMapping.IsAdminInterface && _options.AuthorizationMatcher != null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -18,6 +18,35 @@ namespace WireMock.Net.Tests
|
|||||||
{
|
{
|
||||||
public class FluentMockServerProxyTests
|
public class FluentMockServerProxyTests
|
||||||
{
|
{
|
||||||
|
[Fact]
|
||||||
|
public async Task FluentMockServer_Proxy_Should_log_proxied_requests()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var settings = new FluentMockServerSettings
|
||||||
|
{
|
||||||
|
ProxyAndRecordSettings = new ProxyAndRecordSettings
|
||||||
|
{
|
||||||
|
Url = "http://www.google.com",
|
||||||
|
SaveMapping = true,
|
||||||
|
SaveMappingToFile = false
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var server = FluentMockServer.Start(settings);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var requestMessage = new HttpRequestMessage
|
||||||
|
{
|
||||||
|
Method = HttpMethod.Get,
|
||||||
|
RequestUri = new Uri(server.Urls[0])
|
||||||
|
};
|
||||||
|
var httpClientHandler = new HttpClientHandler { AllowAutoRedirect = false };
|
||||||
|
await new HttpClient(httpClientHandler).SendAsync(requestMessage);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(server.Mappings).HasSize(2);
|
||||||
|
Check.That(server.LogEntries).HasSize(1);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task FluentMockServer_Proxy_Should_proxy_responses()
|
public async Task FluentMockServer_Proxy_Should_proxy_responses()
|
||||||
{
|
{
|
||||||
@@ -40,6 +69,7 @@ namespace WireMock.Net.Tests
|
|||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(server.Mappings).HasSize(1);
|
Check.That(server.Mappings).HasSize(1);
|
||||||
|
Check.That(server.LogEntries).HasSize(1);
|
||||||
Check.That(content).Contains("google");
|
Check.That(content).Contains("google");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user