mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 02:18:15 +08:00
Feature/use any id server for admin area (#232)
* initial commits around using any id servers * add your own id server for admin area * lots of refactoring, now instead of injecting IWebHostBuilder we just set the Ocelot base url as a configuration extension method..this means people can pass it in on the command line aswell as hardcode which is OK I guess, also can now use your own IdentityServer to authenticate admin area * updated docs for #231 * some tests that hopefully bump up coverage
This commit is contained in:
@ -15,6 +15,7 @@ namespace Ocelot.UnitTests.Errors
|
||||
using Moq;
|
||||
using Ocelot.Configuration;
|
||||
using Rafty.Concensus;
|
||||
using Ocelot.Errors;
|
||||
|
||||
public class ExceptionHandlerMiddlewareTests : ServerHostedMiddlewareTest
|
||||
{
|
||||
@ -40,11 +41,6 @@ namespace Ocelot.UnitTests.Errors
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
private void TheRequestIdIsNotSet()
|
||||
{
|
||||
ScopedRepository.Verify(x => x.Add<string>(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DownstreamException()
|
||||
{
|
||||
@ -83,6 +79,55 @@ namespace Ocelot.UnitTests.Errors
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_throw_exception_if_config_provider_returns_error()
|
||||
{
|
||||
this.Given(_ => GivenAnExceptionWillNotBeThrownDownstream())
|
||||
.And(_ => GivenTheConfigReturnsError())
|
||||
.When(_ => WhenICallTheMiddlewareWithTheRequestIdKey("requestidkey", "1234"))
|
||||
.Then(_ => ThenAnExceptionIsThrown())
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_throw_exception_if_config_provider_throws()
|
||||
{
|
||||
this.Given(_ => GivenAnExceptionWillNotBeThrownDownstream())
|
||||
.And(_ => GivenTheConfigThrows())
|
||||
.When(_ => WhenICallTheMiddlewareWithTheRequestIdKey("requestidkey", "1234"))
|
||||
.Then(_ => ThenAnExceptionIsThrown())
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
private void GivenTheConfigThrows()
|
||||
{
|
||||
var ex = new Exception("outer", new Exception("inner"));
|
||||
_provider
|
||||
.Setup(x => x.Get()).ThrowsAsync(ex);
|
||||
}
|
||||
|
||||
private void ThenAnExceptionIsThrown()
|
||||
{
|
||||
ResponseMessage.StatusCode.ShouldBe(HttpStatusCode.InternalServerError);
|
||||
}
|
||||
|
||||
private void GivenTheConfigReturnsError()
|
||||
{
|
||||
var config = new OcelotConfiguration(null, null, null, null);
|
||||
|
||||
var response = new Ocelot.Responses.ErrorResponse<IOcelotConfiguration>(new FakeError());
|
||||
_provider
|
||||
.Setup(x => x.Get()).ReturnsAsync(response);
|
||||
}
|
||||
|
||||
public class FakeError : Error
|
||||
{
|
||||
public FakeError()
|
||||
: base("meh", OcelotErrorCode.CannotAddDataError)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private void TheRequestIdIsSet(string key, string value)
|
||||
{
|
||||
ScopedRepository.Verify(x => x.Add<string>(key, value), Times.Once);
|
||||
@ -140,5 +185,10 @@ namespace Ocelot.UnitTests.Errors
|
||||
{
|
||||
ResponseMessage.StatusCode.ShouldBe(HttpStatusCode.InternalServerError);
|
||||
}
|
||||
|
||||
private void TheRequestIdIsNotSet()
|
||||
{
|
||||
ScopedRepository.Verify(x => x.Add<string>(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user