mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 12:18:16 +08:00
Feature/#574 look at httpclient cache key (#589)
* #574 consolidate some code, man the config stuff is a mess! * #574 just use the downstream re route and the key for caching http clients * #574 added benchmark, i was suprised to learn using a complex type was faster than a string in benchmark .net dictionary tests, hey ho probably dont have enough data in the type...
This commit is contained in:
@ -16,6 +16,7 @@ namespace Ocelot.UnitTests.Authorization
|
||||
using Xunit;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Ocelot.Configuration;
|
||||
using Values;
|
||||
|
||||
public class AuthorisationMiddlewareTests
|
||||
{
|
||||
@ -44,6 +45,7 @@ namespace Ocelot.UnitTests.Authorization
|
||||
{
|
||||
this.Given(x => x.GivenTheDownStreamRouteIs(new List<PlaceholderNameAndValue>(),
|
||||
new DownstreamReRouteBuilder()
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().Build())
|
||||
.WithIsAuthorised(true)
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.Build()))
|
||||
|
@ -13,7 +13,6 @@
|
||||
using Shouldly;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
using Ocelot.DependencyInjection;
|
||||
using Ocelot.Errors;
|
||||
using Ocelot.UnitTests.TestData;
|
||||
using Ocelot.Values;
|
||||
@ -83,9 +82,9 @@
|
||||
.Build();
|
||||
|
||||
var downstreamReRoute = new DownstreamReRouteBuilder()
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
|
||||
.WithDownstreamAddresses(new List<DownstreamHostAndPort>() { new DownstreamHostAndPort("127.0.0.1", 80) })
|
||||
.WithDownstreamPathTemplate("/products/{productId}")
|
||||
.WithUpstreamPathTemplate("/api/products/{productId}")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.WithLoadBalancerKey("CookieStickySessions:sessionid")
|
||||
.Build();
|
||||
@ -116,6 +115,7 @@
|
||||
},
|
||||
}))
|
||||
.And(x => x.GivenTheConfigIsValid())
|
||||
.And(x => GivenTheUpstreamTemplatePatternCreatorReturns("woop", "/api/products/{productId}"))
|
||||
.And(x => GivenTheDownstreamAddresses())
|
||||
.And(x => GivenTheHeaderFindAndReplaceCreatorReturns())
|
||||
.And(x => x.GivenTheFollowingOptionsAreReturned(reRouteOptions))
|
||||
@ -124,7 +124,7 @@
|
||||
{
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamReRoute(downstreamReRoute)
|
||||
.WithUpstreamPathTemplate("/api/products/{productId}")
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.Build()
|
||||
}))
|
||||
@ -206,7 +206,7 @@
|
||||
var lauraReRoute = new ReRouteBuilder()
|
||||
.WithUpstreamHttpMethod(new List<string>() { "Get" })
|
||||
.WithUpstreamHost("localhost")
|
||||
.WithUpstreamPathTemplate("/laura")
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/laura").Build())
|
||||
.WithDownstreamReRoute(lauraDownstreamReRoute)
|
||||
.Build();
|
||||
|
||||
@ -225,14 +225,14 @@
|
||||
var tomReRoute = new ReRouteBuilder()
|
||||
.WithUpstreamHttpMethod(new List<string>() { "Get" })
|
||||
.WithUpstreamHost("localhost")
|
||||
.WithUpstreamPathTemplate("/tom")
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/tom").Build())
|
||||
.WithDownstreamReRoute(tomDownstreamReRoute)
|
||||
.Build();
|
||||
|
||||
expected.Add(tomReRoute);
|
||||
|
||||
var aggregateReReRoute = new ReRouteBuilder()
|
||||
.WithUpstreamPathTemplate("/")
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/").Build())
|
||||
.WithUpstreamHost("localhost")
|
||||
.WithDownstreamReRoute(lauraDownstreamReRoute)
|
||||
.WithDownstreamReRoute(tomDownstreamReRoute)
|
||||
@ -241,7 +241,18 @@
|
||||
|
||||
expected.Add(aggregateReReRoute);
|
||||
|
||||
var tupleList = new List<(string, string)>
|
||||
{
|
||||
("woop", "/laura"),
|
||||
("woop", "/laura"),
|
||||
("woop", "/tom"),
|
||||
("woop", "/tom"),
|
||||
("woop", "/"),
|
||||
("woop", "/")
|
||||
};
|
||||
|
||||
this.Given(x => x.GivenTheConfigIs(configuration))
|
||||
.And(x => GivenTheUpstreamTemplatePatternCreatorReturns(tupleList.ToArray()))
|
||||
.And(x => x.GivenTheFollowingOptionsAreReturned(new ReRouteOptionsBuilder().Build()))
|
||||
.And(x => x.GivenTheFollowingIsReturned(serviceProviderConfig))
|
||||
.And(x => GivenTheDownstreamAddresses())
|
||||
@ -249,7 +260,7 @@
|
||||
.And(x => x.GivenTheConfigIsValid())
|
||||
.When(x => x.WhenICreateTheConfig())
|
||||
.Then(x => x.ThenTheServiceProviderCreatorIsCalledCorrectly())
|
||||
.Then(x => x.ThenTheReRoutesAre(expected))
|
||||
.Then(x => x.ThenTheAggregateReRoutesAre(expected))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
@ -406,9 +417,9 @@
|
||||
.Build();
|
||||
|
||||
var downstreamReRoute = new DownstreamReRouteBuilder()
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
|
||||
.WithDownstreamAddresses(new List<DownstreamHostAndPort>() {new DownstreamHostAndPort("127.0.0.1", 80)})
|
||||
.WithDownstreamPathTemplate("/products/{productId}")
|
||||
.WithUpstreamPathTemplate("/api/products/{productId}")
|
||||
.WithUpstreamHttpMethod(new List<string> {"Get"})
|
||||
.WithLoadBalancerKey("/api/products/{productId}|Get|127.0.0.1:0")
|
||||
.Build();
|
||||
@ -433,6 +444,7 @@
|
||||
},
|
||||
}))
|
||||
.And(x => x.GivenTheConfigIsValid())
|
||||
.And(x => GivenTheUpstreamTemplatePatternCreatorReturns("woop", "/api/products/{productId}"))
|
||||
.And(x => GivenTheDownstreamAddresses())
|
||||
.And(x => GivenTheHeaderFindAndReplaceCreatorReturns())
|
||||
.And(x => x.GivenTheFollowingOptionsAreReturned(reRouteOptions))
|
||||
@ -441,7 +453,7 @@
|
||||
{
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamReRoute(downstreamReRoute)
|
||||
.WithUpstreamPathTemplate("/api/products/{productId}")
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.Build()
|
||||
}))
|
||||
@ -459,7 +471,7 @@
|
||||
var downstreamReRoute = new DownstreamReRouteBuilder()
|
||||
.WithDownstreamScheme("https")
|
||||
.WithDownstreamPathTemplate("/products/{productId}")
|
||||
.WithUpstreamPathTemplate("/api/products/{productId}")
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
|
||||
.WithUpstreamHttpMethod(new List<string> {"Get"})
|
||||
.WithDelegatingHandlers(handlers)
|
||||
.WithLoadBalancerKey("/api/products/{productId}|Get|")
|
||||
@ -480,6 +492,7 @@
|
||||
},
|
||||
}))
|
||||
.And(x => x.GivenTheConfigIsValid())
|
||||
.And(x => GivenTheUpstreamTemplatePatternCreatorReturns("woop", "/api/products/{productId}"))
|
||||
.And(x => GivenTheDownstreamAddresses())
|
||||
.And(x => GivenTheHeaderFindAndReplaceCreatorReturns())
|
||||
.And(x => x.GivenTheFollowingOptionsAreReturned(reRouteOptions))
|
||||
@ -488,7 +501,7 @@
|
||||
{
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamReRoute(downstreamReRoute)
|
||||
.WithUpstreamPathTemplate("/api/products/{productId}")
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.Build()
|
||||
}))
|
||||
@ -503,7 +516,7 @@
|
||||
|
||||
var downstreamReRoute = new DownstreamReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("/products/{productId}")
|
||||
.WithUpstreamPathTemplate("/api/products/{productId}")
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
|
||||
.WithUpstreamHttpMethod(new List<string> {"Get"})
|
||||
.WithUseServiceDiscovery(true)
|
||||
.WithServiceName("ProductService")
|
||||
@ -532,6 +545,7 @@
|
||||
}
|
||||
}))
|
||||
.And(x => x.GivenTheConfigIsValid())
|
||||
.And(x => GivenTheUpstreamTemplatePatternCreatorReturns("woop", "/api/products/{productId}"))
|
||||
.And(x => GivenTheDownstreamAddresses())
|
||||
.And(x => GivenTheHeaderFindAndReplaceCreatorReturns())
|
||||
.And(x => x.GivenTheFollowingOptionsAreReturned(reRouteOptions))
|
||||
@ -540,7 +554,7 @@
|
||||
{
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamReRoute(downstreamReRoute)
|
||||
.WithUpstreamPathTemplate("/api/products/{productId}")
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.Build()
|
||||
}))
|
||||
@ -555,7 +569,7 @@
|
||||
|
||||
var downstreamReRoute = new DownstreamReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("/products/{productId}")
|
||||
.WithUpstreamPathTemplate("/api/products/{productId}")
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
|
||||
.WithUpstreamHttpMethod(new List<string> {"Get"})
|
||||
.WithUseServiceDiscovery(false)
|
||||
.WithLoadBalancerKey("/api/products/{productId}|Get|")
|
||||
@ -575,6 +589,7 @@
|
||||
}
|
||||
}))
|
||||
.And(x => x.GivenTheConfigIsValid())
|
||||
.And(x => GivenTheUpstreamTemplatePatternCreatorReturns("woop", "/api/products/{productId}"))
|
||||
.And(x => GivenTheDownstreamAddresses())
|
||||
.And(x => GivenTheHeaderFindAndReplaceCreatorReturns())
|
||||
.And(x => x.GivenTheFollowingOptionsAreReturned(reRouteOptions))
|
||||
@ -583,7 +598,7 @@
|
||||
{
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamReRoute(downstreamReRoute)
|
||||
.WithUpstreamPathTemplate("/api/products/{productId}")
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.Build()
|
||||
}))
|
||||
@ -598,9 +613,9 @@
|
||||
|
||||
var downstreamReRoute = new DownstreamReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("/products/{productId}")
|
||||
.WithUpstreamPathTemplate("/api/products/{productId}")
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithOriginalValue("/api/products/{productId}").Build())
|
||||
.WithUpstreamHttpMethod(new List<string> {"Get"})
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("(?i)/api/products/.*/$", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("(?i)/api/products/.*/$", 1, false, "/api/products/{productId}"))
|
||||
.WithLoadBalancerKey("/api/products/{productId}|Get|")
|
||||
.Build();
|
||||
|
||||
@ -621,15 +636,15 @@
|
||||
.And(x => GivenTheDownstreamAddresses())
|
||||
.And(x => GivenTheHeaderFindAndReplaceCreatorReturns())
|
||||
.And(x => x.GivenTheFollowingOptionsAreReturned(reRouteOptions))
|
||||
.And(x => x.GivenTheUpstreamTemplatePatternCreatorReturns("(?i)/api/products/.*/$"))
|
||||
.And(x => x.GivenTheUpstreamTemplatePatternCreatorReturns("(?i)/api/products/.*/$", "/api/products/{productId}"))
|
||||
.When(x => x.WhenICreateTheConfig())
|
||||
.Then(x => x.ThenTheReRoutesAre(new List<ReRoute>
|
||||
{
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamReRoute(downstreamReRoute)
|
||||
.WithUpstreamPathTemplate("/api/products/{productId}")
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithOriginalValue("/api/products/{productId}").Build())
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("(?i)/api/products/.*/$", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("(?i)/api/products/.*/$", 1, false, "/api/products/{productId}"))
|
||||
.Build()
|
||||
}))
|
||||
.BDDfy();
|
||||
@ -643,7 +658,7 @@
|
||||
|
||||
var downstreamReRoute = new DownstreamReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("/products/{productId}")
|
||||
.WithUpstreamPathTemplate("/api/products/{productId}")
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
|
||||
.WithUpstreamHttpMethod(new List<string> {"Get"})
|
||||
.WithRequestIdKey("blahhhh")
|
||||
.WithLoadBalancerKey("/api/products/{productId}|Get|")
|
||||
@ -667,6 +682,7 @@
|
||||
}
|
||||
}))
|
||||
.And(x => x.GivenTheConfigIsValid())
|
||||
.And(x => GivenTheUpstreamTemplatePatternCreatorReturns("woop", "/api/products/{productId}"))
|
||||
.And(x => GivenTheDownstreamAddresses())
|
||||
.And(x => GivenTheHeaderFindAndReplaceCreatorReturns())
|
||||
.And(x => x.GivenTheFollowingOptionsAreReturned(reRouteOptions))
|
||||
@ -676,7 +692,7 @@
|
||||
{
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamReRoute(downstreamReRoute)
|
||||
.WithUpstreamPathTemplate("/api/products/{productId}")
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.Build()
|
||||
}))
|
||||
@ -734,7 +750,7 @@
|
||||
|
||||
var downstreamReRoute = new DownstreamReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("/products/{productId}")
|
||||
.WithUpstreamPathTemplate("/api/products/{productId}")
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
|
||||
.WithUpstreamHttpMethod(new List<string> {"Get"})
|
||||
.WithAuthenticationOptions(authenticationOptions)
|
||||
.WithClaimsToHeaders(new List<ClaimToThing>
|
||||
@ -748,12 +764,13 @@
|
||||
{
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamReRoute(downstreamReRoute)
|
||||
.WithUpstreamPathTemplate("/api/products/{productId}")
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.Build()
|
||||
};
|
||||
|
||||
this.Given(x => x.GivenTheConfigIs(fileConfig))
|
||||
.And(x => GivenTheUpstreamTemplatePatternCreatorReturns("woop", "/api/products/{productId}"))
|
||||
.And(x => GivenTheDownstreamAddresses())
|
||||
.And(x => x.GivenTheConfigIsValid())
|
||||
.And(x => GivenTheHeaderFindAndReplaceCreatorReturns())
|
||||
@ -781,7 +798,7 @@
|
||||
|
||||
var downstreamReRoute = new DownstreamReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("/products/{productId}")
|
||||
.WithUpstreamPathTemplate("/api/products/{productId}")
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
|
||||
.WithUpstreamHttpMethod(new List<string> {"Get"})
|
||||
.WithAuthenticationOptions(authenticationOptions)
|
||||
.WithLoadBalancerKey("/api/products/{productId}|Get|")
|
||||
@ -791,12 +808,13 @@
|
||||
{
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamReRoute(downstreamReRoute)
|
||||
.WithUpstreamPathTemplate("/api/products/{productId}")
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithTemplate("woop").WithOriginalValue("/api/products/{productId}").Build())
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.Build()
|
||||
};
|
||||
|
||||
this.Given(x => x.GivenTheConfigIs(fileConfig))
|
||||
.And(x => GivenTheUpstreamTemplatePatternCreatorReturns("woop", "/api/products/{productId}"))
|
||||
.And(x => GivenTheDownstreamAddresses())
|
||||
.And(x => x.GivenTheConfigIsValid())
|
||||
.And(x => GivenTheHeaderFindAndReplaceCreatorReturns())
|
||||
@ -828,11 +846,6 @@
|
||||
var reRouteOptions = new ReRouteOptionsBuilder()
|
||||
.Build();
|
||||
|
||||
var downstreamReRoute = new DownstreamReRouteBuilder()
|
||||
.WithEnableRateLimiting(true)
|
||||
.WithRateLimitOptions(new RateLimitOptionsBuilder().Build())
|
||||
.Build();
|
||||
|
||||
var rateLimitOptions = new RateLimitOptionsBuilder()
|
||||
.WithRateLimitRule(new RateLimitRule("1s", 1, 1))
|
||||
.Build();
|
||||
@ -923,6 +936,31 @@
|
||||
dynamic.RateLimitOptions.RateLimitRule.PeriodTimespan.ShouldBe(rateLimitOptions.PeriodTimespan);
|
||||
}
|
||||
|
||||
private void ThenTheAggregateReRoutesAre(List<ReRoute> expectedReRoutes)
|
||||
{
|
||||
for (int i = 0; i < _config.Data.ReRoutes.Count; i++)
|
||||
{
|
||||
var result = _config.Data.ReRoutes[i];
|
||||
var expected = expectedReRoutes[i];
|
||||
|
||||
result.DownstreamReRoute.Count.ShouldBe(expected.DownstreamReRoute.Count);
|
||||
|
||||
result.UpstreamHttpMethod.ShouldBe(expected.UpstreamHttpMethod);
|
||||
result.UpstreamTemplatePattern.OriginalValue.ShouldBe(expected.UpstreamTemplatePattern.OriginalValue);
|
||||
result.UpstreamTemplatePattern.Template.ShouldBe(expected.UpstreamTemplatePattern.Template);
|
||||
|
||||
result.DownstreamReRoute[0].DownstreamDownstreamPathTemplate.Value.ShouldBe(expected.DownstreamReRoute[0].DownstreamDownstreamPathTemplate.Value);
|
||||
result.DownstreamReRoute[0].ClaimsToClaims.Count.ShouldBe(expected.DownstreamReRoute[0].ClaimsToClaims.Count);
|
||||
result.DownstreamReRoute[0].ClaimsToHeaders.Count.ShouldBe(expected.DownstreamReRoute[0].ClaimsToHeaders.Count);
|
||||
result.DownstreamReRoute[0].ClaimsToQueries.Count.ShouldBe(expected.DownstreamReRoute[0].ClaimsToQueries.Count);
|
||||
result.DownstreamReRoute[0].RequestIdKey.ShouldBe(expected.DownstreamReRoute[0].RequestIdKey);
|
||||
result.DownstreamReRoute[0].LoadBalancerKey.ShouldBe(expected.DownstreamReRoute[0].LoadBalancerKey);
|
||||
result.DownstreamReRoute[0].DelegatingHandlers.ShouldBe(expected.DownstreamReRoute[0].DelegatingHandlers);
|
||||
result.DownstreamReRoute[0].AddHeadersToDownstream.ShouldBe(expected.DownstreamReRoute[0].AddHeadersToDownstream);
|
||||
result.DownstreamReRoute[0].AddHeadersToUpstream.ShouldBe(expected.DownstreamReRoute[0].AddHeadersToUpstream, "AddHeadersToUpstream should be set");
|
||||
}
|
||||
}
|
||||
|
||||
private void ThenTheReRoutesAre(List<ReRoute> expectedReRoutes)
|
||||
{
|
||||
for (int i = 0; i < _config.Data.ReRoutes.Count; i++)
|
||||
@ -932,10 +970,11 @@
|
||||
|
||||
result.DownstreamReRoute.Count.ShouldBe(expected.DownstreamReRoute.Count);
|
||||
|
||||
result.DownstreamReRoute[0].DownstreamPathTemplate.Value.ShouldBe(expected.DownstreamReRoute[0].DownstreamPathTemplate.Value);
|
||||
result.UpstreamHttpMethod.ShouldBe(expected.UpstreamHttpMethod);
|
||||
result.UpstreamPathTemplate.Value.ShouldBe(expected.UpstreamPathTemplate.Value);
|
||||
result.UpstreamTemplatePattern?.Template.ShouldBe(expected.UpstreamTemplatePattern?.Template);
|
||||
result.UpstreamTemplatePattern.OriginalValue.ShouldBe(expected.UpstreamTemplatePattern.OriginalValue);
|
||||
result.UpstreamTemplatePattern.Template.ShouldBe(expected.UpstreamTemplatePattern.Template);
|
||||
|
||||
result.DownstreamReRoute[0].DownstreamDownstreamPathTemplate.Value.ShouldBe(expected.DownstreamReRoute[0].DownstreamDownstreamPathTemplate.Value);
|
||||
result.DownstreamReRoute[0].ClaimsToClaims.Count.ShouldBe(expected.DownstreamReRoute[0].ClaimsToClaims.Count);
|
||||
result.DownstreamReRoute[0].ClaimsToHeaders.Count.ShouldBe(expected.DownstreamReRoute[0].ClaimsToHeaders.Count);
|
||||
result.DownstreamReRoute[0].ClaimsToQueries.Count.ShouldBe(expected.DownstreamReRoute[0].ClaimsToQueries.Count);
|
||||
@ -977,11 +1016,22 @@
|
||||
.Verify(x => x.Create(_fileConfiguration.ReRoutes[0]), Times.Once);
|
||||
}
|
||||
|
||||
private void GivenTheUpstreamTemplatePatternCreatorReturns(string pattern)
|
||||
private void GivenTheUpstreamTemplatePatternCreatorReturns(string pattern, string original)
|
||||
{
|
||||
_upstreamTemplatePatternCreator
|
||||
.Setup(x => x.Create(It.IsAny<FileReRoute>()))
|
||||
.Returns(new UpstreamPathTemplate(pattern, 1, false));
|
||||
.Returns(new UpstreamPathTemplate(pattern, 1, false, original));
|
||||
}
|
||||
|
||||
private void GivenTheUpstreamTemplatePatternCreatorReturns(params (string pattern, string original)[] list)
|
||||
{
|
||||
var builder = _upstreamTemplatePatternCreator
|
||||
.SetupSequence(x => x.Create(It.IsAny<IReRoute>()));
|
||||
|
||||
foreach (var p in list)
|
||||
{
|
||||
builder.Returns(new UpstreamPathTemplate(p.pattern, 1, false, p.original));
|
||||
}
|
||||
}
|
||||
|
||||
private void ThenTheRequestIdKeyCreatorIsCalledCorrectly()
|
||||
|
@ -42,7 +42,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
|
||||
private void ThenTheConfigurationIsReturned()
|
||||
{
|
||||
_getResult.Data.ReRoutes[0].DownstreamReRoute[0].DownstreamPathTemplate.Value.ShouldBe("initial");
|
||||
_getResult.Data.ReRoutes[0].DownstreamReRoute[0].DownstreamDownstreamPathTemplate.Value.ShouldBe("initial");
|
||||
}
|
||||
|
||||
private void WhenIGetTheConfiguration()
|
||||
|
@ -85,7 +85,7 @@
|
||||
new FileReRoute
|
||||
{
|
||||
DownstreamScheme = "DownstreamScheme",
|
||||
DownstreamPathTemplate = "DownstreamPathTemplate",
|
||||
DownstreamPathTemplate = "DownstreamDownstreamPathTemplate",
|
||||
Key = "Key",
|
||||
UpstreamHost = "UpstreamHost",
|
||||
UpstreamHttpMethod = new List<string>
|
||||
|
@ -211,7 +211,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
|
||||
private void ThenTheDownstreamRouteIsCreated()
|
||||
{
|
||||
_result.Data.ReRoute.DownstreamReRoute[0].DownstreamPathTemplate.Value.ShouldBe("/test");
|
||||
_result.Data.ReRoute.DownstreamReRoute[0].DownstreamDownstreamPathTemplate.Value.ShouldBe("/test");
|
||||
_result.Data.ReRoute.UpstreamHttpMethod[0].ShouldBe(HttpMethod.Get);
|
||||
_result.Data.ReRoute.DownstreamReRoute[0].ServiceName.ShouldBe("auth");
|
||||
_result.Data.ReRoute.DownstreamReRoute[0].LoadBalancerKey.ShouldBe("/auth/test|GET");
|
||||
@ -226,21 +226,21 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
|
||||
private void ThenTheDownstreamPathIsForwardSlash()
|
||||
{
|
||||
_result.Data.ReRoute.DownstreamReRoute[0].DownstreamPathTemplate.Value.ShouldBe("/");
|
||||
_result.Data.ReRoute.DownstreamReRoute[0].DownstreamDownstreamPathTemplate.Value.ShouldBe("/");
|
||||
_result.Data.ReRoute.DownstreamReRoute[0].ServiceName.ShouldBe("auth");
|
||||
_result.Data.ReRoute.DownstreamReRoute[0].LoadBalancerKey.ShouldBe("/auth/|GET");
|
||||
}
|
||||
|
||||
private void ThenThePathDoesNotHaveTrailingSlash()
|
||||
{
|
||||
_result.Data.ReRoute.DownstreamReRoute[0].DownstreamPathTemplate.Value.ShouldBe("/test");
|
||||
_result.Data.ReRoute.DownstreamReRoute[0].DownstreamDownstreamPathTemplate.Value.ShouldBe("/test");
|
||||
_result.Data.ReRoute.DownstreamReRoute[0].ServiceName.ShouldBe("auth");
|
||||
_result.Data.ReRoute.DownstreamReRoute[0].LoadBalancerKey.ShouldBe("/auth/test|GET");
|
||||
}
|
||||
|
||||
private void ThenTheQueryStringIsRemoved()
|
||||
{
|
||||
_result.Data.ReRoute.DownstreamReRoute[0].DownstreamPathTemplate.Value.ShouldBe("/test");
|
||||
_result.Data.ReRoute.DownstreamReRoute[0].DownstreamDownstreamPathTemplate.Value.ShouldBe("/test");
|
||||
_result.Data.ReRoute.DownstreamReRoute[0].ServiceName.ShouldBe("auth");
|
||||
_result.Data.ReRoute.DownstreamReRoute[0].LoadBalancerKey.ShouldBe("/auth/test|GET");
|
||||
}
|
||||
|
@ -47,24 +47,20 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamReRoute(new DownstreamReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPath")
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Post" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("test", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("test", 1, false, "someUpstreamPath"))
|
||||
.Build())
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Post" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("test", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("test", 1, false, "someUpstreamPath"))
|
||||
.Build(),
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamReRoute(new DownstreamReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPath")
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Post" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("test", 0, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("test", 0, false, "someUpstreamPath"))
|
||||
.Build())
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Post" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("test", 0, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("test", 0, false, "someUpstreamPath"))
|
||||
.Build()
|
||||
}, string.Empty, serviceProviderConfig))
|
||||
.And(x => x.GivenTheUrlMatcherReturns(new OkResponse<UrlMatch>(new UrlMatch(true))))
|
||||
@ -74,13 +70,11 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamReRoute(new DownstreamReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPath")
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("test", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("test", 1, false, "someUpstreamPath"))
|
||||
.WithUpstreamHttpMethod(new List<string> { "Post" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("test", 1, false))
|
||||
.Build())
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("test", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("test", 1, false, "someUpstreamPath"))
|
||||
.WithUpstreamHttpMethod(new List<string> { "Post" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("test", 1, false))
|
||||
.Build()
|
||||
)))
|
||||
.BDDfy();
|
||||
@ -99,24 +93,20 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamReRoute(new DownstreamReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPath")
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Post" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("test", 0, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("test", 0, false, "someUpstreamPath"))
|
||||
.Build())
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Post" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("test", 0, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("test", 0, false, "someUpstreamPath"))
|
||||
.Build(),
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamReRoute(new DownstreamReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPath")
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Post" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("test", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("test", 1, false, "someUpstreamPath"))
|
||||
.Build())
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Post" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("test", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("test", 1, false, "someUpstreamPath"))
|
||||
.Build()
|
||||
}, string.Empty, serviceProviderConfig))
|
||||
.And(x => x.GivenTheUrlMatcherReturns(new OkResponse<UrlMatch>(new UrlMatch(true))))
|
||||
@ -126,10 +116,10 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamReRoute(new DownstreamReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPath")
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("test", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("test", 1, false, "someUpstreamPath"))
|
||||
.WithUpstreamHttpMethod(new List<string> { "Post" })
|
||||
.Build())
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("test", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("test", 1, false, "someUpstreamPath"))
|
||||
.WithUpstreamHttpMethod(new List<string> { "Post" })
|
||||
.Build()
|
||||
)))
|
||||
@ -150,13 +140,11 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamReRoute(new DownstreamReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPath")
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false, "someUpstreamPath"))
|
||||
.Build())
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false, "someUpstreamPath"))
|
||||
.Build()
|
||||
}, string.Empty, serviceProviderConfig
|
||||
))
|
||||
@ -170,10 +158,10 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
.WithDownstreamReRoute(new DownstreamReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false, "someUpstreamPath"))
|
||||
.Build())
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false, "someUpstreamPath"))
|
||||
.Build()
|
||||
)))
|
||||
.And(x => x.ThenTheUrlMatcherIsCalledCorrectly())
|
||||
@ -194,13 +182,11 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamReRoute(new DownstreamReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPath")
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false, "someUpstreamPath"))
|
||||
.Build())
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false, "someUpstreamPath"))
|
||||
.Build()
|
||||
}, string.Empty, serviceProviderConfig
|
||||
))
|
||||
@ -214,10 +200,10 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
.WithDownstreamReRoute(new DownstreamReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false, "someUpstreamPath"))
|
||||
.Build())
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false, "someUpstreamPath"))
|
||||
.Build()
|
||||
)))
|
||||
.And(x => x.ThenTheUrlMatcherIsCalledCorrectly("matchInUrlMatcher"))
|
||||
@ -239,13 +225,11 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamReRoute(new DownstreamReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPath")
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false, "someUpstreamPath"))
|
||||
.Build())
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false, "someUpstreamPath"))
|
||||
.Build()
|
||||
}, string.Empty, serviceProviderConfig
|
||||
))
|
||||
@ -258,10 +242,10 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
.WithDownstreamReRoute(new DownstreamReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false, "someUpstreamPath"))
|
||||
.Build())
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false, "someUpstreamPath"))
|
||||
.Build()
|
||||
)))
|
||||
.BDDfy();
|
||||
@ -282,24 +266,20 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamReRoute(new DownstreamReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPath")
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("", 1, false, "someUpstreamPath"))
|
||||
.Build())
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("", 1, false, "someUpstreamPath"))
|
||||
.Build(),
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamReRoute(new DownstreamReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPathForAPost")
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Post" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("", 1, false, "someUpstreamPath"))
|
||||
.Build())
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Post" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("", 1, false, "someUpstreamPath"))
|
||||
.Build()
|
||||
}, string.Empty, serviceProviderConfig
|
||||
))
|
||||
@ -312,10 +292,10 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
.WithDownstreamReRoute(new DownstreamReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPathForAPost")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Post" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("", 1, false, "someUpstreamPath"))
|
||||
.Build())
|
||||
.WithUpstreamHttpMethod(new List<string> { "Post" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("", 1, false, "someUpstreamPath"))
|
||||
.Build()
|
||||
)))
|
||||
.BDDfy();
|
||||
@ -332,13 +312,11 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamReRoute(new DownstreamReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("somPath")
|
||||
.WithUpstreamPathTemplate("somePath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("somePath", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("somePath", 1, false, "someUpstreamPath"))
|
||||
.Build())
|
||||
.WithUpstreamPathTemplate("somePath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("somePath", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("somePath", 1, false, "someUpstreamPath"))
|
||||
.Build(),
|
||||
}, string.Empty, serviceProviderConfig
|
||||
))
|
||||
@ -366,13 +344,11 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamReRoute(new DownstreamReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPath")
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get", "Post" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("", 1, false, "someUpstreamPath"))
|
||||
.Build())
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get", "Post" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("", 1, false, "someUpstreamPath"))
|
||||
.Build()
|
||||
}, string.Empty, serviceProviderConfig
|
||||
))
|
||||
@ -385,10 +361,10 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
.WithDownstreamReRoute(new DownstreamReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Post" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("", 1, false, "someUpstreamPath"))
|
||||
.Build())
|
||||
.WithUpstreamHttpMethod(new List<string> { "Post" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("", 1, false, "someUpstreamPath"))
|
||||
.Build()
|
||||
)))
|
||||
.BDDfy();
|
||||
@ -409,13 +385,11 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamReRoute(new DownstreamReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPath")
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string>())
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("", 1, false, "someUpstreamPath"))
|
||||
.Build())
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string>())
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("", 1, false, "someUpstreamPath"))
|
||||
.Build()
|
||||
}, string.Empty, serviceProviderConfig
|
||||
))
|
||||
@ -428,10 +402,10 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
.WithDownstreamReRoute(new DownstreamReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Post" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("", 1, false, "someUpstreamPath"))
|
||||
.Build())
|
||||
.WithUpstreamHttpMethod(new List<string> { "Post" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("", 1, false, "someUpstreamPath"))
|
||||
.Build()
|
||||
)))
|
||||
.BDDfy();
|
||||
@ -452,13 +426,11 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamReRoute(new DownstreamReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPath")
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get", "Patch", "Delete" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("", 1, false, "someUpstreamPath"))
|
||||
.Build())
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get", "Patch", "Delete" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("", 1, false, "someUpstreamPath"))
|
||||
.Build()
|
||||
}, string.Empty, serviceProviderConfig
|
||||
))
|
||||
@ -485,14 +457,12 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamReRoute(new DownstreamReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPath")
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false, "someUpstreamPath"))
|
||||
.WithUpstreamHost("MATCH")
|
||||
.Build())
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false, "someUpstreamPath"))
|
||||
.WithUpstreamHost("MATCH")
|
||||
.Build()
|
||||
}, string.Empty, serviceProviderConfig
|
||||
@ -507,10 +477,10 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
.WithDownstreamReRoute(new DownstreamReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false, "someUpstreamPath"))
|
||||
.Build())
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false, "someUpstreamPath"))
|
||||
.Build()
|
||||
)))
|
||||
.And(x => x.ThenTheUrlMatcherIsCalledCorrectly())
|
||||
@ -532,13 +502,11 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamReRoute(new DownstreamReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPath")
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false, "someUpstreamPath"))
|
||||
.Build())
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false, "someUpstreamPath"))
|
||||
.Build()
|
||||
}, string.Empty, serviceProviderConfig
|
||||
))
|
||||
@ -552,10 +520,10 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
.WithDownstreamReRoute(new DownstreamReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false, "someUpstreamPath"))
|
||||
.Build())
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false, "someUpstreamPath"))
|
||||
.Build()
|
||||
)))
|
||||
.And(x => x.ThenTheUrlMatcherIsCalledCorrectly())
|
||||
@ -575,27 +543,23 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamReRoute(new DownstreamReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPath")
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false, "someUpstreamPath"))
|
||||
.WithUpstreamHost("MATCH")
|
||||
.Build())
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false, "someUpstreamPath"))
|
||||
.WithUpstreamHost("MATCH")
|
||||
.Build(),
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamReRoute(new DownstreamReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPath")
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { }) // empty list of methods
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false, "someUpstreamPath"))
|
||||
.WithUpstreamHost("MATCH")
|
||||
.Build())
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { }) // empty list of methods
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false, "someUpstreamPath"))
|
||||
.WithUpstreamHost("MATCH")
|
||||
.Build()
|
||||
}, string.Empty, serviceProviderConfig
|
||||
@ -621,14 +585,12 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamReRoute(new DownstreamReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPath")
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string>())
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false, "someUpstreamPath"))
|
||||
.WithUpstreamHost("MATCH")
|
||||
.Build())
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string>())
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false, "someUpstreamPath"))
|
||||
.WithUpstreamHost("MATCH")
|
||||
.Build()
|
||||
}, string.Empty, serviceProviderConfig
|
||||
@ -654,14 +616,12 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamReRoute(new DownstreamReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPath")
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string>())
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false, "someUpstreamPath"))
|
||||
.WithUpstreamHost("MATCH")
|
||||
.Build())
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string>())
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false, "someUpstreamPath"))
|
||||
.WithUpstreamHost("MATCH")
|
||||
.Build()
|
||||
}, string.Empty, serviceProviderConfig
|
||||
@ -688,25 +648,21 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamReRoute(new DownstreamReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("THENULLPATH")
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false, "someUpstreamPath"))
|
||||
.Build())
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false, "someUpstreamPath"))
|
||||
.Build(),
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamReRoute(new DownstreamReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPath")
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false, "someUpstreamPath"))
|
||||
.WithUpstreamHost("MATCH")
|
||||
.Build())
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false, "someUpstreamPath"))
|
||||
.WithUpstreamHost("MATCH")
|
||||
.Build()
|
||||
}, string.Empty, serviceProviderConfig
|
||||
@ -721,10 +677,10 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
.WithDownstreamReRoute(new DownstreamReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false, "test"))
|
||||
.Build())
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false))
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1, false, "test"))
|
||||
.Build()
|
||||
)))
|
||||
.And(x => x.ThenTheUrlMatcherIsCalledCorrectly(2))
|
||||
@ -756,25 +712,25 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
private void ThenTheUrlMatcherIsCalledCorrectly()
|
||||
{
|
||||
_mockMatcher
|
||||
.Verify(x => x.Match(_upstreamUrlPath, _upstreamQuery, _reRoutesConfig[0].UpstreamPathTemplate.Value, _reRoutesConfig[0].UpstreamTemplatePattern.ContainsQueryString), Times.Once);
|
||||
.Verify(x => x.Match(_upstreamUrlPath, _upstreamQuery, _reRoutesConfig[0].UpstreamTemplatePattern.Template, _reRoutesConfig[0].UpstreamTemplatePattern.ContainsQueryString), Times.Once);
|
||||
}
|
||||
|
||||
private void ThenTheUrlMatcherIsCalledCorrectly(int times)
|
||||
{
|
||||
_mockMatcher
|
||||
.Verify(x => x.Match(_upstreamUrlPath, _upstreamQuery, _reRoutesConfig[0].UpstreamPathTemplate.Value, _reRoutesConfig[0].UpstreamTemplatePattern.ContainsQueryString), Times.Exactly(times));
|
||||
.Verify(x => x.Match(_upstreamUrlPath, _upstreamQuery, _reRoutesConfig[0].UpstreamTemplatePattern.OriginalValue, _reRoutesConfig[0].UpstreamTemplatePattern.ContainsQueryString), Times.Exactly(times));
|
||||
}
|
||||
|
||||
private void ThenTheUrlMatcherIsCalledCorrectly(string expectedUpstreamUrlPath)
|
||||
{
|
||||
_mockMatcher
|
||||
.Verify(x => x.Match(expectedUpstreamUrlPath, _upstreamQuery, _reRoutesConfig[0].UpstreamPathTemplate.Value, _reRoutesConfig[0].UpstreamTemplatePattern.ContainsQueryString), Times.Once);
|
||||
.Verify(x => x.Match(expectedUpstreamUrlPath, _upstreamQuery, _reRoutesConfig[0].UpstreamTemplatePattern.OriginalValue, _reRoutesConfig[0].UpstreamTemplatePattern.ContainsQueryString), Times.Once);
|
||||
}
|
||||
|
||||
private void ThenTheUrlMatcherIsNotCalled()
|
||||
{
|
||||
_mockMatcher
|
||||
.Verify(x => x.Match(_upstreamUrlPath, _upstreamQuery, _reRoutesConfig[0].UpstreamPathTemplate.Value, _reRoutesConfig[0].UpstreamTemplatePattern.ContainsQueryString), Times.Never);
|
||||
.Verify(x => x.Match(_upstreamUrlPath, _upstreamQuery, _reRoutesConfig[0].UpstreamTemplatePattern.OriginalValue, _reRoutesConfig[0].UpstreamTemplatePattern.ContainsQueryString), Times.Never);
|
||||
}
|
||||
|
||||
private void GivenTheUrlMatcherReturns(Response<UrlMatch> match)
|
||||
@ -803,7 +759,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
|
||||
private void ThenTheFollowingIsReturned(DownstreamRoute expected)
|
||||
{
|
||||
_result.Data.ReRoute.DownstreamReRoute[0].DownstreamPathTemplate.Value.ShouldBe(expected.ReRoute.DownstreamReRoute[0].DownstreamPathTemplate.Value);
|
||||
_result.Data.ReRoute.DownstreamReRoute[0].DownstreamDownstreamPathTemplate.Value.ShouldBe(expected.ReRoute.DownstreamReRoute[0].DownstreamDownstreamPathTemplate.Value);
|
||||
_result.Data.ReRoute.UpstreamTemplatePattern.Priority.ShouldBe(expected.ReRoute.UpstreamTemplatePattern.Priority);
|
||||
|
||||
for (int i = 0; i < _result.Data.TemplatePlaceholderNameAndValues.Count; i++)
|
||||
|
@ -5,11 +5,8 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
using Moq;
|
||||
using Ocelot.Configuration;
|
||||
using Ocelot.Configuration.Builder;
|
||||
using Ocelot.DownstreamRouteFinder;
|
||||
using Ocelot.DownstreamRouteFinder.Finder;
|
||||
using Ocelot.DownstreamRouteFinder.UrlMatcher;
|
||||
using Ocelot.Responses;
|
||||
using Ocelot.Values;
|
||||
using Shouldly;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
@ -30,8 +27,8 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
services.AddSingleton<IPlaceholderNameAndValueFinder, UrlPathPlaceholderNameAndValueFinder>();
|
||||
services.AddSingleton<IUrlPathToUrlTemplateMatcher, RegExUrlMatcher>();
|
||||
services.AddSingleton<IQoSOptionsCreator, QoSOptionsCreator>();
|
||||
services.AddSingleton<IDownstreamRouteProvider, Ocelot.DownstreamRouteFinder.Finder.DownstreamRouteFinder>();
|
||||
services.AddSingleton<IDownstreamRouteProvider, Ocelot.DownstreamRouteFinder.Finder.DownstreamRouteCreator>();
|
||||
services.AddSingleton<IDownstreamRouteProvider, DownstreamRouteFinder>();
|
||||
services.AddSingleton<IDownstreamRouteProvider, DownstreamRouteCreator>();
|
||||
var provider = services.BuildServiceProvider();
|
||||
_logger = new Mock<IOcelotLogger>();
|
||||
_loggerFactory = new Mock<IOcelotLoggerFactory>();
|
||||
@ -49,7 +46,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
|
||||
this.Given(_ => GivenTheReRoutes(reRoutes))
|
||||
.When(_ => WhenIGet())
|
||||
.Then(_ => ThenTheResultShouldBe<Ocelot.DownstreamRouteFinder.Finder.DownstreamRouteFinder>())
|
||||
.Then(_ => ThenTheResultShouldBe<DownstreamRouteFinder>())
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
@ -59,12 +56,12 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
var spConfig = new ServiceProviderConfigurationBuilder().WithHost("test").WithPort(50).WithType("test").Build();
|
||||
var reRoutes = new List<ReRoute>
|
||||
{
|
||||
new ReRouteBuilder().WithUpstreamPathTemplate("woot").Build()
|
||||
new ReRouteBuilder().WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithOriginalValue("woot").Build()).Build()
|
||||
};
|
||||
|
||||
this.Given(_ => GivenTheReRoutes(reRoutes, spConfig))
|
||||
.When(_ => WhenIGet())
|
||||
.Then(_ => ThenTheResultShouldBe<Ocelot.DownstreamRouteFinder.Finder.DownstreamRouteFinder>())
|
||||
.Then(_ => ThenTheResultShouldBe<DownstreamRouteFinder>())
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
@ -76,7 +73,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
|
||||
this.Given(_ => GivenTheReRoutes(reRoutes, spConfig))
|
||||
.When(_ => WhenIGet())
|
||||
.Then(_ => ThenTheResultShouldBe<Ocelot.DownstreamRouteFinder.Finder.DownstreamRouteFinder>())
|
||||
.Then(_ => ThenTheResultShouldBe<DownstreamRouteFinder>())
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
@ -88,7 +85,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
|
||||
this.Given(_ => GivenTheReRoutes(reRoutes, spConfig))
|
||||
.When(_ => WhenIGet())
|
||||
.Then(_ => ThenTheResultShouldBe<Ocelot.DownstreamRouteFinder.Finder.DownstreamRouteFinder>())
|
||||
.Then(_ => ThenTheResultShouldBe<DownstreamRouteFinder>())
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
@ -100,7 +97,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
|
||||
this.Given(_ => GivenTheReRoutes(reRoutes, spConfig))
|
||||
.When(_ => WhenIGet())
|
||||
.Then(_ => ThenTheResultShouldBe<Ocelot.DownstreamRouteFinder.Finder.DownstreamRouteFinder>())
|
||||
.Then(_ => ThenTheResultShouldBe<DownstreamRouteFinder>())
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
@ -112,7 +109,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
|
||||
this.Given(_ => GivenTheReRoutes(reRoutes, spConfig))
|
||||
.When(_ => WhenIGet())
|
||||
.Then(_ => ThenTheResultShouldBe<Ocelot.DownstreamRouteFinder.Finder.DownstreamRouteCreator>())
|
||||
.Then(_ => ThenTheResultShouldBe<DownstreamRouteCreator>())
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
@ -127,7 +124,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
|
||||
this.Given(_ => GivenTheReRoutes(reRoutes, spConfig))
|
||||
.When(_ => WhenIGet())
|
||||
.Then(_ => ThenTheResultShouldBe<Ocelot.DownstreamRouteFinder.Finder.DownstreamRouteCreator>())
|
||||
.Then(_ => ThenTheResultShouldBe<DownstreamRouteCreator>())
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
|
@ -296,7 +296,7 @@
|
||||
.WithDownstreamPathTemplate("/Authorized/{action}?server={server}")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Post", "Get" })
|
||||
.WithDownstreamScheme("http")
|
||||
.WithUpstreamPathTemplate("/uc/Authorized/{server}/{action}")
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithOriginalValue("/uc/Authorized/{server}/{action}").Build())
|
||||
.Build();
|
||||
|
||||
var config = new ServiceProviderConfigurationBuilder()
|
||||
@ -350,7 +350,7 @@
|
||||
{
|
||||
_downstreamPath = new OkResponse<DownstreamPath>(new DownstreamPath(path));
|
||||
_downstreamUrlTemplateVariableReplacer
|
||||
.Setup(x => x.Replace(It.IsAny<PathTemplate>(), It.IsAny<List<PlaceholderNameAndValue>>()))
|
||||
.Setup(x => x.Replace(It.IsAny<DownstreamPathTemplate>(), It.IsAny<List<PlaceholderNameAndValue>>()))
|
||||
.Returns(_downstreamPath);
|
||||
}
|
||||
|
||||
|
@ -199,7 +199,7 @@ namespace Ocelot.UnitTests.DownstreamUrlCreator.UrlTemplateReplacer
|
||||
|
||||
private void WhenIReplaceTheTemplateVariables()
|
||||
{
|
||||
_result = _downstreamPathReplacer.Replace(_downstreamRoute.ReRoute.DownstreamReRoute[0].DownstreamPathTemplate, _downstreamRoute.TemplatePlaceholderNameAndValues);
|
||||
_result = _downstreamPathReplacer.Replace(_downstreamRoute.ReRoute.DownstreamReRoute[0].DownstreamDownstreamPathTemplate, _downstreamRoute.TemplatePlaceholderNameAndValues);
|
||||
}
|
||||
|
||||
private void ThenTheDownstreamUrlPathIsReturned(string expected)
|
||||
|
@ -49,15 +49,22 @@ namespace Ocelot.UnitTests.RateLimit
|
||||
|
||||
[Fact]
|
||||
public void should_call_middleware_and_ratelimiting()
|
||||
{
|
||||
var downstreamRoute = new DownstreamRoute(new List<Ocelot.DownstreamRouteFinder.UrlMatcher.PlaceholderNameAndValue>(),
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamReRoute(new DownstreamReRouteBuilder().WithEnableRateLimiting(true).WithRateLimitOptions(
|
||||
new RateLimitOptions(true, "ClientId", new List<string>(), false, "", "", new RateLimitRule("1s", 100, 3), 429))
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.Build())
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.Build());
|
||||
{
|
||||
var upstreamTemplate = new UpstreamPathTemplateBuilder().Build();
|
||||
|
||||
var downstreamReRoute = new DownstreamReRouteBuilder()
|
||||
.WithEnableRateLimiting(true)
|
||||
.WithRateLimitOptions(new RateLimitOptions(true, "ClientId", new List<string>(), false, "", "", new RateLimitRule("1s", 100, 3), 429))
|
||||
.WithUpstreamHttpMethod(new List<string> {"Get"})
|
||||
.WithUpstreamTemplatePattern(upstreamTemplate)
|
||||
.Build();
|
||||
|
||||
var reRoute = new ReRouteBuilder()
|
||||
.WithDownstreamReRoute(downstreamReRoute)
|
||||
.WithUpstreamHttpMethod(new List<string> {"Get"})
|
||||
.Build();
|
||||
|
||||
var downstreamRoute = new DownstreamRoute(new List<Ocelot.DownstreamRouteFinder.UrlMatcher.PlaceholderNameAndValue>(), reRoute);
|
||||
|
||||
this.Given(x => x.GivenTheDownStreamRouteIs(downstreamRoute))
|
||||
.When(x => x.WhenICallTheMiddlewareMultipleTime(2))
|
||||
|
@ -54,6 +54,7 @@ namespace Ocelot.UnitTests.Requester
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(false, false, false, true))
|
||||
.WithLoadBalancerKey("")
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithOriginalValue("").Build())
|
||||
.WithQosOptions(new QoSOptionsBuilder().Build())
|
||||
.Build();
|
||||
|
||||
@ -74,6 +75,7 @@ namespace Ocelot.UnitTests.Requester
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(false, false, false, true))
|
||||
.WithLoadBalancerKey("")
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithOriginalValue("").Build())
|
||||
.WithQosOptions(new QoSOptionsBuilder().Build())
|
||||
.Build();
|
||||
|
||||
@ -89,6 +91,68 @@ namespace Ocelot.UnitTests.Requester
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_get_from_cache_with_different_query_string()
|
||||
{
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(false, false, false, true))
|
||||
.WithLoadBalancerKey("")
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithOriginalValue("").Build())
|
||||
.WithQosOptions(new QoSOptionsBuilder().Build())
|
||||
.Build();
|
||||
|
||||
this.Given(x => GivenARealCache())
|
||||
.And(x => GivenTheFactoryReturns())
|
||||
.And(x => GivenARequest(reRoute, "http://wwww.someawesomewebsite.com/woot?badman=1"))
|
||||
.And(x => WhenIBuildTheFirstTime())
|
||||
.And(x => WhenISave())
|
||||
.And(x => WhenIBuildAgain())
|
||||
.And(x => GivenARequest(reRoute, "http://wwww.someawesomewebsite.com/woot?badman=2"))
|
||||
.And(x => WhenISave())
|
||||
.When(x => WhenIBuildAgain())
|
||||
.Then(x => ThenTheHttpClientIsFromTheCache())
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_not_get_from_cache_with_different_query_string()
|
||||
{
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.Build();
|
||||
|
||||
var reRouteA = new DownstreamReRouteBuilder()
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(false, false, false, true))
|
||||
.WithLoadBalancerKey("")
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithContainsQueryString(true).WithOriginalValue("").Build())
|
||||
.WithQosOptions(new QoSOptionsBuilder().Build())
|
||||
.Build();
|
||||
|
||||
var reRouteB = new DownstreamReRouteBuilder()
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(false, false, false, true))
|
||||
.WithLoadBalancerKey("")
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithContainsQueryString(true).WithOriginalValue("").Build())
|
||||
.WithQosOptions(new QoSOptionsBuilder().Build())
|
||||
.Build();
|
||||
|
||||
this.Given(x => GivenARealCache())
|
||||
.And(x => GivenTheFactoryReturns())
|
||||
.And(x => GivenARequest(reRouteA, "http://wwww.someawesomewebsite.com/woot?badman=1"))
|
||||
.And(x => WhenIBuildTheFirstTime())
|
||||
.And(x => WhenISave())
|
||||
.And(x => WhenIBuildAgain())
|
||||
.And(x => GivenARequest(reRouteB, "http://wwww.someawesomewebsite.com/woot?badman=2"))
|
||||
.And(x => WhenISave())
|
||||
.When(x => WhenIBuildAgain())
|
||||
.Then(x => ThenTheHttpClientIsNotFromTheCache())
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_log_if_ignoring_ssl_errors()
|
||||
{
|
||||
@ -99,6 +163,7 @@ namespace Ocelot.UnitTests.Requester
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(false, false, false, true))
|
||||
.WithLoadBalancerKey("")
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithOriginalValue("").Build())
|
||||
.WithQosOptions(new QoSOptionsBuilder().Build())
|
||||
.WithDangerousAcceptAnyServerCertificateValidator(true)
|
||||
.Build();
|
||||
@ -121,6 +186,7 @@ namespace Ocelot.UnitTests.Requester
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(false, false, false, true))
|
||||
.WithLoadBalancerKey("")
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithOriginalValue("").Build())
|
||||
.WithQosOptions(new QoSOptionsBuilder().Build())
|
||||
.Build();
|
||||
|
||||
@ -152,6 +218,7 @@ namespace Ocelot.UnitTests.Requester
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(false, true, false, true))
|
||||
.WithLoadBalancerKey("")
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithOriginalValue("").Build())
|
||||
.WithQosOptions(new QoSOptionsBuilder().Build())
|
||||
.Build();
|
||||
|
||||
@ -176,9 +243,9 @@ namespace Ocelot.UnitTests.Requester
|
||||
[InlineData("PATCH")]
|
||||
public void should_add_verb_to_cache_key(string verb)
|
||||
{
|
||||
var client = "http://localhost:5012";
|
||||
var downstreamUrl = "http://localhost:5012/";
|
||||
|
||||
HttpMethod method = new HttpMethod(verb);
|
||||
var method = new HttpMethod(verb);
|
||||
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.Build();
|
||||
@ -187,14 +254,15 @@ namespace Ocelot.UnitTests.Requester
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(false, false, false, true))
|
||||
.WithLoadBalancerKey("")
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplateBuilder().WithOriginalValue("").Build())
|
||||
.WithQosOptions(new QoSOptionsBuilder().Build())
|
||||
.Build();
|
||||
|
||||
this.Given(_ => GivenADownstreamService())
|
||||
.And(_ => GivenARequestWithAUrlAndMethod(reRoute, client, method))
|
||||
.And(_ => GivenARequestWithAUrlAndMethod(reRoute, downstreamUrl, method))
|
||||
.And(_ => GivenTheFactoryReturnsNothing())
|
||||
.And(_ => WhenIBuild())
|
||||
.And(_ => GivenCacheIsCalledWithExpectedKey($"{method.ToString()}:{client}"))
|
||||
.And(_ => GivenCacheIsCalledWithExpectedKey($"{method.ToString()}:{downstreamUrl}"))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
@ -209,6 +277,11 @@ namespace Ocelot.UnitTests.Requester
|
||||
_againHttpClient.ShouldBe(_firstHttpClient);
|
||||
}
|
||||
|
||||
private void ThenTheHttpClientIsNotFromTheCache()
|
||||
{
|
||||
_againHttpClient.ShouldNotBe(_firstHttpClient);
|
||||
}
|
||||
|
||||
private void WhenISave()
|
||||
{
|
||||
_builder.Save();
|
||||
@ -216,17 +289,17 @@ namespace Ocelot.UnitTests.Requester
|
||||
|
||||
private void GivenCacheIsCalledWithExpectedKey(string expectedKey)
|
||||
{
|
||||
_cacheHandlers.Verify(x => x.Get(It.Is<string>(p => p.Equals(expectedKey, StringComparison.OrdinalIgnoreCase))), Times.Once);
|
||||
_cacheHandlers.Verify(x => x.Get(It.IsAny<DownstreamReRoute>()), Times.Once);
|
||||
}
|
||||
|
||||
private void ThenTheDangerousAcceptAnyServerCertificateValidatorWarningIsLogged()
|
||||
{
|
||||
_logger.Verify(x => x.LogWarning($"You have ignored all SSL warnings by using DangerousAcceptAnyServerCertificateValidator for this DownstreamReRoute, UpstreamPathTemplate: {_context.DownstreamReRoute.UpstreamPathTemplate}, DownstreamPathTemplate: {_context.DownstreamReRoute.DownstreamPathTemplate}"), Times.Once);
|
||||
_logger.Verify(x => x.LogWarning($"You have ignored all SSL warnings by using DangerousAcceptAnyServerCertificateValidator for this DownstreamReRoute, UpstreamPathTemplate: {_context.DownstreamReRoute.UpstreamPathTemplate}, DownstreamDownstreamPathTemplate: {_context.DownstreamReRoute.DownstreamDownstreamPathTemplate}"), Times.Once);
|
||||
}
|
||||
|
||||
private void GivenTheClientIsCached()
|
||||
{
|
||||
_cacheHandlers.Setup(x => x.Get(It.IsAny<string>())).Returns(_httpClient);
|
||||
_cacheHandlers.Setup(x => x.Get(It.IsAny<DownstreamReRoute>())).Returns(_httpClient);
|
||||
}
|
||||
|
||||
private void ThenTheCookieIsSet()
|
||||
@ -287,7 +360,12 @@ namespace Ocelot.UnitTests.Requester
|
||||
|
||||
private void GivenARequest(DownstreamReRoute downstream)
|
||||
{
|
||||
GivenARequestWithAUrlAndMethod(downstream, "http://localhost:5003", HttpMethod.Get);
|
||||
GivenARequest(downstream, "http://localhost:5003");
|
||||
}
|
||||
|
||||
private void GivenARequest(DownstreamReRoute downstream, string downstreamUrl)
|
||||
{
|
||||
GivenARequestWithAUrlAndMethod(downstream, downstreamUrl, HttpMethod.Get);
|
||||
}
|
||||
|
||||
private void GivenARequestWithAUrlAndMethod(DownstreamReRoute downstream, string url, HttpMethod method)
|
||||
|
@ -50,6 +50,8 @@ namespace Ocelot.UnitTests.Requester
|
||||
[Fact]
|
||||
public void should_call_request_correctly()
|
||||
{
|
||||
var upstreamTemplate = new UpstreamPathTemplateBuilder().WithOriginalValue("").Build();
|
||||
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.Build();
|
||||
|
||||
@ -57,6 +59,7 @@ namespace Ocelot.UnitTests.Requester
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(false, false, false, true))
|
||||
.WithLoadBalancerKey("")
|
||||
.WithUpstreamTemplatePattern(upstreamTemplate)
|
||||
.WithQosOptions(new QoSOptionsBuilder().Build())
|
||||
.Build();
|
||||
|
||||
@ -76,6 +79,8 @@ namespace Ocelot.UnitTests.Requester
|
||||
[Fact]
|
||||
public void should_call_request_unable_to_complete_request()
|
||||
{
|
||||
var upstreamTemplate = new UpstreamPathTemplateBuilder().WithOriginalValue("").Build();
|
||||
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.Build();
|
||||
|
||||
@ -83,6 +88,7 @@ namespace Ocelot.UnitTests.Requester
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(false, false, false, true))
|
||||
.WithLoadBalancerKey("")
|
||||
.WithUpstreamTemplatePattern(upstreamTemplate)
|
||||
.WithQosOptions(new QoSOptionsBuilder().Build())
|
||||
.Build();
|
||||
|
||||
@ -101,6 +107,8 @@ namespace Ocelot.UnitTests.Requester
|
||||
[Fact]
|
||||
public void http_client_request_times_out()
|
||||
{
|
||||
var upstreamTemplate = new UpstreamPathTemplateBuilder().WithOriginalValue("").Build();
|
||||
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.Build();
|
||||
|
||||
@ -108,6 +116,7 @@ namespace Ocelot.UnitTests.Requester
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(false, false, false, true))
|
||||
.WithLoadBalancerKey("")
|
||||
.WithUpstreamTemplatePattern(upstreamTemplate)
|
||||
.WithQosOptions(new QoSOptionsBuilder().WithTimeoutValue(1).Build())
|
||||
.Build();
|
||||
|
||||
@ -132,7 +141,7 @@ namespace Ocelot.UnitTests.Requester
|
||||
|
||||
private void WhenIGetResponse()
|
||||
{
|
||||
_response = _httpClientRequester.GetResponse(_request).Result;
|
||||
_response = _httpClientRequester.GetResponse(_request).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
private void ThenTheResponseIsCalledCorrectly()
|
||||
|
Reference in New Issue
Block a user