示例#1
0
        public void should_not_use_service_discovery_for_downstream_host_url_when_no_service_name()
        {
            var reRouteOptions = new ReRouteOptionsBuilder()
                                 .Build();

            this.Given(x => x.GivenTheConfigIs(new FileConfiguration
            {
                ReRoutes = new List <FileReRoute>
                {
                    new FileReRoute
                    {
                        UpstreamPathTemplate   = "/api/products/{productId}",
                        DownstreamPathTemplate = "/products/{productId}",
                        UpstreamHttpMethod     = "Get",
                        ReRouteIsCaseSensitive = false,
                    }
                }
            }))
            .And(x => x.GivenTheConfigIsValid())
            .And(x => x.GivenTheFollowingOptionsAreReturned(reRouteOptions))
            .When(x => x.WhenICreateTheConfig())
            .Then(x => x.ThenTheReRoutesAre(new List <ReRoute>
            {
                new ReRouteBuilder()
                .WithDownstreamPathTemplate("/products/{productId}")
                .WithUpstreamPathTemplate("/api/products/{productId}")
                .WithUpstreamHttpMethod("Get")
                .WithServiceProviderConfiguraion(new ServiceProviderConfigurationBuilder()
                                                 .WithUseServiceDiscovery(false)
                                                 .Build())
                .Build()
            }))
            .BDDfy();
        }
        public void should_create_re_route_options()
        {
            var reRoute = new FileReRoute
            {
                RateLimitOptions = new FileRateLimitRule
                {
                    EnableRateLimiting = true
                },
                AuthenticationOptions = new FileAuthenticationOptions()
                {
                    AuthenticationProviderKey = "Test"
                },
                RouteClaimsRequirement = new Dictionary<string, string>()
                {
                    {"",""}
                },
                FileCacheOptions = new FileCacheOptions
                {
                    TtlSeconds = 1
                }
            };

            var expected = new ReRouteOptionsBuilder()
                .WithIsAuthenticated(true)
                .WithIsAuthorised(true)
                .WithIsCached(true)
                .WithRateLimiting(true)
                .Build();

            this.Given(x => x.GivenTheFollowing(reRoute))
                .When(x => x.WhenICreate())
                .Then(x => x.ThenTheFollowingIsReturned(expected))
                .BDDfy();
        }
示例#3
0
        public void should_create_load_balancer()
        {
            var reRouteOptions = new ReRouteOptionsBuilder()
                                 .Build();

            this.Given(x => x.GivenTheConfigIs(new FileConfiguration
            {
                ReRoutes = new List <FileReRoute>
                {
                    new FileReRoute
                    {
                        DownstreamHost         = "127.0.0.1",
                        UpstreamPathTemplate   = "/api/products/{productId}",
                        DownstreamPathTemplate = "/products/{productId}",
                        UpstreamHttpMethod     = "Get",
                    }
                },
            }))
            .And(x => x.GivenTheConfigIsValid())
            .And(x => x.GivenTheFollowingOptionsAreReturned(reRouteOptions))
            .And(x => x.GivenTheLoadBalancerFactoryReturns())
            .When(x => x.WhenICreateTheConfig())
            .Then(x => x.TheLoadBalancerFactoryIsCalledCorrectly())
            .And(x => x.ThenTheLoadBalancerHouseIsCalledCorrectly())
            .BDDfy();
        }
