Feature/#623 (#632)

* #630 only set status code if response hasnt started, otherwise exception

* #623 made {RemoteIpAddress} available as placeholder so you can do x-forwarded-for

* #623 local address different on mac, windows and linux for integration test
This commit is contained in:
Tom Pallister
2018-09-24 08:22:44 +01:00
committed by GitHub
parent 54cdc74293
commit aa14b2f877
14 changed files with 487 additions and 112 deletions

View File

@ -1,27 +1,31 @@
using System;
using System.Net.Http;
using Moq;
using Ocelot.Infrastructure;
using Ocelot.Infrastructure.RequestData;
using Ocelot.Middleware;
using Ocelot.Request.Middleware;
using Ocelot.Responses;
using Shouldly;
using Xunit;
namespace Ocelot.UnitTests.Infrastructure
{
using Microsoft.AspNetCore.Http;
using System;
using System.Net;
using System.Net.Http;
using Moq;
using Ocelot.Infrastructure;
using Ocelot.Infrastructure.RequestData;
using Ocelot.Middleware;
using Ocelot.Request.Middleware;
using Ocelot.Responses;
using Shouldly;
using Xunit;
public class PlaceholdersTests
{
private IPlaceholders _placeholders;
private Mock<IBaseUrlFinder> _finder;
private Mock<IRequestScopedDataRepository> _repo;
private readonly IPlaceholders _placeholders;
private readonly Mock<IBaseUrlFinder> _finder;
private readonly Mock<IRequestScopedDataRepository> _repo;
private readonly Mock<IHttpContextAccessor> _accessor;
public PlaceholdersTests()
{
_accessor = new Mock<IHttpContextAccessor>();
_repo = new Mock<IRequestScopedDataRepository>();
_finder = new Mock<IBaseUrlFinder>();
_placeholders = new Placeholders(_finder.Object, _repo.Object);
_placeholders = new Placeholders(_finder.Object, _repo.Object, _accessor.Object);
}
[Fact]
@ -33,6 +37,15 @@ namespace Ocelot.UnitTests.Infrastructure
result.Data.ShouldBe(baseUrl);
}
[Fact]
public void should_return_remote_ip_address()
{
var httpContext = new DefaultHttpContext(){Connection = { RemoteIpAddress = IPAddress.Any}};
_accessor.Setup(x => x.HttpContext).Returns(httpContext);
var result = _placeholders.Get("{RemoteIpAddress}");
result.Data.ShouldBe(httpContext.Connection.RemoteIpAddress.ToString());
}
[Fact]
public void should_return_key_does_not_exist()
{