rename authorisation to authorization

This commit is contained in:
TomPallister
2020-12-01 16:54:52 +00:00
parent b2dd70f59c
commit b46fedac24
43 changed files with 295 additions and 295 deletions

View File

@ -16,7 +16,7 @@ namespace Ocelot.AcceptanceTests
using TestStack.BDDfy;
using Xunit;
public class AuthorisationTests : IDisposable
public class AuthorizationTests : IDisposable
{
private IWebHost _identityServerBuilder;
private readonly Steps _steps;
@ -24,7 +24,7 @@ namespace Ocelot.AcceptanceTests
private string _identityServerRootUrl;
private readonly ServiceHandler _serviceHandler;
public AuthorisationTests()
public AuthorizationTests()
{
_serviceHandler = new ServiceHandler();
_steps = new Steps();
@ -41,7 +41,7 @@ namespace Ocelot.AcceptanceTests
}
[Fact]
public void should_return_response_200_authorising_route()
public void should_return_response_200_authorizing_route()
{
int port = RandomPortFinder.GetRandomPort();
@ -101,7 +101,7 @@ namespace Ocelot.AcceptanceTests
}
[Fact]
public void should_return_response_403_authorising_route()
public void should_return_response_403_authorizing_route()
{
int port = RandomPortFinder.GetRandomPort();

View File

@ -10,7 +10,7 @@
using System.Net;
using System.Threading.Tasks;
using TestStack.BDDfy;
using Xunit;
using Xunit;
public class CustomMiddlewareTests : IDisposable
{
@ -32,13 +32,13 @@
{
var configuration = new OcelotPipelineConfiguration
{
AuthorisationMiddleware = async (ctx, next) =>
AuthorizationMiddleware = async (ctx, next) =>
{
_counter++;
await next.Invoke();
}
};
};
var port = RandomPortFinder.GetRandomPort();
var fileConfiguration = new FileConfiguration
@ -73,17 +73,17 @@
}
[Fact]
public void should_call_authorisation_middleware()
public void should_call_authorization_middleware()
{
var configuration = new OcelotPipelineConfiguration
{
AuthorisationMiddleware = async (ctx, next) =>
AuthorizationMiddleware = async (ctx, next) =>
{
_counter++;
await next.Invoke();
}
};
};
var port = RandomPortFinder.GetRandomPort();
var fileConfiguration = new FileConfiguration
@ -127,8 +127,8 @@
_counter++;
await next.Invoke();
}
};
};
var port = RandomPortFinder.GetRandomPort();
var fileConfiguration = new FileConfiguration
@ -172,8 +172,8 @@
_counter++;
await next.Invoke();
}
};
};
var port = RandomPortFinder.GetRandomPort();
var fileConfiguration = new FileConfiguration
@ -208,17 +208,17 @@
}
[Fact]
public void should_call_pre_authorisation_middleware()
public void should_call_pre_authorization_middleware()
{
var configuration = new OcelotPipelineConfiguration
{
PreAuthorisationMiddleware = async (ctx, next) =>
PreAuthorizationMiddleware = async (ctx, next) =>
{
_counter++;
await next.Invoke();
}
};
};
var port = RandomPortFinder.GetRandomPort();
var fileConfiguration = new FileConfiguration
@ -262,8 +262,8 @@
_counter++;
await next.Invoke();
}
};
};
var port = RandomPortFinder.GetRandomPort();
var fileConfiguration = new FileConfiguration
@ -295,8 +295,8 @@
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
.And(x => x.ThenTheCounterIs(1))
.BDDfy();
}
}
[Fact(Skip = "This is just an example to show how you could hook into Ocelot pipeline with your own middleware. At the moment you must use Response.OnCompleted callback and cannot change the response :( I will see if this can be changed one day!")]
public void should_fix_issue_237()
{
@ -305,14 +305,14 @@
var httpContext = (HttpContext)state;
if (httpContext.Response.StatusCode > 400)
{
{
Debug.WriteLine("COUNT CALLED");
Console.WriteLine("COUNT CALLED");
}
return Task.CompletedTask;
};
};
var port = RandomPortFinder.GetRandomPort();
var fileConfiguration = new FileConfiguration
@ -376,8 +376,8 @@
public class FakeMiddleware
{
private readonly RequestDelegate _next;
private readonly Func<object, Task> _callback;
private readonly Func<object, Task> _callback;
public FakeMiddleware(RequestDelegate next, Func<object, Task> callback)
{
_next = next;
@ -386,10 +386,10 @@
public async Task Invoke(HttpContext context)
{
await _next(context);
await _next(context);
context.Response.OnCompleted(_callback, context);
}
}
}
}
}

