public void should_create_with_authentication_properties(FileConfiguration fileConfig) { var reRouteOptions = new ReRouteOptionsBuilder() .WithIsAuthenticated(true) .Build(); var authenticationOptions = new AuthenticationOptionsBuilder() .WithAllowedScopes(new List <string>()) .Build(); var expected = new List <ReRoute> { new ReRouteBuilder() .WithDownstreamPathTemplate("/products/{productId}") .WithUpstreamPathTemplate("/api/products/{productId}") .WithUpstreamHttpMethod(new List <string> { "Get" }) .WithAuthenticationOptions(authenticationOptions) .Build() }; this.Given(x => x.GivenTheConfigIs(fileConfig)) .And(x => x.GivenTheConfigIsValid()) .And(x => x.GivenTheFollowingOptionsAreReturned(reRouteOptions)) .And(x => x.GivenTheAuthOptionsCreatorReturns(authenticationOptions)) .When(x => x.WhenICreateTheConfig()) .Then(x => x.ThenTheReRoutesAre(expected)) .And(x => x.ThenTheAuthenticationOptionsAre(expected)) .And(x => x.ThenTheAuthOptionsCreatorIsCalledCorrectly()) .BDDfy(); }
public void should_return_Jwt_auth_options() { var fileReRoute = new FileReRoute() { AuthenticationOptions = new FileAuthenticationOptions { Provider = "Jwt", JwtConfig = new FileJwtConfig() { Audience = "Audience", Authority = "Authority" }, AllowedScopes = new List <string> { "cheese" } } }; var authenticationConfig = new JwtConfigBuilder() .WithAudience(fileReRoute.AuthenticationOptions?.JwtConfig?.Audience) .WithAuthority(fileReRoute.AuthenticationOptions?.JwtConfig?.Authority) .Build(); var expected = new AuthenticationOptionsBuilder() .WithProvider(fileReRoute.AuthenticationOptions?.Provider) .WithAllowedScopes(fileReRoute.AuthenticationOptions?.AllowedScopes) .WithConfig(authenticationConfig) .Build(); this.Given(x => x.GivenTheFollowing(fileReRoute)) .When(x => x.WhenICreateTheAuthenticationOptions()) .Then(x => x.ThenTheFollowingJwtConfigIsReturned(expected)) .BDDfy(); }
public void should_create_with_headers_to_extract() { var authenticationOptions = new AuthenticationOptionsBuilder() .WithProvider("IdentityServer") .WithProviderRootUrl("http://localhost:51888") .WithRequireHttps(false) .WithScopeSecret("secret") .WithScopeName("api") .WithAdditionalScopes(new List <string>()) .Build(); var expected = new List <ReRoute> { new ReRouteBuilder() .WithDownstreamPathTemplate("/products/{productId}") .WithUpstreamPathTemplate("/api/products/{productId}") .WithUpstreamHttpMethod("Get") .WithUpstreamTemplatePattern("/api/products/.*/$") .WithAuthenticationOptions(authenticationOptions) .WithClaimsToHeaders(new List <ClaimToThing> { new ClaimToThing("CustomerId", "CustomerId", "", 0), }) .Build() }; this.Given(x => x.GivenTheConfigIs(new FileConfiguration { ReRoutes = new List <FileReRoute> { new FileReRoute { UpstreamPathTemplate = "/api/products/{productId}", DownstreamPathTemplate = "/products/{productId}", UpstreamHttpMethod = "Get", ReRouteIsCaseSensitive = true, AuthenticationOptions = new FileAuthenticationOptions { AdditionalScopes = new List <string>(), Provider = "IdentityServer", ProviderRootUrl = "http://localhost:51888", RequireHttps = false, ScopeName = "api", ScopeSecret = "secret" }, AddHeadersToRequest = { { "CustomerId", "Claims[CustomerId] > value" }, } } } })) .And(x => x.GivenTheConfigIsValid()) .And(x => x.GivenTheConfigHeaderExtractorReturns(new ClaimToThing("CustomerId", "CustomerId", "", 0))) .And(x => x.GivenTheLoadBalancerFactoryReturns()) .When(x => x.WhenICreateTheConfig()) .Then(x => x.ThenTheReRoutesAre(expected)) .And(x => x.ThenTheAuthenticationOptionsAre(expected)) .BDDfy(); }
public void should_return_auth_options() { var fileReRoute = new FileReRoute() { AuthenticationOptions = new FileAuthenticationOptions { Provider = "Geoff", ProviderRootUrl = "http://www.bbc.co.uk/", ScopeName = "Laura", RequireHttps = true, AdditionalScopes = new List <string> { "cheese" }, ScopeSecret = "secret" } }; var expected = new AuthenticationOptionsBuilder() .WithProvider(fileReRoute.AuthenticationOptions?.Provider) .WithProviderRootUrl(fileReRoute.AuthenticationOptions?.ProviderRootUrl) .WithScopeName(fileReRoute.AuthenticationOptions?.ScopeName) .WithRequireHttps(fileReRoute.AuthenticationOptions.RequireHttps) .WithAdditionalScopes(fileReRoute.AuthenticationOptions?.AdditionalScopes) .WithScopeSecret(fileReRoute.AuthenticationOptions?.ScopeSecret) .Build(); this.Given(x => x.GivenTheFollowing(fileReRoute)) .When(x => x.WhenICreateTheAuthenticationOptions()) .Then(x => x.ThenTheFollowingIsReturned(expected)) .BDDfy(); }
public void should_create_with_authentication_properties() { var reRouteOptions = new ReRouteOptionsBuilder() .WithIsAuthenticated(true) .Build(); var authenticationOptions = new AuthenticationOptionsBuilder() .WithProvider("IdentityServer") .WithProviderRootUrl("http://localhost:51888") .WithRequireHttps(false) .WithScopeSecret("secret") .WithScopeName("api") .WithAdditionalScopes(new List <string>()) .Build(); var expected = new List <ReRoute> { new ReRouteBuilder() .WithDownstreamPathTemplate("/products/{productId}") .WithUpstreamPathTemplate("/api/products/{productId}") .WithUpstreamHttpMethod("Get") .WithAuthenticationOptions(authenticationOptions) .Build() }; this.Given(x => x.GivenTheConfigIs(new FileConfiguration { ReRoutes = new List <FileReRoute> { new FileReRoute { UpstreamPathTemplate = "/api/products/{productId}", DownstreamPathTemplate = "/products/{productId}", UpstreamHttpMethod = "Get", ReRouteIsCaseSensitive = true, AuthenticationOptions = new FileAuthenticationOptions { AdditionalScopes = new List <string>(), Provider = "IdentityServer", ProviderRootUrl = "http://localhost:51888", RequireHttps = false, ScopeName = "api", ScopeSecret = "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(); }
public void should_return_error_if_cannot_create_handler() { var authenticationOptions = new AuthenticationOptionsBuilder() .Build(); this.Given(x => x.GivenTheAuthenticationOptionsAre(authenticationOptions)) .And(x => x.GivenTheCreatorReturnsAnError()) .When(x => x.WhenIGetFromTheFactory()) .Then(x => x.ThenAnErrorResponseIsReturned()) .BDDfy(); }
public void should_return_identity_server_access_token_handler() { var authenticationOptions = new AuthenticationOptionsBuilder() .WithProvider("IdentityServer") .Build(); this.Given(x => x.GivenTheAuthenticationOptionsAre(authenticationOptions)) .And(x => x.GivenTheCreatorReturns()) .When(x => x.WhenIGetFromTheFactory()) .Then(x => x.ThenTheHandlerIsReturned("IdentityServer")) .BDDfy(); }
public void should_create_with_headers_to_extract(FileConfiguration fileConfig) { var reRouteOptions = new ReRouteOptionsBuilder() .WithIsAuthenticated(true) .Build(); var authenticationOptions = new AuthenticationOptionsBuilder() .WithAllowedScopes(new List <string>()) .Build(); var downstreamReRoute = new DownstreamReRouteBuilder() .WithDownstreamPathTemplate("/products/{productId}") .WithUpstreamPathTemplate("/api/products/{productId}") .WithUpstreamHttpMethod(new List <string> { "Get" }) .WithAuthenticationOptions(authenticationOptions) .WithClaimsToHeaders(new List <ClaimToThing> { new ClaimToThing("CustomerId", "CustomerId", "", 0), }) .WithLoadBalancerKey("/api/products/{productId}|Get") .Build(); var expected = new List <ReRoute> { new ReRouteBuilder() .WithDownstreamReRoute(downstreamReRoute) .WithUpstreamPathTemplate("/api/products/{productId}") .WithUpstreamHttpMethod(new List <string> { "Get" }) .Build() }; this.Given(x => x.GivenTheConfigIs(fileConfig)) .And(x => GivenTheDownstreamAddresses()) .And(x => x.GivenTheConfigIsValid()) .And(x => GivenTheHeaderFindAndReplaceCreatorReturns()) .And(x => x.GivenTheAuthOptionsCreatorReturns(authenticationOptions)) .And(x => x.GivenTheFollowingOptionsAreReturned(reRouteOptions)) .And(x => x.GivenTheClaimsToThingCreatorReturns(new List <ClaimToThing> { new ClaimToThing("CustomerId", "CustomerId", "", 0) })) .When(x => x.WhenICreateTheConfig()) .Then(x => x.ThenTheReRoutesAre(expected)) .And(x => x.ThenTheAuthenticationOptionsAre(expected)) .And(x => x.ThenTheAuthOptionsCreatorIsCalledCorrectly()) .BDDfy(); }
public void should_return_auth_options() { var fileReRoute = new FileReRoute() { AuthenticationOptions = new FileAuthenticationOptions { Provider = "Geoff", IdentityServerConfig = new FileIdentityServerConfig() { ProviderRootUrl = "http://www.bbc.co.uk/", ApiName = "Laura", RequireHttps = true, ApiSecret = "secret" }, AllowedScopes = new List <string> { "cheese" }, } }; var authenticationConfig = new IdentityServerConfigBuilder() .WithProviderRootUrl(fileReRoute.AuthenticationOptions?.IdentityServerConfig?.ProviderRootUrl) .WithApiName(fileReRoute.AuthenticationOptions?.IdentityServerConfig?.ApiName) .WithRequireHttps(fileReRoute.AuthenticationOptions.IdentityServerConfig.RequireHttps) .WithApiSecret(fileReRoute.AuthenticationOptions?.IdentityServerConfig?.ApiSecret) .Build(); var expected = new AuthenticationOptionsBuilder() .WithProvider(fileReRoute.AuthenticationOptions?.Provider) .WithAllowedScopes(fileReRoute.AuthenticationOptions?.AllowedScopes) .WithConfig(authenticationConfig) .Build(); this.Given(x => x.GivenTheFollowing(fileReRoute)) .When(x => x.WhenICreateTheAuthenticationOptions()) .Then(x => x.ThenTheFollowingIdentityServerConfigIsReturned(expected)) .BDDfy(); }
public void should_return_auth_options() { var fileReRoute = new FileReRoute() { AuthenticationOptions = new FileAuthenticationOptions { AuthenticationProviderKey = "Test", AllowedScopes = new List <string> { "cheese" }, } }; var expected = new AuthenticationOptionsBuilder() .WithAllowedScopes(fileReRoute.AuthenticationOptions?.AllowedScopes) .WithAuthenticationProviderKey("Test") .Build(); this.Given(x => x.GivenTheFollowing(fileReRoute)) .When(x => x.WhenICreateTheAuthenticationOptions()) .Then(x => x.ThenTheFollowingConfigIsReturned(expected)) .BDDfy(); }