示例#4
0
        public void should_use_downstream_scheme()
        {
            var reRouteOptions = new ReRouteOptionsBuilder()
                                 .Build();

            this.Given(x => x.GivenTheConfigIs(new FileConfiguration
            {
                ReRoutes = new List <FileReRoute>
                {
                    new FileReRoute
                    {
                        DownstreamScheme       = "https",
                        UpstreamPathTemplate   = "/api/products/{productId}",
                        DownstreamPathTemplate = "/products/{productId}",
                        UpstreamHttpMethod     = "Get",
                    }
                },
            }))
            .And(x => x.GivenTheConfigIsValid())
            .And(x => x.GivenTheFollowingOptionsAreReturned(reRouteOptions))
            .When(x => x.WhenICreateTheConfig())
            .Then(x => x.ThenTheReRoutesAre(new List <ReRoute>
            {
                new ReRouteBuilder()
                .WithDownstreamScheme("https")
                .WithDownstreamPathTemplate("/products/{productId}")
                .WithUpstreamPathTemplate("/api/products/{productId}")
                .WithUpstreamHttpMethod("Get")
                .Build()
            }))
            .BDDfy();
        }
        public void should_call_region_creator()
        {
            var reRouteOptions = new ReRouteOptionsBuilder()
                                 .Build();

            this.Given(x => x.GivenTheConfigIs(new FileConfiguration
            {
                ReRoutes = new List <FileReRoute>
                {
                    new FileReRoute
                    {
                        DownstreamHost         = "127.0.0.1",
                        UpstreamPathTemplate   = "/api/products/{productId}",
                        DownstreamPathTemplate = "/products/{productId}",
                        UpstreamHttpMethod     = new List <string> {
                            "Get"
                        },
                        FileCacheOptions = new FileCacheOptions
                        {
                            Region = "region"
                        }
                    }
                },
            }))
            .And(x => x.GivenTheFollowingOptionsAreReturned(reRouteOptions))
            .And(x => x.GivenTheConfigIsValid())
            .And(x => x.GivenTheFollowingRegionIsReturned("region"))
            .When(x => x.WhenICreateTheConfig())
            .Then(x => x.ThenTheRegionCreatorIsCalledCorrectly("region"))
            .BDDfy();
        }
        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_call_rate_limit_options_creator()
        {
            var reRouteOptions = new ReRouteOptionsBuilder()
                                 .Build();

            this.Given(x => x.GivenTheConfigIs(new FileConfiguration
            {
                ReRoutes = new List <FileReRoute>
                {
                    new FileReRoute
                    {
                        DownstreamHostAndPorts = new List <FileHostAndPort>
                        {
                            new FileHostAndPort
                            {
                                Host = "127.0.0.1",
                            }
                        },
                        UpstreamPathTemplate   = "/api/products/{productId}",
                        DownstreamPathTemplate = "/products/{productId}",
                        UpstreamHttpMethod     = new List <string> {
                            "Get"
                        },
                    }
                },
            }))
            .And(x => x.GivenTheConfigIsValid())
            .And(x => GivenTheDownstreamAddresses())
            .And(x => GivenTheHeaderFindAndReplaceCreatorReturns())
            .And(x => x.GivenTheFollowingOptionsAreReturned(reRouteOptions))
            .When(x => x.WhenICreateTheConfig())
            .Then(x => x.ThenTheRateLimitOptionsCreatorIsCalledCorrectly())
            .BDDfy();
        }
        public void should_call_httpHandler_creator()
        {
            var reRouteOptions = new ReRouteOptionsBuilder()
                                 .Build();
            var httpHandlerOptions = new HttpHandlerOptions(true, true);

            this.Given(x => x.GivenTheConfigIs(new FileConfiguration
            {
                ReRoutes = new List <FileReRoute>
                {
                    new FileReRoute
                    {
                        DownstreamHost         = "127.0.0.1",
                        UpstreamPathTemplate   = "/api/products/{productId}",
                        DownstreamPathTemplate = "/products/{productId}",
                        UpstreamHttpMethod     = new List <string> {
                            "Get"
                        }
                    }
                },
            }))
            .And(x => x.GivenTheFollowingOptionsAreReturned(reRouteOptions))
            .And(x => x.GivenTheConfigIsValid())
            .And(x => x.GivenTheFollowingHttpHandlerOptionsAreReturned(httpHandlerOptions))
            .When(x => x.WhenICreateTheConfig())
            .Then(x => x.ThenTheHttpHandlerOptionsCreatorIsCalledCorrectly())
            .BDDfy();
        }
