-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #107 from TomPallister/feature/tokens-work-across-…
…ocelots Feature/tokens work across ocelots
- Loading branch information
Showing
15 changed files
with
242 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/Ocelot/Authentication/Handler/Creator/AuthenticationHandlerCreator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"Logging": { | ||
"IncludeScopes": true, | ||
"LogLevel": { | ||
"Default": "Error", | ||
"System": "Error", | ||
"Microsoft": "Error" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
16 changes: 16 additions & 0 deletions
16
test/Ocelot.UnitTests/Configuration/IdentityServerConfigurationCreatorTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Ocelot.Configuration.Creator; | ||
using Shouldly; | ||
using Xunit; | ||
|
||
namespace Ocelot.UnitTests.Configuration | ||
{ | ||
public class IdentityServerConfigurationCreatorTests | ||
{ | ||
[Fact] | ||
public void happy_path_only_exists_for_test_coverage_even_uncle_bob_probably_wouldnt_test_this() | ||
{ | ||
var result = IdentityServerConfigurationCreator.GetIdentityServerConfiguration(); | ||
result.ApiName.ShouldBe("admin"); | ||
} | ||
} | ||
} |
125 changes: 125 additions & 0 deletions
125
test/Ocelot.UnitTests/Errors/ExceptionHandlerMiddlewareTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
using System; | ||
using System.IO; | ||
using System.Net; | ||
using System.Net.Http; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.TestHost; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Moq; | ||
using Ocelot.DownstreamRouteFinder; | ||
using Ocelot.DownstreamUrlCreator; | ||
using Ocelot.DownstreamUrlCreator.UrlTemplateReplacer; | ||
using Ocelot.Errors.Middleware; | ||
using Ocelot.Infrastructure.RequestData; | ||
using Ocelot.Logging; | ||
using Ocelot.Responses; | ||
using Ocelot.Values; | ||
using Shouldly; | ||
using TestStack.BDDfy; | ||
using Xunit; | ||
|
||
namespace Ocelot.UnitTests.Errors | ||
{ | ||
public class ExceptionHandlerMiddlewareTests | ||
{ | ||
private readonly Mock<IRequestScopedDataRepository> _scopedRepository; | ||
private readonly string _url; | ||
private TestServer _server; | ||
private HttpClient _client; | ||
private HttpResponseMessage _result; | ||
|
||
public ExceptionHandlerMiddlewareTests() | ||
{ | ||
_url = "http://localhost:52879"; | ||
_scopedRepository = new Mock<IRequestScopedDataRepository>(); | ||
} | ||
|
||
[Fact] | ||
public void should_call_next_middleware() | ||
{ | ||
this.Given(_ => GivenASuccessfulRequest()) | ||
.When(_ => WhenIMakeTheRequest()) | ||
.Then(_ => ThenTheResponseIsOk()) | ||
.BDDfy(); | ||
} | ||
|
||
[Fact] | ||
public void should_call_return_error() | ||
{ | ||
this.Given(_ => GivenAnError()) | ||
.When(_ => WhenIMakeTheRequest()) | ||
.Then(_ => ThenTheResponseIsError()) | ||
.BDDfy(); | ||
} | ||
|
||
private void ThenTheResponseIsOk() | ||
{ | ||
_result.StatusCode.ShouldBe(HttpStatusCode.OK); | ||
} | ||
|
||
private void ThenTheResponseIsError() | ||
{ | ||
_result.StatusCode.ShouldBe(HttpStatusCode.InternalServerError); | ||
} | ||
|
||
private void WhenIMakeTheRequest() | ||
{ | ||
_result = _client.GetAsync("/").Result; | ||
} | ||
|
||
private void GivenASuccessfulRequest() | ||
{ | ||
var builder = new WebHostBuilder() | ||
.ConfigureServices(x => | ||
{ | ||
x.AddSingleton<IOcelotLoggerFactory, AspDotNetLoggerFactory>(); | ||
x.AddLogging(); | ||
x.AddSingleton(_scopedRepository.Object); | ||
}) | ||
.UseUrls(_url) | ||
.UseKestrel() | ||
.UseContentRoot(Directory.GetCurrentDirectory()) | ||
.UseIISIntegration() | ||
.UseUrls(_url) | ||
.Configure(app => | ||
{ | ||
app.UseExceptionHandlerMiddleware(); | ||
app.Run(async context => | ||
{ | ||
context.Response.StatusCode = 200; | ||
}); | ||
}); | ||
|
||
_server = new TestServer(builder); | ||
_client = _server.CreateClient(); | ||
} | ||
|
||
private void GivenAnError() | ||
{ | ||
var builder = new WebHostBuilder() | ||
.ConfigureServices(x => | ||
{ | ||
x.AddSingleton<IOcelotLoggerFactory, AspDotNetLoggerFactory>(); | ||
x.AddLogging(); | ||
x.AddSingleton(_scopedRepository.Object); | ||
}) | ||
.UseUrls(_url) | ||
.UseKestrel() | ||
.UseContentRoot(Directory.GetCurrentDirectory()) | ||
.UseIISIntegration() | ||
.UseUrls(_url) | ||
.Configure(app => | ||
{ | ||
app.UseExceptionHandlerMiddleware(); | ||
app.Use(async (context, next) => | ||
{ | ||
throw new Exception("BOOM"); | ||
}); | ||
}); | ||
|
||
_server = new TestServer(builder); | ||
_client = _server.CreateClient(); | ||
} | ||
} | ||
} |