mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-24 01:08:28 +02:00
.
This commit is contained in:
@@ -45,12 +45,12 @@ public class ProxyAndRecordSettingsModel
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines a list from headers which will be excluded from the saved mappings.
|
/// Defines a list from headers which will be excluded from the saved mappings.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string[] ExcludedHeaders { get; set; }
|
public string[] ExcludedHeaders { get; set; } = [];
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines a list of cookies which will be excluded from the saved mappings.
|
/// Defines a list of cookies which will be excluded from the saved mappings.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string[] ExcludedCookies { get; set; }
|
public string[] ExcludedCookies { get; set; } = [];
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Prefer the Proxy Mapping over the saved Mapping (in case SaveMapping is set to <c>true</c>).
|
/// Prefer the Proxy Mapping over the saved Mapping (in case SaveMapping is set to <c>true</c>).
|
||||||
|
|||||||
@@ -32,11 +32,6 @@
|
|||||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<None Remove="../../resources/WireMock.Net-Logo.png" />
|
|
||||||
<None Include="../../resources/WireMock.Net-LogoAspire.png" Pack="true" PackagePath="" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.2" />
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ internal class GlobalExceptionMiddleware
|
|||||||
_responseMapper = Guard.NotNull(responseMapper);
|
_responseMapper = Guard.NotNull(responseMapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RequestDelegate? Next { get; }
|
public RequestDelegate Next { get; }
|
||||||
|
|
||||||
public Task Invoke(HttpContext ctx)
|
public Task Invoke(HttpContext ctx)
|
||||||
{
|
{
|
||||||
@@ -30,10 +30,7 @@ internal class GlobalExceptionMiddleware
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (Next != null)
|
await Next.Invoke(ctx).ConfigureAwait(false);
|
||||||
{
|
|
||||||
await Next.Invoke(ctx).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
// Copyright © WireMock.Net
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using WireMock.Constants;
|
using WireMock.Constants;
|
||||||
@@ -18,7 +17,9 @@ using WireMock.Util;
|
|||||||
namespace WireMock.Owin;
|
namespace WireMock.Owin;
|
||||||
|
|
||||||
internal class WireMockMiddleware(
|
internal class WireMockMiddleware(
|
||||||
|
#pragma warning disable CS9113 // Parameter is unread.
|
||||||
RequestDelegate next,
|
RequestDelegate next,
|
||||||
|
#pragma warning restore CS9113 // Parameter is unread.
|
||||||
IWireMockMiddlewareOptions options,
|
IWireMockMiddlewareOptions options,
|
||||||
IOwinRequestMapper requestMapper,
|
IOwinRequestMapper requestMapper,
|
||||||
IOwinResponseMapper responseMapper,
|
IOwinResponseMapper responseMapper,
|
||||||
|
|||||||
@@ -298,7 +298,7 @@ internal class OpenApiPathsMapper(WireMockOpenApiParserSettings settings)
|
|||||||
var mappedHeaders = headers?
|
var mappedHeaders = headers?
|
||||||
.ToDictionary(item => item.Key, _ => GetExampleMatcherModel(null, _settings.HeaderPatternToUse).Pattern!) ?? [];
|
.ToDictionary(item => item.Key, _ => GetExampleMatcherModel(null, _settings.HeaderPatternToUse).Pattern!) ?? [];
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(responseContentType))
|
if (responseContentType != null)
|
||||||
{
|
{
|
||||||
mappedHeaders.TryAdd(HeaderContentType, responseContentType);
|
mappedHeaders.TryAdd(HeaderContentType, responseContentType);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright © WireMock.Net
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
using System;
|
|
||||||
using WireMock.Models;
|
using WireMock.Models;
|
||||||
using WireMock.Util;
|
using WireMock.Util;
|
||||||
|
|
||||||
@@ -40,6 +39,6 @@ public class RequestMessageProtoBufMatcher : IRequestMatcher
|
|||||||
|
|
||||||
private MatchResult GetMatchResult(IRequestMessage requestMessage)
|
private MatchResult GetMatchResult(IRequestMessage requestMessage)
|
||||||
{
|
{
|
||||||
return Matcher?.IsMatchAsync(requestMessage.BodyAsBytes).GetAwaiter().GetResult() ?? default;
|
return Matcher?.IsMatchAsync(requestMessage.BodyAsBytes).GetAwaiter().GetResult() ?? MatchResult.From(nameof(RequestMessageProtoBufMatcher));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -582,7 +582,7 @@ public class WireMockAdminApiAssertionsTests : IDisposable
|
|||||||
public async Task HaveReceivedACall_FromClientIP_whenACallWasMadeFromClientIP_Should_BeOK()
|
public async Task HaveReceivedACall_FromClientIP_whenACallWasMadeFromClientIP_Should_BeOK()
|
||||||
{
|
{
|
||||||
await _httpClient.GetAsync("", _ct);
|
await _httpClient.GetAsync("", _ct);
|
||||||
var clientIP = _server.LogEntries.Last().RequestMessage.ClientIP;
|
var clientIP = _server.LogEntries.Last().RequestMessage!.ClientIP;
|
||||||
|
|
||||||
_adminApi.Should()
|
_adminApi.Should()
|
||||||
.HaveReceivedACall()
|
.HaveReceivedACall()
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Moq;
|
using Moq;
|
||||||
|
using WireMock.Logging;
|
||||||
using WireMock.Owin;
|
using WireMock.Owin;
|
||||||
using WireMock.Owin.Mappers;
|
using WireMock.Owin.Mappers;
|
||||||
|
|
||||||
@@ -17,20 +18,32 @@ public class GlobalExceptionMiddlewareTests
|
|||||||
public GlobalExceptionMiddlewareTests()
|
public GlobalExceptionMiddlewareTests()
|
||||||
{
|
{
|
||||||
_optionsMock = new Mock<IWireMockMiddlewareOptions>();
|
_optionsMock = new Mock<IWireMockMiddlewareOptions>();
|
||||||
_optionsMock.SetupAllProperties();
|
_optionsMock.SetupGet(o => o.Logger).Returns(Mock.Of<IWireMockLogger>());
|
||||||
|
|
||||||
_responseMapperMock = new Mock<IOwinResponseMapper>();
|
_responseMapperMock = new Mock<IOwinResponseMapper>();
|
||||||
_responseMapperMock.SetupAllProperties();
|
|
||||||
_responseMapperMock.Setup(m => m.MapAsync(It.IsAny<ResponseMessage?>(), It.IsAny<HttpResponse>())).Returns(Task.FromResult(true));
|
_responseMapperMock.Setup(m => m.MapAsync(It.IsAny<ResponseMessage?>(), It.IsAny<HttpResponse>())).Returns(Task.FromResult(true));
|
||||||
|
|
||||||
_sut = new GlobalExceptionMiddleware(null, _optionsMock.Object, _responseMapperMock.Object);
|
_sut = new GlobalExceptionMiddleware(_ => Task.CompletedTask, _optionsMock.Object, _responseMapperMock.Object);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void GlobalExceptionMiddleware_Invoke_NullAsNext_DoesNotInvokeNextAndDoesNotThrow()
|
public void GlobalExceptionMiddleware_Invoke_ValidNext_ShouldNotThrow()
|
||||||
{
|
{
|
||||||
// Act
|
// Act
|
||||||
Action act = () => _sut.Invoke(null);
|
_sut.Invoke(Mock.Of<HttpContext>());
|
||||||
act.Should().NotThrow();
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GlobalExceptionMiddleware_Invoke_InvalidNext_ShouldCallResponseMapperWith500()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var sut = new GlobalExceptionMiddleware(_ => throw new ArgumentException(), _optionsMock.Object, _responseMapperMock.Object);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
sut.Invoke(Mock.Of<HttpContext>());
|
||||||
|
|
||||||
|
// Verify
|
||||||
|
_responseMapperMock.Verify(m => m.MapAsync(It.IsAny<ResponseMessage>(), It.IsAny<HttpResponse>()), Times.Once);
|
||||||
|
_responseMapperMock.VerifyNoOtherCalls();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -35,7 +35,7 @@ public class ResponseWithBodyFromFileTests
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var response = await new HttpClient().GetStringAsync("http://localhost:" + server.Ports[0] + "/v1/content");
|
var response = await new HttpClient().GetStringAsync("http://localhost:" + server.Ports[0] + "/v1/content", _ct);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
response.Should().Contain("<hello>world</hello>");
|
response.Should().Contain("<hello>world</hello>");
|
||||||
|
|||||||
@@ -796,7 +796,7 @@ public class WebSocketIntegrationTests(ITestOutputHelper output, ITestContextAcc
|
|||||||
var proxyUri = new Uri($"{sut.Url}/ws/proxy");
|
var proxyUri = new Uri($"{sut.Url}/ws/proxy");
|
||||||
await client.ConnectAsync(proxyUri, _ct);
|
await client.ConnectAsync(proxyUri, _ct);
|
||||||
|
|
||||||
await Task.Delay(500, _ct);
|
await Task.Delay(250, _ct);
|
||||||
|
|
||||||
var testData = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 };
|
var testData = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 };
|
||||||
|
|
||||||
@@ -805,6 +805,8 @@ public class WebSocketIntegrationTests(ITestOutputHelper output, ITestContextAcc
|
|||||||
|
|
||||||
var receivedData = await client.ReceiveAsBytesAsync(cancellationToken: _ct);
|
var receivedData = await client.ReceiveAsBytesAsync(cancellationToken: _ct);
|
||||||
|
|
||||||
|
await Task.Delay(250, _ct);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
receivedData.Should().BeEquivalentTo(testData, "binary data should be proxied and echoed back");
|
receivedData.Should().BeEquivalentTo(testData, "binary data should be proxied and echoed back");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user