示例#9
0
        public void should_call_template_pattern_creator_correctly()
        {
            var reRouteOptions = new ReRouteOptionsBuilder()
                                 .Build();

            this.Given(x => x.GivenTheConfigIs(new FileConfiguration
            {
                ReRoutes = new List <FileReRoute>
                {
                    new FileReRoute
                    {
                        UpstreamPathTemplate   = "/api/products/{productId}",
                        DownstreamPathTemplate = "/products/{productId}",
                        UpstreamHttpMethod     = "Get",
                        ReRouteIsCaseSensitive = false
                    }
                }
            }))
            .And(x => x.GivenTheConfigIsValid())
            .And(x => x.GivenTheFollowingOptionsAreReturned(reRouteOptions))
            .And(x => x.GivenTheUpstreamTemplatePatternCreatorReturns("(?i)/api/products/.*/$"))
            .When(x => x.WhenICreateTheConfig())
            .Then(x => x.ThenTheReRoutesAre(new List <ReRoute>
            {
                new ReRouteBuilder()
                .WithDownstreamPathTemplate("/products/{productId}")
                .WithUpstreamPathTemplate("/api/products/{productId}")
                .WithUpstreamHttpMethod("Get")
                .WithUpstreamTemplatePattern("(?i)/api/products/.*/$")
                .Build()
            }))
            .BDDfy();
        }
