mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 16:18:14 +08:00
rename authorisation to authorization
This commit is contained in:
@ -3,8 +3,8 @@ namespace Ocelot.UnitTests.Authorization
|
||||
{
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Moq;
|
||||
using Ocelot.Authorisation;
|
||||
using Ocelot.Authorisation.Middleware;
|
||||
using Ocelot.Authorization;
|
||||
using Ocelot.Authorization.Middleware;
|
||||
using Ocelot.Configuration;
|
||||
using Ocelot.Configuration.Builder;
|
||||
using Ocelot.DownstreamRouteFinder.Middleware;
|
||||
@ -18,35 +18,35 @@ namespace Ocelot.UnitTests.Authorization
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
|
||||
public class AuthorisationMiddlewareTests
|
||||
public class AuthorizationMiddlewareTests
|
||||
{
|
||||
private readonly Mock<IClaimsAuthoriser> _authService;
|
||||
private readonly Mock<IScopesAuthoriser> _authScopesService;
|
||||
private readonly Mock<IClaimsAuthorizer> _authService;
|
||||
private readonly Mock<IScopesAuthorizer> _authScopesService;
|
||||
private Mock<IOcelotLoggerFactory> _loggerFactory;
|
||||
private Mock<IOcelotLogger> _logger;
|
||||
private readonly AuthorisationMiddleware _middleware;
|
||||
private readonly AuthorizationMiddleware _middleware;
|
||||
private RequestDelegate _next;
|
||||
private HttpContext _httpContext;
|
||||
|
||||
public AuthorisationMiddlewareTests()
|
||||
public AuthorizationMiddlewareTests()
|
||||
{
|
||||
_httpContext = new DefaultHttpContext();
|
||||
_authService = new Mock<IClaimsAuthoriser>();
|
||||
_authScopesService = new Mock<IScopesAuthoriser>();
|
||||
_authService = new Mock<IClaimsAuthorizer>();
|
||||
_authScopesService = new Mock<IScopesAuthorizer>();
|
||||
_loggerFactory = new Mock<IOcelotLoggerFactory>();
|
||||
_logger = new Mock<IOcelotLogger>();
|
||||
_loggerFactory.Setup(x => x.CreateLogger<AuthorisationMiddleware>()).Returns(_logger.Object);
|
||||
_loggerFactory.Setup(x => x.CreateLogger<AuthorizationMiddleware>()).Returns(_logger.Object);
|
||||
_next = context => Task.CompletedTask;
|
||||
_middleware = new AuthorisationMiddleware(_next, _authService.Object, _authScopesService.Object, _loggerFactory.Object);
|
||||
_middleware = new AuthorizationMiddleware(_next, _authService.Object, _authScopesService.Object, _loggerFactory.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_call_authorisation_service()
|
||||
public void should_call_authorization_service()
|
||||
{
|
||||
this.Given(x => x.GivenTheDownStreamRouteIs(new List<PlaceholderNameAndValue>(),
|
||||
new DownstreamRouteBuilder()
|
||||
.WithUpstreamPathTemplate(new UpstreamPathTemplateBuilder().Build())
|
||||
.WithIsAuthorised(true)
|
||||
.WithIsAuthorized(true)
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.Build()))
|
||||
.And(x => x.GivenTheAuthServiceReturns(new OkResponse<bool>(true)))
|
||||
@ -69,7 +69,7 @@ namespace Ocelot.UnitTests.Authorization
|
||||
private void GivenTheAuthServiceReturns(Response<bool> expected)
|
||||
{
|
||||
_authService
|
||||
.Setup(x => x.Authorise(
|
||||
.Setup(x => x.Authorize(
|
||||
It.IsAny<ClaimsPrincipal>(),
|
||||
It.IsAny<Dictionary<string, string>>(),
|
||||
It.IsAny<List<PlaceholderNameAndValue>>()))
|
||||
@ -79,7 +79,7 @@ namespace Ocelot.UnitTests.Authorization
|
||||
private void ThenTheAuthServiceIsCalledCorrectly()
|
||||
{
|
||||
_authService
|
||||
.Verify(x => x.Authorise(
|
||||
.Verify(x => x.Authorize(
|
||||
It.IsAny<ClaimsPrincipal>(),
|
||||
It.IsAny<Dictionary<string, string>>(),
|
||||
It.IsAny<List<PlaceholderNameAndValue>>())
|
@ -1,4 +1,4 @@
|
||||
using Ocelot.Authorisation;
|
||||
using Ocelot.Authorization;
|
||||
using Ocelot.DownstreamRouteFinder.UrlMatcher;
|
||||
using Ocelot.Responses;
|
||||
using Shouldly;
|
||||
@ -11,21 +11,21 @@ namespace Ocelot.UnitTests.Authorization
|
||||
{
|
||||
using Ocelot.Infrastructure.Claims.Parser;
|
||||
|
||||
public class ClaimsAuthoriserTests
|
||||
public class ClaimsAuthorizerTests
|
||||
{
|
||||
private readonly ClaimsAuthoriser _claimsAuthoriser;
|
||||
private readonly ClaimsAuthorizer _claimsAuthorizer;
|
||||
private ClaimsPrincipal _claimsPrincipal;
|
||||
private Dictionary<string, string> _requirement;
|
||||
private List<PlaceholderNameAndValue> _urlPathPlaceholderNameAndValues;
|
||||
private Response<bool> _result;
|
||||
|
||||
public ClaimsAuthoriserTests()
|
||||
public ClaimsAuthorizerTests()
|
||||
{
|
||||
_claimsAuthoriser = new ClaimsAuthoriser(new ClaimsParser());
|
||||
_claimsAuthorizer = new ClaimsAuthorizer(new ClaimsParser());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_authorise_user()
|
||||
public void should_authorize_user()
|
||||
{
|
||||
this.Given(x => x.GivenAClaimsPrincipal(new ClaimsPrincipal(new ClaimsIdentity(new List<Claim>
|
||||
{
|
||||
@ -35,8 +35,8 @@ namespace Ocelot.UnitTests.Authorization
|
||||
{
|
||||
{"UserType", "registered"}
|
||||
}))
|
||||
.When(x => x.WhenICallTheAuthoriser())
|
||||
.Then(x => x.ThenTheUserIsAuthorised())
|
||||
.When(x => x.WhenICallTheAuthorizer())
|
||||
.Then(x => x.ThenTheUserIsAuthorized())
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
@ -55,8 +55,8 @@ namespace Ocelot.UnitTests.Authorization
|
||||
{
|
||||
new PlaceholderNameAndValue("{userId}", "14")
|
||||
}))
|
||||
.When(x => x.WhenICallTheAuthoriser())
|
||||
.Then(x => x.ThenTheUserIsAuthorised())
|
||||
.When(x => x.WhenICallTheAuthorizer())
|
||||
.Then(x => x.ThenTheUserIsAuthorized())
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
@ -75,13 +75,13 @@ namespace Ocelot.UnitTests.Authorization
|
||||
{
|
||||
new PlaceholderNameAndValue("{userId}", "14")
|
||||
}))
|
||||
.When(x => x.WhenICallTheAuthoriser())
|
||||
.Then(x => x.ThenTheUserIsntAuthorised())
|
||||
.When(x => x.WhenICallTheAuthorizer())
|
||||
.Then(x => x.ThenTheUserIsntAuthorized())
|
||||
.BDDfy();
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_authorise_user_multiple_claims_of_same_type()
|
||||
public void should_authorize_user_multiple_claims_of_same_type()
|
||||
{
|
||||
this.Given(x => x.GivenAClaimsPrincipal(new ClaimsPrincipal(new ClaimsIdentity(new List<Claim>
|
||||
{
|
||||
@ -92,21 +92,21 @@ namespace Ocelot.UnitTests.Authorization
|
||||
{
|
||||
{"UserType", "registered"}
|
||||
}))
|
||||
.When(x => x.WhenICallTheAuthoriser())
|
||||
.Then(x => x.ThenTheUserIsAuthorised())
|
||||
.When(x => x.WhenICallTheAuthorizer())
|
||||
.Then(x => x.ThenTheUserIsAuthorized())
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_not_authorise_user()
|
||||
public void should_not_authorize_user()
|
||||
{
|
||||
this.Given(x => x.GivenAClaimsPrincipal(new ClaimsPrincipal(new ClaimsIdentity(new List<Claim>()))))
|
||||
.And(x => x.GivenARouteClaimsRequirement(new Dictionary<string, string>
|
||||
{
|
||||
{ "UserType", "registered" }
|
||||
}))
|
||||
.When(x => x.WhenICallTheAuthoriser())
|
||||
.Then(x => x.ThenTheUserIsntAuthorised())
|
||||
.When(x => x.WhenICallTheAuthorizer())
|
||||
.Then(x => x.ThenTheUserIsntAuthorized())
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
@ -125,19 +125,19 @@ namespace Ocelot.UnitTests.Authorization
|
||||
_urlPathPlaceholderNameAndValues = urlPathPlaceholderNameAndValues;
|
||||
}
|
||||
|
||||
private void WhenICallTheAuthoriser()
|
||||
private void WhenICallTheAuthorizer()
|
||||
{
|
||||
_result = _claimsAuthoriser.Authorise(_claimsPrincipal, _requirement, _urlPathPlaceholderNameAndValues);
|
||||
_result = _claimsAuthorizer.Authorize(_claimsPrincipal, _requirement, _urlPathPlaceholderNameAndValues);
|
||||
}
|
||||
|
||||
private void ThenTheUserIsAuthorised()
|
||||
private void ThenTheUserIsAuthorized()
|
||||
{
|
||||
_result.Data.ShouldBe(true);
|
||||
}
|
||||
|
||||
private void ThenTheUserIsntAuthorised()
|
||||
private void ThenTheUserIsntAuthorized()
|
||||
{
|
||||
_result.Data.ShouldBe(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user