mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-18 03:13:22 +08:00
Reenabling some tests
This commit is contained in:
parent
9532d940f1
commit
1168eb3110
@ -17,6 +17,10 @@ using Xunit;
|
|||||||
|
|
||||||
namespace Ocelot.UnitTests.Configuration
|
namespace Ocelot.UnitTests.Configuration
|
||||||
{
|
{
|
||||||
|
using System.Collections;
|
||||||
|
|
||||||
|
using Ocelot.UnitTests.TestData;
|
||||||
|
|
||||||
public class FileConfigurationCreatorTests
|
public class FileConfigurationCreatorTests
|
||||||
{
|
{
|
||||||
private readonly Mock<IOptions<FileConfiguration>> _fileConfig;
|
private readonly Mock<IOptions<FileConfiguration>> _fileConfig;
|
||||||
@ -393,132 +397,82 @@ namespace Ocelot.UnitTests.Configuration
|
|||||||
.BDDfy();
|
.BDDfy();
|
||||||
}
|
}
|
||||||
|
|
||||||
//[Fact]
|
[Theory]
|
||||||
//public void should_create_with_headers_to_extract()
|
[MemberData(nameof(AuthenticationConfigTestData.GetAuthenticationData), MemberType = typeof(AuthenticationConfigTestData))]
|
||||||
//{
|
public void should_create_with_headers_to_extract(string provider, IAuthenticationConfig config, FileConfiguration fileConfig)
|
||||||
// var reRouteOptions = new ReRouteOptionsBuilder()
|
{
|
||||||
// .WithIsAuthenticated(true)
|
var reRouteOptions = new ReRouteOptionsBuilder()
|
||||||
// .Build();
|
.WithIsAuthenticated(true)
|
||||||
|
.Build();
|
||||||
|
|
||||||
// var authenticationOptions = new AuthenticationOptionsBuilder()
|
var authenticationOptions = new AuthenticationOptionsBuilder()
|
||||||
// .WithProvider("IdentityServer")
|
.WithProvider(provider)
|
||||||
// .WithProviderRootUrl("http://localhost:51888")
|
.WithAllowedScopes(new List<string>())
|
||||||
// .WithRequireHttps(false)
|
.WithConfig(config)
|
||||||
// .WithApiSecret("secret")
|
.Build();
|
||||||
// .WithApiName("api")
|
|
||||||
// .WithAllowedScopes(new List<string>())
|
|
||||||
// .Build();
|
|
||||||
|
|
||||||
// var expected = new List<ReRoute>
|
var expected = new List<ReRoute>
|
||||||
// {
|
{
|
||||||
// new ReRouteBuilder()
|
new ReRouteBuilder()
|
||||||
// .WithDownstreamPathTemplate("/products/{productId}")
|
.WithDownstreamPathTemplate("/products/{productId}")
|
||||||
// .WithUpstreamPathTemplate("/api/products/{productId}")
|
.WithUpstreamPathTemplate("/api/products/{productId}")
|
||||||
// .WithUpstreamHttpMethod(new List<string> { "Get" })
|
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||||
// .WithAuthenticationOptions(authenticationOptions)
|
.WithAuthenticationOptions(authenticationOptions)
|
||||||
// .WithClaimsToHeaders(new List<ClaimToThing>
|
.WithClaimsToHeaders(new List<ClaimToThing>
|
||||||
// {
|
{
|
||||||
// new ClaimToThing("CustomerId", "CustomerId", "", 0),
|
new ClaimToThing("CustomerId", "CustomerId", "", 0),
|
||||||
// })
|
})
|
||||||
// .Build()
|
.Build()
|
||||||
// };
|
};
|
||||||
|
|
||||||
// this.Given(x => x.GivenTheConfigIs(new FileConfiguration
|
this.Given(x => x.GivenTheConfigIs(fileConfig))
|
||||||
// {
|
.And(x => x.GivenTheConfigIsValid())
|
||||||
// ReRoutes = new List<FileReRoute>
|
.And(x => x.GivenTheAuthOptionsCreatorReturns(authenticationOptions))
|
||||||
// {
|
.And(x => x.GivenTheFollowingOptionsAreReturned(reRouteOptions))
|
||||||
// new FileReRoute
|
.And(x => x.GivenTheClaimsToThingCreatorReturns(new List<ClaimToThing> { new ClaimToThing("CustomerId", "CustomerId", "", 0) }))
|
||||||
// {
|
.And(x => x.GivenTheLoadBalancerFactoryReturns())
|
||||||
// UpstreamPathTemplate = "/api/products/{productId}",
|
.When(x => x.WhenICreateTheConfig())
|
||||||
// DownstreamPathTemplate = "/products/{productId}",
|
.Then(x => x.ThenTheReRoutesAre(expected))
|
||||||
// UpstreamHttpMethod = new List<string> { "Get" },
|
.And(x => x.ThenTheAuthenticationOptionsAre(provider, expected))
|
||||||
// ReRouteIsCaseSensitive = true,
|
.And(x => x.ThenTheAuthOptionsCreatorIsCalledCorrectly())
|
||||||
// AuthenticationOptions = new FileAuthenticationOptions
|
.BDDfy();
|
||||||
// {
|
}
|
||||||
//AllowedScopes= new List<string>(),
|
|
||||||
// Provider = "IdentityServer",
|
|
||||||
// ProviderRootUrl = "http://localhost:51888",
|
|
||||||
// RequireHttps = false,
|
|
||||||
//ApiName= "api",
|
|
||||||
// ApiSecret = "secret"
|
|
||||||
// },
|
|
||||||
// AddHeadersToRequest =
|
|
||||||
// {
|
|
||||||
// {"CustomerId", "Claims[CustomerId] > value"},
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }))
|
|
||||||
// .And(x => x.GivenTheConfigIsValid())
|
|
||||||
// .And(x => x.GivenTheAuthOptionsCreatorReturns(authenticationOptions))
|
|
||||||
// .And(x => x.GivenTheFollowingOptionsAreReturned(reRouteOptions))
|
|
||||||
// .And(x => x.GivenTheClaimsToThingCreatorReturns(new List<ClaimToThing>{new ClaimToThing("CustomerId", "CustomerId", "", 0)}))
|
|
||||||
// .And(x => x.GivenTheLoadBalancerFactoryReturns())
|
|
||||||
// .When(x => x.WhenICreateTheConfig())
|
|
||||||
// .Then(x => x.ThenTheReRoutesAre(expected))
|
|
||||||
// .And(x => x.ThenTheAuthenticationOptionsAre(expected))
|
|
||||||
// .And(x => x.ThenTheAuthOptionsCreatorIsCalledCorrectly())
|
|
||||||
// .BDDfy();
|
|
||||||
//}
|
|
||||||
|
|
||||||
//[Fact]
|
[Theory]
|
||||||
//public void should_create_with_authentication_properties()
|
[MemberData(nameof(AuthenticationConfigTestData.GetAuthenticationData), MemberType = typeof(AuthenticationConfigTestData))]
|
||||||
//{
|
public void should_create_with_authentication_properties(string provider, IAuthenticationConfig config, FileConfiguration fileConfig)
|
||||||
// var reRouteOptions = new ReRouteOptionsBuilder()
|
{
|
||||||
// .WithIsAuthenticated(true)
|
var reRouteOptions = new ReRouteOptionsBuilder()
|
||||||
// .Build();
|
.WithIsAuthenticated(true)
|
||||||
|
.Build();
|
||||||
|
|
||||||
// var authenticationOptions = new AuthenticationOptionsBuilder()
|
var authenticationOptions = new AuthenticationOptionsBuilder()
|
||||||
// .WithProvider("IdentityServer")
|
.WithProvider(provider)
|
||||||
// .WithProviderRootUrl("http://localhost:51888")
|
.WithAllowedScopes(new List<string>())
|
||||||
// .WithRequireHttps(false)
|
.WithConfig(config)
|
||||||
// .WithApiSecret("secret")
|
.Build();
|
||||||
// .WithApiName("api")
|
|
||||||
// .WithAllowedScopes(new List<string>())
|
|
||||||
// .Build();
|
|
||||||
|
|
||||||
// var expected = new List<ReRoute>
|
var expected = new List<ReRoute>
|
||||||
// {
|
{
|
||||||
// new ReRouteBuilder()
|
new ReRouteBuilder()
|
||||||
// .WithDownstreamPathTemplate("/products/{productId}")
|
.WithDownstreamPathTemplate("/products/{productId}")
|
||||||
// .WithUpstreamPathTemplate("/api/products/{productId}")
|
.WithUpstreamPathTemplate("/api/products/{productId}")
|
||||||
// .WithUpstreamHttpMethod(new List<string> { "Get" })
|
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||||
// .WithAuthenticationOptions(authenticationOptions)
|
.WithAuthenticationOptions(authenticationOptions)
|
||||||
// .Build()
|
.Build()
|
||||||
// };
|
};
|
||||||
|
|
||||||
// this.Given(x => x.GivenTheConfigIs(new FileConfiguration
|
this.Given(x => x.GivenTheConfigIs(fileConfig))
|
||||||
// {
|
.And(x => x.GivenTheConfigIsValid())
|
||||||
// ReRoutes = new List<FileReRoute>
|
.And(x => x.GivenTheFollowingOptionsAreReturned(reRouteOptions))
|
||||||
// {
|
.And(x => x.GivenTheAuthOptionsCreatorReturns(authenticationOptions))
|
||||||
// new FileReRoute
|
.And(x => x.GivenTheLoadBalancerFactoryReturns())
|
||||||
// {
|
.When(x => x.WhenICreateTheConfig())
|
||||||
// UpstreamPathTemplate = "/api/products/{productId}",
|
.Then(x => x.ThenTheReRoutesAre(expected))
|
||||||
// DownstreamPathTemplate = "/products/{productId}",
|
.And(x => x.ThenTheAuthenticationOptionsAre(provider, expected))
|
||||||
// UpstreamHttpMethod = new List<string> { "Get" },
|
.And(x => x.ThenTheAuthOptionsCreatorIsCalledCorrectly())
|
||||||
// ReRouteIsCaseSensitive = true,
|
.BDDfy();
|
||||||
// AuthenticationOptions = new FileAuthenticationOptions
|
}
|
||||||
// {
|
|
||||||
//AllowedScopes = new List<string>(),
|
|
||||||
// Provider = "IdentityServer",
|
|
||||||
// ProviderRootUrl = "http://localhost:51888",
|
|
||||||
// RequireHttps = false,
|
|
||||||
//ApiName= "api",
|
|
||||||
// ApiSecret = "secret"
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }))
|
|
||||||
// .And(x => x.GivenTheConfigIsValid())
|
|
||||||
// .And(x => x.GivenTheFollowingOptionsAreReturned(reRouteOptions))
|
|
||||||
// .And(x => x.GivenTheAuthOptionsCreatorReturns(authenticationOptions))
|
|
||||||
// .And(x => x.GivenTheLoadBalancerFactoryReturns())
|
|
||||||
// .When(x => x.WhenICreateTheConfig())
|
|
||||||
// .Then(x => x.ThenTheReRoutesAre(expected))
|
|
||||||
// .And(x => x.ThenTheAuthenticationOptionsAre(expected))
|
|
||||||
// .And(x => x.ThenTheAuthOptionsCreatorIsCalledCorrectly())
|
|
||||||
// .BDDfy();
|
|
||||||
//}
|
|
||||||
|
|
||||||
private void GivenTheFollowingOptionsAreReturned(ReRouteOptions fileReRouteOptions)
|
private void GivenTheFollowingOptionsAreReturned(ReRouteOptions fileReRouteOptions)
|
||||||
{
|
{
|
||||||
@ -586,22 +540,36 @@ namespace Ocelot.UnitTests.Configuration
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//private void ThenTheAuthenticationOptionsAre(List<ReRoute> expectedReRoutes)
|
private void ThenTheAuthenticationOptionsAre(string provider, List<ReRoute> expectedReRoutes)
|
||||||
//{
|
{
|
||||||
// for (int i = 0; i < _config.Data.ReRoutes.Count; i++)
|
for (int i = 0; i < _config.Data.ReRoutes.Count; i++)
|
||||||
// {
|
{
|
||||||
// var result = _config.Data.ReRoutes[i].AuthenticationOptions;
|
var result = _config.Data.ReRoutes[i].AuthenticationOptions;
|
||||||
// var expected = expectedReRoutes[i].AuthenticationOptions;
|
var expected = expectedReRoutes[i].AuthenticationOptions;
|
||||||
|
|
||||||
// result.AllowedScopes.ShouldBe(expected.AllowedScopes);
|
result.AllowedScopes.ShouldBe(expected.AllowedScopes);
|
||||||
// result.Provider.ShouldBe(expected.Provider);
|
result.Provider.ShouldBe(expected.Provider);
|
||||||
// result.ProviderRootUrl.ShouldBe(expected.ProviderRootUrl);
|
|
||||||
// result.RequireHttps.ShouldBe(expected.RequireHttps);
|
|
||||||
// result.ApiName.ShouldBe(expected.ApiName);
|
|
||||||
// result.ApiSecret.ShouldBe(expected.ApiSecret);
|
|
||||||
|
|
||||||
// }
|
if (provider.ToLower() == "identityserver")
|
||||||
//}
|
{
|
||||||
|
var config = result.Config as IdentityServerConfig;
|
||||||
|
var expectedConfig = expected.Config as IdentityServerConfig;
|
||||||
|
|
||||||
|
config.ProviderRootUrl.ShouldBe(expectedConfig.ProviderRootUrl);
|
||||||
|
config.RequireHttps.ShouldBe(expectedConfig.RequireHttps);
|
||||||
|
config.ApiName.ShouldBe(expectedConfig.ApiName);
|
||||||
|
config.ApiSecret.ShouldBe(expectedConfig.ApiSecret);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var config = result.Config as JwtConfig;
|
||||||
|
var expectedConfig = expected.Config as JwtConfig;
|
||||||
|
|
||||||
|
config.Audience.ShouldBe(expectedConfig.Audience);
|
||||||
|
config.Authority.ShouldBe(expectedConfig.Authority);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void GivenTheLoadBalancerFactoryReturns()
|
private void GivenTheLoadBalancerFactoryReturns()
|
||||||
{
|
{
|
||||||
|
@ -0,0 +1,89 @@
|
|||||||
|
namespace Ocelot.UnitTests.TestData
|
||||||
|
{
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
using Ocelot.Configuration.Builder;
|
||||||
|
using Ocelot.Configuration.File;
|
||||||
|
|
||||||
|
public class AuthenticationConfigTestData
|
||||||
|
{
|
||||||
|
public static IEnumerable<object[]> GetAuthenticationData()
|
||||||
|
{
|
||||||
|
yield return new object[]
|
||||||
|
{
|
||||||
|
"IdentityServer",
|
||||||
|
new IdentityServerConfigBuilder()
|
||||||
|
.WithRequireHttps(true)
|
||||||
|
.WithApiName("test")
|
||||||
|
.WithApiSecret("test")
|
||||||
|
.WithProviderRootUrl("test")
|
||||||
|
.Build(),
|
||||||
|
new FileConfiguration
|
||||||
|
{
|
||||||
|
ReRoutes = new List<FileReRoute>
|
||||||
|
{
|
||||||
|
new FileReRoute
|
||||||
|
{
|
||||||
|
UpstreamPathTemplate = "/api/products/{productId}",
|
||||||
|
DownstreamPathTemplate = "/products/{productId}",
|
||||||
|
UpstreamHttpMethod = new List<string> { "Get" },
|
||||||
|
ReRouteIsCaseSensitive = true,
|
||||||
|
AuthenticationOptions = new FileAuthenticationOptions
|
||||||
|
{
|
||||||
|
AllowedScopes = new List<string>(),
|
||||||
|
Provider = "IdentityServer",
|
||||||
|
IdentityServerConfig = new FileIdentityServerConfig
|
||||||
|
{
|
||||||
|
ProviderRootUrl = "http://localhost:51888",
|
||||||
|
RequireHttps = false,
|
||||||
|
ApiName = "api",
|
||||||
|
ApiSecret = "secret"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
AddHeadersToRequest =
|
||||||
|
{
|
||||||
|
{ "CustomerId", "Claims[CustomerId] > value" },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
yield return new object[]
|
||||||
|
{
|
||||||
|
"Jwt",
|
||||||
|
new JwtConfigBuilder()
|
||||||
|
.WithAudience("a")
|
||||||
|
.WithAuthority("au")
|
||||||
|
.Build(),
|
||||||
|
new FileConfiguration
|
||||||
|
{
|
||||||
|
ReRoutes = new List<FileReRoute>
|
||||||
|
{
|
||||||
|
new FileReRoute
|
||||||
|
{
|
||||||
|
UpstreamPathTemplate = "/api/products/{productId}",
|
||||||
|
DownstreamPathTemplate = "/products/{productId}",
|
||||||
|
UpstreamHttpMethod = new List<string> { "Get" },
|
||||||
|
ReRouteIsCaseSensitive = true,
|
||||||
|
AuthenticationOptions = new FileAuthenticationOptions
|
||||||
|
{
|
||||||
|
AllowedScopes = new List<string>(),
|
||||||
|
Provider = "IdentityServer",
|
||||||
|
JwtConfig = new FileJwtConfig
|
||||||
|
{
|
||||||
|
Audience = "a",
|
||||||
|
Authority = "au"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
AddHeadersToRequest =
|
||||||
|
{
|
||||||
|
{ "CustomerId", "Claims[CustomerId] > value" },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user