示例#10
0
        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_use_service_discovery_for_downstream_service_host()
        {
            var reRouteOptions = new ReRouteOptionsBuilder()
                                 .Build();

            var downstreamReRoute = new DownstreamReRouteBuilder()
                                    .WithDownstreamPathTemplate("/products/{productId}")
                                    .WithUpstreamPathTemplate("/api/products/{productId}")
                                    .WithUpstreamHttpMethod(new List <string> {
                "Get"
            })
                                    .WithUseServiceDiscovery(true)
                                    .WithServiceName("ProductService")
                                    .WithLoadBalancerKey("/api/products/{productId}|Get")
                                    .Build();

            this.Given(x => x.GivenTheConfigIs(new FileConfiguration
            {
                ReRoutes = new List <FileReRoute>
                {
                    new FileReRoute
                    {
                        UpstreamPathTemplate   = "/api/products/{productId}",
                        DownstreamPathTemplate = "/products/{productId}",
                        UpstreamHttpMethod     = new List <string> {
                            "Get"
                        },
                        ReRouteIsCaseSensitive = false,
                        ServiceName            = "ProductService"
                    }
                },
                GlobalConfiguration = new FileGlobalConfiguration
                {
                    ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
                    {
                        Host = "127.0.0.1"
                    }
                }
            }))
            .And(x => x.GivenTheConfigIsValid())
            .And(x => GivenTheDownstreamAddresses())
            .And(x => GivenTheHeaderFindAndReplaceCreatorReturns())
            .And(x => x.GivenTheFollowingOptionsAreReturned(reRouteOptions))
            .When(x => x.WhenICreateTheConfig())
            .Then(x => x.ThenTheReRoutesAre(new List <ReRoute>
            {
                new ReRouteBuilder()
                .WithDownstreamReRoute(downstreamReRoute)
                .WithUpstreamPathTemplate("/api/products/{productId}")
                .WithUpstreamHttpMethod(new List <string> {
                    "Get"
                })
                .Build()
            }))
            .BDDfy();
        }
        public void should_use_downstream_host()
        {
            var reRouteOptions = new ReRouteOptionsBuilder()
                                 .Build();

            var downstreamReRoute = new DownstreamReRouteBuilder()
                                    .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")
                                    .Build();

            this.Given(x => x.GivenTheConfigIs(new FileConfiguration
            {
                ReRoutes = new List <FileReRoute>
                {
                    new FileReRoute
                    {
                        DownstreamHostAndPorts = new List <FileHostAndPort>
                        {
                            new FileHostAndPort
                            {
                                Host = "127.0.0.1",
                            }
                        },
                        UpstreamPathTemplate   = "/api/products/{productId}",
                        DownstreamPathTemplate = "/products/{productId}",
                        UpstreamHttpMethod     = new List <string> {
                            "Get"
                        },
                    }
                },
            }))
            .And(x => x.GivenTheConfigIsValid())
            .And(x => GivenTheDownstreamAddresses())
            .And(x => GivenTheHeaderFindAndReplaceCreatorReturns())
            .And(x => x.GivenTheFollowingOptionsAreReturned(reRouteOptions))
            .When(x => x.WhenICreateTheConfig())
            .Then(x => x.ThenTheReRoutesAre(new List <ReRoute>
            {
                new ReRouteBuilder()
                .WithDownstreamReRoute(downstreamReRoute)
                .WithUpstreamPathTemplate("/api/products/{productId}")
                .WithUpstreamHttpMethod(new List <string> {
                    "Get"
                })
                .Build()
            }))
            .BDDfy();
        }
        public void should_call_request_id_creator()
        {
            var reRouteOptions = new ReRouteOptionsBuilder()
                                 .Build();

            var downstreamReRoute = new DownstreamReRouteBuilder()
                                    .WithDownstreamPathTemplate("/products/{productId}")
                                    .WithUpstreamPathTemplate("/api/products/{productId}")
                                    .WithUpstreamHttpMethod(new List <string> {
                "Get"
            })
                                    .WithRequestIdKey("blahhhh")
                                    .WithLoadBalancerKey("/api/products/{productId}|Get")
                                    .Build();

            this.Given(x => x.GivenTheConfigIs(new FileConfiguration
            {
                ReRoutes = new List <FileReRoute>
                {
                    new FileReRoute
                    {
                        UpstreamPathTemplate   = "/api/products/{productId}",
                        DownstreamPathTemplate = "/products/{productId}",
                        UpstreamHttpMethod     = new List <string> {
                            "Get"
                        },
                        ReRouteIsCaseSensitive = true
                    }
                },
                GlobalConfiguration = new FileGlobalConfiguration
                {
                    RequestIdKey = "blahhhh"
                }
            }))
            .And(x => x.GivenTheConfigIsValid())
            .And(x => GivenTheDownstreamAddresses())
            .And(x => GivenTheHeaderFindAndReplaceCreatorReturns())
            .And(x => x.GivenTheFollowingOptionsAreReturned(reRouteOptions))
            .And(x => x.GivenTheRequestIdCreatorReturns("blahhhh"))
            .When(x => x.WhenICreateTheConfig())
            .Then(x => x.ThenTheReRoutesAre(new List <ReRoute>
            {
                new ReRouteBuilder()
                .WithDownstreamReRoute(downstreamReRoute)
                .WithUpstreamPathTemplate("/api/products/{productId}")
                .WithUpstreamHttpMethod(new List <string> {
                    "Get"
                })
                .Build()
            }))
            .And(x => x.ThenTheRequestIdKeyCreatorIsCalledCorrectly())
            .BDDfy();
        }
        public void should_use_downstream_scheme()
        {
            var reRouteOptions = new ReRouteOptionsBuilder()
                                 .Build();

            var handlers = new List <string> {
                "Polly", "Tracer"
            };

            var downstreamReRoute = new DownstreamReRouteBuilder()
                                    .WithDownstreamScheme("https")
                                    .WithDownstreamPathTemplate("/products/{productId}")
                                    .WithUpstreamPathTemplate("/api/products/{productId}")
                                    .WithUpstreamHttpMethod(new List <string> {
                "Get"
            })
                                    .WithDelegatingHandlers(handlers)
                                    .WithLoadBalancerKey("/api/products/{productId}|Get")
                                    .Build();

            this.Given(x => x.GivenTheConfigIs(new FileConfiguration
            {
                ReRoutes = new List <FileReRoute>
                {
                    new FileReRoute
                    {
                        DownstreamScheme       = "https",
                        UpstreamPathTemplate   = "/api/products/{productId}",
                        DownstreamPathTemplate = "/products/{productId}",
                        UpstreamHttpMethod     = new List <string> {
                            "Get"
                        },
                        DelegatingHandlers = handlers
                    }
                },
            }))
            .And(x => x.GivenTheConfigIsValid())
            .And(x => GivenTheDownstreamAddresses())
            .And(x => GivenTheHeaderFindAndReplaceCreatorReturns())
            .And(x => x.GivenTheFollowingOptionsAreReturned(reRouteOptions))
            .When(x => x.WhenICreateTheConfig())
            .Then(x => x.ThenTheReRoutesAre(new List <ReRoute>
            {
                new ReRouteBuilder()
                .WithDownstreamReRoute(downstreamReRoute)
                .WithUpstreamPathTemplate("/api/products/{productId}")
                .WithUpstreamHttpMethod(new List <string> {
                    "Get"
                })
                .Build()
            }))
            .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();
        }
