mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 10:38:15 +08:00
removed thing that checks if route is authorised cos we dont need it
This commit is contained in:
@ -6,7 +6,6 @@ using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.TestHost;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Moq;
|
||||
using Ocelot.Library.Infrastructure.Authentication;
|
||||
using Ocelot.Library.Infrastructure.DownstreamRouteFinder;
|
||||
using Ocelot.Library.Infrastructure.Repository;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
@ -17,9 +16,10 @@ using Xunit;
|
||||
|
||||
namespace Ocelot.UnitTests.Middleware
|
||||
{
|
||||
using Library.Infrastructure.Configuration;
|
||||
|
||||
public class AuthenticationMiddlewareTests : IDisposable
|
||||
{
|
||||
private readonly Mock<IRouteRequiresAuthentication> _requiresAuth;
|
||||
private readonly Mock<IScopedRequestDataRepository> _scopedRepository;
|
||||
private readonly string _url;
|
||||
private readonly TestServer _server;
|
||||
@ -30,13 +30,11 @@ namespace Ocelot.UnitTests.Middleware
|
||||
public AuthenticationMiddlewareTests()
|
||||
{
|
||||
_url = "http://localhost:51879";
|
||||
_requiresAuth = new Mock<IRouteRequiresAuthentication>();
|
||||
_scopedRepository = new Mock<IScopedRequestDataRepository>();
|
||||
|
||||
var builder = new WebHostBuilder()
|
||||
.ConfigureServices(x =>
|
||||
{
|
||||
x.AddSingleton(_requiresAuth.Object);
|
||||
x.AddSingleton(_scopedRepository.Object);
|
||||
})
|
||||
.UseUrls(_url)
|
||||
@ -56,8 +54,7 @@ namespace Ocelot.UnitTests.Middleware
|
||||
[Fact]
|
||||
public void happy_path()
|
||||
{
|
||||
this.Given(x => x.GivenTheDownStreamRouteIs(new DownstreamRoute(new List<TemplateVariableNameAndValue>(), "any old string")))
|
||||
.And(x => x.GivenTheRouteIsNotAuthenticated())
|
||||
this.Given(x => x.GivenTheDownStreamRouteIs(new DownstreamRoute(new List<TemplateVariableNameAndValue>(), new ReRoute("","","","",false, ""))))
|
||||
.When(x => x.WhenICallTheMiddleware())
|
||||
.Then(x => x.ThenNoExceptionsAreThrown())
|
||||
.BDDfy();
|
||||
@ -76,13 +73,6 @@ namespace Ocelot.UnitTests.Middleware
|
||||
.Returns(_downstreamRoute);
|
||||
}
|
||||
|
||||
private void GivenTheRouteIsNotAuthenticated()
|
||||
{
|
||||
_requiresAuth
|
||||
.Setup(x => x.IsAuthenticated(It.IsAny<DownstreamRoute>(), It.IsAny<string>()))
|
||||
.Returns(new OkResponse<bool>(false));
|
||||
}
|
||||
|
||||
private void WhenICallTheMiddleware()
|
||||
{
|
||||
_result = _client.GetAsync(_url).Result;
|
||||
|
@ -4,6 +4,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using Library.Infrastructure.Configuration;
|
||||
using Library.Infrastructure.DownstreamRouteFinder;
|
||||
using Library.Infrastructure.Repository;
|
||||
using Library.Infrastructure.Responses;
|
||||
@ -55,7 +56,7 @@
|
||||
[Fact]
|
||||
public void happy_path()
|
||||
{
|
||||
this.Given(x => x.GivenTheDownStreamRouteFinderReturns(new DownstreamRoute(new List<TemplateVariableNameAndValue>(), "any old string")))
|
||||
this.Given(x => x.GivenTheDownStreamRouteFinderReturns(new DownstreamRoute(new List<TemplateVariableNameAndValue>(), new ReRoute("any old string", "", "", "",false, ""))))
|
||||
.When(x => x.WhenICallTheMiddleware())
|
||||
.Then(x => x.ThenTheScopedDataRepositoryIsCalledCorrectly())
|
||||
.BDDfy();
|
||||
|
@ -4,6 +4,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using Library.Infrastructure.Configuration;
|
||||
using Library.Infrastructure.DownstreamRouteFinder;
|
||||
using Library.Infrastructure.Repository;
|
||||
using Library.Infrastructure.Responses;
|
||||
@ -57,7 +58,7 @@
|
||||
[Fact]
|
||||
public void happy_path()
|
||||
{
|
||||
this.Given(x => x.GivenTheDownStreamRouteIs(new DownstreamRoute(new List<TemplateVariableNameAndValue>(), "any old string")))
|
||||
this.Given(x => x.GivenTheDownStreamRouteIs(new DownstreamRoute(new List<TemplateVariableNameAndValue>(), new ReRoute("any old string", "", "", "", false, ""))))
|
||||
.And(x => x.TheUrlReplacerReturns("any old string"))
|
||||
.When(x => x.WhenICallTheMiddleware())
|
||||
.Then(x => x.ThenTheScopedDataRepositoryIsCalledCorrectly())
|
||||
|
Reference in New Issue
Block a user