View File

@ -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>>())

View File

@ -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);
}
}
}
}

View File

@ -46,7 +46,7 @@ namespace Ocelot.UnitTests.Configuration
var expected = new RouteOptionsBuilder()
.WithIsAuthenticated(true)
.WithIsAuthorised(true)
.WithIsAuthorized(true)
.WithIsCached(true)
.WithRateLimiting(true)
.WithUseServiceDiscovery(true)
@ -71,7 +71,7 @@ namespace Ocelot.UnitTests.Configuration
private void ThenTheFollowingIsReturned(RouteOptions expected)
{
_result.IsAuthenticated.ShouldBe(expected.IsAuthenticated);
_result.IsAuthorised.ShouldBe(expected.IsAuthorised);
_result.IsAuthorized.ShouldBe(expected.IsAuthorized);
_result.IsCached.ShouldBe(expected.IsCached);
_result.EnableRateLimiting.ShouldBe(expected.EnableRateLimiting);
_result.UseServiceDiscovery.ShouldBe(expected.UseServiceDiscovery);

View File

@ -218,7 +218,7 @@
{
_result[routeIndex].DownstreamRoute[0].DownstreamHttpVersion.ShouldBe(_expectedVersion);
_result[routeIndex].DownstreamRoute[0].IsAuthenticated.ShouldBe(_rro.IsAuthenticated);
_result[routeIndex].DownstreamRoute[0].IsAuthorised.ShouldBe(_rro.IsAuthorised);
_result[routeIndex].DownstreamRoute[0].IsAuthorized.ShouldBe(_rro.IsAuthorized);
_result[routeIndex].DownstreamRoute[0].IsCached.ShouldBe(_rro.IsCached);
_result[routeIndex].DownstreamRoute[0].EnableEndpointEndpointRateLimiting.ShouldBe(_rro.EnableRateLimiting);
_result[routeIndex].DownstreamRoute[0].RequestIdKey.ShouldBe(_requestId);

View File

@ -2,7 +2,7 @@ namespace Ocelot.UnitTests.Headers
{
using Microsoft.AspNetCore.Http;
using Moq;
using Ocelot.Authorisation.Middleware;
using Ocelot.Authorization.Middleware;
using Ocelot.Configuration;
using Ocelot.Configuration.Builder;
using Ocelot.DownstreamRouteFinder;
@ -38,7 +38,7 @@ namespace Ocelot.UnitTests.Headers
_postReplacer = new Mock<IHttpResponseHeaderReplacer>();
_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;
_addHeadersToResponse = new Mock<IAddHeadersToResponse>();
_addHeadersToRequest = new Mock<IAddHeadersToRequest>();

View File

@ -1,5 +1,5 @@
using Moq;
using Ocelot.Authorisation;
using Ocelot.Authorization;
using Ocelot.Errors;
using Ocelot.Infrastructure.Claims.Parser;
using Ocelot.Responses;
@ -11,18 +11,18 @@ using Xunit;
namespace Ocelot.UnitTests.Infrastructure
{
public class ScopesAuthoriserTests
public class ScopesAuthorizerTests
{
private ScopesAuthoriser _authoriser;
private ScopesAuthorizer _authorizer;
public Mock<IClaimsParser> _parser;
private ClaimsPrincipal _principal;
private List<string> _allowedScopes;
private Response<bool> _result;
public ScopesAuthoriserTests()
public ScopesAuthorizerTests()
{
_parser = new Mock<IClaimsParser>();
_authoriser = new ScopesAuthoriser(_parser.Object);
_authorizer = new ScopesAuthorizer(_parser.Object);
}
[Fact]
@ -30,7 +30,7 @@ namespace Ocelot.UnitTests.Infrastructure
{
this.Given(_ => GivenTheFollowing(new ClaimsPrincipal()))
.And(_ => GivenTheFollowing(new List<string>()))
.When(_ => WhenIAuthorise())
.When(_ => WhenIAuthorize())
.Then(_ => ThenTheFollowingIsReturned(new OkResponse<bool>(true)))
.BDDfy();
}
@ -40,7 +40,7 @@ namespace Ocelot.UnitTests.Infrastructure
{
this.Given(_ => GivenTheFollowing(new ClaimsPrincipal()))
.And(_ => GivenTheFollowing((List<string>)null))
.When(_ => WhenIAuthorise())
.When(_ => WhenIAuthorize())
.Then(_ => ThenTheFollowingIsReturned(new OkResponse<bool>(true)))
.BDDfy();
}
@ -52,7 +52,7 @@ namespace Ocelot.UnitTests.Infrastructure
this.Given(_ => GivenTheFollowing(new ClaimsPrincipal()))
.And(_ => GivenTheParserReturns(new ErrorResponse<List<string>>(fakeError)))
.And(_ => GivenTheFollowing(new List<string>() { "doesntmatter" }))
.When(_ => WhenIAuthorise())
.When(_ => WhenIAuthorize())
.Then(_ => ThenTheFollowingIsReturned(new ErrorResponse<bool>(fakeError)))
.BDDfy();
}
@ -66,7 +66,7 @@ namespace Ocelot.UnitTests.Infrastructure
this.Given(_ => GivenTheFollowing(claimsPrincipal))
.And(_ => GivenTheParserReturns(new OkResponse<List<string>>(allowedScopes)))
.And(_ => GivenTheFollowing(allowedScopes))
.When(_ => WhenIAuthorise())
.When(_ => WhenIAuthorize())
.Then(_ => ThenTheFollowingIsReturned(new OkResponse<bool>(true)))
.BDDfy();
}
@ -82,7 +82,7 @@ namespace Ocelot.UnitTests.Infrastructure
this.Given(_ => GivenTheFollowing(claimsPrincipal))
.And(_ => GivenTheParserReturns(new OkResponse<List<string>>(userScopes)))
.And(_ => GivenTheFollowing(allowedScopes))
.When(_ => WhenIAuthorise())
.When(_ => WhenIAuthorize())
.Then(_ => ThenTheFollowingIsReturned(new ErrorResponse<bool>(fakeError)))
.BDDfy();
}
@ -102,9 +102,9 @@ namespace Ocelot.UnitTests.Infrastructure
_allowedScopes = allowedScopes;
}
private void WhenIAuthorise()
private void WhenIAuthorize()
{
_result = _authoriser.Authorise(_principal, _allowedScopes);
_result = _authorizer.Authorize(_principal, _allowedScopes);
}
private void ThenTheFollowingIsReturned(Response<bool> expected)

View File

@ -29,10 +29,10 @@ namespace Ocelot.UnitTests.Responder
[Theory]
[InlineData(OcelotErrorCode.CannotFindClaimError)]
[InlineData(OcelotErrorCode.ClaimValueNotAuthorisedError)]
[InlineData(OcelotErrorCode.ScopeNotAuthorisedError)]
[InlineData(OcelotErrorCode.ClaimValueNotAuthorizedError)]
[InlineData(OcelotErrorCode.ScopeNotAuthorizedError)]
[InlineData(OcelotErrorCode.UnauthorizedError)]
[InlineData(OcelotErrorCode.UserDoesNotHaveClaimError)]
[InlineData(OcelotErrorCode.UserDoesNotHaveClaimError)]
public void should_return_forbidden(OcelotErrorCode errorCode)
{
ShouldMapErrorToStatusCode(errorCode, HttpStatusCode.Forbidden);
@ -52,8 +52,8 @@ namespace Ocelot.UnitTests.Responder
public void should_return_internal_server_error(OcelotErrorCode errorCode)
{
ShouldMapErrorToStatusCode(errorCode, HttpStatusCode.InternalServerError);
}
}
[Theory]
[InlineData(OcelotErrorCode.ConnectionToDownstreamServiceError)]
public void should_return_bad_gateway_error(OcelotErrorCode errorCode)
@ -104,7 +104,7 @@ namespace Ocelot.UnitTests.Responder
}
[Fact]
public void AuthorisationErrorsHaveSecondHighestPriority()
public void AuthorizationErrorsHaveSecondHighestPriority()
{
var errors = new List<OcelotErrorCode>
{
@ -177,4 +177,4 @@ namespace Ocelot.UnitTests.Responder
_result.ShouldBe((int)expectedCode);
}
}
}
}