示例#16
0
        public void should_use_service_discovery_for_downstream_service_host()
        {
            var reRouteOptions = new ReRouteOptionsBuilder()
                                 .Build();

            this.Given(x => x.GivenTheConfigIs(new FileConfiguration
            {
                ReRoutes = new List <FileReRoute>
                {
                    new FileReRoute
                    {
                        UpstreamPathTemplate   = "/api/products/{productId}",
                        DownstreamPathTemplate = "/products/{productId}",
                        UpstreamHttpMethod     = new List <string> {
                            "Get"
                        },
                        ReRouteIsCaseSensitive = false,
                        ServiceName            = "ProductService"
                    }
                },
                GlobalConfiguration = new FileGlobalConfiguration
                {
                    ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
                    {
                        Provider = "consul",
                        Host     = "127.0.0.1"
                    }
                }
            }))
            .And(x => x.GivenTheConfigIsValid())
            .And(x => x.GivenTheFollowingOptionsAreReturned(reRouteOptions))
            .When(x => x.WhenICreateTheConfig())
            .Then(x => x.ThenTheReRoutesAre(new List <ReRoute>
            {
                new ReRouteBuilder()
                .WithDownstreamPathTemplate("/products/{productId}")
                .WithUpstreamPathTemplate("/api/products/{productId}")
                .WithUpstreamHttpMethod(new List <string> {
                    "Get"
                })
                .WithServiceProviderConfiguraion(new ServiceProviderConfigurationBuilder()
                                                 .WithUseServiceDiscovery(true)
                                                 .WithServiceDiscoveryProvider("consul")
                                                 .WithServiceDiscoveryProviderHost("127.0.0.1")
                                                 .WithServiceName("ProductService")
                                                 .Build())
                .Build()
            }))
            .BDDfy();
        }
        public void should_call_template_pattern_creator_correctly()
        {
            var reRouteOptions = new ReRouteOptionsBuilder()
                                 .Build();

            var downstreamReRoute = new DownstreamReRouteBuilder()
                                    .WithDownstreamPathTemplate("/products/{productId}")
                                    .WithUpstreamPathTemplate("/api/products/{productId}")
                                    .WithUpstreamHttpMethod(new List <string> {
                "Get"
            })
                                    .WithUpstreamTemplatePattern(new UpstreamPathTemplate("(?i)/api/products/.*/$", 1))
                                    .WithLoadBalancerKey("/api/products/{productId}|Get")
                                    .Build();

            this.Given(x => x.GivenTheConfigIs(new FileConfiguration
            {
                ReRoutes = new List <FileReRoute>
                {
                    new FileReRoute
                    {
                        UpstreamPathTemplate   = "/api/products/{productId}",
                        DownstreamPathTemplate = "/products/{productId}",
                        UpstreamHttpMethod     = new List <string> {
                            "Get"
                        },
                        ReRouteIsCaseSensitive = false
                    }
                }
            }))
            .And(x => x.GivenTheConfigIsValid())
            .And(x => GivenTheDownstreamAddresses())
            .And(x => GivenTheHeaderFindAndReplaceCreatorReturns())
            .And(x => x.GivenTheFollowingOptionsAreReturned(reRouteOptions))
            .And(x => x.GivenTheUpstreamTemplatePatternCreatorReturns("(?i)/api/products/.*/$"))
            .When(x => x.WhenICreateTheConfig())
            .Then(x => x.ThenTheReRoutesAre(new List <ReRoute>
            {
                new ReRouteBuilder()
                .WithDownstreamReRoute(downstreamReRoute)
                .WithUpstreamPathTemplate("/api/products/{productId}")
                .WithUpstreamHttpMethod(new List <string> {
                    "Get"
                })
                .WithUpstreamTemplatePattern(new UpstreamPathTemplate("(?i)/api/products/.*/$", 1))
                .Build()
            }))
            .BDDfy();
        }
        public void should_call_qos_options_creator()
        {
            var expected = new QoSOptionsBuilder()
                           .WithDurationOfBreak(1)
                           .WithExceptionsAllowedBeforeBreaking(1)
                           .WithTimeoutValue(1)
                           .Build();

            var serviceOptions = new ReRouteOptionsBuilder()
                                 .WithIsQos(true)
                                 .Build();

            this.Given(x => x.GivenTheConfigIs(new FileConfiguration
            {
                ReRoutes = new List <FileReRoute>
                {
                    new FileReRoute
                    {
                        DownstreamHostAndPorts = new List <FileHostAndPort>
                        {
                            new FileHostAndPort
                            {
                                Host = "127.0.0.1",
                            }
                        },
                        UpstreamPathTemplate   = "/api/products/{productId}",
                        DownstreamPathTemplate = "/products/{productId}",
                        UpstreamHttpMethod     = new List <string> {
                            "Get"
                        },
                        QoSOptions = new FileQoSOptions
                        {
                            TimeoutValue    = 1,
                            DurationOfBreak = 1,
                            ExceptionsAllowedBeforeBreaking = 1
                        }
                    }
                },
            }))
            .And(x => x.GivenTheConfigIsValid())
            .And(x => GivenTheDownstreamAddresses())
            .And(x => GivenTheHeaderFindAndReplaceCreatorReturns())
            .And(x => x.GivenTheFollowingOptionsAreReturned(serviceOptions))
            .And(x => x.GivenTheQosOptionsCreatorReturns(expected))
            .When(x => x.WhenICreateTheConfig())
            .Then(x => x.ThenTheQosOptionsAre(expected))
            .BDDfy();
        }
