diff --git a/src/Ocelot.Library/Authentication/AuthenticationHandlerCreator.cs b/src/Ocelot.Library/Authentication/AuthenticationHandlerCreator.cs index fd49bf7d..34fedf38 100644 --- a/src/Ocelot.Library/Authentication/AuthenticationHandlerCreator.cs +++ b/src/Ocelot.Library/Authentication/AuthenticationHandlerCreator.cs @@ -25,8 +25,6 @@ namespace Ocelot.Library.Authentication ScopeSecret = authOptions.ScopeSecret }); - builder.UseMvc(); - var authenticationNext = builder.Build(); return new OkResponse(authenticationNext); diff --git a/src/Ocelot.Library/Builder/ReRouteBuilder.cs b/src/Ocelot.Library/Builder/ReRouteBuilder.cs index 5668f15e..2cf9538d 100644 --- a/src/Ocelot.Library/Builder/ReRouteBuilder.cs +++ b/src/Ocelot.Library/Builder/ReRouteBuilder.cs @@ -1,10 +1,8 @@ -using Ocelot.Library.RequestBuilder; +using System.Collections.Generic; +using Ocelot.Library.Configuration; namespace Ocelot.Library.Builder { - using System.Collections.Generic; - using Configuration; - public class ReRouteBuilder { private string _downstreamTemplate; @@ -18,7 +16,7 @@ namespace Ocelot.Library.Builder private List _additionalScopes; private bool _requireHttps; private string _scopeSecret; - private List _configHeaderExtractorProperties; + private List _configHeaderExtractorProperties; public ReRouteBuilder() { @@ -89,7 +87,7 @@ namespace Ocelot.Library.Builder return this; } - public ReRouteBuilder WithConfigurationHeaderExtractorProperties(List input) + public ReRouteBuilder WithConfigurationHeaderExtractorProperties(List input) { _configHeaderExtractorProperties = input; return this; diff --git a/src/Ocelot.Library/RequestBuilder/ConfigurationHeaderExtractorProperties.cs b/src/Ocelot.Library/Configuration/ClaimToHeader.cs similarity index 63% rename from src/Ocelot.Library/RequestBuilder/ConfigurationHeaderExtractorProperties.cs rename to src/Ocelot.Library/Configuration/ClaimToHeader.cs index 0f95b580..d768046a 100644 --- a/src/Ocelot.Library/RequestBuilder/ConfigurationHeaderExtractorProperties.cs +++ b/src/Ocelot.Library/Configuration/ClaimToHeader.cs @@ -1,8 +1,8 @@ -namespace Ocelot.Library.RequestBuilder +namespace Ocelot.Library.Configuration { - public class ConfigurationHeaderExtractorProperties + public class ClaimToHeader { - public ConfigurationHeaderExtractorProperties(string headerKey, string claimKey, string delimiter, int index) + public ClaimToHeader(string headerKey, string claimKey, string delimiter, int index) { ClaimKey = claimKey; Delimiter = delimiter; diff --git a/src/Ocelot.Library/RequestBuilder/HeaderExtrator.cs b/src/Ocelot.Library/Configuration/ClaimToHeaderConfigurationParser.cs similarity index 75% rename from src/Ocelot.Library/RequestBuilder/HeaderExtrator.cs rename to src/Ocelot.Library/Configuration/ClaimToHeaderConfigurationParser.cs index 11165f4e..c81c5468 100644 --- a/src/Ocelot.Library/RequestBuilder/HeaderExtrator.cs +++ b/src/Ocelot.Library/Configuration/ClaimToHeaderConfigurationParser.cs @@ -2,17 +2,18 @@ using System.Collections.Generic; using System.Text.RegularExpressions; using Ocelot.Library.Errors; +using Ocelot.Library.RequestBuilder; using Ocelot.Library.Responses; -namespace Ocelot.Library.RequestBuilder +namespace Ocelot.Library.Configuration { - public class ConfigurationHeaderExtrator : IConfigurationHeaderExtrator + public class ClaimToHeaderConfigurationParser : IClaimToHeaderConfigurationParser { private readonly Regex _claimRegex = new Regex("Claims\\[.*\\]"); private readonly Regex _indexRegex = new Regex("value\\[.*\\]"); private const string SplitToken = ">"; - public Response Extract(string headerKey, string value) + public Response Extract(string headerKey, string value) { try { @@ -20,7 +21,7 @@ namespace Ocelot.Library.RequestBuilder if (instructions.Length <= 1) { - return new ErrorResponse( + return new ErrorResponse( new List { new NoInstructionsError(SplitToken) @@ -31,7 +32,7 @@ namespace Ocelot.Library.RequestBuilder if (!claimMatch) { - return new ErrorResponse( + return new ErrorResponse( new List { new InstructionNotForClaimsError() @@ -48,12 +49,12 @@ namespace Ocelot.Library.RequestBuilder delimiter = instructions[2].Trim(); } - return new OkResponse( - new ConfigurationHeaderExtractorProperties(headerKey, claimKey, delimiter, index)); + return new OkResponse( + new ClaimToHeader(headerKey, claimKey, delimiter, index)); } catch (Exception exception) { - return new ErrorResponse( + return new ErrorResponse( new List { new ParsingConfigurationHeaderError(exception) diff --git a/src/Ocelot.Library/Configuration/IClaimToHeaderConfigurationParser.cs b/src/Ocelot.Library/Configuration/IClaimToHeaderConfigurationParser.cs new file mode 100644 index 00000000..ad627ba5 --- /dev/null +++ b/src/Ocelot.Library/Configuration/IClaimToHeaderConfigurationParser.cs @@ -0,0 +1,9 @@ +using Ocelot.Library.Responses; + +namespace Ocelot.Library.Configuration +{ + public interface IClaimToHeaderConfigurationParser + { + Response Extract(string headerKey, string value); + } +} \ No newline at end of file diff --git a/src/Ocelot.Library/Configuration/OcelotConfiguration.cs b/src/Ocelot.Library/Configuration/OcelotConfiguration.cs index d149baac..ae1cf189 100644 --- a/src/Ocelot.Library/Configuration/OcelotConfiguration.cs +++ b/src/Ocelot.Library/Configuration/OcelotConfiguration.cs @@ -16,17 +16,17 @@ namespace Ocelot.Library.Configuration private readonly List _reRoutes; private const string RegExMatchEverything = ".*"; private const string RegExMatchEndString = "$"; - private readonly IConfigurationHeaderExtrator _configurationHeaderExtrator; + private readonly IClaimToHeaderConfigurationParser _claimToHeaderConfigurationParser; private readonly ILogger _logger; public OcelotConfiguration(IOptions options, IConfigurationValidator configurationValidator, - IConfigurationHeaderExtrator configurationHeaderExtrator, + IClaimToHeaderConfigurationParser claimToHeaderConfigurationParser, ILogger logger) { _options = options; _configurationValidator = configurationValidator; - _configurationHeaderExtrator = configurationHeaderExtrator; + _claimToHeaderConfigurationParser = claimToHeaderConfigurationParser; _logger = logger; _reRoutes = new List(); SetUpConfiguration(); @@ -92,17 +92,17 @@ namespace Ocelot.Library.Configuration else { _reRoutes.Add(new ReRoute(reRoute.DownstreamTemplate, reRoute.UpstreamTemplate, reRoute.UpstreamHttpMethod, - upstreamTemplate, isAuthenticated, null, new List())); + upstreamTemplate, isAuthenticated, null, new List())); } } - private List GetHeadersToAddToRequest(YamlReRoute reRoute) + private List GetHeadersToAddToRequest(YamlReRoute reRoute) { - var configHeaders = new List(); + var configHeaders = new List(); foreach (var add in reRoute.AddHeadersToRequest) { - var configurationHeader = _configurationHeaderExtrator.Extract(add.Key, add.Value); + var configurationHeader = _claimToHeaderConfigurationParser.Extract(add.Key, add.Value); if (configurationHeader.IsError) { diff --git a/src/Ocelot.Library/Configuration/ReRoute.cs b/src/Ocelot.Library/Configuration/ReRoute.cs index a94913ae..d6df121d 100644 --- a/src/Ocelot.Library/Configuration/ReRoute.cs +++ b/src/Ocelot.Library/Configuration/ReRoute.cs @@ -1,11 +1,10 @@ using System.Collections.Generic; -using Ocelot.Library.RequestBuilder; namespace Ocelot.Library.Configuration { public class ReRoute { - public ReRoute(string downstreamTemplate, string upstreamTemplate, string upstreamHttpMethod, string upstreamTemplatePattern, bool isAuthenticated, AuthenticationOptions authenticationOptions, List configurationHeaderExtractorProperties) + public ReRoute(string downstreamTemplate, string upstreamTemplate, string upstreamHttpMethod, string upstreamTemplatePattern, bool isAuthenticated, AuthenticationOptions authenticationOptions, List configurationHeaderExtractorProperties) { DownstreamTemplate = downstreamTemplate; UpstreamTemplate = upstreamTemplate; @@ -13,8 +12,8 @@ namespace Ocelot.Library.Configuration UpstreamTemplatePattern = upstreamTemplatePattern; IsAuthenticated = isAuthenticated; AuthenticationOptions = authenticationOptions; - ConfigurationHeaderExtractorProperties = configurationHeaderExtractorProperties - ?? new List(); + ClaimsToHeaders = configurationHeaderExtractorProperties + ?? new List(); } public string DownstreamTemplate { get; private set; } @@ -23,6 +22,6 @@ namespace Ocelot.Library.Configuration public string UpstreamHttpMethod { get; private set; } public bool IsAuthenticated { get; private set; } public AuthenticationOptions AuthenticationOptions { get; private set; } - public List ConfigurationHeaderExtractorProperties { get; private set; } + public List ClaimsToHeaders { get; private set; } } } \ No newline at end of file diff --git a/src/Ocelot.Library/DependencyInjection/ServiceCollectionExtensions.cs b/src/Ocelot.Library/DependencyInjection/ServiceCollectionExtensions.cs index 2bcdf6a6..19f80900 100644 --- a/src/Ocelot.Library/DependencyInjection/ServiceCollectionExtensions.cs +++ b/src/Ocelot.Library/DependencyInjection/ServiceCollectionExtensions.cs @@ -18,12 +18,18 @@ { public static IServiceCollection AddOcelot(this IServiceCollection services, IConfigurationRoot configurationRoot) { + // framework services + services.AddOptions(); + services.AddMvcCore().AddJsonFormatters(); + services.AddLogging(); + + // initial configuration from yaml services.Configure(configurationRoot); - // Add framework services. + // ocelot services. services.AddSingleton(); services.AddSingleton(); - services.AddSingleton(); + services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); @@ -38,6 +44,7 @@ services.AddSingleton(); // see this for why we register this as singleton http://stackoverflow.com/questions/37371264/invalidoperationexception-unable-to-resolve-service-for-type-microsoft-aspnetc + // could maybe use a scoped data repository services.AddSingleton(); services.AddScoped(); diff --git a/src/Ocelot.Library/Middleware/HttpRequestHeadersBuilderMiddleware.cs b/src/Ocelot.Library/Middleware/HttpRequestHeadersBuilderMiddleware.cs index 1d45b6c4..562f898b 100644 --- a/src/Ocelot.Library/Middleware/HttpRequestHeadersBuilderMiddleware.cs +++ b/src/Ocelot.Library/Middleware/HttpRequestHeadersBuilderMiddleware.cs @@ -30,9 +30,9 @@ namespace Ocelot.Library.Middleware { var downstreamRoute = _scopedRequestDataRepository.Get("DownstreamRoute"); - if (downstreamRoute.Data.ReRoute.ConfigurationHeaderExtractorProperties.Any()) + if (downstreamRoute.Data.ReRoute.ClaimsToHeaders.Any()) { - _addHeadersToRequest.SetHeadersOnContext(downstreamRoute.Data.ReRoute.ConfigurationHeaderExtractorProperties, context); + _addHeadersToRequest.SetHeadersOnContext(downstreamRoute.Data.ReRoute.ClaimsToHeaders, context); } await _next.Invoke(context); diff --git a/src/Ocelot.Library/RequestBuilder/AddHeadersToRequest.cs b/src/Ocelot.Library/RequestBuilder/AddHeadersToRequest.cs index 387c69bc..88823097 100644 --- a/src/Ocelot.Library/RequestBuilder/AddHeadersToRequest.cs +++ b/src/Ocelot.Library/RequestBuilder/AddHeadersToRequest.cs @@ -2,6 +2,7 @@ using System.Linq; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Primitives; +using Ocelot.Library.Configuration; using Ocelot.Library.Responses; namespace Ocelot.Library.RequestBuilder @@ -15,7 +16,7 @@ namespace Ocelot.Library.RequestBuilder _claimsParser = claimsParser; } - public Response SetHeadersOnContext(List configurationHeaderExtractorProperties, HttpContext context) + public Response SetHeadersOnContext(List configurationHeaderExtractorProperties, HttpContext context) { foreach (var config in configurationHeaderExtractorProperties) { diff --git a/src/Ocelot.Library/RequestBuilder/IAddHeadersToRequest.cs b/src/Ocelot.Library/RequestBuilder/IAddHeadersToRequest.cs index d35cfb95..d1e96506 100644 --- a/src/Ocelot.Library/RequestBuilder/IAddHeadersToRequest.cs +++ b/src/Ocelot.Library/RequestBuilder/IAddHeadersToRequest.cs @@ -1,12 +1,13 @@ using System.Collections.Generic; using Microsoft.AspNetCore.Http; +using Ocelot.Library.Configuration; using Ocelot.Library.Responses; namespace Ocelot.Library.RequestBuilder { public interface IAddHeadersToRequest { - Response SetHeadersOnContext(List configurationHeaderExtractorProperties, + Response SetHeadersOnContext(List configurationHeaderExtractorProperties, HttpContext context); } } diff --git a/src/Ocelot.Library/RequestBuilder/IConfigurationHeaderExtrator.cs b/src/Ocelot.Library/RequestBuilder/IConfigurationHeaderExtrator.cs deleted file mode 100644 index 29c3c153..00000000 --- a/src/Ocelot.Library/RequestBuilder/IConfigurationHeaderExtrator.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System.Collections.Generic; -using Ocelot.Library.Responses; - -namespace Ocelot.Library.RequestBuilder -{ - public interface IConfigurationHeaderExtrator - { - Response Extract(string headerKey, string value); - } -} \ No newline at end of file diff --git a/src/Ocelot/Controllers/HomeController.cs b/src/Ocelot/Controllers/HomeController.cs deleted file mode 100644 index c6dbe9d2..00000000 --- a/src/Ocelot/Controllers/HomeController.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; - -namespace Ocelot.Controllers -{ - /// - /// This controller is a catch all for requests so that if we build it into a pipeline - /// the requests get authorised. - /// - public class HomeController : Controller - { - //[Authorize] - [Route("{*url}")] - public void Index() - { - if (true == true) - { - - } - } - } -} diff --git a/src/Ocelot/Startup.cs b/src/Ocelot/Startup.cs index 6b7d7973..66989428 100644 --- a/src/Ocelot/Startup.cs +++ b/src/Ocelot/Startup.cs @@ -28,11 +28,6 @@ namespace Ocelot // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { - services.AddOptions(); - services.AddMvc(); - services.AddMvcCore().AddAuthorization().AddJsonFormatters(); - services.AddAuthentication(); - services.AddLogging(); services.AddOcelot(Configuration); } diff --git a/test/Ocelot.AcceptanceTests/OcelotTests.cs b/test/Ocelot.AcceptanceTests/RoutingTests.cs similarity index 98% rename from test/Ocelot.AcceptanceTests/OcelotTests.cs rename to test/Ocelot.AcceptanceTests/RoutingTests.cs index b838736b..22accf7b 100644 --- a/test/Ocelot.AcceptanceTests/OcelotTests.cs +++ b/test/Ocelot.AcceptanceTests/RoutingTests.cs @@ -16,7 +16,7 @@ namespace Ocelot.AcceptanceTests { using Library.Configuration.Yaml; - public class OcelotTests : IDisposable + public class RoutingTests : IDisposable { private TestServer _server; private HttpClient _client; @@ -28,7 +28,7 @@ namespace Ocelot.AcceptanceTests // Sadly we need to change this when we update the netcoreapp version to make the test update the config correctly private double _netCoreAppVersion = 1.4; - public OcelotTests() + public RoutingTests() { _configurationPath = $"./bin/Debug/netcoreapp{_netCoreAppVersion}/configuration.yaml"; } diff --git a/test/Ocelot.UnitTests/Configuration/OcelotConfigurationTests.cs b/test/Ocelot.UnitTests/Configuration/OcelotConfigurationTests.cs index 7c37e4a9..8846d60d 100644 --- a/test/Ocelot.UnitTests/Configuration/OcelotConfigurationTests.cs +++ b/test/Ocelot.UnitTests/Configuration/OcelotConfigurationTests.cs @@ -20,13 +20,13 @@ namespace Ocelot.UnitTests.Configuration private readonly Mock _validator; private OcelotConfiguration _config; private YamlConfiguration _yamlConfiguration; - private readonly Mock _configExtractor; + private readonly Mock _configExtractor; private readonly Mock> _logger; public OcelotConfigurationTests() { _logger = new Mock>(); - _configExtractor = new Mock(); + _configExtractor = new Mock(); _validator = new Mock(); _yamlConfig = new Mock>(); } @@ -75,9 +75,9 @@ namespace Ocelot.UnitTests.Configuration .WithRequireHttps(false) .WithScopeSecret("secret") .WithAuthenticationProviderScopeName("api") - .WithConfigurationHeaderExtractorProperties(new List + .WithConfigurationHeaderExtractorProperties(new List { - new ConfigurationHeaderExtractorProperties("CustomerId", "CustomerId", "", 0), + new ClaimToHeader("CustomerId", "CustomerId", "", 0), }) .Build() }; @@ -108,18 +108,18 @@ namespace Ocelot.UnitTests.Configuration } })) .And(x => x.GivenTheYamlConfigIsValid()) - .And(x => x.GivenTheConfigHeaderExtractorReturns(new ConfigurationHeaderExtractorProperties("CustomerId", "CustomerId", "", 0))) + .And(x => x.GivenTheConfigHeaderExtractorReturns(new ClaimToHeader("CustomerId", "CustomerId", "", 0))) .When(x => x.WhenIInstanciateTheOcelotConfig()) .Then(x => x.ThenTheReRoutesAre(expected)) .And(x => x.ThenTheAuthenticationOptionsAre(expected)) .BDDfy(); } - private void GivenTheConfigHeaderExtractorReturns(ConfigurationHeaderExtractorProperties expected) + private void GivenTheConfigHeaderExtractorReturns(ClaimToHeader expected) { _configExtractor .Setup(x => x.Extract(It.IsAny(), It.IsAny())) - .Returns(new OkResponse(expected)); + .Returns(new OkResponse(expected)); } [Fact] diff --git a/test/Ocelot.UnitTests/Middleware/HttpRequestHeadersBuilderMiddlewareTests.cs b/test/Ocelot.UnitTests/Middleware/HttpRequestHeadersBuilderMiddlewareTests.cs index 6dc7f77e..f04efbfc 100644 --- a/test/Ocelot.UnitTests/Middleware/HttpRequestHeadersBuilderMiddlewareTests.cs +++ b/test/Ocelot.UnitTests/Middleware/HttpRequestHeadersBuilderMiddlewareTests.cs @@ -8,6 +8,7 @@ using Microsoft.AspNetCore.TestHost; using Microsoft.Extensions.DependencyInjection; using Moq; using Ocelot.Library.Builder; +using Ocelot.Library.Configuration; using Ocelot.Library.DownstreamRouteFinder; using Ocelot.Library.Middleware; using Ocelot.Library.Repository; @@ -60,9 +61,9 @@ namespace Ocelot.UnitTests.Middleware var downstreamRoute = new DownstreamRoute(new List(), new ReRouteBuilder() .WithDownstreamTemplate("any old string") - .WithConfigurationHeaderExtractorProperties(new List + .WithConfigurationHeaderExtractorProperties(new List { - new ConfigurationHeaderExtractorProperties("UserId", "Subject", "", 0) + new ClaimToHeader("UserId", "Subject", "", 0) }) .Build()); @@ -76,7 +77,7 @@ namespace Ocelot.UnitTests.Middleware private void GivenTheAddHeadersToRequestReturns(string claimValue) { _addHeaders - .Setup(x => x.SetHeadersOnContext(It.IsAny>(), + .Setup(x => x.SetHeadersOnContext(It.IsAny>(), It.IsAny())) .Returns(new OkResponse()); } @@ -84,7 +85,7 @@ namespace Ocelot.UnitTests.Middleware private void ThenTheAddHeadersToRequestIsCalledCorrectly() { _addHeaders - .Verify(x => x.SetHeadersOnContext(It.IsAny>(), + .Verify(x => x.SetHeadersOnContext(It.IsAny>(), It.IsAny()), Times.Once); } diff --git a/test/Ocelot.UnitTests/RequestBuilder/AddHeadersToRequestTests.cs b/test/Ocelot.UnitTests/RequestBuilder/AddHeadersToRequestTests.cs index 28300c17..91359d28 100644 --- a/test/Ocelot.UnitTests/RequestBuilder/AddHeadersToRequestTests.cs +++ b/test/Ocelot.UnitTests/RequestBuilder/AddHeadersToRequestTests.cs @@ -4,6 +4,7 @@ using System.Security.Claims; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Primitives; using Moq; +using Ocelot.Library.Configuration; using Ocelot.Library.Errors; using Ocelot.Library.RequestBuilder; using Ocelot.Library.Responses; @@ -17,7 +18,7 @@ namespace Ocelot.UnitTests.RequestBuilder { private readonly AddHeadersToRequest _addHeadersToRequest; private readonly Mock _parser; - private List _configuration; + private List _configuration; private HttpContext _context; private Response _result; private Response _claimValue; @@ -40,9 +41,9 @@ namespace Ocelot.UnitTests.RequestBuilder }; this.Given( - x => x.GivenConfigurationHeaderExtractorProperties(new List + x => x.GivenConfigurationHeaderExtractorProperties(new List { - new ConfigurationHeaderExtractorProperties("header-key", "", "", 0) + new ClaimToHeader("header-key", "", "", 0) })) .Given(x => x.GivenHttpContext(context)) .And(x => x.GivenTheClaimParserReturns(new OkResponse("value"))) @@ -66,9 +67,9 @@ namespace Ocelot.UnitTests.RequestBuilder context.Request.Headers.Add("header-key", new StringValues("initial")); this.Given( - x => x.GivenConfigurationHeaderExtractorProperties(new List + x => x.GivenConfigurationHeaderExtractorProperties(new List { - new ConfigurationHeaderExtractorProperties("header-key", "", "", 0) + new ClaimToHeader("header-key", "", "", 0) })) .Given(x => x.GivenHttpContext(context)) .And(x => x.GivenTheClaimParserReturns(new OkResponse("value"))) @@ -82,9 +83,9 @@ namespace Ocelot.UnitTests.RequestBuilder public void should_return_error() { this.Given( - x => x.GivenConfigurationHeaderExtractorProperties(new List + x => x.GivenConfigurationHeaderExtractorProperties(new List { - new ConfigurationHeaderExtractorProperties("", "", "", 0) + new ClaimToHeader("", "", "", 0) })) .Given(x => x.GivenHttpContext(new DefaultHttpContext())) .And(x => x.GivenTheClaimParserReturns(new ErrorResponse(new List @@ -102,7 +103,7 @@ namespace Ocelot.UnitTests.RequestBuilder header.Value.First().ShouldBe(_claimValue.Data); } - private void GivenConfigurationHeaderExtractorProperties(List configuration) + private void GivenConfigurationHeaderExtractorProperties(List configuration) { _configuration = configuration; } diff --git a/test/Ocelot.UnitTests/RequestBuilder/ConfigurationHeadersExtractorTests.cs b/test/Ocelot.UnitTests/RequestBuilder/ConfigurationHeadersExtractorTests.cs index 238d9f1a..48e93b8a 100644 --- a/test/Ocelot.UnitTests/RequestBuilder/ConfigurationHeadersExtractorTests.cs +++ b/test/Ocelot.UnitTests/RequestBuilder/ConfigurationHeadersExtractorTests.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Linq; +using Ocelot.Library.Configuration; using Ocelot.Library.Errors; using Ocelot.Library.RequestBuilder; using Ocelot.Library.Responses; @@ -12,12 +13,12 @@ namespace Ocelot.UnitTests.RequestBuilder public class ConfigurationHeadersExtractorTests { private Dictionary _dictionary; - private readonly IConfigurationHeaderExtrator _configurationHeaderExtrator; - private Response _result; + private readonly IClaimToHeaderConfigurationParser _claimToHeaderConfigurationParser; + private Response _result; public ConfigurationHeadersExtractorTests() { - _configurationHeaderExtrator = new ConfigurationHeaderExtrator(); + _claimToHeaderConfigurationParser = new ClaimToHeaderConfigurationParser(); } [Fact] @@ -30,7 +31,7 @@ namespace Ocelot.UnitTests.RequestBuilder .When(x => x.WhenICallTheExtractor()) .Then( x => - x.ThenAnErrorIsReturned(new ErrorResponse( + x.ThenAnErrorIsReturned(new ErrorResponse( new List { new NoInstructionsError(">") @@ -48,7 +49,7 @@ namespace Ocelot.UnitTests.RequestBuilder .When(x => x.WhenICallTheExtractor()) .Then( x => - x.ThenAnErrorIsReturned(new ErrorResponse( + x.ThenAnErrorIsReturned(new ErrorResponse( new List { new InstructionNotForClaimsError() @@ -67,8 +68,8 @@ namespace Ocelot.UnitTests.RequestBuilder .Then( x => x.ThenTheClaimParserPropertiesAreReturned( - new OkResponse( - new ConfigurationHeaderExtractorProperties("CustomerId", "CustomerId", "", 0)))) + new OkResponse( + new ClaimToHeader("CustomerId", "CustomerId", "", 0)))) .BDDfy(); } @@ -83,18 +84,18 @@ namespace Ocelot.UnitTests.RequestBuilder .Then( x => x.ThenTheClaimParserPropertiesAreReturned( - new OkResponse( - new ConfigurationHeaderExtractorProperties("UserId", "Subject", "|", 0)))) + new OkResponse( + new ClaimToHeader("UserId", "Subject", "|", 0)))) .BDDfy(); } - private void ThenAnErrorIsReturned(Response expected) + private void ThenAnErrorIsReturned(Response expected) { _result.IsError.ShouldBe(expected.IsError); _result.Errors[0].ShouldBeOfType(expected.Errors[0].GetType()); } - private void ThenTheClaimParserPropertiesAreReturned(Response expected) + private void ThenTheClaimParserPropertiesAreReturned(Response expected) { _result.Data.ClaimKey.ShouldBe(expected.Data.ClaimKey); _result.Data.Delimiter.ShouldBe(expected.Data.Delimiter); @@ -105,7 +106,7 @@ namespace Ocelot.UnitTests.RequestBuilder private void WhenICallTheExtractor() { var first = _dictionary.First(); - _result = _configurationHeaderExtrator.Extract(first.Key, first.Value); + _result = _claimToHeaderConfigurationParser.Extract(first.Key, first.Value); } private void GivenTheDictionaryIs(Dictionary dictionary)