diff --git a/README.md b/README.md index 738ffbe1..3ef6d6b6 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,7 @@ Ocelot's primary functionality is to take incomeing http requests and forward th to a downstream service. At the moment in the form of another http request (in the future this could be any transport mechanism.). -Ocelot always adds a trailing slash to an UpstreamTemplate. +Ocelot always adds a trailing slash to an UpstreamPathTemplate. Ocelot's describes the routing of one request to another as a ReRoute. In order to get anything working in Ocelot you need to set up a ReRoute in the configuration. @@ -140,16 +140,16 @@ the following. "DownstreamScheme": "https", "DownstreamPort": 80, "DownstreamHost" "localhost" - "UpstreamTemplate": "/posts/{postId}", + "UpstreamPathTemplate": "/posts/{postId}", "UpstreamHttpMethod": "Put" } The DownstreamPathTemplate,Scheme, Port and Host make the URL that this request will be forwarded to. -The UpstreamTemplate is the URL that Ocelot will use to identity which +The UpstreamPathTemplate is the URL that Ocelot will use to identity which DownstreamPathTemplate to use for a given request. Finally the UpstreamHttpMethod is used so Ocelot can distinguish between requests to the same URL and is obviously needed to work :) In Ocelot you can add placeholders for variables to your Templates in the form of {something}. -The placeholder needs to be in both the DownstreamPathTemplate and UpstreamTemplate. If it is +The placeholder needs to be in both the DownstreamPathTemplate and UpstreamPathTemplate. If it is Ocelot will attempt to replace the placeholder with the correct variable value from the Upstream URL when the request comes in. @@ -190,7 +190,7 @@ and LeastConnection algorithm you can use. If no load balancer is specified Ocel { "DownstreamPathTemplate": "/api/posts/{postId}", "DownstreamScheme": "https", - "UpstreamTemplate": "/posts/{postId}", + "UpstreamPathTemplate": "/posts/{postId}", "UpstreamHttpMethod": "Put", "ServiceName": "product" "LoadBalancer": "LeastConnection" diff --git a/configuration-explanation.txt b/configuration-explanation.txt index b6db84a2..d7b4077f 100644 --- a/configuration-explanation.txt +++ b/configuration-explanation.txt @@ -15,7 +15,7 @@ # The path template we are listening on for this re route, Ocelot will add a trailing # slash to this property. Then when a request is made Ocelot makes sure a trailing # slash is added, so everything matches - "UpstreamTemplate": "/identityserverexample", + "UpstreamPathTemplate": "/identityserverexample", # The method we are listening for on this re route "UpstreamHttpMethod": "Get", # Only support identity server at the moment diff --git a/src/Ocelot/Authorisation/Middleware/AuthorisationMiddleware.cs b/src/Ocelot/Authorisation/Middleware/AuthorisationMiddleware.cs index 547fc7f7..760d2a38 100644 --- a/src/Ocelot/Authorisation/Middleware/AuthorisationMiddleware.cs +++ b/src/Ocelot/Authorisation/Middleware/AuthorisationMiddleware.cs @@ -61,7 +61,7 @@ namespace Ocelot.Authorisation.Middleware SetPipelineError(new List { new UnauthorisedError( - $"{context.User.Identity.Name} unable to access {DownstreamRoute.ReRoute.UpstreamTemplate}") + $"{context.User.Identity.Name} unable to access {DownstreamRoute.ReRoute.UpstreamPathTemplate.Value}") }); } } diff --git a/src/Ocelot/Configuration/Builder/AuthenticationOptionsBuilder.cs b/src/Ocelot/Configuration/Builder/AuthenticationOptionsBuilder.cs new file mode 100644 index 00000000..61d5e847 --- /dev/null +++ b/src/Ocelot/Configuration/Builder/AuthenticationOptionsBuilder.cs @@ -0,0 +1,56 @@ +using System.Collections.Generic; + +namespace Ocelot.Configuration.Builder +{ + public class AuthenticationOptionsBuilder + { + + private string _provider; + private string _providerRootUrl; + private string _scopeName; + private string _scopeSecret; + private bool _requireHttps; + private List _additionalScopes; + + public AuthenticationOptionsBuilder WithProvider(string provider) + { + _provider = provider; + return this; + } + + public AuthenticationOptionsBuilder WithProviderRootUrl(string providerRootUrl) + { + _providerRootUrl = providerRootUrl; + return this; + } + + public AuthenticationOptionsBuilder WithScopeName(string scopeName) + { + _scopeName = scopeName; + return this; + } + + public AuthenticationOptionsBuilder WithScopeSecret(string scopeSecret) + { + _scopeSecret = scopeSecret; + return this; + } + + public AuthenticationOptionsBuilder WithRequireHttps(bool requireHttps) + { + _requireHttps = requireHttps; + return this; + } + + public AuthenticationOptionsBuilder WithAdditionalScopes(List additionalScopes) + { + _additionalScopes = additionalScopes; + return this; + } + + public AuthenticationOptions Build() + { + return new AuthenticationOptions(_provider, _providerRootUrl, _scopeName, _requireHttps, _additionalScopes, _scopeSecret); + } + } +} \ No newline at end of file diff --git a/src/Ocelot/Configuration/Builder/ReRouteBuilder.cs b/src/Ocelot/Configuration/Builder/ReRouteBuilder.cs index 78c96fb5..d6615d11 100644 --- a/src/Ocelot/Configuration/Builder/ReRouteBuilder.cs +++ b/src/Ocelot/Configuration/Builder/ReRouteBuilder.cs @@ -1,23 +1,19 @@ using System; using System.Collections.Generic; +using System.Net.Http; using Ocelot.Values; namespace Ocelot.Configuration.Builder { public class ReRouteBuilder { + private AuthenticationOptions _authenticationOptions; private string _loadBalancerKey; private string _downstreamPathTemplate; private string _upstreamTemplate; private string _upstreamTemplatePattern; private string _upstreamHttpMethod; private bool _isAuthenticated; - private string _authenticationProvider; - private string _authenticationProviderUrl; - private string _scopeName; - private List _additionalScopes; - private bool _requireHttps; - private string _scopeSecret; private List _configHeaderExtractorProperties; private List _claimToClaims; private Dictionary _routeClaimRequirement; @@ -33,11 +29,6 @@ namespace Ocelot.Configuration.Builder private string _loadBalancer; private ServiceProviderConfiguraion _serviceProviderConfiguraion; - public ReRouteBuilder() - { - _additionalScopes = new List(); - } - public ReRouteBuilder WithLoadBalancer(string loadBalancer) { _loadBalancer = loadBalancer; @@ -68,7 +59,7 @@ namespace Ocelot.Configuration.Builder return this; } - public ReRouteBuilder WithUpstreamTemplate(string input) + public ReRouteBuilder WithUpstreamPathTemplate(string input) { _upstreamTemplate = input; return this; @@ -96,42 +87,6 @@ namespace Ocelot.Configuration.Builder return this; } - public ReRouteBuilder WithAuthenticationProvider(string input) - { - _authenticationProvider = input; - return this; - } - - public ReRouteBuilder WithAuthenticationProviderUrl(string input) - { - _authenticationProviderUrl = input; - return this; - } - - public ReRouteBuilder WithAuthenticationProviderScopeName(string input) - { - _scopeName = input; - return this; - } - - public ReRouteBuilder WithAuthenticationProviderAdditionalScopes(List input) - { - _additionalScopes = input; - return this; - } - - public ReRouteBuilder WithRequireHttps(bool input) - { - _requireHttps = input; - return this; - } - - public ReRouteBuilder WithScopeSecret(string input) - { - _scopeSecret = input; - return this; - } - public ReRouteBuilder WithRequestIdKey(string input) { _requestIdHeaderKey = input; @@ -192,13 +147,35 @@ namespace Ocelot.Configuration.Builder return this; } + public ReRouteBuilder WithAuthenticationOptions(AuthenticationOptions authenticationOptions) + { + _authenticationOptions = authenticationOptions; + return this; + } + public ReRoute Build() { - return new ReRoute(new PathTemplate(_downstreamPathTemplate), new PathTemplate(_upstreamTemplate), _upstreamHttpMethod, _upstreamTemplatePattern, - _isAuthenticated, new AuthenticationOptions(_authenticationProvider, _authenticationProviderUrl, _scopeName, - _requireHttps, _additionalScopes, _scopeSecret), _configHeaderExtractorProperties, _claimToClaims, _routeClaimRequirement, - _isAuthorised, _claimToQueries, _requestIdHeaderKey, _isCached, _fileCacheOptions, _downstreamScheme, _loadBalancer, - _downstreamHost, _downstreamPort, _loadBalancerKey, _serviceProviderConfiguraion); + return new ReRoute( + new PathTemplate(_downstreamPathTemplate), + new PathTemplate(_upstreamTemplate), + new HttpMethod(_upstreamHttpMethod), + _upstreamTemplatePattern, + _isAuthenticated, + _authenticationOptions, + _configHeaderExtractorProperties, + _claimToClaims, + _routeClaimRequirement, + _isAuthorised, + _claimToQueries, + _requestIdHeaderKey, + _isCached, + _fileCacheOptions, + _downstreamScheme, + _loadBalancer, + _downstreamHost, + _downstreamPort, + _loadBalancerKey, + _serviceProviderConfiguraion); } } } diff --git a/src/Ocelot/Configuration/ServiceProviderConfiguraionBuilder.cs b/src/Ocelot/Configuration/Builder/ServiceProviderConfiguraionBuilder.cs similarity index 98% rename from src/Ocelot/Configuration/ServiceProviderConfiguraionBuilder.cs rename to src/Ocelot/Configuration/Builder/ServiceProviderConfiguraionBuilder.cs index e8609683..129acae8 100644 --- a/src/Ocelot/Configuration/ServiceProviderConfiguraionBuilder.cs +++ b/src/Ocelot/Configuration/Builder/ServiceProviderConfiguraionBuilder.cs @@ -1,4 +1,4 @@ -namespace Ocelot.Configuration +namespace Ocelot.Configuration.Builder { public class ServiceProviderConfiguraionBuilder { diff --git a/src/Ocelot/Configuration/Creator/FileOcelotConfigurationCreator.cs b/src/Ocelot/Configuration/Creator/FileOcelotConfigurationCreator.cs index e02fccd5..cf6a2b54 100644 --- a/src/Ocelot/Configuration/Creator/FileOcelotConfigurationCreator.cs +++ b/src/Ocelot/Configuration/Creator/FileOcelotConfigurationCreator.cs @@ -1,9 +1,11 @@ using System; using System.Collections.Generic; +using System.Net.Http; using System.Text; using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; +using Ocelot.Configuration.Builder; using Ocelot.Configuration.File; using Ocelot.Configuration.Parser; using Ocelot.Configuration.Validator; @@ -88,7 +90,7 @@ namespace Ocelot.Configuration.Creator { var globalRequestIdConfiguration = !string.IsNullOrEmpty(globalConfiguration?.RequestIdKey); - var upstreamTemplate = BuildUpstreamTemplate(fileReRoute); + var upstreamTemplatePattern = BuildUpstreamTemplate(fileReRoute); var isAuthenticated = !string.IsNullOrEmpty(fileReRoute.AuthenticationOptions?.Provider); @@ -104,7 +106,7 @@ namespace Ocelot.Configuration.Creator && !string.IsNullOrEmpty(globalConfiguration?.ServiceDiscoveryProvider?.Provider); //note - not sure if this is the correct key, but this is probably the only unique key i can think of given my poor brain - var loadBalancerKey = $"{fileReRoute.UpstreamTemplate}{fileReRoute.UpstreamHttpMethod}"; + var loadBalancerKey = $"{fileReRoute.UpstreamPathTemplate}{fileReRoute.UpstreamHttpMethod}"; ReRoute reRoute; @@ -132,20 +134,29 @@ namespace Ocelot.Configuration.Creator var claimsToQueries = GetAddThingsToRequest(fileReRoute.AddQueriesToRequest); reRoute = new ReRoute(new PathTemplate(fileReRoute.DownstreamPathTemplate), - new PathTemplate(fileReRoute.UpstreamTemplate), - fileReRoute.UpstreamHttpMethod, upstreamTemplate, isAuthenticated, + new PathTemplate(fileReRoute.UpstreamPathTemplate), + new HttpMethod(fileReRoute.UpstreamHttpMethod), upstreamTemplatePattern, isAuthenticated, authOptionsForRoute, claimsToHeaders, claimsToClaims, fileReRoute.RouteClaimsRequirement, isAuthorised, claimsToQueries, requestIdKey, isCached, new CacheOptions(fileReRoute.FileCacheOptions.TtlSeconds) , fileReRoute.DownstreamScheme, fileReRoute.LoadBalancer, fileReRoute.DownstreamHost, fileReRoute.DownstreamPort, loadBalancerKey, serviceProviderConfiguration); + + //reRoute = new ReRouteBuilder() + // .WithDownstreamPathTemplate(fileReRoute.DownstreamPathTemplate) + // .WithUpstreamPathTemplate(fileReRoute.UpstreamPathTemplate) + // .WithUpstreamHttpMethod(fileReRoute.UpstreamHttpMethod) + // .WithUpstreamTemplatePattern(upstreamTemplatePattern) + // .WithIsAuthenticated(isAuthenticated) + //.Build(); + } else { reRoute = new ReRoute(new PathTemplate(fileReRoute.DownstreamPathTemplate), - new PathTemplate(fileReRoute.UpstreamTemplate), - fileReRoute.UpstreamHttpMethod, upstreamTemplate, isAuthenticated, + new PathTemplate(fileReRoute.UpstreamPathTemplate), + new HttpMethod(fileReRoute.UpstreamHttpMethod), upstreamTemplatePattern, isAuthenticated, null, new List(), new List(), fileReRoute.RouteClaimsRequirement, isAuthorised, new List(), requestIdKey, isCached, new CacheOptions(fileReRoute.FileCacheOptions.TtlSeconds), @@ -161,7 +172,7 @@ namespace Ocelot.Configuration.Creator private string BuildUpstreamTemplate(FileReRoute reRoute) { - var upstreamTemplate = reRoute.UpstreamTemplate; + var upstreamTemplate = reRoute.UpstreamPathTemplate; upstreamTemplate = upstreamTemplate.SetLastCharacterAs('/'); diff --git a/src/Ocelot/Configuration/File/FileReRoute.cs b/src/Ocelot/Configuration/File/FileReRoute.cs index 0d0fc7bd..6d3fea4f 100644 --- a/src/Ocelot/Configuration/File/FileReRoute.cs +++ b/src/Ocelot/Configuration/File/FileReRoute.cs @@ -15,7 +15,7 @@ namespace Ocelot.Configuration.File } public string DownstreamPathTemplate { get; set; } - public string UpstreamTemplate { get; set; } + public string UpstreamPathTemplate { get; set; } public string UpstreamHttpMethod { get; set; } public FileAuthenticationOptions AuthenticationOptions { get; set; } public Dictionary AddHeadersToRequest { get; set; } diff --git a/src/Ocelot/Configuration/ReRoute.cs b/src/Ocelot/Configuration/ReRoute.cs index 419096af..82d13e02 100644 --- a/src/Ocelot/Configuration/ReRoute.cs +++ b/src/Ocelot/Configuration/ReRoute.cs @@ -8,7 +8,7 @@ namespace Ocelot.Configuration public class ReRoute { public ReRoute(PathTemplate downstreamPathTemplate, - PathTemplate upstreamTemplate, string upstreamHttpMethod, + PathTemplate upstreamTemplate, HttpMethod upstreamHttpMethod, string upstreamTemplatePattern, bool isAuthenticated, AuthenticationOptions authenticationOptions, List configurationHeaderExtractorProperties, @@ -25,8 +25,8 @@ namespace Ocelot.Configuration DownstreamHost = downstreamHost; DownstreamPort = downstreamPort; DownstreamPathTemplate = downstreamPathTemplate; - UpstreamTemplate = upstreamTemplate; - UpstreamHttpMethod = new HttpMethod(upstreamHttpMethod); + UpstreamPathTemplate = upstreamTemplate; + UpstreamHttpMethod = upstreamHttpMethod; UpstreamTemplatePattern = upstreamTemplatePattern; IsAuthenticated = isAuthenticated; AuthenticationOptions = authenticationOptions; @@ -46,7 +46,7 @@ namespace Ocelot.Configuration public string LoadBalancerKey {get;private set;} public PathTemplate DownstreamPathTemplate { get; private set; } - public PathTemplate UpstreamTemplate { get; private set; } + public PathTemplate UpstreamPathTemplate { get; private set; } public string UpstreamTemplatePattern { get; private set; } public HttpMethod UpstreamHttpMethod { get; private set; } public bool IsAuthenticated { get; private set; } diff --git a/src/Ocelot/Configuration/Validator/FileConfigurationValidator.cs b/src/Ocelot/Configuration/Validator/FileConfigurationValidator.cs index 412613eb..98301ab4 100644 --- a/src/Ocelot/Configuration/Validator/FileConfigurationValidator.cs +++ b/src/Ocelot/Configuration/Validator/FileConfigurationValidator.cs @@ -54,7 +54,7 @@ namespace Ocelot.Configuration.Validator continue; } - var error = new UnsupportedAuthenticationProviderError($"{reRoute.AuthenticationOptions?.Provider} is unsupported authentication provider, upstream template is {reRoute.UpstreamTemplate}, upstream method is {reRoute.UpstreamHttpMethod}"); + var error = new UnsupportedAuthenticationProviderError($"{reRoute.AuthenticationOptions?.Provider} is unsupported authentication provider, upstream template is {reRoute.UpstreamPathTemplate}, upstream method is {reRoute.UpstreamHttpMethod}"); errors.Add(error); } @@ -94,18 +94,18 @@ namespace Ocelot.Configuration.Validator private ConfigurationValidationResult CheckForDupliateReRoutes(FileConfiguration configuration) { var hasDupes = configuration.ReRoutes - .GroupBy(x => new { x.UpstreamTemplate, x.UpstreamHttpMethod }).Any(x => x.Skip(1).Any()); + .GroupBy(x => new { x.UpstreamPathTemplate, x.UpstreamHttpMethod }).Any(x => x.Skip(1).Any()); if (!hasDupes) { return new ConfigurationValidationResult(false); } - var dupes = configuration.ReRoutes.GroupBy(x => new { x.UpstreamTemplate, x.UpstreamHttpMethod }) + var dupes = configuration.ReRoutes.GroupBy(x => new { x.UpstreamPathTemplate, x.UpstreamHttpMethod }) .Where(x => x.Skip(1).Any()); var errors = dupes - .Select(d => new DownstreamPathTemplateAlreadyUsedError(string.Format("Duplicate DownstreamPath: {0}", d.Key.UpstreamTemplate))) + .Select(d => new DownstreamPathTemplateAlreadyUsedError(string.Format("Duplicate DownstreamPath: {0}", d.Key.UpstreamPathTemplate))) .Cast() .ToList(); diff --git a/src/Ocelot/DownstreamRouteFinder/Finder/DownstreamRouteFinder.cs b/src/Ocelot/DownstreamRouteFinder/Finder/DownstreamRouteFinder.cs index 0e591416..e504a430 100644 --- a/src/Ocelot/DownstreamRouteFinder/Finder/DownstreamRouteFinder.cs +++ b/src/Ocelot/DownstreamRouteFinder/Finder/DownstreamRouteFinder.cs @@ -34,7 +34,7 @@ namespace Ocelot.DownstreamRouteFinder.Finder if (urlMatch.Data.Match) { - var templateVariableNameAndValues = _urlPathPlaceholderNameAndValueFinder.Find(upstreamUrlPath, reRoute.UpstreamTemplate.Value); + var templateVariableNameAndValues = _urlPathPlaceholderNameAndValueFinder.Find(upstreamUrlPath, reRoute.UpstreamPathTemplate.Value); return new OkResponse(new DownstreamRoute(templateVariableNameAndValues.Data, reRoute)); } diff --git a/test/Ocelot.AcceptanceTests/AuthenticationTests.cs b/test/Ocelot.AcceptanceTests/AuthenticationTests.cs index 8b14f4f1..87419ae6 100644 --- a/test/Ocelot.AcceptanceTests/AuthenticationTests.cs +++ b/test/Ocelot.AcceptanceTests/AuthenticationTests.cs @@ -47,7 +47,7 @@ namespace Ocelot.AcceptanceTests DownstreamPort = _downstreamServicePort, DownstreamHost = _downstreamServiceHost, DownstreamScheme = _downstreamServiceScheme, - UpstreamTemplate = "/", + UpstreamPathTemplate = "/", UpstreamHttpMethod = "Post", AuthenticationOptions = new FileAuthenticationOptions { @@ -85,7 +85,7 @@ namespace Ocelot.AcceptanceTests DownstreamPort = _downstreamServicePort, DownstreamHost = _downstreamServiceHost, DownstreamScheme = _downstreamServiceScheme, - UpstreamTemplate = "/", + UpstreamPathTemplate = "/", UpstreamHttpMethod = "Post", AuthenticationOptions = new FileAuthenticationOptions { @@ -123,7 +123,7 @@ namespace Ocelot.AcceptanceTests DownstreamPort = _downstreamServicePort, DownstreamHost = _downstreamServiceHost, DownstreamScheme = _downstreamServiceScheme, - UpstreamTemplate = "/", + UpstreamPathTemplate = "/", UpstreamHttpMethod = "Get", AuthenticationOptions = new FileAuthenticationOptions { @@ -163,7 +163,7 @@ namespace Ocelot.AcceptanceTests DownstreamPort = _downstreamServicePort, DownstreamHost = _downstreamServiceHost, DownstreamScheme = _downstreamServiceScheme, - UpstreamTemplate = "/", + UpstreamPathTemplate = "/", UpstreamHttpMethod = "Post", AuthenticationOptions = new FileAuthenticationOptions { @@ -203,7 +203,7 @@ namespace Ocelot.AcceptanceTests DownstreamPort = _downstreamServicePort, DownstreamHost = _downstreamServiceHost, DownstreamScheme = _downstreamServiceScheme, - UpstreamTemplate = "/", + UpstreamPathTemplate = "/", UpstreamHttpMethod = "Post", AuthenticationOptions = new FileAuthenticationOptions { diff --git a/test/Ocelot.AcceptanceTests/AuthorisationTests.cs b/test/Ocelot.AcceptanceTests/AuthorisationTests.cs index 1f86c6ff..a89616b9 100644 --- a/test/Ocelot.AcceptanceTests/AuthorisationTests.cs +++ b/test/Ocelot.AcceptanceTests/AuthorisationTests.cs @@ -41,7 +41,7 @@ namespace Ocelot.AcceptanceTests DownstreamPort = 51876, DownstreamScheme = "http", DownstreamHost = "localhost", - UpstreamTemplate = "/", + UpstreamPathTemplate = "/", UpstreamHttpMethod = "Get", AuthenticationOptions = new FileAuthenticationOptions { @@ -98,7 +98,7 @@ namespace Ocelot.AcceptanceTests DownstreamPort = 51876, DownstreamScheme = "http", DownstreamHost = "localhost", - UpstreamTemplate = "/", + UpstreamPathTemplate = "/", UpstreamHttpMethod = "Get", AuthenticationOptions = new FileAuthenticationOptions { diff --git a/test/Ocelot.AcceptanceTests/CachingTests.cs b/test/Ocelot.AcceptanceTests/CachingTests.cs index e4e628af..a8364855 100644 --- a/test/Ocelot.AcceptanceTests/CachingTests.cs +++ b/test/Ocelot.AcceptanceTests/CachingTests.cs @@ -35,7 +35,7 @@ namespace Ocelot.AcceptanceTests DownstreamPort = 51879, DownstreamScheme = "http", DownstreamHost = "localhost", - UpstreamTemplate = "/", + UpstreamPathTemplate = "/", UpstreamHttpMethod = "Get", FileCacheOptions = new FileCacheOptions { @@ -71,7 +71,7 @@ namespace Ocelot.AcceptanceTests DownstreamPort = 51879, DownstreamScheme = "http", DownstreamHost = "localhost", - UpstreamTemplate = "/", + UpstreamPathTemplate = "/", UpstreamHttpMethod = "Get", FileCacheOptions = new FileCacheOptions { diff --git a/test/Ocelot.AcceptanceTests/CaseSensitiveRoutingTests.cs b/test/Ocelot.AcceptanceTests/CaseSensitiveRoutingTests.cs index 81824602..7b1dfc75 100644 --- a/test/Ocelot.AcceptanceTests/CaseSensitiveRoutingTests.cs +++ b/test/Ocelot.AcceptanceTests/CaseSensitiveRoutingTests.cs @@ -34,7 +34,7 @@ namespace Ocelot.AcceptanceTests DownstreamPort = 51879, DownstreamScheme = "http", DownstreamHost = "localhost", - UpstreamTemplate = "/products/{productId}", + UpstreamPathTemplate = "/products/{productId}", UpstreamHttpMethod = "Get" } } @@ -61,7 +61,7 @@ namespace Ocelot.AcceptanceTests DownstreamPort = 51879, DownstreamScheme = "http", DownstreamHost = "localhost", - UpstreamTemplate = "/products/{productId}", + UpstreamPathTemplate = "/products/{productId}", UpstreamHttpMethod = "Get", ReRouteIsCaseSensitive = false } @@ -89,7 +89,7 @@ namespace Ocelot.AcceptanceTests DownstreamPort = 51879, DownstreamScheme = "http", DownstreamHost = "localhost", - UpstreamTemplate = "/products/{productId}", + UpstreamPathTemplate = "/products/{productId}", UpstreamHttpMethod = "Get", ReRouteIsCaseSensitive = true } @@ -117,7 +117,7 @@ namespace Ocelot.AcceptanceTests DownstreamPort = 51879, DownstreamScheme = "http", DownstreamHost = "localhost", - UpstreamTemplate = "/PRODUCTS/{productId}", + UpstreamPathTemplate = "/PRODUCTS/{productId}", UpstreamHttpMethod = "Get", ReRouteIsCaseSensitive = true } @@ -145,7 +145,7 @@ namespace Ocelot.AcceptanceTests DownstreamPort = 51879, DownstreamScheme = "http", DownstreamHost = "localhost", - UpstreamTemplate = "/products/{productId}", + UpstreamPathTemplate = "/products/{productId}", UpstreamHttpMethod = "Get", ReRouteIsCaseSensitive = true } @@ -173,7 +173,7 @@ namespace Ocelot.AcceptanceTests DownstreamPort = 51879, DownstreamScheme = "http", DownstreamHost = "localhost", - UpstreamTemplate = "/PRODUCTS/{productId}", + UpstreamPathTemplate = "/PRODUCTS/{productId}", UpstreamHttpMethod = "Get", ReRouteIsCaseSensitive = true } diff --git a/test/Ocelot.AcceptanceTests/ClaimsToHeadersForwardingTests.cs b/test/Ocelot.AcceptanceTests/ClaimsToHeadersForwardingTests.cs index 08bbd968..2d6bf163 100644 --- a/test/Ocelot.AcceptanceTests/ClaimsToHeadersForwardingTests.cs +++ b/test/Ocelot.AcceptanceTests/ClaimsToHeadersForwardingTests.cs @@ -55,7 +55,7 @@ namespace Ocelot.AcceptanceTests DownstreamPort = 52876, DownstreamScheme = "http", DownstreamHost = "localhost", - UpstreamTemplate = "/", + UpstreamPathTemplate = "/", UpstreamHttpMethod = "Get", AuthenticationOptions = new FileAuthenticationOptions { diff --git a/test/Ocelot.AcceptanceTests/ClaimsToQueryStringForwardingTests.cs b/test/Ocelot.AcceptanceTests/ClaimsToQueryStringForwardingTests.cs index 04dc25db..0c10c3e4 100644 --- a/test/Ocelot.AcceptanceTests/ClaimsToQueryStringForwardingTests.cs +++ b/test/Ocelot.AcceptanceTests/ClaimsToQueryStringForwardingTests.cs @@ -55,7 +55,7 @@ namespace Ocelot.AcceptanceTests DownstreamPort = 57876, DownstreamScheme = "http", DownstreamHost = "localhost", - UpstreamTemplate = "/", + UpstreamPathTemplate = "/", UpstreamHttpMethod = "Get", AuthenticationOptions = new FileAuthenticationOptions { diff --git a/test/Ocelot.AcceptanceTests/CustomMiddlewareTests.cs b/test/Ocelot.AcceptanceTests/CustomMiddlewareTests.cs index f6f6de20..085ce2a5 100644 --- a/test/Ocelot.AcceptanceTests/CustomMiddlewareTests.cs +++ b/test/Ocelot.AcceptanceTests/CustomMiddlewareTests.cs @@ -49,7 +49,7 @@ namespace Ocelot.AcceptanceTests DownstreamPort = 41879, DownstreamScheme = "http", DownstreamHost = "localhost", - UpstreamTemplate = "/", + UpstreamPathTemplate = "/", UpstreamHttpMethod = "Get", } } @@ -86,7 +86,7 @@ namespace Ocelot.AcceptanceTests DownstreamPort = 41879, DownstreamScheme = "http", DownstreamHost = "localhost", - UpstreamTemplate = "/", + UpstreamPathTemplate = "/", UpstreamHttpMethod = "Get", } } @@ -123,7 +123,7 @@ namespace Ocelot.AcceptanceTests DownstreamPort = 41879, DownstreamScheme = "http", DownstreamHost = "localhost", - UpstreamTemplate = "/", + UpstreamPathTemplate = "/", UpstreamHttpMethod = "Get", } } @@ -160,7 +160,7 @@ namespace Ocelot.AcceptanceTests DownstreamPort = 41879, DownstreamScheme = "http", DownstreamHost = "localhost", - UpstreamTemplate = "/", + UpstreamPathTemplate = "/", UpstreamHttpMethod = "Get", } } @@ -197,7 +197,7 @@ namespace Ocelot.AcceptanceTests DownstreamPort = 41879, DownstreamScheme = "http", DownstreamHost = "localhost", - UpstreamTemplate = "/", + UpstreamPathTemplate = "/", UpstreamHttpMethod = "Get", } } @@ -234,7 +234,7 @@ namespace Ocelot.AcceptanceTests DownstreamPort = 41879, DownstreamScheme = "http", DownstreamHost = "localhost", - UpstreamTemplate = "/", + UpstreamPathTemplate = "/", UpstreamHttpMethod = "Get", } } diff --git a/test/Ocelot.AcceptanceTests/RequestIdTests.cs b/test/Ocelot.AcceptanceTests/RequestIdTests.cs index 9334786b..8b9cd805 100644 --- a/test/Ocelot.AcceptanceTests/RequestIdTests.cs +++ b/test/Ocelot.AcceptanceTests/RequestIdTests.cs @@ -37,7 +37,7 @@ namespace Ocelot.AcceptanceTests DownstreamPort = 51879, DownstreamScheme = "http", DownstreamHost = "localhost", - UpstreamTemplate = "/", + UpstreamPathTemplate = "/", UpstreamHttpMethod = "Get", RequestIdKey = _steps.RequestIdKey } @@ -65,7 +65,7 @@ namespace Ocelot.AcceptanceTests DownstreamPort = 51879, DownstreamScheme = "http", DownstreamHost = "localhost", - UpstreamTemplate = "/", + UpstreamPathTemplate = "/", UpstreamHttpMethod = "Get", RequestIdKey = _steps.RequestIdKey } @@ -95,7 +95,7 @@ namespace Ocelot.AcceptanceTests DownstreamPort = 51879, DownstreamScheme = "http", DownstreamHost = "localhost", - UpstreamTemplate = "/", + UpstreamPathTemplate = "/", UpstreamHttpMethod = "Get", } }, diff --git a/test/Ocelot.AcceptanceTests/ReturnsErrorTests.cs b/test/Ocelot.AcceptanceTests/ReturnsErrorTests.cs index 81307781..f9222b86 100644 --- a/test/Ocelot.AcceptanceTests/ReturnsErrorTests.cs +++ b/test/Ocelot.AcceptanceTests/ReturnsErrorTests.cs @@ -30,7 +30,7 @@ namespace Ocelot.AcceptanceTests new FileReRoute { DownstreamPathTemplate = "http://localhost:53876/", - UpstreamTemplate = "/", + UpstreamPathTemplate = "/", UpstreamHttpMethod = "Get" } } diff --git a/test/Ocelot.AcceptanceTests/RoutingTests.cs b/test/Ocelot.AcceptanceTests/RoutingTests.cs index 4f97114f..14f5af8a 100644 --- a/test/Ocelot.AcceptanceTests/RoutingTests.cs +++ b/test/Ocelot.AcceptanceTests/RoutingTests.cs @@ -44,7 +44,7 @@ namespace Ocelot.AcceptanceTests DownstreamScheme = "http", DownstreamHost = "localhost", DownstreamPort = 51879, - UpstreamTemplate = "/", + UpstreamPathTemplate = "/", UpstreamHttpMethod = "Get", } } @@ -72,7 +72,7 @@ namespace Ocelot.AcceptanceTests DownstreamScheme = "http", DownstreamHost = "localhost", DownstreamPort = 51879, - UpstreamTemplate = "/", + UpstreamPathTemplate = "/", UpstreamHttpMethod = "Get", } } @@ -100,7 +100,7 @@ namespace Ocelot.AcceptanceTests DownstreamScheme = "http", DownstreamHost = "localhost/", DownstreamPort = 51879, - UpstreamTemplate = "/", + UpstreamPathTemplate = "/", UpstreamHttpMethod = "Get", } } @@ -128,7 +128,7 @@ namespace Ocelot.AcceptanceTests DownstreamScheme = "http", DownstreamHost = "localhost", DownstreamPort = 51879, - UpstreamTemplate = "/products/", + UpstreamPathTemplate = "/products/", UpstreamHttpMethod = "Get", } } @@ -156,7 +156,7 @@ namespace Ocelot.AcceptanceTests DownstreamScheme = "http", DownstreamHost = "localhost", DownstreamPort = 51879, - UpstreamTemplate = "/products", + UpstreamPathTemplate = "/products", UpstreamHttpMethod = "Get", } } @@ -184,7 +184,7 @@ namespace Ocelot.AcceptanceTests DownstreamScheme = "http", DownstreamHost = "localhost", DownstreamPort = 51879, - UpstreamTemplate = "/products/{productId}", + UpstreamPathTemplate = "/products/{productId}", UpstreamHttpMethod = "Get", } } @@ -211,7 +211,7 @@ namespace Ocelot.AcceptanceTests DownstreamScheme = "http", DownstreamHost = "localhost", DownstreamPort = 51879, - UpstreamTemplate = "/products/{productId}", + UpstreamPathTemplate = "/products/{productId}", UpstreamHttpMethod = "Get" } } @@ -239,7 +239,7 @@ namespace Ocelot.AcceptanceTests DownstreamHost = "localhost", DownstreamPort = 51879, DownstreamScheme = "http", - UpstreamTemplate = "/", + UpstreamPathTemplate = "/", UpstreamHttpMethod = "Post" } } @@ -264,7 +264,7 @@ namespace Ocelot.AcceptanceTests new FileReRoute { DownstreamPathTemplate = "/newThing", - UpstreamTemplate = "/newThing", + UpstreamPathTemplate = "/newThing", DownstreamScheme = "http", DownstreamHost = "localhost", DownstreamPort = 51879, diff --git a/test/Ocelot.AcceptanceTests/ServiceDiscoveryTests.cs b/test/Ocelot.AcceptanceTests/ServiceDiscoveryTests.cs index ef7e0dd7..fcf75b14 100644 --- a/test/Ocelot.AcceptanceTests/ServiceDiscoveryTests.cs +++ b/test/Ocelot.AcceptanceTests/ServiceDiscoveryTests.cs @@ -68,7 +68,7 @@ namespace Ocelot.AcceptanceTests { DownstreamPathTemplate = "/", DownstreamScheme = "http", - UpstreamTemplate = "/", + UpstreamPathTemplate = "/", UpstreamHttpMethod = "Get", ServiceName = serviceName, LoadBalancer = "LeastConnection", diff --git a/test/Ocelot.AcceptanceTests/configuration.json b/test/Ocelot.AcceptanceTests/configuration.json index d7db55c7..a08843bb 100755 --- a/test/Ocelot.AcceptanceTests/configuration.json +++ b/test/Ocelot.AcceptanceTests/configuration.json @@ -1 +1 @@ -{"ReRoutes":[{"DownstreamPathTemplate":"41879/","UpstreamTemplate":"/","UpstreamHttpMethod":"Get","AuthenticationOptions":{"Provider":null,"ProviderRootUrl":null,"ScopeName":null,"RequireHttps":false,"AdditionalScopes":[],"ScopeSecret":null},"AddHeadersToRequest":{},"AddClaimsToRequest":{},"RouteClaimsRequirement":{},"AddQueriesToRequest":{},"RequestIdKey":null,"FileCacheOptions":{"TtlSeconds":0},"ReRouteIsCaseSensitive":false,"ServiceName":null,"DownstreamScheme":"http","DownstreamHost":"localhost","DownstreamPort":41879,"LoadBalancer":null}],"GlobalConfiguration":{"RequestIdKey":null,"ServiceDiscoveryProvider":{"Provider":null,"Host":null,"Port":0}}} \ No newline at end of file +{"ReRoutes":[{"DownstreamPathTemplate":"41879/","UpstreamPathTemplate":"/","UpstreamHttpMethod":"Get","AuthenticationOptions":{"Provider":null,"ProviderRootUrl":null,"ScopeName":null,"RequireHttps":false,"AdditionalScopes":[],"ScopeSecret":null},"AddHeadersToRequest":{},"AddClaimsToRequest":{},"RouteClaimsRequirement":{},"AddQueriesToRequest":{},"RequestIdKey":null,"FileCacheOptions":{"TtlSeconds":0},"ReRouteIsCaseSensitive":false,"ServiceName":null,"DownstreamScheme":"http","DownstreamHost":"localhost","DownstreamPort":41879,"LoadBalancer":null}],"GlobalConfiguration":{"RequestIdKey":null,"ServiceDiscoveryProvider":{"Provider":null,"Host":null,"Port":0}}} \ No newline at end of file diff --git a/test/Ocelot.UnitTests/Configuration/ConfigurationValidationTests.cs b/test/Ocelot.UnitTests/Configuration/ConfigurationValidationTests.cs index 8a3e24f9..382471c6 100644 --- a/test/Ocelot.UnitTests/Configuration/ConfigurationValidationTests.cs +++ b/test/Ocelot.UnitTests/Configuration/ConfigurationValidationTests.cs @@ -29,7 +29,7 @@ namespace Ocelot.UnitTests.Configuration new FileReRoute { DownstreamPathTemplate = "http://www.bbc.co.uk/api/products/{productId}", - UpstreamTemplate = "http://asdf.com" + UpstreamPathTemplate = "http://asdf.com" } } })) @@ -48,7 +48,7 @@ namespace Ocelot.UnitTests.Configuration new FileReRoute { DownstreamPathTemplate = "/api/products/", - UpstreamTemplate = "http://asdf.com" + UpstreamPathTemplate = "http://asdf.com" } } })) @@ -67,7 +67,7 @@ namespace Ocelot.UnitTests.Configuration new FileReRoute { DownstreamPathTemplate = "/api/products/", - UpstreamTemplate = "http://asdf.com", + UpstreamPathTemplate = "http://asdf.com", AuthenticationOptions = new FileAuthenticationOptions { Provider = "IdentityServer" @@ -90,7 +90,7 @@ namespace Ocelot.UnitTests.Configuration new FileReRoute { DownstreamPathTemplate = "/api/products/", - UpstreamTemplate = "http://asdf.com", + UpstreamPathTemplate = "http://asdf.com", AuthenticationOptions = new FileAuthenticationOptions { Provider = "BootyBootyBottyRockinEverywhere" @@ -114,12 +114,12 @@ namespace Ocelot.UnitTests.Configuration new FileReRoute { DownstreamPathTemplate = "/api/products/", - UpstreamTemplate = "http://asdf.com" + UpstreamPathTemplate = "http://asdf.com" }, new FileReRoute { DownstreamPathTemplate = "http://www.bbc.co.uk", - UpstreamTemplate = "http://asdf.com" + UpstreamPathTemplate = "http://asdf.com" } } })) diff --git a/test/Ocelot.UnitTests/Configuration/FileConfigurationCreatorTests.cs b/test/Ocelot.UnitTests/Configuration/FileConfigurationCreatorTests.cs index 5ecf4810..2d2a48ef 100644 --- a/test/Ocelot.UnitTests/Configuration/FileConfigurationCreatorTests.cs +++ b/test/Ocelot.UnitTests/Configuration/FileConfigurationCreatorTests.cs @@ -53,7 +53,7 @@ namespace Ocelot.UnitTests.Configuration new FileReRoute { DownstreamHost = "127.0.0.1", - UpstreamTemplate = "/api/products/{productId}", + UpstreamPathTemplate = "/api/products/{productId}", DownstreamPathTemplate = "/products/{productId}", UpstreamHttpMethod = "Get", } @@ -78,7 +78,7 @@ namespace Ocelot.UnitTests.Configuration new FileReRoute { DownstreamHost = "127.0.0.1", - UpstreamTemplate = "/api/products/{productId}", + UpstreamPathTemplate = "/api/products/{productId}", DownstreamPathTemplate = "/products/{productId}", UpstreamHttpMethod = "Get", } @@ -91,7 +91,7 @@ namespace Ocelot.UnitTests.Configuration new ReRouteBuilder() .WithDownstreamHost("127.0.0.1") .WithDownstreamPathTemplate("/products/{productId}") - .WithUpstreamTemplate("/api/products/{productId}") + .WithUpstreamPathTemplate("/api/products/{productId}") .WithUpstreamHttpMethod("Get") .WithUpstreamTemplatePattern("(?i)/api/products/.*/$") .Build() @@ -109,7 +109,7 @@ namespace Ocelot.UnitTests.Configuration new FileReRoute { DownstreamScheme = "https", - UpstreamTemplate = "/api/products/{productId}", + UpstreamPathTemplate = "/api/products/{productId}", DownstreamPathTemplate = "/products/{productId}", UpstreamHttpMethod = "Get", } @@ -122,7 +122,7 @@ namespace Ocelot.UnitTests.Configuration new ReRouteBuilder() .WithDownstreamScheme("https") .WithDownstreamPathTemplate("/products/{productId}") - .WithUpstreamTemplate("/api/products/{productId}") + .WithUpstreamPathTemplate("/api/products/{productId}") .WithUpstreamHttpMethod("Get") .WithUpstreamTemplatePattern("(?i)/api/products/.*/$") .Build() @@ -139,7 +139,7 @@ namespace Ocelot.UnitTests.Configuration { new FileReRoute { - UpstreamTemplate = "/api/products/{productId}", + UpstreamPathTemplate = "/api/products/{productId}", DownstreamPathTemplate = "/products/{productId}", UpstreamHttpMethod = "Get", ReRouteIsCaseSensitive = false, @@ -161,7 +161,7 @@ namespace Ocelot.UnitTests.Configuration { new ReRouteBuilder() .WithDownstreamPathTemplate("/products/{productId}") - .WithUpstreamTemplate("/api/products/{productId}") + .WithUpstreamPathTemplate("/api/products/{productId}") .WithUpstreamHttpMethod("Get") .WithUpstreamTemplatePattern("(?i)/api/products/.*/$") .WithServiceName("ProductService") @@ -184,7 +184,7 @@ namespace Ocelot.UnitTests.Configuration { new FileReRoute { - UpstreamTemplate = "/api/products/{productId}", + UpstreamPathTemplate = "/api/products/{productId}", DownstreamPathTemplate = "/products/{productId}", UpstreamHttpMethod = "Get", ReRouteIsCaseSensitive = false, @@ -197,7 +197,7 @@ namespace Ocelot.UnitTests.Configuration { new ReRouteBuilder() .WithDownstreamPathTemplate("/products/{productId}") - .WithUpstreamTemplate("/api/products/{productId}") + .WithUpstreamPathTemplate("/api/products/{productId}") .WithUpstreamHttpMethod("Get") .WithUpstreamTemplatePattern("(?i)/api/products/.*/$") .WithServiceProviderConfiguraion(new ServiceProviderConfiguraionBuilder() @@ -217,7 +217,7 @@ namespace Ocelot.UnitTests.Configuration { new FileReRoute { - UpstreamTemplate = "/api/products/{productId}", + UpstreamPathTemplate = "/api/products/{productId}", DownstreamPathTemplate = "/products/{productId}", UpstreamHttpMethod = "Get", ReRouteIsCaseSensitive = false @@ -230,7 +230,7 @@ namespace Ocelot.UnitTests.Configuration { new ReRouteBuilder() .WithDownstreamPathTemplate("/products/{productId}") - .WithUpstreamTemplate("/api/products/{productId}") + .WithUpstreamPathTemplate("/api/products/{productId}") .WithUpstreamHttpMethod("Get") .WithUpstreamTemplatePattern("(?i)/api/products/.*/$") .Build() @@ -247,7 +247,7 @@ namespace Ocelot.UnitTests.Configuration { new FileReRoute { - UpstreamTemplate = "/api/products/{productId}", + UpstreamPathTemplate = "/api/products/{productId}", DownstreamPathTemplate = "/products/{productId}", UpstreamHttpMethod = "Get" } @@ -259,7 +259,7 @@ namespace Ocelot.UnitTests.Configuration { new ReRouteBuilder() .WithDownstreamPathTemplate("/products/{productId}") - .WithUpstreamTemplate("/api/products/{productId}") + .WithUpstreamPathTemplate("/api/products/{productId}") .WithUpstreamHttpMethod("Get") .WithUpstreamTemplatePattern("(?i)/api/products/.*/$") .Build() @@ -276,7 +276,7 @@ namespace Ocelot.UnitTests.Configuration { new FileReRoute { - UpstreamTemplate = "/api/products/{productId}", + UpstreamPathTemplate = "/api/products/{productId}", DownstreamPathTemplate = "/products/{productId}", UpstreamHttpMethod = "Get", ReRouteIsCaseSensitive = true @@ -289,7 +289,7 @@ namespace Ocelot.UnitTests.Configuration { new ReRouteBuilder() .WithDownstreamPathTemplate("/products/{productId}") - .WithUpstreamTemplate("/api/products/{productId}") + .WithUpstreamPathTemplate("/api/products/{productId}") .WithUpstreamHttpMethod("Get") .WithUpstreamTemplatePattern("/api/products/.*/$") .Build() @@ -306,7 +306,7 @@ namespace Ocelot.UnitTests.Configuration { new FileReRoute { - UpstreamTemplate = "/api/products/{productId}", + UpstreamPathTemplate = "/api/products/{productId}", DownstreamPathTemplate = "/products/{productId}", UpstreamHttpMethod = "Get", ReRouteIsCaseSensitive = true @@ -323,7 +323,7 @@ namespace Ocelot.UnitTests.Configuration { new ReRouteBuilder() .WithDownstreamPathTemplate("/products/{productId}") - .WithUpstreamTemplate("/api/products/{productId}") + .WithUpstreamPathTemplate("/api/products/{productId}") .WithUpstreamHttpMethod("Get") .WithUpstreamTemplatePattern("/api/products/.*/$") .WithRequestIdKey("blahhhh") @@ -341,7 +341,7 @@ namespace Ocelot.UnitTests.Configuration { new FileReRoute { - UpstreamTemplate = "/api/products/{productId}", + UpstreamPathTemplate = "/api/products/{productId}", DownstreamPathTemplate = "/products/{productId}", UpstreamHttpMethod = "Get", ReRouteIsCaseSensitive = true @@ -354,7 +354,7 @@ namespace Ocelot.UnitTests.Configuration { new ReRouteBuilder() .WithDownstreamPathTemplate("/products/{productId}") - .WithUpstreamTemplate("/api/products/{productId}") + .WithUpstreamPathTemplate("/api/products/{productId}") .WithUpstreamHttpMethod("Get") .WithUpstreamTemplatePattern("/api/products/.*/$") .Build() @@ -365,18 +365,23 @@ namespace Ocelot.UnitTests.Configuration [Fact] public void should_create_with_headers_to_extract() { + var authenticationOptions = new AuthenticationOptionsBuilder() + .WithProvider("IdentityServer") + .WithProviderRootUrl("http://localhost:51888") + .WithRequireHttps(false) + .WithScopeSecret("secret") + .WithScopeName("api") + .WithAdditionalScopes(new List()) + .Build(); + var expected = new List { new ReRouteBuilder() .WithDownstreamPathTemplate("/products/{productId}") - .WithUpstreamTemplate("/api/products/{productId}") + .WithUpstreamPathTemplate("/api/products/{productId}") .WithUpstreamHttpMethod("Get") .WithUpstreamTemplatePattern("/api/products/.*/$") - .WithAuthenticationProvider("IdentityServer") - .WithAuthenticationProviderUrl("http://localhost:51888") - .WithRequireHttps(false) - .WithScopeSecret("secret") - .WithAuthenticationProviderScopeName("api") + .WithAuthenticationOptions(authenticationOptions) .WithClaimsToHeaders(new List { new ClaimToThing("CustomerId", "CustomerId", "", 0), @@ -390,7 +395,7 @@ namespace Ocelot.UnitTests.Configuration { new FileReRoute { - UpstreamTemplate = "/api/products/{productId}", + UpstreamPathTemplate = "/api/products/{productId}", DownstreamPathTemplate = "/products/{productId}", UpstreamHttpMethod = "Get", ReRouteIsCaseSensitive = true, @@ -429,18 +434,23 @@ namespace Ocelot.UnitTests.Configuration [Fact] public void should_create_with_authentication_properties() { + var authenticationOptions = new AuthenticationOptionsBuilder() + .WithProvider("IdentityServer") + .WithProviderRootUrl("http://localhost:51888") + .WithRequireHttps(false) + .WithScopeSecret("secret") + .WithScopeName("api") + .WithAdditionalScopes(new List()) + .Build(); + var expected = new List { new ReRouteBuilder() .WithDownstreamPathTemplate("/products/{productId}") - .WithUpstreamTemplate("/api/products/{productId}") + .WithUpstreamPathTemplate("/api/products/{productId}") .WithUpstreamHttpMethod("Get") .WithUpstreamTemplatePattern("/api/products/.*/$") - .WithAuthenticationProvider("IdentityServer") - .WithAuthenticationProviderUrl("http://localhost:51888") - .WithRequireHttps(false) - .WithScopeSecret("secret") - .WithAuthenticationProviderScopeName("api") + .WithAuthenticationOptions(authenticationOptions) .Build() }; @@ -450,7 +460,7 @@ namespace Ocelot.UnitTests.Configuration { new FileReRoute { - UpstreamTemplate = "/api/products/{productId}", + UpstreamPathTemplate = "/api/products/{productId}", DownstreamPathTemplate = "/products/{productId}", UpstreamHttpMethod = "Get", ReRouteIsCaseSensitive = true, @@ -483,7 +493,7 @@ namespace Ocelot.UnitTests.Configuration { new FileReRoute { - UpstreamTemplate = "/api/products/{productId}/variants/{variantId}", + UpstreamPathTemplate = "/api/products/{productId}/variants/{variantId}", DownstreamPathTemplate = "/products/{productId}", UpstreamHttpMethod = "Get", ReRouteIsCaseSensitive = true @@ -496,7 +506,7 @@ namespace Ocelot.UnitTests.Configuration { new ReRouteBuilder() .WithDownstreamPathTemplate("/products/{productId}") - .WithUpstreamTemplate("/api/products/{productId}/variants/{variantId}") + .WithUpstreamPathTemplate("/api/products/{productId}/variants/{variantId}") .WithUpstreamHttpMethod("Get") .WithUpstreamTemplatePattern("/api/products/.*/variants/.*/$") .Build() @@ -513,7 +523,7 @@ namespace Ocelot.UnitTests.Configuration { new FileReRoute { - UpstreamTemplate = "/api/products/{productId}/variants/{variantId}/", + UpstreamPathTemplate = "/api/products/{productId}/variants/{variantId}/", DownstreamPathTemplate = "/products/{productId}", UpstreamHttpMethod = "Get", ReRouteIsCaseSensitive = true @@ -526,7 +536,7 @@ namespace Ocelot.UnitTests.Configuration { new ReRouteBuilder() .WithDownstreamPathTemplate("/products/{productId}") - .WithUpstreamTemplate("/api/products/{productId}/variants/{variantId}/") + .WithUpstreamPathTemplate("/api/products/{productId}/variants/{variantId}/") .WithUpstreamHttpMethod("Get") .WithUpstreamTemplatePattern("/api/products/.*/variants/.*/$") .Build() @@ -543,7 +553,7 @@ namespace Ocelot.UnitTests.Configuration { new FileReRoute { - UpstreamTemplate = "/", + UpstreamPathTemplate = "/", DownstreamPathTemplate = "/api/products/", UpstreamHttpMethod = "Get", ReRouteIsCaseSensitive = true @@ -556,7 +566,7 @@ namespace Ocelot.UnitTests.Configuration { new ReRouteBuilder() .WithDownstreamPathTemplate("/api/products/") - .WithUpstreamTemplate("/") + .WithUpstreamPathTemplate("/") .WithUpstreamHttpMethod("Get") .WithUpstreamTemplatePattern("/$") .Build() @@ -593,7 +603,7 @@ namespace Ocelot.UnitTests.Configuration result.DownstreamPathTemplate.Value.ShouldBe(expected.DownstreamPathTemplate.Value); result.UpstreamHttpMethod.ShouldBe(expected.UpstreamHttpMethod); - result.UpstreamTemplate.Value.ShouldBe(expected.UpstreamTemplate.Value); + result.UpstreamPathTemplate.Value.ShouldBe(expected.UpstreamPathTemplate.Value); result.UpstreamTemplatePattern.ShouldBe(expected.UpstreamTemplatePattern); } } diff --git a/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteFinderTests.cs b/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteFinderTests.cs index d65024f5..81fc7022 100644 --- a/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteFinderTests.cs +++ b/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteFinderTests.cs @@ -45,7 +45,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder { new ReRouteBuilder() .WithDownstreamPathTemplate("someDownstreamPath") - .WithUpstreamTemplate("someUpstreamPath") + .WithUpstreamPathTemplate("someUpstreamPath") .WithUpstreamHttpMethod("Get") .WithUpstreamTemplatePattern("someUpstreamPath") .Build() @@ -77,13 +77,13 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder { new ReRouteBuilder() .WithDownstreamPathTemplate("someDownstreamPath") - .WithUpstreamTemplate("someUpstreamPath") + .WithUpstreamPathTemplate("someUpstreamPath") .WithUpstreamHttpMethod("Get") .WithUpstreamTemplatePattern("") .Build(), new ReRouteBuilder() .WithDownstreamPathTemplate("someDownstreamPathForAPost") - .WithUpstreamTemplate("someUpstreamPath") + .WithUpstreamPathTemplate("someUpstreamPath") .WithUpstreamHttpMethod("Post") .WithUpstreamTemplatePattern("") .Build() @@ -110,7 +110,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder { new ReRouteBuilder() .WithDownstreamPathTemplate("somPath") - .WithUpstreamTemplate("somePath") + .WithUpstreamPathTemplate("somePath") .WithUpstreamHttpMethod("Get") .WithUpstreamTemplatePattern("somePath") .Build(), @@ -145,7 +145,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder private void ThenTheUrlMatcherIsCalledCorrectly() { _mockMatcher - .Verify(x => x.Match(_upstreamUrlPath, _reRoutesConfig[0].UpstreamTemplate.Value), Times.Once); + .Verify(x => x.Match(_upstreamUrlPath, _reRoutesConfig[0].UpstreamPathTemplate.Value), Times.Once); } private void GivenTheUrlMatcherReturns(Response match) diff --git a/test/Ocelot.UnitTests/ServiceDiscovery/ServiceProviderFactoryTests.cs b/test/Ocelot.UnitTests/ServiceDiscovery/ServiceProviderFactoryTests.cs index 7ba4608f..b3053afa 100644 --- a/test/Ocelot.UnitTests/ServiceDiscovery/ServiceProviderFactoryTests.cs +++ b/test/Ocelot.UnitTests/ServiceDiscovery/ServiceProviderFactoryTests.cs @@ -1,4 +1,5 @@ using Ocelot.Configuration; +using Ocelot.Configuration.Builder; using Ocelot.ServiceDiscovery; using Shouldly; using TestStack.BDDfy;