示例#19
0
        public ReRouteOptions Create(FileReRoute fileReRoute)
        {
            var isAuthenticated    = IsAuthenticated(fileReRoute);
            var isAuthorised       = IsAuthorised(fileReRoute);
            var isCached           = IsCached(fileReRoute);
            var enableRateLimiting = IsEnableRateLimiting(fileReRoute);

            var options = new ReRouteOptionsBuilder()
                          .WithIsAuthenticated(isAuthenticated)
                          .WithIsAuthorised(isAuthorised)
                          .WithIsCached(isCached)
                          .WithRateLimiting(enableRateLimiting)
                          .Build();

            return(options);
        }
示例#20
0
        public void should_not_use_service_discovery_for_downstream_host_url_when_no_service_name()
        {
            var reRouteOptions = new ReRouteOptionsBuilder()
                                 .Build();

            var downstreamReRoute = new DownstreamReRouteBuilder()
                                    .WithDownstreamPathTemplate("/products/{productId}")
                                    .WithUpstreamPathTemplate("/api/products/{productId}")
                                    .WithUpstreamHttpMethod(new List <string> {
                "Get"
            })
                                    .WithUseServiceDiscovery(false)
                                    .Build();


            this.Given(x => x.GivenTheConfigIs(new FileConfiguration
            {
                ReRoutes = new List <FileReRoute>
                {
                    new FileReRoute
                    {
                        UpstreamPathTemplate   = "/api/products/{productId}",
                        DownstreamPathTemplate = "/products/{productId}",
                        UpstreamHttpMethod     = new List <string> {
                            "Get"
                        },
                        ReRouteIsCaseSensitive = false,
                    }
                }
            }))
            .And(x => x.GivenTheConfigIsValid())
            .And(x => GivenTheDownstreamAddresses())
            .And(x => GivenTheHeaderFindAndReplaceCreatorReturns())
            .And(x => x.GivenTheFollowingOptionsAreReturned(reRouteOptions))
            .When(x => x.WhenICreateTheConfig())
            .Then(x => x.ThenTheReRoutesAre(new List <ReRoute>
            {
                new ReRouteBuilder()
                .WithDownstreamReRoute(downstreamReRoute)
                .WithUpstreamPathTemplate("/api/products/{productId}")
                .WithUpstreamHttpMethod(new List <string> {
                    "Get"
                })
                .Build()
            }))
            .BDDfy();
        }
