mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 05:48:16 +08:00
merge
This commit is contained in:
@ -10,8 +10,8 @@ namespace Ocelot.UnitTests.Configuration
|
||||
{
|
||||
public class ConfigurationValidationTests
|
||||
{
|
||||
private FileConfiguration _fileConfiguration;
|
||||
private readonly IConfigurationValidator _configurationValidator;
|
||||
private FileConfiguration _fileConfiguration;
|
||||
private Response<ConfigurationValidationResult> _result;
|
||||
|
||||
public ConfigurationValidationTests()
|
||||
@ -22,32 +22,13 @@ namespace Ocelot.UnitTests.Configuration
|
||||
[Fact]
|
||||
public void configuration_is_invalid_if_scheme_in_downstream_template()
|
||||
{
|
||||
this.Given(x => x.GivenAConfiguration(new FileConfiguration()
|
||||
this.Given(x => x.GivenAConfiguration(new FileConfiguration
|
||||
{
|
||||
ReRoutes = new List<FileReRoute>
|
||||
{
|
||||
new FileReRoute
|
||||
{
|
||||
DownstreamTemplate = "http://www.bbc.co.uk/api/products/{productId}",
|
||||
UpstreamTemplate = "http://asdf.com"
|
||||
}
|
||||
}
|
||||
}))
|
||||
.When(x => x.WhenIValidateTheConfiguration())
|
||||
.Then(x => x.ThenTheResultIsNotValid())
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void configuration_is_invalid_if_host_in_downstream_template()
|
||||
{
|
||||
this.Given(x => x.GivenAConfiguration(new FileConfiguration()
|
||||
{
|
||||
ReRoutes = new List<FileReRoute>
|
||||
{
|
||||
new FileReRoute
|
||||
{
|
||||
DownstreamTemplate = "www.bbc.co.uk/api/products/{productId}",
|
||||
DownstreamPathTemplate = "http://www.bbc.co.uk/api/products/{productId}",
|
||||
UpstreamTemplate = "http://asdf.com"
|
||||
}
|
||||
}
|
||||
@ -60,13 +41,13 @@ namespace Ocelot.UnitTests.Configuration
|
||||
[Fact]
|
||||
public void configuration_is_valid_with_one_reroute()
|
||||
{
|
||||
this.Given(x => x.GivenAConfiguration(new FileConfiguration()
|
||||
this.Given(x => x.GivenAConfiguration(new FileConfiguration
|
||||
{
|
||||
ReRoutes = new List<FileReRoute>
|
||||
{
|
||||
new FileReRoute
|
||||
{
|
||||
DownstreamTemplate = "/api/products/",
|
||||
DownstreamPathTemplate = "/api/products/",
|
||||
UpstreamTemplate = "http://asdf.com"
|
||||
}
|
||||
}
|
||||
@ -79,13 +60,13 @@ namespace Ocelot.UnitTests.Configuration
|
||||
[Fact]
|
||||
public void configuration_is_valid_with_valid_authentication_provider()
|
||||
{
|
||||
this.Given(x => x.GivenAConfiguration(new FileConfiguration()
|
||||
this.Given(x => x.GivenAConfiguration(new FileConfiguration
|
||||
{
|
||||
ReRoutes = new List<FileReRoute>
|
||||
{
|
||||
new FileReRoute
|
||||
{
|
||||
DownstreamTemplate = "/api/products/",
|
||||
DownstreamPathTemplate = "/api/products/",
|
||||
UpstreamTemplate = "http://asdf.com",
|
||||
AuthenticationOptions = new FileAuthenticationOptions
|
||||
{
|
||||
@ -102,13 +83,13 @@ namespace Ocelot.UnitTests.Configuration
|
||||
[Fact]
|
||||
public void configuration_is_invalid_with_invalid_authentication_provider()
|
||||
{
|
||||
this.Given(x => x.GivenAConfiguration(new FileConfiguration()
|
||||
this.Given(x => x.GivenAConfiguration(new FileConfiguration
|
||||
{
|
||||
ReRoutes = new List<FileReRoute>
|
||||
{
|
||||
new FileReRoute
|
||||
{
|
||||
DownstreamTemplate = "/api/products/",
|
||||
DownstreamPathTemplate = "/api/products/",
|
||||
UpstreamTemplate = "http://asdf.com",
|
||||
AuthenticationOptions = new FileAuthenticationOptions
|
||||
{
|
||||
@ -126,25 +107,25 @@ namespace Ocelot.UnitTests.Configuration
|
||||
[Fact]
|
||||
public void configuration_is_not_valid_with_duplicate_reroutes()
|
||||
{
|
||||
this.Given(x => x.GivenAConfiguration(new FileConfiguration()
|
||||
this.Given(x => x.GivenAConfiguration(new FileConfiguration
|
||||
{
|
||||
ReRoutes = new List<FileReRoute>
|
||||
{
|
||||
new FileReRoute
|
||||
{
|
||||
DownstreamTemplate = "/api/products/",
|
||||
DownstreamPathTemplate = "/api/products/",
|
||||
UpstreamTemplate = "http://asdf.com"
|
||||
},
|
||||
new FileReRoute
|
||||
{
|
||||
DownstreamTemplate = "http://www.bbc.co.uk",
|
||||
DownstreamPathTemplate = "http://www.bbc.co.uk",
|
||||
UpstreamTemplate = "http://asdf.com"
|
||||
}
|
||||
}
|
||||
}))
|
||||
.When(x => x.WhenIValidateTheConfiguration())
|
||||
.Then(x => x.ThenTheResultIsNotValid())
|
||||
.And(x => x.ThenTheErrorIs<DownstreamTemplateAlreadyUsedError>())
|
||||
.And(x => x.ThenTheErrorIs<DownstreamPathTemplateAlreadyUsedError>())
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
@ -173,4 +154,4 @@ namespace Ocelot.UnitTests.Configuration
|
||||
_result.Data.Errors[0].ShouldBeOfType<T>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -46,7 +46,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
{
|
||||
DownstreamHost = "127.0.0.1",
|
||||
UpstreamTemplate = "/api/products/{productId}",
|
||||
DownstreamTemplate = "/products/{productId}",
|
||||
DownstreamPathTemplate = "/products/{productId}",
|
||||
UpstreamHttpMethod = "Get",
|
||||
}
|
||||
},
|
||||
@ -57,7 +57,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
{
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamHost("127.0.0.1")
|
||||
.WithDownstreamTemplate("/products/{productId}")
|
||||
.WithDownstreamPathTemplate("/products/{productId}")
|
||||
.WithUpstreamTemplate("/api/products/{productId}")
|
||||
.WithUpstreamHttpMethod("Get")
|
||||
.WithUpstreamTemplatePattern("(?i)/api/products/.*/$")
|
||||
@ -76,7 +76,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
{
|
||||
DownstreamScheme = "https",
|
||||
UpstreamTemplate = "/api/products/{productId}",
|
||||
DownstreamTemplate = "/products/{productId}",
|
||||
DownstreamPathTemplate = "/products/{productId}",
|
||||
UpstreamHttpMethod = "Get",
|
||||
}
|
||||
},
|
||||
@ -87,7 +87,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
{
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamScheme("https")
|
||||
.WithDownstreamTemplate("/products/{productId}")
|
||||
.WithDownstreamPathTemplate("/products/{productId}")
|
||||
.WithUpstreamTemplate("/api/products/{productId}")
|
||||
.WithUpstreamHttpMethod("Get")
|
||||
.WithUpstreamTemplatePattern("(?i)/api/products/.*/$")
|
||||
@ -106,7 +106,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
new FileReRoute
|
||||
{
|
||||
UpstreamTemplate = "/api/products/{productId}",
|
||||
DownstreamTemplate = "/products/{productId}",
|
||||
DownstreamPathTemplate = "/products/{productId}",
|
||||
UpstreamHttpMethod = "Get",
|
||||
ReRouteIsCaseSensitive = false,
|
||||
ServiceName = "ProductService"
|
||||
@ -126,7 +126,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
.Then(x => x.ThenTheReRoutesAre(new List<ReRoute>
|
||||
{
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamTemplate("/products/{productId}")
|
||||
.WithDownstreamPathTemplate("/products/{productId}")
|
||||
.WithUpstreamTemplate("/api/products/{productId}")
|
||||
.WithUpstreamHttpMethod("Get")
|
||||
.WithUpstreamTemplatePattern("(?i)/api/products/.*/$")
|
||||
@ -149,7 +149,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
new FileReRoute
|
||||
{
|
||||
UpstreamTemplate = "/api/products/{productId}",
|
||||
DownstreamTemplate = "/products/{productId}",
|
||||
DownstreamPathTemplate = "/products/{productId}",
|
||||
UpstreamHttpMethod = "Get",
|
||||
ReRouteIsCaseSensitive = false,
|
||||
}
|
||||
@ -160,7 +160,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
.Then(x => x.ThenTheReRoutesAre(new List<ReRoute>
|
||||
{
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamTemplate("/products/{productId}")
|
||||
.WithDownstreamPathTemplate("/products/{productId}")
|
||||
.WithUpstreamTemplate("/api/products/{productId}")
|
||||
.WithUpstreamHttpMethod("Get")
|
||||
.WithUpstreamTemplatePattern("(?i)/api/products/.*/$")
|
||||
@ -182,7 +182,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
new FileReRoute
|
||||
{
|
||||
UpstreamTemplate = "/api/products/{productId}",
|
||||
DownstreamTemplate = "/products/{productId}",
|
||||
DownstreamPathTemplate = "/products/{productId}",
|
||||
UpstreamHttpMethod = "Get",
|
||||
ReRouteIsCaseSensitive = false
|
||||
}
|
||||
@ -193,7 +193,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
.Then(x => x.ThenTheReRoutesAre(new List<ReRoute>
|
||||
{
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamTemplate("/products/{productId}")
|
||||
.WithDownstreamPathTemplate("/products/{productId}")
|
||||
.WithUpstreamTemplate("/api/products/{productId}")
|
||||
.WithUpstreamHttpMethod("Get")
|
||||
.WithUpstreamTemplatePattern("(?i)/api/products/.*/$")
|
||||
@ -212,7 +212,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
new FileReRoute
|
||||
{
|
||||
UpstreamTemplate = "/api/products/{productId}",
|
||||
DownstreamTemplate = "/products/{productId}",
|
||||
DownstreamPathTemplate = "/products/{productId}",
|
||||
UpstreamHttpMethod = "Get"
|
||||
}
|
||||
}
|
||||
@ -222,7 +222,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
.Then(x => x.ThenTheReRoutesAre(new List<ReRoute>
|
||||
{
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamTemplate("/products/{productId}")
|
||||
.WithDownstreamPathTemplate("/products/{productId}")
|
||||
.WithUpstreamTemplate("/api/products/{productId}")
|
||||
.WithUpstreamHttpMethod("Get")
|
||||
.WithUpstreamTemplatePattern("(?i)/api/products/.*/$")
|
||||
@ -241,7 +241,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
new FileReRoute
|
||||
{
|
||||
UpstreamTemplate = "/api/products/{productId}",
|
||||
DownstreamTemplate = "/products/{productId}",
|
||||
DownstreamPathTemplate = "/products/{productId}",
|
||||
UpstreamHttpMethod = "Get",
|
||||
ReRouteIsCaseSensitive = true
|
||||
}
|
||||
@ -252,7 +252,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
.Then(x => x.ThenTheReRoutesAre(new List<ReRoute>
|
||||
{
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamTemplate("/products/{productId}")
|
||||
.WithDownstreamPathTemplate("/products/{productId}")
|
||||
.WithUpstreamTemplate("/api/products/{productId}")
|
||||
.WithUpstreamHttpMethod("Get")
|
||||
.WithUpstreamTemplatePattern("/api/products/.*/$")
|
||||
@ -271,7 +271,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
new FileReRoute
|
||||
{
|
||||
UpstreamTemplate = "/api/products/{productId}",
|
||||
DownstreamTemplate = "/products/{productId}",
|
||||
DownstreamPathTemplate = "/products/{productId}",
|
||||
UpstreamHttpMethod = "Get",
|
||||
ReRouteIsCaseSensitive = true
|
||||
}
|
||||
@ -286,7 +286,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
.Then(x => x.ThenTheReRoutesAre(new List<ReRoute>
|
||||
{
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamTemplate("/products/{productId}")
|
||||
.WithDownstreamPathTemplate("/products/{productId}")
|
||||
.WithUpstreamTemplate("/api/products/{productId}")
|
||||
.WithUpstreamHttpMethod("Get")
|
||||
.WithUpstreamTemplatePattern("/api/products/.*/$")
|
||||
@ -306,7 +306,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
new FileReRoute
|
||||
{
|
||||
UpstreamTemplate = "/api/products/{productId}",
|
||||
DownstreamTemplate = "/products/{productId}",
|
||||
DownstreamPathTemplate = "/products/{productId}",
|
||||
UpstreamHttpMethod = "Get",
|
||||
ReRouteIsCaseSensitive = true
|
||||
}
|
||||
@ -317,7 +317,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
.Then(x => x.ThenTheReRoutesAre(new List<ReRoute>
|
||||
{
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamTemplate("/products/{productId}")
|
||||
.WithDownstreamPathTemplate("/products/{productId}")
|
||||
.WithUpstreamTemplate("/api/products/{productId}")
|
||||
.WithUpstreamHttpMethod("Get")
|
||||
.WithUpstreamTemplatePattern("/api/products/.*/$")
|
||||
@ -332,7 +332,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
var expected = new List<ReRoute>
|
||||
{
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamTemplate("/products/{productId}")
|
||||
.WithDownstreamPathTemplate("/products/{productId}")
|
||||
.WithUpstreamTemplate("/api/products/{productId}")
|
||||
.WithUpstreamHttpMethod("Get")
|
||||
.WithUpstreamTemplatePattern("/api/products/.*/$")
|
||||
@ -355,7 +355,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
new FileReRoute
|
||||
{
|
||||
UpstreamTemplate = "/api/products/{productId}",
|
||||
DownstreamTemplate = "/products/{productId}",
|
||||
DownstreamPathTemplate = "/products/{productId}",
|
||||
UpstreamHttpMethod = "Get",
|
||||
ReRouteIsCaseSensitive = true,
|
||||
AuthenticationOptions = new FileAuthenticationOptions
|
||||
@ -395,7 +395,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
var expected = new List<ReRoute>
|
||||
{
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamTemplate("/products/{productId}")
|
||||
.WithDownstreamPathTemplate("/products/{productId}")
|
||||
.WithUpstreamTemplate("/api/products/{productId}")
|
||||
.WithUpstreamHttpMethod("Get")
|
||||
.WithUpstreamTemplatePattern("/api/products/.*/$")
|
||||
@ -414,7 +414,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
new FileReRoute
|
||||
{
|
||||
UpstreamTemplate = "/api/products/{productId}",
|
||||
DownstreamTemplate = "/products/{productId}",
|
||||
DownstreamPathTemplate = "/products/{productId}",
|
||||
UpstreamHttpMethod = "Get",
|
||||
ReRouteIsCaseSensitive = true,
|
||||
AuthenticationOptions = new FileAuthenticationOptions
|
||||
@ -446,7 +446,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
new FileReRoute
|
||||
{
|
||||
UpstreamTemplate = "/api/products/{productId}/variants/{variantId}",
|
||||
DownstreamTemplate = "/products/{productId}",
|
||||
DownstreamPathTemplate = "/products/{productId}",
|
||||
UpstreamHttpMethod = "Get",
|
||||
ReRouteIsCaseSensitive = true
|
||||
}
|
||||
@ -457,7 +457,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
.Then(x => x.ThenTheReRoutesAre(new List<ReRoute>
|
||||
{
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamTemplate("/products/{productId}")
|
||||
.WithDownstreamPathTemplate("/products/{productId}")
|
||||
.WithUpstreamTemplate("/api/products/{productId}/variants/{variantId}")
|
||||
.WithUpstreamHttpMethod("Get")
|
||||
.WithUpstreamTemplatePattern("/api/products/.*/variants/.*/$")
|
||||
@ -476,7 +476,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
new FileReRoute
|
||||
{
|
||||
UpstreamTemplate = "/api/products/{productId}/variants/{variantId}/",
|
||||
DownstreamTemplate = "/products/{productId}",
|
||||
DownstreamPathTemplate = "/products/{productId}",
|
||||
UpstreamHttpMethod = "Get",
|
||||
ReRouteIsCaseSensitive = true
|
||||
}
|
||||
@ -487,7 +487,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
.Then(x => x.ThenTheReRoutesAre(new List<ReRoute>
|
||||
{
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamTemplate("/products/{productId}")
|
||||
.WithDownstreamPathTemplate("/products/{productId}")
|
||||
.WithUpstreamTemplate("/api/products/{productId}/variants/{variantId}/")
|
||||
.WithUpstreamHttpMethod("Get")
|
||||
.WithUpstreamTemplatePattern("/api/products/.*/variants/.*/$")
|
||||
@ -506,7 +506,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
new FileReRoute
|
||||
{
|
||||
UpstreamTemplate = "/",
|
||||
DownstreamTemplate = "/api/products/",
|
||||
DownstreamPathTemplate = "/api/products/",
|
||||
UpstreamHttpMethod = "Get",
|
||||
ReRouteIsCaseSensitive = true
|
||||
}
|
||||
@ -517,7 +517,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
.Then(x => x.ThenTheReRoutesAre(new List<ReRoute>
|
||||
{
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamTemplate("/api/products/")
|
||||
.WithDownstreamPathTemplate("/api/products/")
|
||||
.WithUpstreamTemplate("/")
|
||||
.WithUpstreamHttpMethod("Get")
|
||||
.WithUpstreamTemplatePattern("/$")
|
||||
@ -553,7 +553,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
var result = _config.Data.ReRoutes[i];
|
||||
var expected = expectedReRoutes[i];
|
||||
|
||||
result.DownstreamTemplate.ShouldBe(expected.DownstreamTemplate);
|
||||
result.DownstreamPathTemplate.Value.ShouldBe(expected.DownstreamPathTemplate.Value);
|
||||
result.UpstreamHttpMethod.ShouldBe(expected.UpstreamHttpMethod);
|
||||
result.UpstreamTemplate.ShouldBe(expected.UpstreamTemplate);
|
||||
result.UpstreamTemplatePattern.ShouldBe(expected.UpstreamTemplatePattern);
|
||||
|
@ -44,7 +44,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
|
||||
private void ThenTheConfigurationIsReturned()
|
||||
{
|
||||
_getResult.Data.ReRoutes[0].DownstreamTemplate.ShouldBe("initial");
|
||||
_getResult.Data.ReRoutes[0].DownstreamPathTemplate.Value.ShouldBe("initial");
|
||||
}
|
||||
|
||||
private void WhenIGetTheConfiguration()
|
||||
@ -75,16 +75,16 @@ namespace Ocelot.UnitTests.Configuration
|
||||
|
||||
class FakeConfig : IOcelotConfiguration
|
||||
{
|
||||
private readonly string _downstreamTemplate;
|
||||
private readonly string _downstreamTemplatePath;
|
||||
|
||||
public FakeConfig(string downstreamTemplate)
|
||||
public FakeConfig(string downstreamTemplatePath)
|
||||
{
|
||||
_downstreamTemplate = downstreamTemplate;
|
||||
_downstreamTemplatePath = downstreamTemplatePath;
|
||||
}
|
||||
|
||||
public List<ReRoute> ReRoutes => new List<ReRoute>
|
||||
{
|
||||
new ReRouteBuilder().WithDownstreamTemplate(_downstreamTemplate).Build()
|
||||
new ReRouteBuilder().WithDownstreamPathTemplate(_downstreamTemplatePath).Build()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user