示例#21
0
        public ReRouteOptions Create(FileReRoute fileReRoute)
        {
            var isAuthenticated     = IsAuthenticated(fileReRoute);
            var isAuthorised        = IsAuthorised(fileReRoute);
            var isCached            = IsCached(fileReRoute);
            var enableRateLimiting  = IsEnableRateLimiting(fileReRoute);
            var useServiceDiscovery = !string.IsNullOrEmpty(fileReRoute.ServiceName);

            var options = new ReRouteOptionsBuilder()
                          .WithIsAuthenticated(isAuthenticated)
                          .WithIsAuthorised(isAuthorised)
                          .WithIsCached(isCached)
                          .WithRateLimiting(enableRateLimiting)
                          .WithUseServiceDiscovery(useServiceDiscovery)
                          .Build();

            return(options);
        }
示例#22
0
        public void should_call_qos_options_creator()
        {
            var expected = new QoSOptionsBuilder()
                           .WithDurationOfBreak(1)
                           .WithExceptionsAllowedBeforeBreaking(1)
                           .WithTimeoutValue(1)
                           .Build();

            var serviceOptions = new ReRouteOptionsBuilder()
                                 .WithIsQos(true)
                                 .Build();

            this.Given(x => x.GivenTheConfigIs(new FileConfiguration
            {
                ReRoutes = new List <FileReRoute>
                {
                    new FileReRoute
                    {
                        DownstreamHost         = "127.0.0.1",
                        UpstreamPathTemplate   = "/api/products/{productId}",
                        DownstreamPathTemplate = "/products/{productId}",
                        UpstreamHttpMethod     = "Get",
                        QoSOptions             = new FileQoSOptions
                        {
                            TimeoutValue    = 1,
                            DurationOfBreak = 1,
                            ExceptionsAllowedBeforeBreaking = 1
                        }
                    }
                },
            }))
            .And(x => x.GivenTheConfigIsValid())
            .And(x => x.GivenTheFollowingOptionsAreReturned(serviceOptions))
            .And(x => x.GivenTheQosProviderFactoryReturns())
            .And(x => x.GivenTheQosOptionsCreatorReturns(expected))
            .When(x => x.WhenICreateTheConfig())
            .Then(x => x.ThenTheQosOptionsAre(expected))
            .And(x => x.TheQosProviderFactoryIsCalledCorrectly())
            .And(x => x.ThenTheQosProviderHouseIsCalledCorrectly())
            .BDDfy();
        }
示例#23
0
        public void should_create_re_route_options()
        {
            var reRoute = new FileReRoute
            {
                RateLimitOptions = new FileRateLimitRule
                {
                    EnableRateLimiting = true
                },
                QoSOptions = new FileQoSOptions
                {
                    ExceptionsAllowedBeforeBreaking = 1,
                    TimeoutValue = 1
                },
                AuthenticationOptions = new FileAuthenticationOptions
                {
                    Provider = "IdentityServer"
                },
                RouteClaimsRequirement = new Dictionary <string, string>()
                {
                    { "", "" }
                },
                FileCacheOptions = new FileCacheOptions
                {
                    TtlSeconds = 1
                }
            };

            var expected = new ReRouteOptionsBuilder()
                           .WithIsAuthenticated(true)
                           .WithIsAuthorised(true)
                           .WithIsCached(true)
                           .WithIsQos(true)
                           .WithRateLimiting(true)
                           .Build();

            this.Given(x => x.GivenTheFollowing(reRoute))
            .When(x => x.WhenICreate())
            .Then(x => x.ThenTheFollowingIsReturned(expected))
            .BDDfy();
        }
示例#24
0
        public void should_create_with_headers_to_extract()
        {
            var reRouteOptions = new ReRouteOptionsBuilder()
                                 .WithIsAuthenticated(true)
                                 .Build();

            var authenticationOptions = new AuthenticationOptionsBuilder()
                                        .WithProvider("IdentityServer")
                                        .WithProviderRootUrl("http://localhost:51888")
                                        .WithRequireHttps(false)
                                        .WithApiSecret("secret")
                                        .WithApiName("api")
                                        .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)
                .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     = new List <string> {
                            "Get"
                        },
                        ReRouteIsCaseSensitive = true,
                        AuthenticationOptions  = new FileAuthenticationOptions
                        {
                            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();
        }