mirror of
				https://github.com/nsnail/Ocelot.git
				synced 2025-11-04 15:50:49 +08:00 
			
		
		
		
	@@ -30,7 +30,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_fix_issue_597()
 | 
			
		||||
        {
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -46,7 +47,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                            new FileHostAndPort
 | 
			
		||||
                            {
 | 
			
		||||
                                Host = "localhost",
 | 
			
		||||
                                Port = 8571
 | 
			
		||||
                                Port = port
 | 
			
		||||
                            }
 | 
			
		||||
                        },
 | 
			
		||||
                        Key = "key1"
 | 
			
		||||
@@ -62,7 +63,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                            new FileHostAndPort
 | 
			
		||||
                            {
 | 
			
		||||
                                Host = "localhost",
 | 
			
		||||
                                Port = 8571
 | 
			
		||||
                                Port = port
 | 
			
		||||
                            }
 | 
			
		||||
                        },
 | 
			
		||||
                        Key = "key2"
 | 
			
		||||
@@ -78,7 +79,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                            new FileHostAndPort
 | 
			
		||||
                            {
 | 
			
		||||
                                Host = "localhost",
 | 
			
		||||
                                Port = 8571
 | 
			
		||||
                                Port = port
 | 
			
		||||
                            }
 | 
			
		||||
                        },
 | 
			
		||||
                        Key = "key3"
 | 
			
		||||
@@ -94,7 +95,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                            new FileHostAndPort
 | 
			
		||||
                            {
 | 
			
		||||
                                Host = "localhost",
 | 
			
		||||
                                Port = 8571
 | 
			
		||||
                                Port = port
 | 
			
		||||
                            }
 | 
			
		||||
                        },
 | 
			
		||||
                        Key = "key4"
 | 
			
		||||
@@ -129,7 +130,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
 | 
			
		||||
            var expected = "{\"key1\":some_data,\"key2\":some_data}";
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenServiceIsRunning("http://localhost:8571", 200, "some_data"))
 | 
			
		||||
            this.Given(x => x.GivenServiceIsRunning($"http://localhost:{port}", 200, "some_data"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/EmpDetail/US/1"))
 | 
			
		||||
@@ -140,7 +141,10 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_200_with_advanced_aggregate_configs()
 | 
			
		||||
        {
 | 
			
		||||
        {
 | 
			
		||||
            var port1 = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var port2 = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var port3 = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -154,7 +158,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 51889,
 | 
			
		||||
                                    Port = port1,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamPathTemplate = "/Comments",
 | 
			
		||||
@@ -170,7 +174,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 54030,
 | 
			
		||||
                                    Port = port2,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamPathTemplate = "/UserDetails",
 | 
			
		||||
@@ -186,7 +190,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 51887,
 | 
			
		||||
                                    Port = port3,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamPathTemplate = "/PostDetails",
 | 
			
		||||
@@ -221,9 +225,9 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
 | 
			
		||||
            var expected = "{\"Comments\":" + commentsResponseContent + ",\"UserDetails\":" + userDetailsResponseContent + ",\"PostDetails\":" + postDetailsResponseContent + "}";
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenServiceOneIsRunning("http://localhost:51889", "/", 200, commentsResponseContent))
 | 
			
		||||
                .Given(x => x.GivenServiceTwoIsRunning("http://localhost:54030", "/users/1", 200, userDetailsResponseContent))
 | 
			
		||||
                .Given(x => x.GivenServiceTwoIsRunning("http://localhost:51887", "/posts/2", 200, postDetailsResponseContent))
 | 
			
		||||
            this.Given(x => x.GivenServiceOneIsRunning($"http://localhost:{port1}", "/", 200, commentsResponseContent))
 | 
			
		||||
                .Given(x => x.GivenServiceTwoIsRunning($"http://localhost:{port2}", "/users/1", 200, userDetailsResponseContent))
 | 
			
		||||
                .Given(x => x.GivenServiceTwoIsRunning($"http://localhost:{port3}", "/posts/2", 200, postDetailsResponseContent))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
@@ -234,7 +238,9 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_200_with_simple_url_user_defined_aggregate()
 | 
			
		||||
        {
 | 
			
		||||
        {
 | 
			
		||||
            var port1 = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var port2 = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -248,7 +254,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 51885,
 | 
			
		||||
                                    Port = port1,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamPathTemplate = "/laura",
 | 
			
		||||
@@ -264,7 +270,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 51886,
 | 
			
		||||
                                    Port = port2,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamPathTemplate = "/tom",
 | 
			
		||||
@@ -290,8 +296,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
 | 
			
		||||
            var expected = "Bye from Laura, Bye from Tom";
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenServiceOneIsRunning("http://localhost:51885", "/", 200, "{Hello from Laura}"))
 | 
			
		||||
                .Given(x => x.GivenServiceTwoIsRunning("http://localhost:51886", "/", 200, "{Hello from Tom}"))
 | 
			
		||||
            this.Given(x => x.GivenServiceOneIsRunning($"http://localhost:{port1}", "/", 200, "{Hello from Laura}"))
 | 
			
		||||
                .Given(x => x.GivenServiceTwoIsRunning($"http://localhost:{port2}", "/", 200, "{Hello from Tom}"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunningWithSpecficAggregatorsRegisteredInDi<FakeDefinedAggregator, FakeDepdendency>())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
@@ -303,7 +309,9 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_200_with_simple_url()
 | 
			
		||||
        {
 | 
			
		||||
        {
 | 
			
		||||
            var port1 = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var port2 = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -317,7 +325,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 51875,
 | 
			
		||||
                                    Port = port1,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamPathTemplate = "/laura",
 | 
			
		||||
@@ -333,7 +341,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 52476,
 | 
			
		||||
                                    Port = port2,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamPathTemplate = "/tom",
 | 
			
		||||
@@ -358,8 +366,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
 | 
			
		||||
            var expected = "{\"Laura\":{Hello from Laura},\"Tom\":{Hello from Tom}}";
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenServiceOneIsRunning("http://localhost:51875", "/", 200, "{Hello from Laura}"))
 | 
			
		||||
                .Given(x => x.GivenServiceTwoIsRunning("http://localhost:52476", "/", 200, "{Hello from Tom}"))
 | 
			
		||||
            this.Given(x => x.GivenServiceOneIsRunning($"http://localhost:{port1}", "/", 200, "{Hello from Laura}"))
 | 
			
		||||
                .Given(x => x.GivenServiceTwoIsRunning($"http://localhost:{port2}", "/", 200, "{Hello from Tom}"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
@@ -371,7 +379,9 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_200_with_simple_url_one_service_404()
 | 
			
		||||
        {
 | 
			
		||||
        {
 | 
			
		||||
            var port1 = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var port2 = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -385,7 +395,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 51881,
 | 
			
		||||
                                    Port = port1,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamPathTemplate = "/laura",
 | 
			
		||||
@@ -401,7 +411,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 51889,
 | 
			
		||||
                                    Port = port2,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamPathTemplate = "/tom",
 | 
			
		||||
@@ -426,8 +436,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
 | 
			
		||||
            var expected = "{\"Laura\":,\"Tom\":{Hello from Tom}}";
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenServiceOneIsRunning("http://localhost:51881", "/", 404, ""))
 | 
			
		||||
                .Given(x => x.GivenServiceTwoIsRunning("http://localhost:51889", "/", 200, "{Hello from Tom}"))
 | 
			
		||||
            this.Given(x => x.GivenServiceOneIsRunning($"http://localhost:{port1}", "/", 404, ""))
 | 
			
		||||
                .Given(x => x.GivenServiceTwoIsRunning($"http://localhost:{port2}", "/", 200, "{Hello from Tom}"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
@@ -439,7 +449,9 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_200_with_simple_url_both_service_404()
 | 
			
		||||
        {
 | 
			
		||||
        {
 | 
			
		||||
            var port1 = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var port2 = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -453,7 +465,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 51883,
 | 
			
		||||
                                    Port = port1,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamPathTemplate = "/laura",
 | 
			
		||||
@@ -469,7 +481,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 51884,
 | 
			
		||||
                                    Port = port2,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamPathTemplate = "/tom",
 | 
			
		||||
@@ -494,8 +506,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
 | 
			
		||||
            var expected = "{\"Laura\":,\"Tom\":}";
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenServiceOneIsRunning("http://localhost:51883", "/", 404, ""))
 | 
			
		||||
                .Given(x => x.GivenServiceTwoIsRunning("http://localhost:51884", "/", 404, ""))
 | 
			
		||||
            this.Given(x => x.GivenServiceOneIsRunning($"http://localhost:{port1}", "/", 404, ""))
 | 
			
		||||
                .Given(x => x.GivenServiceTwoIsRunning($"http://localhost:{port2}", "/", 404, ""))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
@@ -507,7 +519,9 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_be_thread_safe()
 | 
			
		||||
        {
 | 
			
		||||
        {
 | 
			
		||||
            var port1 = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var port2 = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -521,7 +535,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 51878,
 | 
			
		||||
                                    Port = port1,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamPathTemplate = "/laura",
 | 
			
		||||
@@ -537,7 +551,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 51880,
 | 
			
		||||
                                    Port = port2,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamPathTemplate = "/tom",
 | 
			
		||||
@@ -560,8 +574,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenServiceOneIsRunning("http://localhost:51878", "/", 200, "{Hello from Laura}"))
 | 
			
		||||
                .Given(x => x.GivenServiceTwoIsRunning("http://localhost:51880", "/", 200, "{Hello from Tom}"))
 | 
			
		||||
            this.Given(x => x.GivenServiceOneIsRunning($"http://localhost:{port1}", "/", 200, "{Hello from Laura}"))
 | 
			
		||||
                .Given(x => x.GivenServiceTwoIsRunning($"http://localhost:{port2}", "/", 200, "{Hello from Tom}"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIMakeLotsOfDifferentRequestsToTheApiGateway())
 | 
			
		||||
 
 | 
			
		||||
@@ -20,7 +20,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
    {
 | 
			
		||||
        private readonly Steps _steps;
 | 
			
		||||
        private IWebHost _identityServerBuilder;
 | 
			
		||||
        private string _identityServerRootUrl = "http://localhost:51888";
 | 
			
		||||
        private string _identityServerRootUrl;
 | 
			
		||||
        private string _downstreamServicePath = "/";
 | 
			
		||||
        private string _downstreamServiceHost = "localhost";
 | 
			
		||||
        private string _downstreamServiceScheme = "http";
 | 
			
		||||
@@ -31,7 +31,9 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        public AuthenticationTests()
 | 
			
		||||
        {
 | 
			
		||||
            _serviceHandler = new ServiceHandler();
 | 
			
		||||
            _steps = new Steps();
 | 
			
		||||
            _steps = new Steps();
 | 
			
		||||
            var identityServerPort = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            _identityServerRootUrl = $"http://localhost:{identityServerPort}";
 | 
			
		||||
            _options = o =>
 | 
			
		||||
            {
 | 
			
		||||
                o.Authority = _identityServerRootUrl;
 | 
			
		||||
@@ -45,7 +47,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_401_using_identity_server_access_token()
 | 
			
		||||
        {
 | 
			
		||||
            int port = 54329;
 | 
			
		||||
            int port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
@@ -86,7 +88,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_200_using_identity_server()
 | 
			
		||||
        {
 | 
			
		||||
            int port = 54099;
 | 
			
		||||
            int port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
@@ -129,7 +131,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_401_using_identity_server_with_token_requested_for_other_api()
 | 
			
		||||
        {
 | 
			
		||||
            int port = 54196;
 | 
			
		||||
            int port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
@@ -171,7 +173,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_201_using_identity_server_access_token()
 | 
			
		||||
        {
 | 
			
		||||
            int port = 52226;
 | 
			
		||||
            int port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
@@ -214,7 +216,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_201_using_identity_server_reference_token()
 | 
			
		||||
        {
 | 
			
		||||
            int port = 52222;
 | 
			
		||||
            int port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
 
 | 
			
		||||
@@ -21,13 +21,15 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        private IWebHost _identityServerBuilder;
 | 
			
		||||
        private readonly Steps _steps;
 | 
			
		||||
        private readonly Action<IdentityServerAuthenticationOptions> _options;
 | 
			
		||||
        private string _identityServerRootUrl = "http://localhost:51888";
 | 
			
		||||
        private string _identityServerRootUrl;
 | 
			
		||||
        private readonly ServiceHandler _serviceHandler;
 | 
			
		||||
 | 
			
		||||
        public AuthorisationTests()
 | 
			
		||||
        {
 | 
			
		||||
            _serviceHandler = new ServiceHandler();
 | 
			
		||||
            _steps = new Steps();
 | 
			
		||||
            _steps = new Steps();
 | 
			
		||||
            var identityServerPort = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            _identityServerRootUrl = $"http://localhost:{identityServerPort}";
 | 
			
		||||
            _options = o =>
 | 
			
		||||
            {
 | 
			
		||||
                o.Authority = _identityServerRootUrl;
 | 
			
		||||
@@ -41,7 +43,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_200_authorising_route()
 | 
			
		||||
        {
 | 
			
		||||
            int port = 52875;
 | 
			
		||||
            int port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
@@ -86,9 +88,9 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                   }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:51888", "api", AccessTokenType.Jwt))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", AccessTokenType.Jwt))
 | 
			
		||||
                .And(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200, "Hello from Laura"))
 | 
			
		||||
                .And(x => _steps.GivenIHaveAToken("http://localhost:51888"))
 | 
			
		||||
                .And(x => _steps.GivenIHaveAToken(_identityServerRootUrl))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning(_options, "Test"))
 | 
			
		||||
                .And(x => _steps.GivenIHaveAddedATokenToMyRequest())
 | 
			
		||||
@@ -101,7 +103,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_403_authorising_route()
 | 
			
		||||
        {
 | 
			
		||||
            int port = 59471;
 | 
			
		||||
            int port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
@@ -145,9 +147,9 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                   }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:51888", "api", AccessTokenType.Jwt))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", AccessTokenType.Jwt))
 | 
			
		||||
                .And(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200, "Hello from Laura"))
 | 
			
		||||
                .And(x => _steps.GivenIHaveAToken("http://localhost:51888"))
 | 
			
		||||
                .And(x => _steps.GivenIHaveAToken(_identityServerRootUrl))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning(_options, "Test"))
 | 
			
		||||
                .And(x => _steps.GivenIHaveAddedATokenToMyRequest())
 | 
			
		||||
@@ -159,7 +161,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_200_using_identity_server_with_allowed_scope()
 | 
			
		||||
        {
 | 
			
		||||
            int port = 63471;
 | 
			
		||||
            int port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
@@ -188,9 +190,9 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                   }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:51888", "api", AccessTokenType.Jwt))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", AccessTokenType.Jwt))
 | 
			
		||||
                .And(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200, "Hello from Laura"))
 | 
			
		||||
                .And(x => _steps.GivenIHaveATokenForApiReadOnlyScope("http://localhost:51888"))
 | 
			
		||||
                .And(x => _steps.GivenIHaveATokenForApiReadOnlyScope(_identityServerRootUrl))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning(_options, "Test"))
 | 
			
		||||
                .And(x => _steps.GivenIHaveAddedATokenToMyRequest())
 | 
			
		||||
@@ -202,7 +204,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_403_using_identity_server_with_scope_not_allowed()
 | 
			
		||||
        {
 | 
			
		||||
            int port = 60571;
 | 
			
		||||
            int port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
@@ -231,9 +233,9 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                   }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:51888", "api", AccessTokenType.Jwt))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", AccessTokenType.Jwt))
 | 
			
		||||
                .And(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200, "Hello from Laura"))
 | 
			
		||||
                .And(x => _steps.GivenIHaveATokenForApiReadOnlyScope("http://localhost:51888"))
 | 
			
		||||
                .And(x => _steps.GivenIHaveATokenForApiReadOnlyScope(_identityServerRootUrl))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning(_options, "Test"))
 | 
			
		||||
                .And(x => _steps.GivenIHaveAddedATokenToMyRequest())
 | 
			
		||||
@@ -245,7 +247,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_fix_issue_240()
 | 
			
		||||
        {
 | 
			
		||||
            int port = 61071;
 | 
			
		||||
            int port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
@@ -292,9 +294,9 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:51888", "api", AccessTokenType.Jwt, users))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", AccessTokenType.Jwt, users))
 | 
			
		||||
                .And(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200, "Hello from Laura"))
 | 
			
		||||
                .And(x => _steps.GivenIHaveAToken("http://localhost:51888"))
 | 
			
		||||
                .And(x => _steps.GivenIHaveAToken(_identityServerRootUrl))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning(_options, "Test"))
 | 
			
		||||
                .And(x => _steps.GivenIHaveAddedATokenToMyRequest())
 | 
			
		||||
 
 | 
			
		||||
@@ -35,6 +35,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_forward_tracing_information_from_ocelot_and_downstream_services()
 | 
			
		||||
        {
 | 
			
		||||
            int port1 = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            int port2 = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -48,7 +50,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 51887,
 | 
			
		||||
                                    Port = port1,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamPathTemplate = "/api001/values",
 | 
			
		||||
@@ -67,7 +69,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 51388,
 | 
			
		||||
                                    Port = port2,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamPathTemplate = "/api002/values",
 | 
			
		||||
@@ -79,12 +81,13 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            var butterflyUrl = "http://localhost:9618";
 | 
			
		||||
            
 | 
			
		||||
            var butterflyPort = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var butterflyUrl = $"http://localhost:{butterflyPort}";
 | 
			
		||||
 | 
			
		||||
            this.Given(x => GivenFakeButterfly(butterflyUrl))
 | 
			
		||||
                .And(x => GivenServiceOneIsRunning("http://localhost:51887", "/api/values", 200, "Hello from Laura", butterflyUrl))
 | 
			
		||||
                .And(x => GivenServiceTwoIsRunning("http://localhost:51388", "/api/values", 200, "Hello from Tom", butterflyUrl))
 | 
			
		||||
                .And(x => GivenServiceOneIsRunning($"http://localhost:{port1}", "/api/values", 200, "Hello from Laura", butterflyUrl))
 | 
			
		||||
                .And(x => GivenServiceTwoIsRunning($"http://localhost:{port2}", "/api/values", 200, "Hello from Tom", butterflyUrl))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunningUsingButterfly(butterflyUrl))
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/api001/values"))
 | 
			
		||||
@@ -105,6 +108,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_tracing_header()
 | 
			
		||||
        {
 | 
			
		||||
            int port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -118,7 +122,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 51387,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamPathTemplate = "/api001/values",
 | 
			
		||||
@@ -136,10 +140,11 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            var butterflyUrl = "http://localhost:9618";
 | 
			
		||||
            var butterflyPort = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var butterflyUrl = $"http://localhost:{butterflyPort}";
 | 
			
		||||
 | 
			
		||||
            this.Given(x => GivenFakeButterfly(butterflyUrl))
 | 
			
		||||
                .And(x => GivenServiceOneIsRunning("http://localhost:51387", "/api/values", 200, "Hello from Laura", butterflyUrl))
 | 
			
		||||
                .And(x => GivenServiceOneIsRunning($"http://localhost:{port}", "/api/values", 200, "Hello from Laura", butterflyUrl))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunningUsingButterfly(butterflyUrl))
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/api001/values"))
 | 
			
		||||
 
 | 
			
		||||
@@ -22,7 +22,9 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_cached_response()
 | 
			
		||||
        {
 | 
			
		||||
        {
 | 
			
		||||
            int port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -35,7 +37,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 57899,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            DownstreamScheme = "http",
 | 
			
		||||
@@ -49,13 +51,13 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:57899", 200, "Hello from Laura", null, null))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200, "Hello from Laura", null, null))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
                .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
 | 
			
		||||
                .And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura"))
 | 
			
		||||
                .Given(x => x.GivenTheServiceNowReturns("http://localhost:57899", 200, "Hello from Tom"))
 | 
			
		||||
                .Given(x => x.GivenTheServiceNowReturns($"http://localhost:{port}", 200, "Hello from Tom"))
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
                .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
 | 
			
		||||
                .And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura"))
 | 
			
		||||
@@ -65,7 +67,9 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_cached_response_with_expires_header()
 | 
			
		||||
        {
 | 
			
		||||
        {
 | 
			
		||||
            int port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -78,7 +82,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 52839,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            DownstreamScheme = "http",
 | 
			
		||||
@@ -92,13 +96,13 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:52839", 200, "Hello from Laura", "Expires", "-1"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200, "Hello from Laura", "Expires", "-1"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
                .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
 | 
			
		||||
                .And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura"))
 | 
			
		||||
                .Given(x => x.GivenTheServiceNowReturns("http://localhost:52839", 200, "Hello from Tom"))
 | 
			
		||||
                .Given(x => x.GivenTheServiceNowReturns($"http://localhost:{port}", 200, "Hello from Tom"))
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
                .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
 | 
			
		||||
                .And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura"))
 | 
			
		||||
@@ -109,7 +113,9 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_cached_response_when_using_jsonserialized_cache()
 | 
			
		||||
        {
 | 
			
		||||
        {
 | 
			
		||||
            int port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -122,7 +128,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 57879,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            DownstreamScheme = "http",
 | 
			
		||||
@@ -136,13 +142,13 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:57879", 200, "Hello from Laura", null, null))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200, "Hello from Laura", null, null))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunningUsingJsonSerializedCache())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
                .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
 | 
			
		||||
                .And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura"))
 | 
			
		||||
                .Given(x => x.GivenTheServiceNowReturns("http://localhost:57879", 200, "Hello from Tom"))
 | 
			
		||||
                .Given(x => x.GivenTheServiceNowReturns($"http://localhost:{port}", 200, "Hello from Tom"))
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
                .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
 | 
			
		||||
                .And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura"))
 | 
			
		||||
@@ -151,7 +157,9 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_not_return_cached_response_as_ttl_expires()
 | 
			
		||||
        {
 | 
			
		||||
        {
 | 
			
		||||
            int port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -164,7 +172,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 57873,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            DownstreamScheme = "http",
 | 
			
		||||
@@ -178,13 +186,13 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:57873", 200, "Hello from Laura", null, null))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200, "Hello from Laura", null, null))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
                .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
 | 
			
		||||
                .And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura"))
 | 
			
		||||
                .Given(x => x.GivenTheServiceNowReturns("http://localhost:57873", 200, "Hello from Tom"))
 | 
			
		||||
                .Given(x => x.GivenTheServiceNowReturns($"http://localhost:{port}", 200, "Hello from Tom"))
 | 
			
		||||
                .And(x => x.GivenTheCacheExpires())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
                .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
 | 
			
		||||
 
 | 
			
		||||
@@ -21,7 +21,9 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_200_when_global_ignore_case_sensitivity_set()
 | 
			
		||||
        {
 | 
			
		||||
        {
 | 
			
		||||
            int port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -34,7 +36,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 51877,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            DownstreamScheme = "http",
 | 
			
		||||
@@ -44,7 +46,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51877", "/api/products/1", 200, "Some Product"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/api/products/1", 200, "Some Product"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/PRODUCTS/1"))
 | 
			
		||||
@@ -54,7 +56,9 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_200_when_reroute_ignore_case_sensitivity_set()
 | 
			
		||||
        {
 | 
			
		||||
        {
 | 
			
		||||
            int port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -67,7 +71,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 51877,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            DownstreamScheme = "http",
 | 
			
		||||
@@ -78,7 +82,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51877", "/api/products/1", 200, "Some Product"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/api/products/1", 200, "Some Product"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/PRODUCTS/1"))
 | 
			
		||||
@@ -88,7 +92,9 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_404_when_reroute_respect_case_sensitivity_set()
 | 
			
		||||
        {
 | 
			
		||||
        {
 | 
			
		||||
            int port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -101,7 +107,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 51877,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            DownstreamScheme = "http",
 | 
			
		||||
@@ -112,7 +118,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51877", "/api/products/1", 200, "Some Product"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/api/products/1", 200, "Some Product"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/PRODUCTS/1"))
 | 
			
		||||
@@ -122,7 +128,9 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_200_when_reroute_respect_case_sensitivity_set()
 | 
			
		||||
        {
 | 
			
		||||
        {
 | 
			
		||||
            int port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -135,7 +143,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 51877,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            DownstreamScheme = "http",
 | 
			
		||||
@@ -146,7 +154,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51877", "/api/products/1", 200, "Some Product"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/api/products/1", 200, "Some Product"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/PRODUCTS/1"))
 | 
			
		||||
@@ -156,7 +164,9 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_404_when_global_respect_case_sensitivity_set()
 | 
			
		||||
        {
 | 
			
		||||
        {
 | 
			
		||||
            int port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -169,7 +179,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 51877,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            DownstreamScheme = "http",
 | 
			
		||||
@@ -180,7 +190,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51877", "/api/products/1", 200, "Some Product"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/api/products/1", 200, "Some Product"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/PRODUCTS/1"))
 | 
			
		||||
@@ -190,7 +200,9 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_200_when_global_respect_case_sensitivity_set()
 | 
			
		||||
        {
 | 
			
		||||
        {
 | 
			
		||||
            int port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -203,7 +215,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 51877,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            DownstreamScheme = "http",
 | 
			
		||||
@@ -214,7 +226,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51877", "/api/products/1", 200, "Some Product"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/api/products/1", 200, "Some Product"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/PRODUCTS/1"))
 | 
			
		||||
 
 | 
			
		||||
@@ -23,11 +23,13 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        private IWebHost _identityServerBuilder;
 | 
			
		||||
        private readonly Steps _steps;
 | 
			
		||||
        private Action<IdentityServerAuthenticationOptions> _options;
 | 
			
		||||
        private string _identityServerRootUrl = "http://localhost:57888";
 | 
			
		||||
        private string _identityServerRootUrl;
 | 
			
		||||
        private string _downstreamFinalPath;
 | 
			
		||||
 | 
			
		||||
        public ClaimsToDownstreamPathTests()
 | 
			
		||||
        {
 | 
			
		||||
            var identityServerPort = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            _identityServerRootUrl = $"http://localhost:{identityServerPort}";
 | 
			
		||||
            _steps = new Steps();
 | 
			
		||||
            _options = o =>
 | 
			
		||||
            {
 | 
			
		||||
@@ -49,6 +51,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                SubjectId = "registered|1231231",
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            int port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -61,7 +65,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                               new FileHostAndPort
 | 
			
		||||
                               {
 | 
			
		||||
                                   Host = "localhost",
 | 
			
		||||
                                   Port = 57876,
 | 
			
		||||
                                   Port = port,
 | 
			
		||||
                               },
 | 
			
		||||
                           },
 | 
			
		||||
                           DownstreamScheme = "http",
 | 
			
		||||
@@ -83,9 +87,9 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                   },
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:57888", "api", AccessTokenType.Jwt, user))
 | 
			
		||||
                .And(x => x.GivenThereIsAServiceRunningOn("http://localhost:57876", 200))
 | 
			
		||||
                .And(x => _steps.GivenIHaveAToken("http://localhost:57888"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", AccessTokenType.Jwt, user))
 | 
			
		||||
                .And(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200))
 | 
			
		||||
                .And(x => _steps.GivenIHaveAToken(_identityServerRootUrl))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning(_options, "Test"))
 | 
			
		||||
                .And(x => _steps.GivenIHaveAddedATokenToMyRequest())
 | 
			
		||||
 
 | 
			
		||||
@@ -25,13 +25,15 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        private IWebHost _identityServerBuilder;
 | 
			
		||||
        private readonly Steps _steps;
 | 
			
		||||
        private Action<IdentityServerAuthenticationOptions> _options;
 | 
			
		||||
        private string _identityServerRootUrl = "http://localhost:52888";
 | 
			
		||||
        private string _identityServerRootUrl;
 | 
			
		||||
        private readonly ServiceHandler _serviceHandler;
 | 
			
		||||
 | 
			
		||||
        public ClaimsToHeadersForwardingTests()
 | 
			
		||||
        {
 | 
			
		||||
            _serviceHandler = new ServiceHandler();
 | 
			
		||||
            _steps = new Steps();
 | 
			
		||||
            _steps = new Steps();
 | 
			
		||||
            var identityServerPort = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            _identityServerRootUrl = $"http://localhost:{identityServerPort}";
 | 
			
		||||
            _options = o =>
 | 
			
		||||
            {
 | 
			
		||||
                o.Authority = _identityServerRootUrl;
 | 
			
		||||
@@ -57,6 +59,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
               }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            int port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -69,7 +73,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                               new FileHostAndPort
 | 
			
		||||
                               {
 | 
			
		||||
                                   Host = "localhost",
 | 
			
		||||
                                   Port = 52876,
 | 
			
		||||
                                   Port = port,
 | 
			
		||||
                               }
 | 
			
		||||
                           },
 | 
			
		||||
                           DownstreamScheme = "http",
 | 
			
		||||
@@ -94,9 +98,9 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                   }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:52888", "api", AccessTokenType.Jwt, user))
 | 
			
		||||
                .And(x => x.GivenThereIsAServiceRunningOn("http://localhost:52876", 200))
 | 
			
		||||
                .And(x => _steps.GivenIHaveAToken("http://localhost:52888"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", AccessTokenType.Jwt, user))
 | 
			
		||||
                .And(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200))
 | 
			
		||||
                .And(x => _steps.GivenIHaveAToken(_identityServerRootUrl))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning(_options, "Test"))
 | 
			
		||||
                .And(x => _steps.GivenIHaveAddedATokenToMyRequest())
 | 
			
		||||
 
 | 
			
		||||
@@ -25,12 +25,14 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        private IWebHost _identityServerBuilder;
 | 
			
		||||
        private readonly Steps _steps;
 | 
			
		||||
        private Action<IdentityServerAuthenticationOptions> _options;
 | 
			
		||||
        private string _identityServerRootUrl = "http://localhost:57888";
 | 
			
		||||
        private string _identityServerRootUrl;
 | 
			
		||||
        private string _downstreamQueryString;
 | 
			
		||||
 | 
			
		||||
        public ClaimsToQueryStringForwardingTests()
 | 
			
		||||
        {
 | 
			
		||||
            _steps = new Steps();
 | 
			
		||||
            _steps = new Steps();
 | 
			
		||||
            var identityServerPort = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            _identityServerRootUrl = $"http://localhost:{identityServerPort}";
 | 
			
		||||
            _options = o =>
 | 
			
		||||
            {
 | 
			
		||||
                o.Authority = _identityServerRootUrl;
 | 
			
		||||
@@ -56,6 +58,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
               }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            int port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -68,7 +72,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                               new FileHostAndPort
 | 
			
		||||
                               {
 | 
			
		||||
                                   Host = "localhost",
 | 
			
		||||
                                   Port = 57876,
 | 
			
		||||
                                   Port = port,
 | 
			
		||||
                               }
 | 
			
		||||
                           },
 | 
			
		||||
                           DownstreamScheme = "http",
 | 
			
		||||
@@ -93,9 +97,9 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                   }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:57888", "api", AccessTokenType.Jwt, user))
 | 
			
		||||
                .And(x => x.GivenThereIsAServiceRunningOn("http://localhost:57876", 200))
 | 
			
		||||
                .And(x => _steps.GivenIHaveAToken("http://localhost:57888"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", AccessTokenType.Jwt, user))
 | 
			
		||||
                .And(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200))
 | 
			
		||||
                .And(x => _steps.GivenIHaveAToken(_identityServerRootUrl))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning(_options, "Test"))
 | 
			
		||||
                .And(x => _steps.GivenIHaveAddedATokenToMyRequest())
 | 
			
		||||
@@ -120,6 +124,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
               }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            int port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -132,7 +138,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                               new FileHostAndPort
 | 
			
		||||
                               {
 | 
			
		||||
                                   Host = "localhost",
 | 
			
		||||
                                   Port = 57876,
 | 
			
		||||
                                   Port = port,
 | 
			
		||||
                               }
 | 
			
		||||
                           },
 | 
			
		||||
                           DownstreamScheme = "http",
 | 
			
		||||
@@ -157,9 +163,9 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                   }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:57888", "api", AccessTokenType.Jwt, user))
 | 
			
		||||
                .And(x => x.GivenThereIsAServiceRunningOn("http://localhost:57876", 200))
 | 
			
		||||
                .And(x => _steps.GivenIHaveAToken("http://localhost:57888"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", AccessTokenType.Jwt, user))
 | 
			
		||||
                .And(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200))
 | 
			
		||||
                .And(x => _steps.GivenIHaveAToken(_identityServerRootUrl))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning(_options, "Test"))
 | 
			
		||||
                .And(x => _steps.GivenIHaveAddedATokenToMyRequest())
 | 
			
		||||
 
 | 
			
		||||
@@ -23,6 +23,8 @@
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_call_withratelimiting()
 | 
			
		||||
        {
 | 
			
		||||
            int port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -35,7 +37,7 @@
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 51876,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            DownstreamScheme = "http",
 | 
			
		||||
@@ -66,7 +68,7 @@
 | 
			
		||||
                }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51876", "/api/ClientRateLimit"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/api/ClientRateLimit"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGatewayMultipleTimesForRateLimit("/api/ClientRateLimit", 1))
 | 
			
		||||
@@ -81,6 +83,8 @@
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_wait_for_period_timespan_to_elapse_before_making_next_request()
 | 
			
		||||
        {
 | 
			
		||||
            int port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -93,7 +97,7 @@
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 51926,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            DownstreamScheme = "http",
 | 
			
		||||
@@ -125,7 +129,7 @@
 | 
			
		||||
                }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51926", "/api/ClientRateLimit"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/api/ClientRateLimit"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGatewayMultipleTimesForRateLimit("/api/ClientRateLimit", 1))
 | 
			
		||||
@@ -146,7 +150,7 @@
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_call_middleware_withWhitelistClient()
 | 
			
		||||
        {
 | 
			
		||||
            int port = 61876;
 | 
			
		||||
            int port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
 
 | 
			
		||||
@@ -32,6 +32,9 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_200_with_simple_url_when_using_jsonserialized_cache()
 | 
			
		||||
        {
 | 
			
		||||
            int consulPort = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            int servicePort = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -45,7 +48,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 51779,
 | 
			
		||||
                                    Port = servicePort,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamPathTemplate = "/",
 | 
			
		||||
@@ -57,15 +60,15 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                    ServiceDiscoveryProvider = new FileServiceDiscoveryProvider()
 | 
			
		||||
                    {
 | 
			
		||||
                        Host = "localhost",
 | 
			
		||||
                        Port = 9502
 | 
			
		||||
                        Port = consulPort
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            var fakeConsulServiceDiscoveryUrl = "http://localhost:9502";
 | 
			
		||||
            var fakeConsulServiceDiscoveryUrl = $"http://localhost:{consulPort}";
 | 
			
		||||
 | 
			
		||||
            this.Given(x => GivenThereIsAFakeConsulServiceDiscoveryProvider(fakeConsulServiceDiscoveryUrl, ""))
 | 
			
		||||
                .And(x => x.GivenThereIsAServiceRunningOn("http://localhost:51779", "", 200, "Hello from Laura"))
 | 
			
		||||
                .And(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{servicePort}", "", 200, "Hello from Laura"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunningUsingConsulToStoreConfigAndJsonSerializedCache())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,6 @@
 | 
			
		||||
using Ocelot.Configuration.File;
 | 
			
		||||
using System;
 | 
			
		||||
using Ocelot.Configuration.ChangeTracking;
 | 
			
		||||
using TestStack.BDDfy;
 | 
			
		||||
using Xunit;
 | 
			
		||||
 | 
			
		||||
@@ -54,6 +55,33 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_trigger_change_token_on_change()
 | 
			
		||||
        {
 | 
			
		||||
            this.Given(x => _steps.GivenThereIsAConfiguration(_initialConfig))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunningReloadingConfig(true))
 | 
			
		||||
                .And(x => _steps.GivenIHaveAChangeToken())
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(_anotherConfig))
 | 
			
		||||
                .And(x => _steps.GivenIWait(MillisecondsToWaitForChangeToken))
 | 
			
		||||
                .Then(x => _steps.TheChangeTokenShouldBeActive(true))
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_not_trigger_change_token_with_no_change()
 | 
			
		||||
        {
 | 
			
		||||
            this.Given(x => _steps.GivenThereIsAConfiguration(_initialConfig))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunningReloadingConfig(false))
 | 
			
		||||
                .And(x => _steps.GivenIHaveAChangeToken())
 | 
			
		||||
                .And(x => _steps.GivenIWait(MillisecondsToWaitForChangeToken)) // Wait for prior activation to expire.
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(_anotherConfig))
 | 
			
		||||
                .And(x => _steps.GivenIWait(MillisecondsToWaitForChangeToken))
 | 
			
		||||
                .Then(x => _steps.TheChangeTokenShouldBeActive(false))
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private const int MillisecondsToWaitForChangeToken = (int) (OcelotConfigurationChangeToken.PollingIntervalSeconds*1000) - 100;
 | 
			
		||||
 | 
			
		||||
        public void Dispose()
 | 
			
		||||
        {
 | 
			
		||||
            _steps.Dispose();
 | 
			
		||||
 
 | 
			
		||||
@@ -34,6 +34,9 @@
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_200_with_simple_url()
 | 
			
		||||
        {
 | 
			
		||||
            int consulPort = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            int servicePort = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -47,7 +50,7 @@
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 51779,
 | 
			
		||||
                                    Port = servicePort,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamPathTemplate = "/",
 | 
			
		||||
@@ -59,15 +62,15 @@
 | 
			
		||||
                    ServiceDiscoveryProvider = new FileServiceDiscoveryProvider()
 | 
			
		||||
                    {
 | 
			
		||||
                        Host = "localhost",
 | 
			
		||||
                        Port = 9500
 | 
			
		||||
                        Port = consulPort
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            var fakeConsulServiceDiscoveryUrl = "http://localhost:9500";
 | 
			
		||||
            var fakeConsulServiceDiscoveryUrl = $"http://localhost:{consulPort}";
 | 
			
		||||
 | 
			
		||||
            this.Given(x => GivenThereIsAFakeConsulServiceDiscoveryProvider(fakeConsulServiceDiscoveryUrl, ""))
 | 
			
		||||
                .And(x => x.GivenThereIsAServiceRunningOn("http://localhost:51779", "", 200, "Hello from Laura"))
 | 
			
		||||
                .And(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{servicePort}", "", 200, "Hello from Laura"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunningUsingConsulToStoreConfig())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
@@ -79,7 +82,8 @@
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_load_configuration_out_of_consul()
 | 
			
		||||
        {
 | 
			
		||||
            var consulPort = 8500;
 | 
			
		||||
            var consulPort = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            int servicePort = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
@@ -108,7 +112,7 @@
 | 
			
		||||
                            new FileHostAndPort
 | 
			
		||||
                            {
 | 
			
		||||
                                Host = "localhost",
 | 
			
		||||
                                Port = 51779,
 | 
			
		||||
                                Port = servicePort,
 | 
			
		||||
                            }
 | 
			
		||||
                        },
 | 
			
		||||
                        UpstreamPathTemplate = "/cs/status",
 | 
			
		||||
@@ -127,7 +131,7 @@
 | 
			
		||||
 | 
			
		||||
            this.Given(x => GivenTheConsulConfigurationIs(consulConfig))
 | 
			
		||||
                .And(x => GivenThereIsAFakeConsulServiceDiscoveryProvider(fakeConsulServiceDiscoveryUrl, ""))
 | 
			
		||||
                .And(x => x.GivenThereIsAServiceRunningOn("http://localhost:51779", "/status", 200, "Hello from Laura"))
 | 
			
		||||
                .And(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{servicePort}", "/status", 200, "Hello from Laura"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunningUsingConsulToStoreConfig())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/cs/status"))
 | 
			
		||||
@@ -139,7 +143,9 @@
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_load_configuration_out_of_consul_if_it_is_changed()
 | 
			
		||||
        {
 | 
			
		||||
            var consulPort = 8506;
 | 
			
		||||
            var consulPort = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            int servicePort = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                GlobalConfiguration = new FileGlobalConfiguration()
 | 
			
		||||
@@ -167,7 +173,7 @@
 | 
			
		||||
                            new FileHostAndPort
 | 
			
		||||
                            {
 | 
			
		||||
                                Host = "localhost",
 | 
			
		||||
                                Port = 51780,
 | 
			
		||||
                                Port = servicePort,
 | 
			
		||||
                            }
 | 
			
		||||
                        },
 | 
			
		||||
                        UpstreamPathTemplate = "/cs/status",
 | 
			
		||||
@@ -197,7 +203,7 @@
 | 
			
		||||
                            new FileHostAndPort
 | 
			
		||||
                            {
 | 
			
		||||
                                Host = "localhost",
 | 
			
		||||
                                Port = 51780,
 | 
			
		||||
                                Port = servicePort,
 | 
			
		||||
                            }
 | 
			
		||||
                        },
 | 
			
		||||
                        UpstreamPathTemplate = "/cs/status/awesome",
 | 
			
		||||
@@ -216,7 +222,7 @@
 | 
			
		||||
 | 
			
		||||
            this.Given(x => GivenTheConsulConfigurationIs(consulConfig))
 | 
			
		||||
                .And(x => GivenThereIsAFakeConsulServiceDiscoveryProvider(fakeConsulServiceDiscoveryUrl, ""))
 | 
			
		||||
                .And(x => x.GivenThereIsAServiceRunningOn("http://localhost:51780", "/status", 200, "Hello from Laura"))
 | 
			
		||||
                .And(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{servicePort}", "/status", 200, "Hello from Laura"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunningUsingConsulToStoreConfig())
 | 
			
		||||
                .And(x => _steps.WhenIGetUrlOnTheApiGateway("/cs/status"))
 | 
			
		||||
@@ -230,9 +236,9 @@
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_handle_request_to_consul_for_downstream_service_and_make_request_no_re_routes_and_rate_limit()
 | 
			
		||||
        {
 | 
			
		||||
            const int consulPort = 8523;
 | 
			
		||||
            int consulPort = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            const string serviceName = "web";
 | 
			
		||||
            const int downstreamServicePort = 8187;
 | 
			
		||||
            int downstreamServicePort = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var downstreamServiceOneUrl = $"http://localhost:{downstreamServicePort}";
 | 
			
		||||
            var fakeConsulServiceDiscoveryUrl = $"http://localhost:{consulPort}";
 | 
			
		||||
            var serviceEntryOne = new ServiceEntry()
 | 
			
		||||
 
 | 
			
		||||
@@ -34,14 +34,14 @@
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_proxy_websocket_input_to_downstream_service_and_use_service_discovery_and_load_balancer()
 | 
			
		||||
        {
 | 
			
		||||
            var downstreamPort = 5007;
 | 
			
		||||
            var downstreamPort = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var downstreamHost = "localhost";
 | 
			
		||||
 | 
			
		||||
            var secondDownstreamPort = 5008;
 | 
			
		||||
            var secondDownstreamPort = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var secondDownstreamHost = "localhost";
 | 
			
		||||
 | 
			
		||||
            var serviceName = "websockets";
 | 
			
		||||
            var consulPort = 8509;
 | 
			
		||||
            var consulPort = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var fakeConsulServiceDiscoveryUrl = $"http://localhost:{consulPort}";
 | 
			
		||||
            var serviceEntryOne = new ServiceEntry()
 | 
			
		||||
            {
 | 
			
		||||
 
 | 
			
		||||
@@ -26,6 +26,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_not_add_content_type_or_content_length_headers()
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -39,7 +41,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 51339,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamPathTemplate = "/",
 | 
			
		||||
@@ -48,7 +50,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51339", "/", 200, "Hello from Laura"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/", 200, "Hello from Laura"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
@@ -62,6 +64,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_add_content_type_and_content_length_headers()
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -74,7 +78,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 51349,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            DownstreamScheme = "http",
 | 
			
		||||
@@ -86,7 +90,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
 | 
			
		||||
            var contentType = "application/json";
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51349", "/", 201, string.Empty))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/", 201, string.Empty))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .And(x => _steps.GivenThePostHasContent("postContent"))
 | 
			
		||||
@@ -101,6 +105,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_add_default_content_type_header()
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -113,7 +119,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 51359,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            DownstreamScheme = "http",
 | 
			
		||||
@@ -123,7 +129,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51359", "/", 201, string.Empty))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/", 201, string.Empty))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .And(x => _steps.GivenThePostHasContent("postContent"))
 | 
			
		||||
 
 | 
			
		||||
@@ -37,7 +37,9 @@
 | 
			
		||||
                    _counter++;
 | 
			
		||||
                    await next.Invoke();
 | 
			
		||||
                }
 | 
			
		||||
            };
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var fileConfiguration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
@@ -51,7 +53,7 @@
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 41879,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            DownstreamScheme = "http",
 | 
			
		||||
@@ -61,7 +63,7 @@
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:41879", 200, ""))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200, ""))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(fileConfiguration, _configurationPath))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning(configuration))
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
@@ -80,7 +82,9 @@
 | 
			
		||||
                    _counter++;
 | 
			
		||||
                    await next.Invoke();
 | 
			
		||||
                }
 | 
			
		||||
            };
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var fileConfiguration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
@@ -94,7 +98,7 @@
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 41879,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            DownstreamScheme = "http",
 | 
			
		||||
@@ -104,7 +108,7 @@
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:41879", 200, ""))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200, ""))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(fileConfiguration, _configurationPath))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning(configuration))
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
@@ -123,7 +127,9 @@
 | 
			
		||||
                    _counter++;
 | 
			
		||||
                    await next.Invoke();
 | 
			
		||||
                }
 | 
			
		||||
            };
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var fileConfiguration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
@@ -137,7 +143,7 @@
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 41879,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            DownstreamScheme = "http",
 | 
			
		||||
@@ -147,7 +153,7 @@
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:41879", 200, ""))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200, ""))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(fileConfiguration, _configurationPath))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning(configuration))
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
@@ -166,7 +172,9 @@
 | 
			
		||||
                    _counter++;
 | 
			
		||||
                    await next.Invoke();
 | 
			
		||||
                }
 | 
			
		||||
            };
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var fileConfiguration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
@@ -180,7 +188,7 @@
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 41879,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            DownstreamScheme = "http",
 | 
			
		||||
@@ -190,7 +198,7 @@
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:41879", 200, ""))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200, ""))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(fileConfiguration, _configurationPath))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning(configuration))
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
@@ -209,7 +217,9 @@
 | 
			
		||||
                    _counter++;
 | 
			
		||||
                    await next.Invoke();
 | 
			
		||||
                }
 | 
			
		||||
            };
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var fileConfiguration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
@@ -223,7 +233,7 @@
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 41879,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            DownstreamScheme = "http",
 | 
			
		||||
@@ -233,7 +243,7 @@
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:41879", 200, ""))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200, ""))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(fileConfiguration, _configurationPath))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning(configuration))
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
@@ -252,7 +262,9 @@
 | 
			
		||||
                    _counter++;
 | 
			
		||||
                    await next.Invoke();
 | 
			
		||||
                }
 | 
			
		||||
            };
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var fileConfiguration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
@@ -266,7 +278,7 @@
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 41879,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            DownstreamScheme = "http",
 | 
			
		||||
@@ -276,7 +288,7 @@
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:41879", 200, ""))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200, ""))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(fileConfiguration, _configurationPath))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning(configuration))
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
@@ -299,7 +311,9 @@
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                return Task.CompletedTask;
 | 
			
		||||
            };
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var fileConfiguration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
@@ -313,7 +327,7 @@
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 41880,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            DownstreamScheme = "http",
 | 
			
		||||
@@ -323,7 +337,7 @@
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:41880", 200, "/test"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200, "/test"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(fileConfiguration, _configurationPath))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunningWithMiddleareBeforePipeline<FakeMiddleware>(callback))
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
 
 | 
			
		||||
@@ -28,7 +28,7 @@
 | 
			
		||||
        {
 | 
			
		||||
            var eurekaPort = 8761;
 | 
			
		||||
            var serviceName = "product";
 | 
			
		||||
            var downstreamServicePort = 50371;
 | 
			
		||||
            var downstreamServicePort = RandomPortFinder.GetRandomPort();           
 | 
			
		||||
            var downstreamServiceOneUrl = $"http://localhost:{downstreamServicePort}";
 | 
			
		||||
            var fakeEurekaServiceDiscoveryUrl = $"http://localhost:{eurekaPort}";
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -25,7 +25,9 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_200_with_simple_url()
 | 
			
		||||
        {
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -39,7 +41,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 51179,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamPathTemplate = "/",
 | 
			
		||||
@@ -50,7 +52,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
 | 
			
		||||
            var input = "people";
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51179", "/", 200, "Hello from Laura", "\"people\""))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/", 200, "Hello from Laura", "\"people\""))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .And(x => _steps.GivenThePostHasGzipContent(input))
 | 
			
		||||
 
 | 
			
		||||
@@ -24,7 +24,9 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_transform_upstream_header()
 | 
			
		||||
        {
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -38,7 +40,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 51871,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamPathTemplate = "/",
 | 
			
		||||
@@ -51,7 +53,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51871", "/", 200, "Laz"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/", 200, "Laz"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .And(x => _steps.GivenIAddAHeader("Laz", "D"))
 | 
			
		||||
@@ -63,7 +65,9 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_transform_downstream_header()
 | 
			
		||||
        {
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -77,7 +81,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 51871,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamPathTemplate = "/",
 | 
			
		||||
@@ -90,7 +94,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51871", "/", 200, "Location", "http://www.bbc.co.uk/"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/", 200, "Location", "http://www.bbc.co.uk/"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
@@ -101,7 +105,9 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_fix_issue_190()
 | 
			
		||||
        {
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -115,14 +121,14 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 6773,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamPathTemplate = "/",
 | 
			
		||||
                            UpstreamHttpMethod = new List<string> { "Get" },
 | 
			
		||||
                            DownstreamHeaderTransform = new Dictionary<string,string>
 | 
			
		||||
                            {
 | 
			
		||||
                                {"Location", "http://localhost:6773, {BaseUrl}"}
 | 
			
		||||
                                {"Location", $"http://localhost:{port}, {{BaseUrl}}"}
 | 
			
		||||
                            },
 | 
			
		||||
                            HttpHandlerOptions = new FileHttpHandlerOptions
 | 
			
		||||
                            {
 | 
			
		||||
@@ -132,7 +138,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:6773", "/", 302, "Location", "http://localhost:6773/pay/Receive"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/", 302, "Location", $"http://localhost:{port}/pay/Receive"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
@@ -143,7 +149,9 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_fix_issue_205()
 | 
			
		||||
        {
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -157,7 +165,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 6773,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamPathTemplate = "/",
 | 
			
		||||
@@ -174,7 +182,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:6773", "/", 302, "Location", "http://localhost:6773/pay/Receive"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/", 302, "Location", $"http://localhost:{port}/pay/Receive"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
@@ -185,7 +193,9 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_fix_issue_417()
 | 
			
		||||
        {
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -199,7 +209,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 6773,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamPathTemplate = "/",
 | 
			
		||||
@@ -220,7 +230,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:6773", "/", 302, "Location", "http://localhost:6773/pay/Receive"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/", 302, "Location", $"http://localhost:{port}/pay/Receive"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
@@ -231,7 +241,9 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void request_should_reuse_cookies_with_cookie_container()
 | 
			
		||||
        {
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -245,7 +257,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                            new FileHostAndPort
 | 
			
		||||
                            {
 | 
			
		||||
                                Host = "localhost",
 | 
			
		||||
                                Port = 6774,
 | 
			
		||||
                                Port = port,
 | 
			
		||||
                            }
 | 
			
		||||
                        },
 | 
			
		||||
                        UpstreamPathTemplate = "/sso/{everything}",
 | 
			
		||||
@@ -258,7 +270,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:6774", "/sso/test", 200))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/sso/test", 200))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .And(x => _steps.WhenIGetUrlOnTheApiGateway("/sso/test"))
 | 
			
		||||
@@ -272,7 +284,9 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void request_should_have_own_cookies_no_cookie_container()
 | 
			
		||||
        {
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -286,7 +300,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                            new FileHostAndPort
 | 
			
		||||
                            {
 | 
			
		||||
                                Host = "localhost",
 | 
			
		||||
                                Port = 6775,
 | 
			
		||||
                                Port = port,
 | 
			
		||||
                            }
 | 
			
		||||
                        },
 | 
			
		||||
                        UpstreamPathTemplate = "/sso/{everything}",
 | 
			
		||||
@@ -299,7 +313,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:6775", "/sso/test", 200))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/sso/test", 200))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .And(x => _steps.WhenIGetUrlOnTheApiGateway("/sso/test"))
 | 
			
		||||
@@ -313,7 +327,9 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void issue_474_should_not_put_spaces_in_header()
 | 
			
		||||
        {
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -327,7 +343,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 52866,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamPathTemplate = "/",
 | 
			
		||||
@@ -336,7 +352,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:52866", "/", 200, "Accept"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/", 200, "Accept"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .And(x => _steps.GivenIAddAHeader("Accept", "text/html,application/xhtml+xml,application/xml;"))
 | 
			
		||||
@@ -348,7 +364,9 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void issue_474_should_put_spaces_in_header()
 | 
			
		||||
        {
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -362,7 +380,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 51874,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamPathTemplate = "/",
 | 
			
		||||
@@ -371,7 +389,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51874", "/", 200, "Accept"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/", 200, "Accept"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .And(x => _steps.GivenIAddAHeader("Accept", "text/html"))
 | 
			
		||||
 
 | 
			
		||||
@@ -26,7 +26,9 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_cache_one_http_client_same_re_route()
 | 
			
		||||
        {
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -40,7 +42,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 58814,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamPathTemplate = "/",
 | 
			
		||||
@@ -51,7 +53,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
 | 
			
		||||
            var cache = new FakeHttpClientCache();
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:58814", 200, "Hello from Laura"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200, "Hello from Laura"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunningWithFakeHttpClientCache(cache))
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
@@ -66,7 +68,9 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_cache_two_http_client_different_re_route()
 | 
			
		||||
        {
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -80,7 +84,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                            new FileHostAndPort
 | 
			
		||||
                            {
 | 
			
		||||
                                Host = "localhost",
 | 
			
		||||
                                Port = 58817,
 | 
			
		||||
                                Port = port,
 | 
			
		||||
                            }
 | 
			
		||||
                        },
 | 
			
		||||
                        UpstreamPathTemplate = "/",
 | 
			
		||||
@@ -95,7 +99,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                            new FileHostAndPort
 | 
			
		||||
                            {
 | 
			
		||||
                                Host = "localhost",
 | 
			
		||||
                                Port = 58817,
 | 
			
		||||
                                Port = port,
 | 
			
		||||
                            }
 | 
			
		||||
                        },
 | 
			
		||||
                        UpstreamPathTemplate = "/two",
 | 
			
		||||
@@ -106,7 +110,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
 | 
			
		||||
            var cache = new FakeHttpClientCache();
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:58817", 200, "Hello from Laura"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200, "Hello from Laura"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunningWithFakeHttpClientCache(cache))
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
 
 | 
			
		||||
@@ -27,6 +27,8 @@
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_call_re_route_ordered_specific_handlers()
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -40,7 +42,7 @@
 | 
			
		||||
                            new FileHostAndPort
 | 
			
		||||
                            {
 | 
			
		||||
                                Host = "localhost",
 | 
			
		||||
                                Port = 7197,
 | 
			
		||||
                                Port = port,
 | 
			
		||||
                            }
 | 
			
		||||
                        },
 | 
			
		||||
                        UpstreamPathTemplate = "/",
 | 
			
		||||
@@ -54,7 +56,7 @@
 | 
			
		||||
                }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:7197", "/", 200, "Hello from Laura"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/", 200, "Hello from Laura"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunningWithSpecficHandlersRegisteredInDi<FakeHandler, FakeHandlerTwo>())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
@@ -67,6 +69,8 @@
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_call_global_di_handlers()
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -80,7 +84,7 @@
 | 
			
		||||
                            new FileHostAndPort
 | 
			
		||||
                            {
 | 
			
		||||
                                Host = "localhost",
 | 
			
		||||
                                Port = 7187,
 | 
			
		||||
                                Port = port,
 | 
			
		||||
                            }
 | 
			
		||||
                        },
 | 
			
		||||
                        UpstreamPathTemplate = "/",
 | 
			
		||||
@@ -89,7 +93,7 @@
 | 
			
		||||
                }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:7187", "/", 200, "Hello from Laura"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/", 200, "Hello from Laura"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunningWithGlobalHandlersRegisteredInDi<FakeHandler, FakeHandlerTwo>())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
@@ -102,6 +106,8 @@
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_call_global_di_handlers_multiple_times()
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -115,7 +121,7 @@
 | 
			
		||||
                            new FileHostAndPort
 | 
			
		||||
                            {
 | 
			
		||||
                                Host = "localhost",
 | 
			
		||||
                                Port = 9187,
 | 
			
		||||
                                Port = port,
 | 
			
		||||
                            }
 | 
			
		||||
                        },
 | 
			
		||||
                        UpstreamPathTemplate = "/",
 | 
			
		||||
@@ -124,7 +130,7 @@
 | 
			
		||||
                }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:9187", "/", 200, "Hello from Laura"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/", 200, "Hello from Laura"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunningWithGlobalHandlerRegisteredInDi<FakeHandlerAgain>())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
@@ -153,6 +159,8 @@
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_call_global_di_handlers_with_dependency()
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -166,7 +174,7 @@
 | 
			
		||||
                            new FileHostAndPort
 | 
			
		||||
                            {
 | 
			
		||||
                                Host = "localhost",
 | 
			
		||||
                                Port = 7188,
 | 
			
		||||
                                Port = port,
 | 
			
		||||
                            }
 | 
			
		||||
                        },
 | 
			
		||||
                        UpstreamPathTemplate = "/",
 | 
			
		||||
@@ -177,7 +185,7 @@
 | 
			
		||||
 | 
			
		||||
            var dependency = new FakeDependency();
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:7188", "/", 200, "Hello from Laura"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/", 200, "Hello from Laura"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunningWithGlobalHandlersRegisteredInDi<FakeHandlerWithDependency>(dependency))
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										243
									
								
								test/Ocelot.AcceptanceTests/HttpTests.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										243
									
								
								test/Ocelot.AcceptanceTests/HttpTests.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,243 @@
 | 
			
		||||
namespace Ocelot.AcceptanceTests
 | 
			
		||||
{
 | 
			
		||||
    using Microsoft.AspNetCore.Http;
 | 
			
		||||
    using Ocelot.Configuration.File;
 | 
			
		||||
    using System;
 | 
			
		||||
    using System.Collections.Generic;
 | 
			
		||||
    using System.IO;
 | 
			
		||||
    using System.Net;
 | 
			
		||||
    using System.Net.Http;
 | 
			
		||||
    using Microsoft.AspNetCore.Server.Kestrel.Core;
 | 
			
		||||
    using TestStack.BDDfy;
 | 
			
		||||
    using Xunit;
 | 
			
		||||
 | 
			
		||||
    public class HttpTests : IDisposable
 | 
			
		||||
    {
 | 
			
		||||
        private readonly Steps _steps;
 | 
			
		||||
        private readonly ServiceHandler _serviceHandler;
 | 
			
		||||
 | 
			
		||||
        public HttpTests()
 | 
			
		||||
        {
 | 
			
		||||
            _serviceHandler = new ServiceHandler();
 | 
			
		||||
            _steps = new Steps();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_200_when_using_http_one()
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
                {
 | 
			
		||||
                    new FileReRoute
 | 
			
		||||
                    {
 | 
			
		||||
                        DownstreamPathTemplate = "/{url}",
 | 
			
		||||
                        DownstreamScheme = "https",
 | 
			
		||||
                        UpstreamPathTemplate = "/{url}",
 | 
			
		||||
                        UpstreamHttpMethod = new List<string> { "Get" },
 | 
			
		||||
                        DownstreamHostAndPorts = new List<FileHostAndPort>
 | 
			
		||||
                        {
 | 
			
		||||
                            new FileHostAndPort
 | 
			
		||||
                            {
 | 
			
		||||
                                Host = "localhost",
 | 
			
		||||
                                Port = port,
 | 
			
		||||
                            },
 | 
			
		||||
                        },
 | 
			
		||||
                        DownstreamHttpMethod = "POST",
 | 
			
		||||
                        DownstreamHttpVersion = "1.0",
 | 
			
		||||
                        DangerousAcceptAnyServerCertificateValidator = true
 | 
			
		||||
                    },
 | 
			
		||||
                },
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}/", "/", port, HttpProtocols.Http1))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
                .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_200_when_using_http_one_point_one()
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
                    {
 | 
			
		||||
                        new FileReRoute
 | 
			
		||||
                        {
 | 
			
		||||
                            DownstreamPathTemplate = "/{url}",
 | 
			
		||||
                            DownstreamScheme = "https",
 | 
			
		||||
                            UpstreamPathTemplate = "/{url}",
 | 
			
		||||
                            UpstreamHttpMethod = new List<string> { "Get" },
 | 
			
		||||
                            DownstreamHostAndPorts = new List<FileHostAndPort>
 | 
			
		||||
                            {
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                },
 | 
			
		||||
                            },
 | 
			
		||||
                            DownstreamHttpMethod = "POST",
 | 
			
		||||
                            DownstreamHttpVersion = "1.1",
 | 
			
		||||
                            DangerousAcceptAnyServerCertificateValidator = true
 | 
			
		||||
                        },
 | 
			
		||||
                    },
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}/", "/", port, HttpProtocols.Http1))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
                .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_200_when_using_http_two_point_zero()
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
                {
 | 
			
		||||
                    new FileReRoute
 | 
			
		||||
                    {
 | 
			
		||||
                        DownstreamPathTemplate = "/{url}",
 | 
			
		||||
                        DownstreamScheme = "https",
 | 
			
		||||
                        UpstreamPathTemplate = "/{url}",
 | 
			
		||||
                        UpstreamHttpMethod = new List<string> { "Get" },
 | 
			
		||||
                        DownstreamHostAndPorts = new List<FileHostAndPort>
 | 
			
		||||
                        {
 | 
			
		||||
                            new FileHostAndPort
 | 
			
		||||
                            {
 | 
			
		||||
                                Host = "localhost",
 | 
			
		||||
                                Port = port,
 | 
			
		||||
                            },
 | 
			
		||||
                        },
 | 
			
		||||
                        DownstreamHttpMethod = "POST",
 | 
			
		||||
                        DownstreamHttpVersion = "2.0",
 | 
			
		||||
                        DangerousAcceptAnyServerCertificateValidator = true
 | 
			
		||||
                    },
 | 
			
		||||
                },
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            const string expected = "here is some content";
 | 
			
		||||
            var httpContent = new StringContent(expected);
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}/", "/", port, HttpProtocols.Http2))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/", httpContent))
 | 
			
		||||
                .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
 | 
			
		||||
                .And(_ => _steps.ThenTheResponseBodyShouldBe(expected))
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_500_when_using_http_one_to_talk_to_server_running_http_two()
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
                {
 | 
			
		||||
                    new FileReRoute
 | 
			
		||||
                    {
 | 
			
		||||
                        DownstreamPathTemplate = "/{url}",
 | 
			
		||||
                        DownstreamScheme = "https",
 | 
			
		||||
                        UpstreamPathTemplate = "/{url}",
 | 
			
		||||
                        UpstreamHttpMethod = new List<string> { "Get" },
 | 
			
		||||
                        DownstreamHostAndPorts = new List<FileHostAndPort>
 | 
			
		||||
                        {
 | 
			
		||||
                            new FileHostAndPort
 | 
			
		||||
                            {
 | 
			
		||||
                                Host = "localhost",
 | 
			
		||||
                                Port = port,
 | 
			
		||||
                            },
 | 
			
		||||
                        },
 | 
			
		||||
                        DownstreamHttpMethod = "POST",
 | 
			
		||||
                        DownstreamHttpVersion = "1.1",
 | 
			
		||||
                        DangerousAcceptAnyServerCertificateValidator = true
 | 
			
		||||
                    },
 | 
			
		||||
                },
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            const string expected = "here is some content";
 | 
			
		||||
            var httpContent = new StringContent(expected);
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}/", "/", port, HttpProtocols.Http2))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/", httpContent))
 | 
			
		||||
                .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.InternalServerError))
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_200_when_using_http_two_to_talk_to_server_running_http_one_point_one()
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
                {
 | 
			
		||||
                    new FileReRoute
 | 
			
		||||
                    {
 | 
			
		||||
                        DownstreamPathTemplate = "/{url}",
 | 
			
		||||
                        DownstreamScheme = "https",
 | 
			
		||||
                        UpstreamPathTemplate = "/{url}",
 | 
			
		||||
                        UpstreamHttpMethod = new List<string> { "Get" },
 | 
			
		||||
                        DownstreamHostAndPorts = new List<FileHostAndPort>
 | 
			
		||||
                        {
 | 
			
		||||
                            new FileHostAndPort
 | 
			
		||||
                            {
 | 
			
		||||
                                Host = "localhost",
 | 
			
		||||
                                Port = port,
 | 
			
		||||
                            },
 | 
			
		||||
                        },
 | 
			
		||||
                        DownstreamHttpMethod = "POST",
 | 
			
		||||
                        DownstreamHttpVersion = "2.0",
 | 
			
		||||
                        DangerousAcceptAnyServerCertificateValidator = true
 | 
			
		||||
                    },
 | 
			
		||||
                },
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            const string expected = "here is some content";
 | 
			
		||||
            var httpContent = new StringContent(expected);
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}/", "/", port, HttpProtocols.Http1))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/", httpContent))
 | 
			
		||||
                .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
 | 
			
		||||
                .And(_ => _steps.ThenTheResponseBodyShouldBe(expected))
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, int port, HttpProtocols protocols)
 | 
			
		||||
        {
 | 
			
		||||
            _serviceHandler.GivenThereIsAServiceRunningOn(baseUrl, basePath, async context =>
 | 
			
		||||
            {
 | 
			
		||||
                context.Response.StatusCode = 200;
 | 
			
		||||
                var reader = new StreamReader(context.Request.Body);
 | 
			
		||||
                var body = await reader.ReadToEndAsync();
 | 
			
		||||
                await context.Response.WriteAsync(body);
 | 
			
		||||
            }, port, protocols);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void Dispose()
 | 
			
		||||
        {
 | 
			
		||||
            _serviceHandler.Dispose();
 | 
			
		||||
            _steps.Dispose();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -26,8 +26,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_load_balance_request_with_least_connection()
 | 
			
		||||
        {
 | 
			
		||||
            int portOne = 50591;
 | 
			
		||||
            int portTwo = 51482;
 | 
			
		||||
            int portOne = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            int portTwo = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var downstreamServiceOneUrl = $"http://localhost:{portOne}";
 | 
			
		||||
            var downstreamServiceTwoUrl = $"http://localhost:{portTwo}";
 | 
			
		||||
@@ -76,8 +76,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_load_balance_request_with_round_robin()
 | 
			
		||||
        {
 | 
			
		||||
            var downstreamPortOne = 51701;
 | 
			
		||||
            var downstreamPortTwo = 53802;
 | 
			
		||||
            var downstreamPortOne = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var downstreamPortTwo = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var downstreamServiceOneUrl = $"http://localhost:{downstreamPortOne}";
 | 
			
		||||
            var downstreamServiceTwoUrl = $"http://localhost:{downstreamPortTwo}";
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										164
									
								
								test/Ocelot.AcceptanceTests/MethodTests.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										164
									
								
								test/Ocelot.AcceptanceTests/MethodTests.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,164 @@
 | 
			
		||||
namespace Ocelot.AcceptanceTests
 | 
			
		||||
{
 | 
			
		||||
    using Microsoft.AspNetCore.Http;
 | 
			
		||||
    using Ocelot.Configuration.File;
 | 
			
		||||
    using System;
 | 
			
		||||
    using System.Collections.Generic;
 | 
			
		||||
    using System.IO;
 | 
			
		||||
    using System.Net;
 | 
			
		||||
    using System.Net.Http;
 | 
			
		||||
    using TestStack.BDDfy;
 | 
			
		||||
    using Xunit;
 | 
			
		||||
 | 
			
		||||
    public class MethodTests : IDisposable
 | 
			
		||||
    {
 | 
			
		||||
        private readonly Steps _steps;
 | 
			
		||||
        private readonly ServiceHandler _serviceHandler;
 | 
			
		||||
 | 
			
		||||
        public MethodTests()
 | 
			
		||||
        {
 | 
			
		||||
            _serviceHandler = new ServiceHandler();
 | 
			
		||||
            _steps = new Steps();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_200_when_get_converted_to_post()
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
                    {
 | 
			
		||||
                        new FileReRoute
 | 
			
		||||
                        {
 | 
			
		||||
                            DownstreamPathTemplate = "/{url}",
 | 
			
		||||
                            DownstreamScheme = "http",
 | 
			
		||||
                            UpstreamPathTemplate = "/{url}",
 | 
			
		||||
                            UpstreamHttpMethod = new List<string> { "Get" },
 | 
			
		||||
                            DownstreamHostAndPorts = new List<FileHostAndPort>
 | 
			
		||||
                            {
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                },
 | 
			
		||||
                            },
 | 
			
		||||
                            DownstreamHttpMethod = "POST",
 | 
			
		||||
                        },
 | 
			
		||||
                    },
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}/", "/", "POST"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
                .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_200_when_get_converted_to_post_with_content()
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
                {
 | 
			
		||||
                    new FileReRoute
 | 
			
		||||
                    {
 | 
			
		||||
                        DownstreamPathTemplate = "/{url}",
 | 
			
		||||
                        DownstreamScheme = "http",
 | 
			
		||||
                        UpstreamPathTemplate = "/{url}",
 | 
			
		||||
                        UpstreamHttpMethod = new List<string> { "Get" },
 | 
			
		||||
                        DownstreamHostAndPorts = new List<FileHostAndPort>
 | 
			
		||||
                        {
 | 
			
		||||
                            new FileHostAndPort
 | 
			
		||||
                            {
 | 
			
		||||
                                Host = "localhost",
 | 
			
		||||
                                Port = port,
 | 
			
		||||
                            },
 | 
			
		||||
                        },
 | 
			
		||||
                        DownstreamHttpMethod = "POST",
 | 
			
		||||
                    },
 | 
			
		||||
                },
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            const string expected = "here is some content";
 | 
			
		||||
            var httpContent = new StringContent(expected);
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}/", "/", "POST"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/", httpContent))
 | 
			
		||||
                .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
 | 
			
		||||
                .And(_ => _steps.ThenTheResponseBodyShouldBe(expected))
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_200_when_get_converted_to_get_with_content()
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
                {
 | 
			
		||||
                    new FileReRoute
 | 
			
		||||
                    {
 | 
			
		||||
                        DownstreamPathTemplate = "/{url}",
 | 
			
		||||
                        DownstreamScheme = "http",
 | 
			
		||||
                        UpstreamPathTemplate = "/{url}",
 | 
			
		||||
                        UpstreamHttpMethod = new List<string> { "Post" },
 | 
			
		||||
                        DownstreamHostAndPorts = new List<FileHostAndPort>
 | 
			
		||||
                        {
 | 
			
		||||
                            new FileHostAndPort
 | 
			
		||||
                            {
 | 
			
		||||
                                Host = "localhost",
 | 
			
		||||
                                Port = port,
 | 
			
		||||
                            },
 | 
			
		||||
                        },
 | 
			
		||||
                        DownstreamHttpMethod = "GET",
 | 
			
		||||
                    },
 | 
			
		||||
                },
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            const string expected = "here is some content";
 | 
			
		||||
            var httpContent = new StringContent(expected);
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}/", "/", "GET"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIPostUrlOnTheApiGateway("/", httpContent))
 | 
			
		||||
                .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
 | 
			
		||||
                .And(_ => _steps.ThenTheResponseBodyShouldBe(expected))
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, string expected)
 | 
			
		||||
        {
 | 
			
		||||
            _serviceHandler.GivenThereIsAServiceRunningOn(baseUrl, basePath, async context =>
 | 
			
		||||
            {
 | 
			
		||||
                if (context.Request.Method == expected)
 | 
			
		||||
                {
 | 
			
		||||
                    context.Response.StatusCode = 200;
 | 
			
		||||
                    var reader = new StreamReader(context.Request.Body);
 | 
			
		||||
                    var body = await reader.ReadToEndAsync();
 | 
			
		||||
                    await context.Response.WriteAsync(body);
 | 
			
		||||
                }
 | 
			
		||||
                else
 | 
			
		||||
                {
 | 
			
		||||
                    context.Response.StatusCode = 500;
 | 
			
		||||
                }
 | 
			
		||||
            });
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void Dispose()
 | 
			
		||||
        {
 | 
			
		||||
            _serviceHandler.Dispose();
 | 
			
		||||
            _steps.Dispose();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -24,7 +24,9 @@
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_not_timeout()
 | 
			
		||||
        {
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -37,7 +39,7 @@
 | 
			
		||||
                            new FileHostAndPort
 | 
			
		||||
                            {
 | 
			
		||||
                                Host = "localhost",
 | 
			
		||||
                                Port = 51569,
 | 
			
		||||
                                Port = port,
 | 
			
		||||
                            }
 | 
			
		||||
                        },
 | 
			
		||||
                        DownstreamScheme = "http",
 | 
			
		||||
@@ -52,7 +54,7 @@
 | 
			
		||||
                }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51569", 200, string.Empty, 10))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200, string.Empty, 10))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunningWithPolly())
 | 
			
		||||
                .And(x => _steps.GivenThePostHasContent("postContent"))
 | 
			
		||||
@@ -63,7 +65,9 @@
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_timeout()
 | 
			
		||||
        {
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -76,7 +80,7 @@
 | 
			
		||||
                            new FileHostAndPort
 | 
			
		||||
                            {
 | 
			
		||||
                                Host = "localhost",
 | 
			
		||||
                                Port = 51579,
 | 
			
		||||
                                Port = port,
 | 
			
		||||
                            }
 | 
			
		||||
                        },
 | 
			
		||||
                        DownstreamScheme = "http",
 | 
			
		||||
@@ -91,7 +95,7 @@
 | 
			
		||||
                }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51579", 201, string.Empty, 1000))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 201, string.Empty, 1000))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunningWithPolly())
 | 
			
		||||
                .And(x => _steps.GivenThePostHasContent("postContent"))
 | 
			
		||||
@@ -102,7 +106,9 @@
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_open_circuit_breaker_then_close()
 | 
			
		||||
        {
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -116,7 +122,7 @@
 | 
			
		||||
                            new FileHostAndPort
 | 
			
		||||
                            {
 | 
			
		||||
                                Host = "localhost",
 | 
			
		||||
                                Port = 51892,
 | 
			
		||||
                                Port = port,
 | 
			
		||||
                            }
 | 
			
		||||
                        },
 | 
			
		||||
                        UpstreamPathTemplate = "/",
 | 
			
		||||
@@ -131,7 +137,7 @@
 | 
			
		||||
                }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAPossiblyBrokenServiceRunningOn("http://localhost:51892", "Hello from Laura"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAPossiblyBrokenServiceRunningOn($"http://localhost:{port}", "Hello from Laura"))
 | 
			
		||||
                .Given(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .Given(x => _steps.GivenOcelotIsRunningWithPolly())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
@@ -152,7 +158,10 @@
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void open_circuit_should_not_effect_different_reRoute()
 | 
			
		||||
        {
 | 
			
		||||
        {
 | 
			
		||||
            var port1 = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var port2 = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -166,7 +175,7 @@
 | 
			
		||||
                            new FileHostAndPort
 | 
			
		||||
                            {
 | 
			
		||||
                                Host = "localhost",
 | 
			
		||||
                                Port = 51870,
 | 
			
		||||
                                Port = port1,
 | 
			
		||||
                            }
 | 
			
		||||
                        },
 | 
			
		||||
                        UpstreamPathTemplate = "/",
 | 
			
		||||
@@ -187,7 +196,7 @@
 | 
			
		||||
                            new FileHostAndPort
 | 
			
		||||
                            {
 | 
			
		||||
                                Host = "localhost",
 | 
			
		||||
                                Port = 51880,
 | 
			
		||||
                                Port = port2,
 | 
			
		||||
                            }
 | 
			
		||||
                        },
 | 
			
		||||
                        UpstreamPathTemplate = "/working",
 | 
			
		||||
@@ -196,8 +205,8 @@
 | 
			
		||||
                }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAPossiblyBrokenServiceRunningOn("http://localhost:51870", "Hello from Laura"))
 | 
			
		||||
                .And(x => x.GivenThereIsAServiceRunningOn("http://localhost:51880/", 200, "Hello from Tom", 0))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAPossiblyBrokenServiceRunningOn($"http://localhost:{port1}", "Hello from Laura"))
 | 
			
		||||
                .And(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port2}/", 200, "Hello from Tom", 0))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunningWithPolly())
 | 
			
		||||
                .And(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										58
									
								
								test/Ocelot.AcceptanceTests/RandomPortFinder.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								test/Ocelot.AcceptanceTests/RandomPortFinder.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,58 @@
 | 
			
		||||
namespace Ocelot.AcceptanceTests
 | 
			
		||||
{
 | 
			
		||||
    using System;
 | 
			
		||||
    using System.Collections.Concurrent;
 | 
			
		||||
    using System.Linq;
 | 
			
		||||
    using System.Net;
 | 
			
		||||
    using System.Net.Sockets;
 | 
			
		||||
 | 
			
		||||
    public static class RandomPortFinder
 | 
			
		||||
    {
 | 
			
		||||
        private const int TrialNumber = 100;
 | 
			
		||||
        private const int BeginPortRange = 20000;
 | 
			
		||||
        private const int EndPortRange = 45000;
 | 
			
		||||
        private static readonly Random Random = new Random();
 | 
			
		||||
        private static readonly ConcurrentBag<int> UsedPorts = new ConcurrentBag<int>();
 | 
			
		||||
 | 
			
		||||
        public static int GetRandomPort()
 | 
			
		||||
        {
 | 
			
		||||
            for (var i = 0; i < TrialNumber; i++)
 | 
			
		||||
            {
 | 
			
		||||
                var randomPort = Random.Next(BeginPortRange, EndPortRange);
 | 
			
		||||
 | 
			
		||||
                if (!PortInUse(randomPort))
 | 
			
		||||
                {
 | 
			
		||||
                    try
 | 
			
		||||
                    {
 | 
			
		||||
                        return UsePort(randomPort);
 | 
			
		||||
                    }
 | 
			
		||||
                    catch (Exception)
 | 
			
		||||
                    {
 | 
			
		||||
                        // ignored
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            throw new Exception("Cannot find available port to bind to.");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private static int UsePort(int randomPort)
 | 
			
		||||
        {
 | 
			
		||||
            UsedPorts.Add(randomPort);
 | 
			
		||||
 | 
			
		||||
            var ipe = new IPEndPoint(IPAddress.Loopback, randomPort);
 | 
			
		||||
 | 
			
		||||
            using (var socket = new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp))
 | 
			
		||||
            {
 | 
			
		||||
                socket.Bind(ipe);
 | 
			
		||||
                socket.Close();
 | 
			
		||||
                return randomPort;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private static bool PortInUse(int randomPort)
 | 
			
		||||
        {
 | 
			
		||||
            return UsedPorts.Any(p => p == randomPort);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -25,6 +25,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_reason_phrase()
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -38,7 +40,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 51339,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamPathTemplate = "/",
 | 
			
		||||
@@ -47,7 +49,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51339", "/", "some reason"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/", "some reason"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
 
 | 
			
		||||
@@ -21,7 +21,9 @@
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_use_default_request_id_and_forward()
 | 
			
		||||
        {
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -34,7 +36,7 @@
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 51873,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            DownstreamScheme = "http",
 | 
			
		||||
@@ -45,7 +47,7 @@
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51873"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
@@ -55,7 +57,9 @@
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_use_request_id_and_forward()
 | 
			
		||||
        {
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -68,7 +72,7 @@
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 51873,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            DownstreamScheme = "http",
 | 
			
		||||
@@ -80,7 +84,7 @@
 | 
			
		||||
 | 
			
		||||
            var requestId = Guid.NewGuid().ToString();
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51873"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/", requestId))
 | 
			
		||||
@@ -90,7 +94,9 @@
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_use_global_request_id_and_forward()
 | 
			
		||||
        {
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -103,7 +109,7 @@
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 51873,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            DownstreamScheme = "http",
 | 
			
		||||
@@ -119,7 +125,7 @@
 | 
			
		||||
 | 
			
		||||
            var requestId = Guid.NewGuid().ToString();
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51873"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/", requestId))
 | 
			
		||||
@@ -129,7 +135,9 @@
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_use_global_request_id_create_and_forward()
 | 
			
		||||
        {
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -142,7 +150,7 @@
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 51873,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            DownstreamScheme = "http",
 | 
			
		||||
@@ -156,7 +164,7 @@
 | 
			
		||||
                }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51873"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
 
 | 
			
		||||
@@ -20,7 +20,9 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_304_when_service_returns_304()
 | 
			
		||||
        {
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -34,7 +36,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 51092,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamPathTemplate = "/{everything}",
 | 
			
		||||
@@ -43,7 +45,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51092", "/inline.132.bundle.js", 304))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/inline.132.bundle.js", 304))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/inline.132.bundle.js"))
 | 
			
		||||
 
 | 
			
		||||
@@ -53,6 +53,7 @@
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_internal_server_error_if_downstream_service_returns_internal_server_error()
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
@@ -68,7 +69,7 @@
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 53876,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            DownstreamScheme = "http",
 | 
			
		||||
@@ -76,7 +77,7 @@
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:53876"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
@@ -87,6 +88,8 @@
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_log_warning_if_downstream_service_returns_internal_server_error()
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -101,7 +104,7 @@
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 53876,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                },
 | 
			
		||||
                            },
 | 
			
		||||
                            DownstreamScheme = "http",
 | 
			
		||||
@@ -109,7 +112,7 @@
 | 
			
		||||
                    },
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:53876"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunningWithLogger())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
 
 | 
			
		||||
@@ -24,7 +24,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_not_match_forward_slash_in_pattern_before_next_forward_slash()
 | 
			
		||||
        {
 | 
			
		||||
            var port = 31879;
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -69,6 +69,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_200_with_forward_slash_and_placeholder_only()
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -84,14 +86,14 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 57873,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:57873/", "/", 200, "Hello from Laura"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}/", "/", 200, "Hello from Laura"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
@@ -103,6 +105,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_200_favouring_forward_slash_with_path_route()
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -116,7 +120,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 51880,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamPathTemplate = "/{url}",
 | 
			
		||||
@@ -140,7 +144,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51880/", "/test", 200, "Hello from Laura"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}/", "/test", 200, "Hello from Laura"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/test"))
 | 
			
		||||
@@ -152,6 +156,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_200_favouring_forward_slash()
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -180,7 +185,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 50810,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamPathTemplate = "/",
 | 
			
		||||
@@ -189,7 +194,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:50810/", "/", 200, "Hello from Laura"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}/", "/", 200, "Hello from Laura"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
@@ -201,6 +206,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_200_favouring_forward_slash_route_because_it_is_first()
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -214,7 +221,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 51880,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamPathTemplate = "/",
 | 
			
		||||
@@ -238,7 +245,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51880/", "/", 200, "Hello from Laura"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}/", "/", 200, "Hello from Laura"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
@@ -250,6 +257,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_200_with_nothing_and_placeholder_only()
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -263,7 +272,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 51005,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamPathTemplate = "/{url}",
 | 
			
		||||
@@ -272,7 +281,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51005", "/", 200, "Hello from Laura"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/", 200, "Hello from Laura"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway(""))
 | 
			
		||||
@@ -284,6 +293,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_200_with_simple_url()
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -297,7 +308,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 58589,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamPathTemplate = "/",
 | 
			
		||||
@@ -306,7 +317,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:58589", "/", 200, "Hello from Laura"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/", 200, "Hello from Laura"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
@@ -318,6 +329,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void bug()
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -331,7 +344,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                            new FileHostAndPort
 | 
			
		||||
                            {
 | 
			
		||||
                                Host = "localhost",
 | 
			
		||||
                                Port = 51874,
 | 
			
		||||
                                Port = port,
 | 
			
		||||
                            }
 | 
			
		||||
                        },
 | 
			
		||||
                        UpstreamPathTemplate = "/vacancy/",
 | 
			
		||||
@@ -347,7 +360,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                            new FileHostAndPort
 | 
			
		||||
                            {
 | 
			
		||||
                                Host = "localhost",
 | 
			
		||||
                                Port = 51874,
 | 
			
		||||
                                Port = port,
 | 
			
		||||
                            }
 | 
			
		||||
                        },
 | 
			
		||||
                        UpstreamPathTemplate = "/vacancy/{vacancyId}",
 | 
			
		||||
@@ -357,7 +370,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51874", "/api/v1/vacancy/1", 200, "Hello from Laura"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/api/v1/vacancy/1", 200, "Hello from Laura"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/vacancy/1"))
 | 
			
		||||
@@ -369,6 +382,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_200_when_path_missing_forward_slash_as_first_char()
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -382,7 +397,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 51206,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamPathTemplate = "/",
 | 
			
		||||
@@ -391,7 +406,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51206", "/api/products", 200, "Hello from Laura"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/api/products", 200, "Hello from Laura"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
@@ -403,6 +418,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_200_when_host_has_trailing_slash()
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -416,7 +433,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 51990,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamPathTemplate = "/",
 | 
			
		||||
@@ -425,7 +442,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51990", "/api/products", 200, "Hello from Laura"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/api/products", 200, "Hello from Laura"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
@@ -437,6 +454,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_ok_when_upstream_url_ends_with_forward_slash_but_template_does_not()
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -450,7 +469,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 58804,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamPathTemplate = "/products/",
 | 
			
		||||
@@ -459,7 +478,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:58804", "/products", 200, "Hello from Laura"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/products", 200, "Hello from Laura"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/products"))
 | 
			
		||||
@@ -471,6 +490,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_not_found_when_upstream_url_ends_with_forward_slash_but_template_does_not()
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -484,7 +505,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 54015,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamPathTemplate = "/products",
 | 
			
		||||
@@ -493,7 +514,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:54015", "/products", 200, "Hello from Laura"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/products", 200, "Hello from Laura"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/products/"))
 | 
			
		||||
@@ -504,6 +525,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_not_found()
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -517,7 +540,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                            new FileHostAndPort
 | 
			
		||||
                            {
 | 
			
		||||
                                Host = "localhost",
 | 
			
		||||
                                Port = 54072,
 | 
			
		||||
                                Port = port,
 | 
			
		||||
                            }
 | 
			
		||||
                        },
 | 
			
		||||
                        UpstreamPathTemplate = "/products/{productId}",
 | 
			
		||||
@@ -526,7 +549,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:54072", "/products", 200, "Hello from Laura"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/products", 200, "Hello from Laura"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/products/"))
 | 
			
		||||
@@ -537,6 +560,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_200_with_complex_url()
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -550,7 +575,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 55961,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamPathTemplate = "/products/{productId}",
 | 
			
		||||
@@ -559,7 +584,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:55961", "/api/products/1", 200, "Some Product"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/api/products/1", 200, "Some Product"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/products/1"))
 | 
			
		||||
@@ -571,6 +596,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_200_with_complex_url_that_starts_with_placeholder()
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -584,7 +611,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 51116,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamPathTemplate = "/{variantId}/products/{productId}",
 | 
			
		||||
@@ -593,7 +620,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51116", "/api/23/products/1", 200, "Some Product"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/api/23/products/1", 200, "Some Product"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("23/products/1"))
 | 
			
		||||
@@ -605,6 +632,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_not_add_trailing_slash_to_downstream_url()
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -618,7 +647,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 51809,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamPathTemplate = "/products/{productId}",
 | 
			
		||||
@@ -627,7 +656,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => GivenThereIsAServiceRunningOn("http://localhost:51809", "/api/products/1", 200, "Some Product"))
 | 
			
		||||
            this.Given(x => GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/api/products/1", 200, "Some Product"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/products/1"))
 | 
			
		||||
@@ -638,6 +667,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_201_with_simple_url()
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -650,7 +681,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 56615,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            DownstreamScheme = "http",
 | 
			
		||||
@@ -660,7 +691,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:56615", "/", 201, string.Empty))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/", 201, string.Empty))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .And(x => _steps.GivenThePostHasContent("postContent"))
 | 
			
		||||
@@ -672,6 +703,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_201_with_complex_query_string()
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -686,7 +719,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 57771,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamHttpMethod = new List<string> { "Get" },
 | 
			
		||||
@@ -694,7 +727,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:57771", "/newThing", 200, "Hello from Laura"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/newThing", 200, "Hello from Laura"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/newThing?DeviceType=IphoneApp&Browser=moonpigIphone&BrowserString=-&CountryCode=123&DeviceName=iPhone 5 (GSM+CDMA)&OperatingSystem=iPhone OS 7.1.2&BrowserVersion=3708AdHoc&ipAddress=-"))
 | 
			
		||||
@@ -706,6 +739,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_200_with_placeholder_for_final_url_path()
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -719,7 +754,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 55609,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamPathTemplate = "/myApp1Name/api/{urlPath}",
 | 
			
		||||
@@ -728,7 +763,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:55609", "/api/products/1", 200, "Some Product"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/api/products/1", 200, "Some Product"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/myApp1Name/api/products/1"))
 | 
			
		||||
@@ -740,6 +775,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_201_with_simple_url_and_multiple_upstream_http_method()
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -752,7 +789,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 59911,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            DownstreamScheme = "http",
 | 
			
		||||
@@ -762,7 +799,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:59911", "", 201, string.Empty))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "", 201, string.Empty))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .And(x => _steps.GivenThePostHasContent("postContent"))
 | 
			
		||||
@@ -774,6 +811,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_200_with_simple_url_and_any_upstream_http_method()
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -786,7 +825,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 59187,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            DownstreamScheme = "http",
 | 
			
		||||
@@ -796,7 +835,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:59187", "/", 200, "Hello from Laura"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/", 200, "Hello from Laura"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
@@ -808,6 +847,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_404_when_calling_upstream_route_with_no_matching_downstream_re_route_github_issue_134()
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -821,7 +862,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                            new FileHostAndPort
 | 
			
		||||
                            {
 | 
			
		||||
                                Host = "localhost",
 | 
			
		||||
                                Port = 54079,
 | 
			
		||||
                                Port = port,
 | 
			
		||||
                            }
 | 
			
		||||
                        },
 | 
			
		||||
                        UpstreamPathTemplate = "/vacancy/",
 | 
			
		||||
@@ -837,7 +878,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                            new FileHostAndPort
 | 
			
		||||
                            {
 | 
			
		||||
                                Host = "localhost",
 | 
			
		||||
                                Port = 54079,
 | 
			
		||||
                                Port = port,
 | 
			
		||||
                            }
 | 
			
		||||
                        },
 | 
			
		||||
                        UpstreamPathTemplate = "/vacancy/{vacancyId}",
 | 
			
		||||
@@ -847,7 +888,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:54079", "/api/v1/vacancy/1", 200, "Hello from Laura"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/api/v1/vacancy/1", 200, "Hello from Laura"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("api/vacancy/1"))
 | 
			
		||||
@@ -858,6 +899,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_not_set_trailing_slash_on_url_template()
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -871,7 +914,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 51899,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamPathTemplate = "/platform/{url}",
 | 
			
		||||
@@ -880,7 +923,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51899", "/api/swagger/lib/backbone-min.js", 200, "Hello from Laura"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/api/swagger/lib/backbone-min.js", 200, "Hello from Laura"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/platform/swagger/lib/backbone-min.js"))
 | 
			
		||||
@@ -893,6 +936,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_use_priority()
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -924,14 +969,14 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 52879,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:52879/", "/goods/delete", 200, "Hello from Laura"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}/", "/goods/delete", 200, "Hello from Laura"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/goods/delete"))
 | 
			
		||||
@@ -943,7 +988,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_match_multiple_paths_with_catch_all()
 | 
			
		||||
        {
 | 
			
		||||
            var port = 61999;
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -978,6 +1024,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_fix_issue_271()
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -993,7 +1041,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 54879,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                        },
 | 
			
		||||
@@ -1015,7 +1063,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:54879/", "/api/v1/modules/Test", 200, "Hello from Laura"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}/", "/api/v1/modules/Test", 200, "Hello from Laura"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/api/v1/modules/Test"))
 | 
			
		||||
 
 | 
			
		||||
@@ -24,6 +24,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        {
 | 
			
		||||
            var subscriptionId = Guid.NewGuid().ToString();
 | 
			
		||||
            var unitId = Guid.NewGuid().ToString();
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
@@ -38,7 +39,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 61879,
 | 
			
		||||
                                    Port = port,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamPathTemplate = "/api/units/{subscriptionId}/{unitId}/updates",
 | 
			
		||||
@@ -47,7 +48,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                    }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:61879", $"/api/subscriptions/{subscriptionId}/updates", $"?unitId={unitId}", 200, "Hello from Laura"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", $"/api/subscriptions/{subscriptionId}/updates", $"?unitId={unitId}", 200, "Hello from Laura"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway($"/api/units/{subscriptionId}/{unitId}/updates"))
 | 
			
		||||
@@ -61,7 +62,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        {
 | 
			
		||||
            var subscriptionId = Guid.NewGuid().ToString();
 | 
			
		||||
            var unitId = Guid.NewGuid().ToString();
 | 
			
		||||
            var port = 57359;
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
@@ -99,6 +100,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        {
 | 
			
		||||
            var subscriptionId = Guid.NewGuid().ToString();
 | 
			
		||||
            var unitId = Guid.NewGuid().ToString();
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
@@ -113,7 +115,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                            new FileHostAndPort
 | 
			
		||||
                            {
 | 
			
		||||
                                Host = "localhost",
 | 
			
		||||
                                Port = 64879,
 | 
			
		||||
                                Port = port,
 | 
			
		||||
                            }
 | 
			
		||||
                        },
 | 
			
		||||
                        UpstreamPathTemplate = "/api/subscriptions/{subscriptionId}/updates?unitId={unitId}",
 | 
			
		||||
@@ -122,7 +124,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:64879", $"/api/units/{subscriptionId}/{unitId}/updates", "", 200, "Hello from Laura"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", $"/api/units/{subscriptionId}/{unitId}/updates", "", 200, "Hello from Laura"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway($"/api/subscriptions/{subscriptionId}/updates?unitId={unitId}"))
 | 
			
		||||
@@ -136,6 +138,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        {
 | 
			
		||||
            var subscriptionId = Guid.NewGuid().ToString();
 | 
			
		||||
            var unitId = Guid.NewGuid().ToString();
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
@@ -150,7 +153,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                            new FileHostAndPort
 | 
			
		||||
                            {
 | 
			
		||||
                                Host = "localhost",
 | 
			
		||||
                                Port = 64879,
 | 
			
		||||
                                Port = port,
 | 
			
		||||
                            }
 | 
			
		||||
                        },
 | 
			
		||||
                        UpstreamPathTemplate = "/api/subscriptions/{subscriptionId}/updates?unitId={unitId}",
 | 
			
		||||
@@ -159,7 +162,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:64879", $"/api/units/{subscriptionId}/{unitId}/updates", "", 200, "Hello from Laura"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", $"/api/units/{subscriptionId}/{unitId}/updates", "", 200, "Hello from Laura"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway($"/api/subscriptions/{subscriptionId}/updates"))
 | 
			
		||||
@@ -172,6 +175,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        {
 | 
			
		||||
            var subscriptionId = Guid.NewGuid().ToString();
 | 
			
		||||
            var unitId = Guid.NewGuid().ToString();
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
@@ -186,7 +190,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                            new FileHostAndPort
 | 
			
		||||
                            {
 | 
			
		||||
                                Host = "localhost",
 | 
			
		||||
                                Port = 64879,
 | 
			
		||||
                                Port = port,
 | 
			
		||||
                            }
 | 
			
		||||
                        },
 | 
			
		||||
                        UpstreamPathTemplate = "/api/subscriptions/{subscriptionId}/updates?unitId={unitId}",
 | 
			
		||||
@@ -195,7 +199,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:64879", $"/api/units/{subscriptionId}/{unitId}/updates", "", 200, "Hello from Laura"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", $"/api/units/{subscriptionId}/{unitId}/updates", "", 200, "Hello from Laura"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway($"/api/subscriptions/{subscriptionId}/updates?test=1"))
 | 
			
		||||
@@ -208,6 +212,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        {
 | 
			
		||||
            var subscriptionId = Guid.NewGuid().ToString();
 | 
			
		||||
            var unitId = Guid.NewGuid().ToString();
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
@@ -222,7 +227,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                            new FileHostAndPort
 | 
			
		||||
                            {
 | 
			
		||||
                                Host = "localhost",
 | 
			
		||||
                                Port = 64879,
 | 
			
		||||
                                Port = port,
 | 
			
		||||
                            }
 | 
			
		||||
                        },
 | 
			
		||||
                        UpstreamPathTemplate = "/api/subscriptions/{subscriptionId}/updates?unitId={unitId}",
 | 
			
		||||
@@ -231,7 +236,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:64879", $"/api/units/{subscriptionId}/{unitId}/updates", "?productId=1", 200, "Hello from Laura"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", $"/api/units/{subscriptionId}/{unitId}/updates", "?productId=1", 200, "Hello from Laura"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway($"/api/subscriptions/{subscriptionId}/updates?unitId={unitId}&productId=1"))
 | 
			
		||||
 
 | 
			
		||||
@@ -33,10 +33,12 @@
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_use_consul_service_discovery_and_load_balance_request()
 | 
			
		||||
        {
 | 
			
		||||
            var consulPort = 8502;
 | 
			
		||||
            var consulPort = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var servicePort1 = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var servicePort2 = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var serviceName = "product";
 | 
			
		||||
            var downstreamServiceOneUrl = "http://localhost:50881";
 | 
			
		||||
            var downstreamServiceTwoUrl = "http://localhost:50882";
 | 
			
		||||
            var downstreamServiceOneUrl = $"http://localhost:{servicePort1}";
 | 
			
		||||
            var downstreamServiceTwoUrl = $"http://localhost:{servicePort2}";
 | 
			
		||||
            var fakeConsulServiceDiscoveryUrl = $"http://localhost:{consulPort}";
 | 
			
		||||
            var serviceEntryOne = new ServiceEntry()
 | 
			
		||||
            {
 | 
			
		||||
@@ -44,7 +46,7 @@
 | 
			
		||||
                {
 | 
			
		||||
                    Service = serviceName,
 | 
			
		||||
                    Address = "localhost",
 | 
			
		||||
                    Port = 50881,
 | 
			
		||||
                    Port = servicePort1,
 | 
			
		||||
                    ID = Guid.NewGuid().ToString(),
 | 
			
		||||
                    Tags = new string[0]
 | 
			
		||||
                },
 | 
			
		||||
@@ -55,7 +57,7 @@
 | 
			
		||||
                {
 | 
			
		||||
                    Service = serviceName,
 | 
			
		||||
                    Address = "localhost",
 | 
			
		||||
                    Port = 50882,
 | 
			
		||||
                    Port = servicePort2,
 | 
			
		||||
                    ID = Guid.NewGuid().ToString(),
 | 
			
		||||
                    Tags = new string[0]
 | 
			
		||||
                },
 | 
			
		||||
@@ -100,9 +102,10 @@
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_handle_request_to_consul_for_downstream_service_and_make_request()
 | 
			
		||||
        {
 | 
			
		||||
            const int consulPort = 8505;
 | 
			
		||||
            int consulPort = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            int servicePort = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            const string serviceName = "web";
 | 
			
		||||
            const string downstreamServiceOneUrl = "http://localhost:8080";
 | 
			
		||||
            string downstreamServiceOneUrl = $"http://localhost:{servicePort}";
 | 
			
		||||
            var fakeConsulServiceDiscoveryUrl = $"http://localhost:{consulPort}";
 | 
			
		||||
            var serviceEntryOne = new ServiceEntry()
 | 
			
		||||
            {
 | 
			
		||||
@@ -110,7 +113,7 @@
 | 
			
		||||
                {
 | 
			
		||||
                    Service = serviceName,
 | 
			
		||||
                    Address = "localhost",
 | 
			
		||||
                    Port = 8080,
 | 
			
		||||
                    Port = servicePort,
 | 
			
		||||
                    ID = "web_90_0_2_224_8080",
 | 
			
		||||
                    Tags = new[] { "version-v1" }
 | 
			
		||||
                },
 | 
			
		||||
@@ -154,9 +157,9 @@
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_handle_request_to_consul_for_downstream_service_and_make_request_no_re_routes()
 | 
			
		||||
        {
 | 
			
		||||
            const int consulPort = 8513;
 | 
			
		||||
            int consulPort = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            const string serviceName = "web";
 | 
			
		||||
            const int downstreamServicePort = 8087;
 | 
			
		||||
            int downstreamServicePort = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var downstreamServiceOneUrl = $"http://localhost:{downstreamServicePort}";
 | 
			
		||||
            var fakeConsulServiceDiscoveryUrl = $"http://localhost:{consulPort}";
 | 
			
		||||
            var serviceEntryOne = new ServiceEntry()
 | 
			
		||||
@@ -204,10 +207,10 @@
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_use_consul_service_discovery_and_load_balance_request_no_re_routes()
 | 
			
		||||
        {
 | 
			
		||||
            var consulPort = 8510;
 | 
			
		||||
            var consulPort = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var serviceName = "product";
 | 
			
		||||
            var serviceOnePort = 50888;
 | 
			
		||||
            var serviceTwoPort = 50889;
 | 
			
		||||
            var serviceOnePort = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var serviceTwoPort = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var downstreamServiceOneUrl = $"http://localhost:{serviceOnePort}";
 | 
			
		||||
            var downstreamServiceTwoUrl = $"http://localhost:{serviceTwoPort}";
 | 
			
		||||
            var fakeConsulServiceDiscoveryUrl = $"http://localhost:{consulPort}";
 | 
			
		||||
@@ -264,9 +267,10 @@
 | 
			
		||||
        public void should_use_token_to_make_request_to_consul()
 | 
			
		||||
        {
 | 
			
		||||
            var token = "abctoken";
 | 
			
		||||
            var consulPort = 8515;
 | 
			
		||||
            var consulPort = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var serviceName = "web";
 | 
			
		||||
            var downstreamServiceOneUrl = "http://localhost:8081";
 | 
			
		||||
            var servicePort = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var downstreamServiceOneUrl = $"http://localhost:{servicePort}";
 | 
			
		||||
            var fakeConsulServiceDiscoveryUrl = $"http://localhost:{consulPort}";
 | 
			
		||||
            var serviceEntryOne = new ServiceEntry()
 | 
			
		||||
            {
 | 
			
		||||
@@ -274,7 +278,7 @@
 | 
			
		||||
                {
 | 
			
		||||
                    Service = serviceName,
 | 
			
		||||
                    Address = "localhost",
 | 
			
		||||
                    Port = 8081,
 | 
			
		||||
                    Port = servicePort,
 | 
			
		||||
                    ID = "web_90_0_2_224_8080",
 | 
			
		||||
                    Tags = new[] { "version-v1" }
 | 
			
		||||
                },
 | 
			
		||||
@@ -320,10 +324,12 @@
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_send_request_to_service_after_it_becomes_available_in_consul()
 | 
			
		||||
        {
 | 
			
		||||
            var consulPort = 8501;
 | 
			
		||||
            var consulPort = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var serviceName = "product";
 | 
			
		||||
            var downstreamServiceOneUrl = "http://localhost:50879";
 | 
			
		||||
            var downstreamServiceTwoUrl = "http://localhost:50880";
 | 
			
		||||
            var servicePort1 = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var servicePort2 = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var downstreamServiceOneUrl = $"http://localhost:{servicePort1}";
 | 
			
		||||
            var downstreamServiceTwoUrl = $"http://localhost:{servicePort2}";
 | 
			
		||||
            var fakeConsulServiceDiscoveryUrl = $"http://localhost:{consulPort}";
 | 
			
		||||
            var serviceEntryOne = new ServiceEntry()
 | 
			
		||||
            {
 | 
			
		||||
@@ -331,7 +337,7 @@
 | 
			
		||||
                {
 | 
			
		||||
                    Service = serviceName,
 | 
			
		||||
                    Address = "localhost",
 | 
			
		||||
                    Port = 50879,
 | 
			
		||||
                    Port = servicePort1,
 | 
			
		||||
                    ID = Guid.NewGuid().ToString(),
 | 
			
		||||
                    Tags = new string[0]
 | 
			
		||||
                },
 | 
			
		||||
@@ -342,7 +348,7 @@
 | 
			
		||||
                {
 | 
			
		||||
                    Service = serviceName,
 | 
			
		||||
                    Address = "localhost",
 | 
			
		||||
                    Port = 50880,
 | 
			
		||||
                    Port = servicePort2,
 | 
			
		||||
                    ID = Guid.NewGuid().ToString(),
 | 
			
		||||
                    Tags = new string[0]
 | 
			
		||||
                },
 | 
			
		||||
@@ -396,9 +402,9 @@
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_handle_request_to_poll_consul_for_downstream_service_and_make_request()
 | 
			
		||||
        {
 | 
			
		||||
            const int consulPort = 8518;
 | 
			
		||||
            int consulPort = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            const string serviceName = "web";
 | 
			
		||||
            const int downstreamServicePort = 8082;
 | 
			
		||||
            int downstreamServicePort = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var downstreamServiceOneUrl = $"http://localhost:{downstreamServicePort}";
 | 
			
		||||
            var fakeConsulServiceDiscoveryUrl = $"http://localhost:{consulPort}";
 | 
			
		||||
            var serviceEntryOne = new ServiceEntry()
 | 
			
		||||
 
 | 
			
		||||
@@ -23,6 +23,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_fix_issue_555()
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -41,13 +43,13 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                    ServiceDiscoveryProvider = new FileServiceDiscoveryProvider()
 | 
			
		||||
                    {
 | 
			
		||||
                        Host = "localhost",
 | 
			
		||||
                        Port = 19081,
 | 
			
		||||
                        Port = port,
 | 
			
		||||
                        Type = "ServiceFabric"
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:19081", "/OcelotServiceApplication/OcelotApplicationService/a", 200, "Hello from Laura", "b=c"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/OcelotServiceApplication/OcelotApplicationService/a", 200, "Hello from Laura", "b=c"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/a?b=c"))
 | 
			
		||||
@@ -59,6 +61,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_support_service_fabric_naming_and_dns_service_stateless_and_guest()
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -77,13 +81,13 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                    ServiceDiscoveryProvider = new FileServiceDiscoveryProvider()
 | 
			
		||||
                    {
 | 
			
		||||
                        Host = "localhost",
 | 
			
		||||
                        Port = 19081,
 | 
			
		||||
                        Port = port,
 | 
			
		||||
                        Type = "ServiceFabric"
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:19081", "/OcelotServiceApplication/OcelotApplicationService/api/values", 200, "Hello from Laura", "test=best"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/OcelotServiceApplication/OcelotApplicationService/api/values", 200, "Hello from Laura", "test=best"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/EquipmentInterfaces?test=best"))
 | 
			
		||||
@@ -95,6 +99,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_support_service_fabric_naming_and_dns_service_statefull_and_actors()
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -113,13 +119,13 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                    ServiceDiscoveryProvider = new FileServiceDiscoveryProvider()
 | 
			
		||||
                    {
 | 
			
		||||
                        Host = "localhost",
 | 
			
		||||
                        Port = 19081,
 | 
			
		||||
                        Port = port,
 | 
			
		||||
                        Type = "ServiceFabric"
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:19081", "/OcelotServiceApplication/OcelotApplicationService/api/values", 200, "Hello from Laura", "PartitionKind=test&PartitionKey=1"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/OcelotServiceApplication/OcelotApplicationService/api/values", 200, "Hello from Laura", "PartitionKind=test&PartitionKey=1"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/EquipmentInterfaces?PartitionKind=test&PartitionKey=1"))
 | 
			
		||||
@@ -131,6 +137,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_support_placeholder_in_service_fabric_service_name()
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -149,13 +157,13 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
                    ServiceDiscoveryProvider = new FileServiceDiscoveryProvider()
 | 
			
		||||
                    {
 | 
			
		||||
                        Host = "localhost",
 | 
			
		||||
                        Port = 19081,
 | 
			
		||||
                        Port = port,
 | 
			
		||||
                        Type = "ServiceFabric"
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:19081", "/Service_1.0/Api/values", 200, "Hello from Laura", "test=best"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/Service_1.0/Api/values", 200, "Hello from Laura", "test=best"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/api/1.0/values?test=best"))
 | 
			
		||||
 
 | 
			
		||||
@@ -6,9 +6,11 @@
 | 
			
		||||
    using Microsoft.Extensions.Configuration;
 | 
			
		||||
    using Microsoft.Extensions.Logging;
 | 
			
		||||
    using System;
 | 
			
		||||
    using System.ComponentModel;
 | 
			
		||||
    using System.IO;
 | 
			
		||||
    using System.Net;
 | 
			
		||||
    using System.Threading.Tasks;
 | 
			
		||||
    using Microsoft.AspNetCore.Server.Kestrel.Core;
 | 
			
		||||
 | 
			
		||||
    public class ServiceHandler : IDisposable
 | 
			
		||||
    {
 | 
			
		||||
@@ -47,6 +49,31 @@
 | 
			
		||||
            _builder.Start();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, RequestDelegate del, int port, HttpProtocols protocols)
 | 
			
		||||
        {
 | 
			
		||||
            _builder = new WebHostBuilder()
 | 
			
		||||
                .UseUrls(baseUrl)
 | 
			
		||||
                .UseKestrel()
 | 
			
		||||
                .ConfigureKestrel(serverOptions =>
 | 
			
		||||
                {
 | 
			
		||||
                    serverOptions.Listen(IPAddress.Loopback, port, listenOptions =>
 | 
			
		||||
                        {
 | 
			
		||||
                            listenOptions.UseHttps("idsrv3test.pfx", "idsrv3test");
 | 
			
		||||
                            listenOptions.Protocols = protocols;
 | 
			
		||||
                        });
 | 
			
		||||
                })
 | 
			
		||||
                .UseContentRoot(Directory.GetCurrentDirectory())
 | 
			
		||||
                .UseIISIntegration()
 | 
			
		||||
                .Configure(app =>
 | 
			
		||||
                {
 | 
			
		||||
                    app.UsePathBase(basePath);
 | 
			
		||||
                    app.Run(del);
 | 
			
		||||
                })
 | 
			
		||||
                .Build();
 | 
			
		||||
 | 
			
		||||
            _builder.Start();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, string fileName, string password, int port, RequestDelegate del)
 | 
			
		||||
        {
 | 
			
		||||
            _builder = new WebHostBuilder()
 | 
			
		||||
 
 | 
			
		||||
@@ -23,7 +23,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_dangerous_accept_any_server_certificate_validator()
 | 
			
		||||
        {
 | 
			
		||||
            int port = 51129;
 | 
			
		||||
            int port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
@@ -60,7 +60,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_not_dangerous_accept_any_server_certificate_validator()
 | 
			
		||||
        {
 | 
			
		||||
            int port = 52129;
 | 
			
		||||
            int port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
 
 | 
			
		||||
@@ -27,6 +27,8 @@
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_not_try_and_write_to_disk_on_startup_when_not_using_admin_api()
 | 
			
		||||
        {
 | 
			
		||||
            var port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -40,7 +42,7 @@
 | 
			
		||||
                            new FileHostAndPort
 | 
			
		||||
                            {
 | 
			
		||||
                                Host = "localhost",
 | 
			
		||||
                                Port = 52179,
 | 
			
		||||
                                Port = port,
 | 
			
		||||
                            }
 | 
			
		||||
                        },
 | 
			
		||||
                        UpstreamPathTemplate = "/",
 | 
			
		||||
@@ -51,7 +53,7 @@
 | 
			
		||||
 | 
			
		||||
            var fakeRepo = new FakeFileConfigurationRepository();
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:52179", "/", 200, "Hello from Laura"))
 | 
			
		||||
            this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/", 200, "Hello from Laura"))
 | 
			
		||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
			
		||||
                .And(x => _steps.GivenOcelotIsRunningWithBlowingUpDiskRepo(fakeRepo))
 | 
			
		||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,6 @@
 | 
			
		||||
namespace Ocelot.AcceptanceTests
 | 
			
		||||
using Ocelot.Configuration.ChangeTracking;
 | 
			
		||||
 | 
			
		||||
namespace Ocelot.AcceptanceTests
 | 
			
		||||
{
 | 
			
		||||
    using Caching;
 | 
			
		||||
    using Configuration.Repository;
 | 
			
		||||
@@ -54,6 +56,7 @@
 | 
			
		||||
        private IWebHostBuilder _webHostBuilder;
 | 
			
		||||
        private WebHostBuilder _ocelotBuilder;
 | 
			
		||||
        private IWebHost _ocelotHost;
 | 
			
		||||
        private IOcelotConfigurationChangeTokenSource _changeToken;
 | 
			
		||||
 | 
			
		||||
        public Steps()
 | 
			
		||||
        {
 | 
			
		||||
@@ -216,6 +219,11 @@
 | 
			
		||||
            _ocelotClient = _ocelotServer.CreateClient();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void GivenIHaveAChangeToken()
 | 
			
		||||
        {
 | 
			
		||||
            _changeToken = _ocelotServer.Host.Services.GetRequiredService<IOcelotConfigurationChangeTokenSource>();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// This is annoying cos it should be in the constructor but we need to set up the file before calling startup so its a step.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
@@ -384,6 +392,7 @@
 | 
			
		||||
            _ocelotServer = new TestServer(_webHostBuilder);
 | 
			
		||||
 | 
			
		||||
            _ocelotClient = _ocelotServer.CreateClient();
 | 
			
		||||
            Thread.Sleep(1000);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void WhenIGetUrlOnTheApiGatewayWaitingForTheResponseToBeOk(string url)
 | 
			
		||||
@@ -901,6 +910,18 @@
 | 
			
		||||
            _response = _ocelotClient.GetAsync(url).Result;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void WhenIGetUrlOnTheApiGateway(string url, HttpContent content)
 | 
			
		||||
        {
 | 
			
		||||
            var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, url) {Content = content};
 | 
			
		||||
            _response = _ocelotClient.SendAsync(httpRequestMessage).Result;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void WhenIPostUrlOnTheApiGateway(string url, HttpContent content)
 | 
			
		||||
        {
 | 
			
		||||
            var httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, url) { Content = content };
 | 
			
		||||
            _response = _ocelotClient.SendAsync(httpRequestMessage).Result;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void WhenIGetUrlOnTheApiGateway(string url, string cookie, string value)
 | 
			
		||||
        {
 | 
			
		||||
            var request = _ocelotServer.CreateRequest(url);
 | 
			
		||||
@@ -1123,6 +1144,11 @@
 | 
			
		||||
            _ocelotClient = _ocelotServer.CreateClient();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void TheChangeTokenShouldBeActive(bool itShouldBeActive)
 | 
			
		||||
        {
 | 
			
		||||
            _changeToken.ChangeToken.HasChanged.ShouldBe(itShouldBeActive);
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        public void GivenOcelotIsRunningWithLogger()
 | 
			
		||||
        {
 | 
			
		||||
            _webHostBuilder = new WebHostBuilder();
 | 
			
		||||
 
 | 
			
		||||
@@ -25,8 +25,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_use_same_downstream_host()
 | 
			
		||||
        {
 | 
			
		||||
            var downstreamPortOne = 51375;
 | 
			
		||||
            var downstreamPortTwo = 51892;
 | 
			
		||||
            var downstreamPortOne = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var downstreamPortTwo = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var downstreamServiceOneUrl = $"http://localhost:{downstreamPortOne}";
 | 
			
		||||
            var downstreamServiceTwoUrl = $"http://localhost:{downstreamPortTwo}";
 | 
			
		||||
 | 
			
		||||
@@ -76,8 +76,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_use_different_downstream_host_for_different_re_route()
 | 
			
		||||
        {
 | 
			
		||||
            var downstreamPortOne = 52881;
 | 
			
		||||
            var downstreamPortTwo = 52892;
 | 
			
		||||
            var downstreamPortOne = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var downstreamPortTwo = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var downstreamServiceOneUrl = $"http://localhost:{downstreamPortOne}";
 | 
			
		||||
            var downstreamServiceTwoUrl = $"http://localhost:{downstreamPortTwo}";
 | 
			
		||||
 | 
			
		||||
@@ -154,8 +154,8 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_use_same_downstream_host_for_different_re_route()
 | 
			
		||||
        {
 | 
			
		||||
            var downstreamPortOne = 53881;
 | 
			
		||||
            var downstreamPortTwo = 53892;
 | 
			
		||||
            var downstreamPortOne = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var downstreamPortTwo = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var downstreamServiceOneUrl = $"http://localhost:{downstreamPortOne}";
 | 
			
		||||
            var downstreamServiceTwoUrl = $"http://localhost:{downstreamPortTwo}";
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -28,9 +28,11 @@
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_fix_issue_194()
 | 
			
		||||
        {
 | 
			
		||||
            var consulPort = 8503;
 | 
			
		||||
            var downstreamServiceOneUrl = "http://localhost:8362";
 | 
			
		||||
            var downstreamServiceTwoUrl = "http://localhost:8330";
 | 
			
		||||
            var consulPort = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var servicePort1 = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var servicePort2 = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var downstreamServiceOneUrl = $"http://localhost:{servicePort1}";
 | 
			
		||||
            var downstreamServiceTwoUrl = $"http://localhost:{servicePort2}";
 | 
			
		||||
            var fakeConsulServiceDiscoveryUrl = $"http://localhost:{consulPort}";
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
@@ -46,7 +48,7 @@
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 8362,
 | 
			
		||||
                                    Port = servicePort1,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamPathTemplate = "/api/user/{user}",
 | 
			
		||||
@@ -61,7 +63,7 @@
 | 
			
		||||
                                new FileHostAndPort
 | 
			
		||||
                                {
 | 
			
		||||
                                    Host = "localhost",
 | 
			
		||||
                                    Port = 8330,
 | 
			
		||||
                                    Port = servicePort2,
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            UpstreamPathTemplate = "/api/product/{product}",
 | 
			
		||||
 
 | 
			
		||||
@@ -23,7 +23,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_200_with_simple_url_and_hosts_match()
 | 
			
		||||
        {
 | 
			
		||||
            int port = 64905;
 | 
			
		||||
            int port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
@@ -60,7 +60,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_200_with_simple_url_and_hosts_match_multiple_re_routes()
 | 
			
		||||
        {
 | 
			
		||||
            int port = 64904;
 | 
			
		||||
            int port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
@@ -113,7 +113,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_200_with_simple_url_and_hosts_match_multiple_re_routes_reversed()
 | 
			
		||||
        {
 | 
			
		||||
            int port = 64903;
 | 
			
		||||
            int port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
@@ -166,7 +166,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_200_with_simple_url_and_hosts_match_multiple_re_routes_reversed_with_no_host_first()
 | 
			
		||||
        {
 | 
			
		||||
            int port = 64902;
 | 
			
		||||
            int port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
@@ -218,7 +218,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_response_404_with_simple_url_and_hosts_dont_match()
 | 
			
		||||
        {
 | 
			
		||||
            int port = 64901;
 | 
			
		||||
            int port = RandomPortFinder.GetRandomPort();
 | 
			
		||||
 | 
			
		||||
            var configuration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
 
 | 
			
		||||
@@ -29,7 +29,7 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_proxy_websocket_input_to_downstream_service()
 | 
			
		||||
        {
 | 
			
		||||
            var downstreamPort = 5001;
 | 
			
		||||
            var downstreamPort = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var downstreamHost = "localhost";
 | 
			
		||||
 | 
			
		||||
            var config = new FileConfiguration
 | 
			
		||||
@@ -64,9 +64,9 @@ namespace Ocelot.AcceptanceTests
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_proxy_websocket_input_to_downstream_service_and_use_load_balancer()
 | 
			
		||||
        {
 | 
			
		||||
            var downstreamPort = 5005;
 | 
			
		||||
            var downstreamPort = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var downstreamHost = "localhost";
 | 
			
		||||
            var secondDownstreamPort = 5006;
 | 
			
		||||
            var secondDownstreamPort = RandomPortFinder.GetRandomPort();
 | 
			
		||||
            var secondDownstreamHost = "localhost";
 | 
			
		||||
 | 
			
		||||
            var config = new FileConfiguration
 | 
			
		||||
 
 | 
			
		||||
@@ -59,7 +59,7 @@ namespace Ocelot.Benchmarks
 | 
			
		||||
 | 
			
		||||
            _downstreamContext = new DownstreamContext(httpContext)
 | 
			
		||||
            {
 | 
			
		||||
                Configuration = new InternalConfiguration(new List<ReRoute>(), null, null, null, null, null, null, null)
 | 
			
		||||
                Configuration = new InternalConfiguration(new List<ReRoute>(), null, null, null, null, null, null, null, null)
 | 
			
		||||
            };
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -0,0 +1,35 @@
 | 
			
		||||
namespace Ocelot.UnitTests.Configuration.ChangeTracking
 | 
			
		||||
{
 | 
			
		||||
    using Ocelot.Configuration.ChangeTracking;
 | 
			
		||||
    using Shouldly;
 | 
			
		||||
    using TestStack.BDDfy;
 | 
			
		||||
    using Xunit;
 | 
			
		||||
 | 
			
		||||
    public class OcelotConfigurationChangeTokenSourceTests
 | 
			
		||||
    {
 | 
			
		||||
        private readonly IOcelotConfigurationChangeTokenSource _source;
 | 
			
		||||
 | 
			
		||||
        public OcelotConfigurationChangeTokenSourceTests()
 | 
			
		||||
        {
 | 
			
		||||
            _source = new OcelotConfigurationChangeTokenSource();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_activate_change_token()
 | 
			
		||||
        {
 | 
			
		||||
            this.Given(_ => GivenIActivateTheChangeTokenSource())
 | 
			
		||||
                .Then(_ => ThenTheChangeTokenShouldBeActivated())
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void GivenIActivateTheChangeTokenSource()
 | 
			
		||||
        {
 | 
			
		||||
            _source.Activate();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void ThenTheChangeTokenShouldBeActivated()
 | 
			
		||||
        {
 | 
			
		||||
            _source.ChangeToken.HasChanged.ShouldBeTrue();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,91 @@
 | 
			
		||||
using Xunit;
 | 
			
		||||
 | 
			
		||||
namespace Ocelot.UnitTests.Configuration.ChangeTracking
 | 
			
		||||
{
 | 
			
		||||
    using System;
 | 
			
		||||
    using Shouldly;
 | 
			
		||||
    using Ocelot.Configuration.ChangeTracking;
 | 
			
		||||
    using TestStack.BDDfy;
 | 
			
		||||
 | 
			
		||||
    public class OcelotConfigurationChangeTokenTests
 | 
			
		||||
    {
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_call_callback_with_state()
 | 
			
		||||
        {
 | 
			
		||||
            this.Given(_ => GivenIHaveAChangeToken())
 | 
			
		||||
                .And(_ => AndIRegisterACallback())
 | 
			
		||||
                .Then(_ => ThenIShouldGetADisposableWrapper())
 | 
			
		||||
                .Given(_ => GivenIActivateTheToken())
 | 
			
		||||
                .Then(_ => ThenTheCallbackShouldBeCalled())
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_not_call_callback_if_it_is_disposed()
 | 
			
		||||
        {
 | 
			
		||||
            this.Given(_ => GivenIHaveAChangeToken())
 | 
			
		||||
                .And(_ => AndIRegisterACallback())
 | 
			
		||||
                .Then(_ => ThenIShouldGetADisposableWrapper())
 | 
			
		||||
                .And(_ => GivenIActivateTheToken())
 | 
			
		||||
                .And(_ => AndIDisposeTheCallbackWrapper())
 | 
			
		||||
                .And(_ => GivenIActivateTheToken())
 | 
			
		||||
                .Then(_ => ThenTheCallbackShouldNotBeCalled())
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private OcelotConfigurationChangeToken _changeToken;
 | 
			
		||||
        private IDisposable _callbackWrapper;
 | 
			
		||||
        private int _callbackCounter;
 | 
			
		||||
        private readonly object _callbackInitialState = new object();
 | 
			
		||||
        private object _callbackState;
 | 
			
		||||
 | 
			
		||||
        private void Callback(object state)
 | 
			
		||||
        {
 | 
			
		||||
            _callbackCounter++;
 | 
			
		||||
            _callbackState = state;
 | 
			
		||||
            _changeToken.HasChanged.ShouldBeTrue();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void GivenIHaveAChangeToken()
 | 
			
		||||
        {
 | 
			
		||||
            _changeToken = new OcelotConfigurationChangeToken();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void AndIRegisterACallback()
 | 
			
		||||
        {
 | 
			
		||||
            _callbackWrapper = _changeToken.RegisterChangeCallback(Callback, _callbackInitialState);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void ThenIShouldGetADisposableWrapper()
 | 
			
		||||
        {
 | 
			
		||||
            _callbackWrapper.ShouldNotBeNull();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void GivenIActivateTheToken()
 | 
			
		||||
        {
 | 
			
		||||
            _callbackCounter = 0;
 | 
			
		||||
            _callbackState = null;
 | 
			
		||||
            _changeToken.Activate();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void ThenTheCallbackShouldBeCalled()
 | 
			
		||||
        {
 | 
			
		||||
            _callbackCounter.ShouldBe(1);
 | 
			
		||||
            _callbackState.ShouldNotBeNull();
 | 
			
		||||
            _callbackState.ShouldBeSameAs(_callbackInitialState);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void ThenTheCallbackShouldNotBeCalled()
 | 
			
		||||
        {
 | 
			
		||||
            _callbackCounter.ShouldBe(0);
 | 
			
		||||
            _callbackState.ShouldBeNull();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void AndIDisposeTheCallbackWrapper()
 | 
			
		||||
        {
 | 
			
		||||
            _callbackState = null;
 | 
			
		||||
            _callbackCounter = 0;
 | 
			
		||||
            _callbackWrapper.Dispose();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -19,6 +19,7 @@ namespace Ocelot.UnitTests.Configuration
 | 
			
		||||
        private readonly Mock<IQoSOptionsCreator> _qosCreator;
 | 
			
		||||
        private readonly Mock<IHttpHandlerOptionsCreator> _hhoCreator;
 | 
			
		||||
        private readonly Mock<ILoadBalancerOptionsCreator> _lboCreator;
 | 
			
		||||
        private readonly Mock<IVersionCreator> _vCreator;
 | 
			
		||||
        private FileConfiguration _fileConfig;
 | 
			
		||||
        private List<ReRoute> _reRoutes;
 | 
			
		||||
        private ServiceProviderConfiguration _spc;
 | 
			
		||||
@@ -30,6 +31,7 @@ namespace Ocelot.UnitTests.Configuration
 | 
			
		||||
 | 
			
		||||
        public ConfigurationCreatorTests()
 | 
			
		||||
        {
 | 
			
		||||
            _vCreator = new Mock<IVersionCreator>();
 | 
			
		||||
            _lboCreator = new Mock<ILoadBalancerOptionsCreator>();
 | 
			
		||||
            _hhoCreator = new Mock<IHttpHandlerOptionsCreator>();
 | 
			
		||||
            _qosCreator = new Mock<IQoSOptionsCreator>();
 | 
			
		||||
@@ -117,7 +119,7 @@ namespace Ocelot.UnitTests.Configuration
 | 
			
		||||
        private void WhenICreate()
 | 
			
		||||
        {
 | 
			
		||||
            var serviceProvider = _serviceCollection.BuildServiceProvider();
 | 
			
		||||
            _creator = new ConfigurationCreator(_spcCreator.Object, _qosCreator.Object, _hhoCreator.Object, serviceProvider, _lboCreator.Object);
 | 
			
		||||
            _creator = new ConfigurationCreator(_spcCreator.Object, _qosCreator.Object, _hhoCreator.Object, serviceProvider, _lboCreator.Object, _vCreator.Object);
 | 
			
		||||
            _result = _creator.Create(_fileConfig, _reRoutes);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -3,6 +3,7 @@ namespace Ocelot.UnitTests.Configuration
 | 
			
		||||
    using Microsoft.AspNetCore.Hosting;
 | 
			
		||||
    using Moq;
 | 
			
		||||
    using Newtonsoft.Json;
 | 
			
		||||
    using Ocelot.Configuration.ChangeTracking;
 | 
			
		||||
    using Ocelot.Configuration.File;
 | 
			
		||||
    using Ocelot.Configuration.Repository;
 | 
			
		||||
    using Shouldly;
 | 
			
		||||
@@ -16,6 +17,7 @@ namespace Ocelot.UnitTests.Configuration
 | 
			
		||||
    public class DiskFileConfigurationRepositoryTests : IDisposable
 | 
			
		||||
    {
 | 
			
		||||
        private readonly Mock<IWebHostEnvironment> _hostingEnvironment;
 | 
			
		||||
        private readonly Mock<IOcelotConfigurationChangeTokenSource> _changeTokenSource;
 | 
			
		||||
        private IFileConfigurationRepository _repo;
 | 
			
		||||
        private string _environmentSpecificPath;
 | 
			
		||||
        private string _ocelotJsonPath;
 | 
			
		||||
@@ -35,7 +37,9 @@ namespace Ocelot.UnitTests.Configuration
 | 
			
		||||
            _semaphore.Wait();
 | 
			
		||||
            _hostingEnvironment = new Mock<IWebHostEnvironment>();
 | 
			
		||||
            _hostingEnvironment.Setup(he => he.EnvironmentName).Returns(_environmentName);
 | 
			
		||||
            _repo = new DiskFileConfigurationRepository(_hostingEnvironment.Object);
 | 
			
		||||
            _changeTokenSource = new Mock<IOcelotConfigurationChangeTokenSource>(MockBehavior.Strict);
 | 
			
		||||
            _changeTokenSource.Setup(m => m.Activate());
 | 
			
		||||
            _repo = new DiskFileConfigurationRepository(_hostingEnvironment.Object, _changeTokenSource.Object);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
@@ -70,6 +74,7 @@ namespace Ocelot.UnitTests.Configuration
 | 
			
		||||
                .When(_ => WhenISetTheConfiguration())
 | 
			
		||||
                .Then(_ => ThenTheConfigurationIsStoredAs(config))
 | 
			
		||||
                .And(_ => ThenTheConfigurationJsonIsIndented(config))
 | 
			
		||||
                .And(x => AndTheChangeTokenIsActivated())
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -117,7 +122,7 @@ namespace Ocelot.UnitTests.Configuration
 | 
			
		||||
        {
 | 
			
		||||
            _environmentName = null;
 | 
			
		||||
            _hostingEnvironment.Setup(he => he.EnvironmentName).Returns(_environmentName);
 | 
			
		||||
            _repo = new DiskFileConfigurationRepository(_hostingEnvironment.Object);
 | 
			
		||||
            _repo = new DiskFileConfigurationRepository(_hostingEnvironment.Object, _changeTokenSource.Object);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void GivenIHaveAConfiguration(FileConfiguration fileConfiguration)
 | 
			
		||||
@@ -210,6 +215,11 @@ namespace Ocelot.UnitTests.Configuration
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void AndTheChangeTokenIsActivated()
 | 
			
		||||
        {
 | 
			
		||||
            _changeTokenSource.Verify(m => m.Activate(), Times.Once);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private FileConfiguration FakeFileConfigurationForSet()
 | 
			
		||||
        {
 | 
			
		||||
            var reRoutes = new List<FileReRoute>
 | 
			
		||||
@@ -222,11 +232,11 @@ namespace Ocelot.UnitTests.Configuration
 | 
			
		||||
                        {
 | 
			
		||||
                            Host = "123.12.12.12",
 | 
			
		||||
                            Port = 80,
 | 
			
		||||
                        }
 | 
			
		||||
                        },
 | 
			
		||||
                    },
 | 
			
		||||
                    DownstreamScheme = "https",
 | 
			
		||||
                    DownstreamPathTemplate = "/asdfs/test/{test}"
 | 
			
		||||
                }
 | 
			
		||||
                    DownstreamPathTemplate = "/asdfs/test/{test}",
 | 
			
		||||
                },
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            var globalConfiguration = new FileGlobalConfiguration
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,6 @@
 | 
			
		||||
namespace Ocelot.UnitTests.Configuration
 | 
			
		||||
{
 | 
			
		||||
    using System;
 | 
			
		||||
    using Moq;
 | 
			
		||||
    using Ocelot.Configuration;
 | 
			
		||||
    using Ocelot.Configuration.Builder;
 | 
			
		||||
@@ -14,15 +15,18 @@
 | 
			
		||||
    {
 | 
			
		||||
        private readonly DynamicsCreator _creator;
 | 
			
		||||
        private readonly Mock<IRateLimitOptionsCreator> _rloCreator;
 | 
			
		||||
        private readonly Mock<IVersionCreator> _versionCreator;
 | 
			
		||||
        private List<ReRoute> _result;
 | 
			
		||||
        private FileConfiguration _fileConfig;
 | 
			
		||||
        private RateLimitOptions _rlo1;
 | 
			
		||||
        private RateLimitOptions _rlo2;
 | 
			
		||||
        private Version _version;
 | 
			
		||||
 | 
			
		||||
        public DynamicsCreatorTests()
 | 
			
		||||
        {
 | 
			
		||||
            _versionCreator = new Mock<IVersionCreator>();
 | 
			
		||||
            _rloCreator = new Mock<IRateLimitOptionsCreator>();
 | 
			
		||||
            _creator = new DynamicsCreator(_rloCreator.Object);
 | 
			
		||||
            _creator = new DynamicsCreator(_rloCreator.Object, _versionCreator.Object);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
@@ -50,7 +54,8 @@
 | 
			
		||||
                        RateLimitRule = new FileRateLimitRule
 | 
			
		||||
                        {
 | 
			
		||||
                            EnableRateLimiting = false
 | 
			
		||||
                        }
 | 
			
		||||
                        },
 | 
			
		||||
                        DownstreamHttpVersion = "1.1"
 | 
			
		||||
                    },
 | 
			
		||||
                    new FileDynamicReRoute
 | 
			
		||||
                    {
 | 
			
		||||
@@ -58,16 +63,19 @@
 | 
			
		||||
                        RateLimitRule = new FileRateLimitRule
 | 
			
		||||
                        {
 | 
			
		||||
                            EnableRateLimiting = true
 | 
			
		||||
                        }
 | 
			
		||||
                        },
 | 
			
		||||
                        DownstreamHttpVersion = "2.0"
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(_ => GivenThe(fileConfig))
 | 
			
		||||
                .And(_ => GivenTheRloCreatorReturns())
 | 
			
		||||
                .And(_ => GivenTheVersionCreatorReturns())
 | 
			
		||||
                .When(_ => WhenICreate())
 | 
			
		||||
                .Then(_ => ThenTheReRoutesAreReturned())
 | 
			
		||||
                .And(_ => ThenTheRloCreatorIsCalledCorrectly())
 | 
			
		||||
                .And(_ => ThenTheVersionCreatorIsCalledCorrectly())
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -80,18 +88,32 @@
 | 
			
		||||
                _fileConfig.GlobalConfiguration), Times.Once);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void ThenTheVersionCreatorIsCalledCorrectly()
 | 
			
		||||
        {
 | 
			
		||||
            _versionCreator.Verify(x => x.Create(_fileConfig.DynamicReRoutes[0].DownstreamHttpVersion), Times.Once);
 | 
			
		||||
            _versionCreator.Verify(x => x.Create(_fileConfig.DynamicReRoutes[1].DownstreamHttpVersion), Times.Once);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void ThenTheReRoutesAreReturned()
 | 
			
		||||
        {
 | 
			
		||||
            _result.Count.ShouldBe(2);
 | 
			
		||||
            _result[0].DownstreamReRoute[0].EnableEndpointEndpointRateLimiting.ShouldBeFalse();
 | 
			
		||||
            _result[0].DownstreamReRoute[0].RateLimitOptions.ShouldBe(_rlo1);
 | 
			
		||||
            _result[0].DownstreamReRoute[0].DownstreamHttpVersion.ShouldBe(_version);
 | 
			
		||||
            _result[0].DownstreamReRoute[0].ServiceName.ShouldBe(_fileConfig.DynamicReRoutes[0].ServiceName);
 | 
			
		||||
 | 
			
		||||
            _result[1].DownstreamReRoute[0].EnableEndpointEndpointRateLimiting.ShouldBeTrue();
 | 
			
		||||
            _result[1].DownstreamReRoute[0].RateLimitOptions.ShouldBe(_rlo2);
 | 
			
		||||
            _result[1].DownstreamReRoute[0].DownstreamHttpVersion.ShouldBe(_version);
 | 
			
		||||
            _result[1].DownstreamReRoute[0].ServiceName.ShouldBe(_fileConfig.DynamicReRoutes[1].ServiceName);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void GivenTheVersionCreatorReturns()
 | 
			
		||||
        {
 | 
			
		||||
            _version = new Version("1.1");
 | 
			
		||||
            _versionCreator.Setup(x => x.Create(It.IsAny<string>())).Returns(_version);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void GivenTheRloCreatorReturns()
 | 
			
		||||
        {
 | 
			
		||||
            _rlo1 = new RateLimitOptionsBuilder().Build();
 | 
			
		||||
 
 | 
			
		||||
@@ -9,11 +9,14 @@ using Ocelot.Errors;
 | 
			
		||||
using Ocelot.Responses;
 | 
			
		||||
using Shouldly;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using Ocelot.Configuration.ChangeTracking;
 | 
			
		||||
using TestStack.BDDfy;
 | 
			
		||||
using Xunit;
 | 
			
		||||
 | 
			
		||||
namespace Ocelot.UnitTests.Configuration
 | 
			
		||||
{
 | 
			
		||||
    using System;
 | 
			
		||||
 | 
			
		||||
    public class FileConfigurationSetterTests
 | 
			
		||||
    {
 | 
			
		||||
        private FileConfiguration _fileConfiguration;
 | 
			
		||||
@@ -21,7 +24,7 @@ namespace Ocelot.UnitTests.Configuration
 | 
			
		||||
        private Mock<IInternalConfigurationRepository> _configRepo;
 | 
			
		||||
        private Mock<IInternalConfigurationCreator> _configCreator;
 | 
			
		||||
        private Response<IInternalConfiguration> _configuration;
 | 
			
		||||
        private object _result;
 | 
			
		||||
        private object _result;
 | 
			
		||||
        private Mock<IFileConfigurationRepository> _repo;
 | 
			
		||||
 | 
			
		||||
        public FileConfigurationSetterTests()
 | 
			
		||||
@@ -37,7 +40,7 @@ namespace Ocelot.UnitTests.Configuration
 | 
			
		||||
        {
 | 
			
		||||
            var fileConfig = new FileConfiguration();
 | 
			
		||||
            var serviceProviderConfig = new ServiceProviderConfigurationBuilder().Build();
 | 
			
		||||
            var config = new InternalConfiguration(new List<ReRoute>(), string.Empty, serviceProviderConfig, "asdf", new LoadBalancerOptionsBuilder().Build(), "", new QoSOptionsBuilder().Build(), new HttpHandlerOptionsBuilder().Build());
 | 
			
		||||
            var config = new InternalConfiguration(new List<ReRoute>(), string.Empty, serviceProviderConfig, "asdf", new LoadBalancerOptionsBuilder().Build(), "", new QoSOptionsBuilder().Build(), new HttpHandlerOptionsBuilder().Build(), new Version("1.1"));
 | 
			
		||||
 | 
			
		||||
            this.Given(x => GivenTheFollowingConfiguration(fileConfig))
 | 
			
		||||
                .And(x => GivenTheRepoReturns(new OkResponse()))
 | 
			
		||||
@@ -104,8 +107,7 @@ namespace Ocelot.UnitTests.Configuration
 | 
			
		||||
 | 
			
		||||
        private void ThenTheConfigurationRepositoryIsCalledCorrectly()
 | 
			
		||||
        {
 | 
			
		||||
            _configRepo
 | 
			
		||||
                .Verify(x => x.AddOrReplace(_configuration.Data), Times.Once);
 | 
			
		||||
            _configRepo.Verify(x => x.AddOrReplace(_configuration.Data), Times.Once);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -87,7 +87,7 @@
 | 
			
		||||
            _reRoutes = new List<ReRoute> { new ReRouteBuilder().Build() };
 | 
			
		||||
            _aggregates = new List<ReRoute> { new ReRouteBuilder().Build() };
 | 
			
		||||
            _dynamics = new List<ReRoute> { new ReRouteBuilder().Build() };
 | 
			
		||||
            _internalConfig = new InternalConfiguration(null, "", null, "", null, "", null, null);
 | 
			
		||||
            _internalConfig = new InternalConfiguration(null, "", null, "", null, "", null, null, null);
 | 
			
		||||
 | 
			
		||||
            _reRoutesCreator.Setup(x => x.Create(It.IsAny<FileConfiguration>())).Returns(_reRoutes);
 | 
			
		||||
            _aggregatesCreator.Setup(x => x.Create(It.IsAny<FileConfiguration>(), It.IsAny<List<ReRoute>>())).Returns(_aggregates);
 | 
			
		||||
 
 | 
			
		||||
@@ -5,6 +5,8 @@ using Ocelot.Responses;
 | 
			
		||||
using Shouldly;
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using Moq;
 | 
			
		||||
using Ocelot.Configuration.ChangeTracking;
 | 
			
		||||
using TestStack.BDDfy;
 | 
			
		||||
using Xunit;
 | 
			
		||||
 | 
			
		||||
@@ -16,10 +18,13 @@ namespace Ocelot.UnitTests.Configuration
 | 
			
		||||
        private IInternalConfiguration _config;
 | 
			
		||||
        private Response _result;
 | 
			
		||||
        private Response<IInternalConfiguration> _getResult;
 | 
			
		||||
        private readonly Mock<IOcelotConfigurationChangeTokenSource> _changeTokenSource;
 | 
			
		||||
 | 
			
		||||
        public InMemoryConfigurationRepositoryTests()
 | 
			
		||||
        {
 | 
			
		||||
            _repo = new InMemoryInternalConfigurationRepository();
 | 
			
		||||
            _changeTokenSource = new Mock<IOcelotConfigurationChangeTokenSource>(MockBehavior.Strict);
 | 
			
		||||
            _changeTokenSource.Setup(m => m.Activate());
 | 
			
		||||
            _repo = new InMemoryInternalConfigurationRepository(_changeTokenSource.Object);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
@@ -28,6 +33,7 @@ namespace Ocelot.UnitTests.Configuration
 | 
			
		||||
            this.Given(x => x.GivenTheConfigurationIs(new FakeConfig("initial", "adminath")))
 | 
			
		||||
                .When(x => x.WhenIAddOrReplaceTheConfig())
 | 
			
		||||
                .Then(x => x.ThenNoErrorsAreReturned())
 | 
			
		||||
                .And(x => AndTheChangeTokenIsActivated())
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -71,6 +77,11 @@ namespace Ocelot.UnitTests.Configuration
 | 
			
		||||
            _result.IsError.ShouldBeFalse();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void AndTheChangeTokenIsActivated()
 | 
			
		||||
        {
 | 
			
		||||
            _changeTokenSource.Verify(m => m.Activate(), Times.Once);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private class FakeConfig : IInternalConfiguration
 | 
			
		||||
        {
 | 
			
		||||
            private readonly string _downstreamTemplatePath;
 | 
			
		||||
@@ -109,6 +120,7 @@ namespace Ocelot.UnitTests.Configuration
 | 
			
		||||
            public string DownstreamScheme { get; }
 | 
			
		||||
            public QoSOptions QoSOptions { get; }
 | 
			
		||||
            public HttpHandlerOptions HttpHandlerOptions { get; }
 | 
			
		||||
            public Version DownstreamHttpVersion { get; }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,6 @@
 | 
			
		||||
namespace Ocelot.UnitTests.Configuration
 | 
			
		||||
{
 | 
			
		||||
    using System;
 | 
			
		||||
    using Moq;
 | 
			
		||||
    using Ocelot.Cache;
 | 
			
		||||
    using Ocelot.Configuration;
 | 
			
		||||
@@ -30,6 +31,7 @@
 | 
			
		||||
        private Mock<ILoadBalancerOptionsCreator> _lboCreator;
 | 
			
		||||
        private Mock<IReRouteKeyCreator> _rrkCreator;
 | 
			
		||||
        private Mock<ISecurityOptionsCreator> _soCreator;
 | 
			
		||||
        private Mock<IVersionCreator> _versionCreator;
 | 
			
		||||
        private FileConfiguration _fileConfig;
 | 
			
		||||
        private ReRouteOptions _rro;
 | 
			
		||||
        private string _requestId;
 | 
			
		||||
@@ -46,6 +48,7 @@
 | 
			
		||||
        private LoadBalancerOptions _lbo;
 | 
			
		||||
        private List<ReRoute> _result;
 | 
			
		||||
        private SecurityOptions _securityOptions;
 | 
			
		||||
        private Version _expectedVersion;
 | 
			
		||||
 | 
			
		||||
        public ReRoutesCreatorTests()
 | 
			
		||||
        {
 | 
			
		||||
@@ -63,6 +66,7 @@
 | 
			
		||||
            _lboCreator = new Mock<ILoadBalancerOptionsCreator>();
 | 
			
		||||
            _rrkCreator = new Mock<IReRouteKeyCreator>();
 | 
			
		||||
            _soCreator = new Mock<ISecurityOptionsCreator>();
 | 
			
		||||
            _versionCreator = new Mock<IVersionCreator>();
 | 
			
		||||
 | 
			
		||||
            _creator = new ReRoutesCreator(
 | 
			
		||||
                _cthCreator.Object,
 | 
			
		||||
@@ -78,7 +82,8 @@
 | 
			
		||||
                _daCreator.Object,
 | 
			
		||||
                _lboCreator.Object,
 | 
			
		||||
                _rrkCreator.Object,
 | 
			
		||||
                _soCreator.Object
 | 
			
		||||
                _soCreator.Object,
 | 
			
		||||
                _versionCreator.Object
 | 
			
		||||
                );
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -155,6 +160,7 @@
 | 
			
		||||
 | 
			
		||||
        private void GivenTheDependenciesAreSetUpCorrectly()
 | 
			
		||||
        {
 | 
			
		||||
            _expectedVersion = new Version("1.1");
 | 
			
		||||
            _rro = new ReRouteOptions(false, false, false, false, false);
 | 
			
		||||
            _requestId = "testy";
 | 
			
		||||
            _rrk = "besty";
 | 
			
		||||
@@ -182,6 +188,7 @@
 | 
			
		||||
            _hfarCreator.Setup(x => x.Create(It.IsAny<FileReRoute>())).Returns(_ht);
 | 
			
		||||
            _daCreator.Setup(x => x.Create(It.IsAny<FileReRoute>())).Returns(_dhp);
 | 
			
		||||
            _lboCreator.Setup(x => x.Create(It.IsAny<FileLoadBalancerOptions>())).Returns(_lbo);
 | 
			
		||||
            _versionCreator.Setup(x => x.Create(It.IsAny<string>())).Returns(_expectedVersion);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void ThenTheReRoutesAreCreated()
 | 
			
		||||
@@ -209,6 +216,7 @@
 | 
			
		||||
 | 
			
		||||
        private void ThenTheReRouteIsSet(FileReRoute expected, int reRouteIndex)
 | 
			
		||||
        {
 | 
			
		||||
            _result[reRouteIndex].DownstreamReRoute[0].DownstreamHttpVersion.ShouldBe(_expectedVersion);
 | 
			
		||||
            _result[reRouteIndex].DownstreamReRoute[0].IsAuthenticated.ShouldBe(_rro.IsAuthenticated);
 | 
			
		||||
            _result[reRouteIndex].DownstreamReRoute[0].IsAuthorised.ShouldBe(_rro.IsAuthorised);
 | 
			
		||||
            _result[reRouteIndex].DownstreamReRoute[0].IsCached.ShouldBe(_rro.IsCached);
 | 
			
		||||
 
 | 
			
		||||
@@ -305,6 +305,71 @@
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Theory]
 | 
			
		||||
        [InlineData("1.0")]
 | 
			
		||||
        [InlineData("1.1")]
 | 
			
		||||
        [InlineData("2.0")]
 | 
			
		||||
        [InlineData("1,0")]
 | 
			
		||||
        [InlineData("1,1")]
 | 
			
		||||
        [InlineData("2,0")]
 | 
			
		||||
        [InlineData("1")]
 | 
			
		||||
        [InlineData("2")]
 | 
			
		||||
        [InlineData("")]
 | 
			
		||||
        [InlineData(null)]
 | 
			
		||||
        public void should_be_valid_re_route_using_downstream_http_version(string version)
 | 
			
		||||
        {
 | 
			
		||||
            var fileReRoute = new FileReRoute
 | 
			
		||||
            {
 | 
			
		||||
                DownstreamPathTemplate = "/test",
 | 
			
		||||
                UpstreamPathTemplate = "/test",
 | 
			
		||||
                DownstreamHostAndPorts = new List<FileHostAndPort>
 | 
			
		||||
                {
 | 
			
		||||
                    new FileHostAndPort
 | 
			
		||||
                    {
 | 
			
		||||
                        Host = "localhost",
 | 
			
		||||
                        Port = 5000,
 | 
			
		||||
                    },
 | 
			
		||||
                },
 | 
			
		||||
                DownstreamHttpVersion = version,
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(_ => GivenThe(fileReRoute))
 | 
			
		||||
                .When(_ => WhenIValidate())
 | 
			
		||||
                .Then(_ => ThenTheResultIsValid())
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Theory]
 | 
			
		||||
        [InlineData("retg1.1")]
 | 
			
		||||
        [InlineData("re2.0")]
 | 
			
		||||
        [InlineData("1,0a")]
 | 
			
		||||
        [InlineData("a1,1")]
 | 
			
		||||
        [InlineData("12,0")]
 | 
			
		||||
        [InlineData("asdf")]
 | 
			
		||||
        public void should_be_invalid_re_route_using_downstream_http_version(string version)
 | 
			
		||||
        {
 | 
			
		||||
            var fileReRoute = new FileReRoute
 | 
			
		||||
            {
 | 
			
		||||
                DownstreamPathTemplate = "/test",
 | 
			
		||||
                UpstreamPathTemplate = "/test",
 | 
			
		||||
                DownstreamHostAndPorts = new List<FileHostAndPort>
 | 
			
		||||
                {
 | 
			
		||||
                    new FileHostAndPort
 | 
			
		||||
                    {
 | 
			
		||||
                        Host = "localhost",
 | 
			
		||||
                        Port = 5000,
 | 
			
		||||
                    },
 | 
			
		||||
                },
 | 
			
		||||
                DownstreamHttpVersion = version,
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(_ => GivenThe(fileReRoute))
 | 
			
		||||
                .When(_ => WhenIValidate())
 | 
			
		||||
                .Then(_ => ThenTheResultIsInvalid())
 | 
			
		||||
                .And(_ => ThenTheErrorsContains("'Downstream Http Version' is not in the correct format."))
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void GivenAnAuthProvider(string key)
 | 
			
		||||
        {
 | 
			
		||||
            var schemes = new List<AuthenticationScheme>
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										54
									
								
								test/Ocelot.UnitTests/Configuration/VersionCreatorTests.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								test/Ocelot.UnitTests/Configuration/VersionCreatorTests.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,54 @@
 | 
			
		||||
namespace Ocelot.UnitTests.Configuration
 | 
			
		||||
{
 | 
			
		||||
    using System;
 | 
			
		||||
    using Ocelot.Configuration.Creator;
 | 
			
		||||
    using Shouldly;
 | 
			
		||||
    using TestStack.BDDfy;
 | 
			
		||||
    using Xunit;
 | 
			
		||||
 | 
			
		||||
    public class VersionCreatorTests
 | 
			
		||||
    {
 | 
			
		||||
        private readonly HttpVersionCreator _creator;
 | 
			
		||||
        private string _input;
 | 
			
		||||
        private Version _result;
 | 
			
		||||
 | 
			
		||||
        public VersionCreatorTests()
 | 
			
		||||
        {
 | 
			
		||||
            _creator = new HttpVersionCreator();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_create_version_based_on_input()
 | 
			
		||||
        {
 | 
			
		||||
            this.Given(_ => GivenTheInput("2.0"))
 | 
			
		||||
                .When(_ => WhenICreate())
 | 
			
		||||
                .Then(_ => ThenTheResultIs(2, 0))
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_default_to_version_one_point_one()
 | 
			
		||||
        {
 | 
			
		||||
            this.Given(_ => GivenTheInput(""))
 | 
			
		||||
                .When(_ => WhenICreate())
 | 
			
		||||
                .Then(_ => ThenTheResultIs(1, 1))
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void GivenTheInput(string input)
 | 
			
		||||
        {
 | 
			
		||||
            _input = input;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void WhenICreate()
 | 
			
		||||
        {
 | 
			
		||||
            _result = _creator.Create(_input);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void ThenTheResultIs(int major, int minor)
 | 
			
		||||
        {
 | 
			
		||||
            _result.Major.ShouldBe(major);
 | 
			
		||||
            _result.Minor.ShouldBe(minor);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,5 +1,6 @@
 | 
			
		||||
namespace Ocelot.UnitTests.DownstreamRouteFinder
 | 
			
		||||
{
 | 
			
		||||
    using System;
 | 
			
		||||
    using Moq;
 | 
			
		||||
    using Ocelot.Configuration;
 | 
			
		||||
    using Ocelot.Configuration.Builder;
 | 
			
		||||
@@ -44,7 +45,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_create_downstream_route()
 | 
			
		||||
        {
 | 
			
		||||
            var configuration = new InternalConfiguration(null, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", _qoSOptions, _handlerOptions);
 | 
			
		||||
            var configuration = new InternalConfiguration(null, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", _qoSOptions, _handlerOptions, new Version("1.1"));
 | 
			
		||||
 | 
			
		||||
            this.Given(_ => GivenTheConfiguration(configuration))
 | 
			
		||||
                .When(_ => WhenICreate())
 | 
			
		||||
@@ -71,7 +72,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
 | 
			
		||||
 | 
			
		||||
            var reRoutes = new List<ReRoute> { reRoute };
 | 
			
		||||
 | 
			
		||||
            var configuration = new InternalConfiguration(reRoutes, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", _qoSOptions, _handlerOptions);
 | 
			
		||||
            var configuration = new InternalConfiguration(reRoutes, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", _qoSOptions, _handlerOptions, new Version("1.1"));
 | 
			
		||||
 | 
			
		||||
            this.Given(_ => GivenTheConfiguration(configuration))
 | 
			
		||||
                .When(_ => WhenICreate())
 | 
			
		||||
@@ -83,7 +84,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_cache_downstream_route()
 | 
			
		||||
        {
 | 
			
		||||
            var configuration = new InternalConfiguration(null, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", _qoSOptions, _handlerOptions);
 | 
			
		||||
            var configuration = new InternalConfiguration(null, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", _qoSOptions, _handlerOptions, new Version("1.1"));
 | 
			
		||||
 | 
			
		||||
            this.Given(_ => GivenTheConfiguration(configuration, "/geoffisthebest/"))
 | 
			
		||||
                .When(_ => WhenICreate())
 | 
			
		||||
@@ -96,7 +97,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_not_cache_downstream_route()
 | 
			
		||||
        {
 | 
			
		||||
            var configuration = new InternalConfiguration(null, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", _qoSOptions, _handlerOptions);
 | 
			
		||||
            var configuration = new InternalConfiguration(null, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", _qoSOptions, _handlerOptions, new Version("1.1"));
 | 
			
		||||
 | 
			
		||||
            this.Given(_ => GivenTheConfiguration(configuration, "/geoffistheworst/"))
 | 
			
		||||
                .When(_ => WhenICreate())
 | 
			
		||||
@@ -110,7 +111,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
 | 
			
		||||
        public void should_create_downstream_route_with_no_path()
 | 
			
		||||
        {
 | 
			
		||||
            var upstreamUrlPath = "/auth/";
 | 
			
		||||
            var configuration = new InternalConfiguration(null, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", _qoSOptions, _handlerOptions);
 | 
			
		||||
            var configuration = new InternalConfiguration(null, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", _qoSOptions, _handlerOptions, new Version("1.1"));
 | 
			
		||||
 | 
			
		||||
            this.Given(_ => GivenTheConfiguration(configuration, upstreamUrlPath))
 | 
			
		||||
                .When(_ => WhenICreate())
 | 
			
		||||
@@ -122,7 +123,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
 | 
			
		||||
        public void should_create_downstream_route_with_only_first_segment_no_traling_slash()
 | 
			
		||||
        {
 | 
			
		||||
            var upstreamUrlPath = "/auth";
 | 
			
		||||
            var configuration = new InternalConfiguration(null, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", _qoSOptions, _handlerOptions);
 | 
			
		||||
            var configuration = new InternalConfiguration(null, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", _qoSOptions, _handlerOptions, new Version("1.1"));
 | 
			
		||||
 | 
			
		||||
            this.Given(_ => GivenTheConfiguration(configuration, upstreamUrlPath))
 | 
			
		||||
                .When(_ => WhenICreate())
 | 
			
		||||
@@ -134,7 +135,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
 | 
			
		||||
        public void should_create_downstream_route_with_segments_no_traling_slash()
 | 
			
		||||
        {
 | 
			
		||||
            var upstreamUrlPath = "/auth/test";
 | 
			
		||||
            var configuration = new InternalConfiguration(null, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", _qoSOptions, _handlerOptions);
 | 
			
		||||
            var configuration = new InternalConfiguration(null, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", _qoSOptions, _handlerOptions, new Version("1.1"));
 | 
			
		||||
 | 
			
		||||
            this.Given(_ => GivenTheConfiguration(configuration, upstreamUrlPath))
 | 
			
		||||
                .When(_ => WhenICreate())
 | 
			
		||||
@@ -146,7 +147,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
 | 
			
		||||
        public void should_create_downstream_route_and_remove_query_string()
 | 
			
		||||
        {
 | 
			
		||||
            var upstreamUrlPath = "/auth/test?test=1&best=2";
 | 
			
		||||
            var configuration = new InternalConfiguration(null, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", _qoSOptions, _handlerOptions);
 | 
			
		||||
            var configuration = new InternalConfiguration(null, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", _qoSOptions, _handlerOptions, new Version("1.1"));
 | 
			
		||||
 | 
			
		||||
            this.Given(_ => GivenTheConfiguration(configuration, upstreamUrlPath))
 | 
			
		||||
                .When(_ => WhenICreate())
 | 
			
		||||
@@ -158,7 +159,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
 | 
			
		||||
        public void should_create_downstream_route_for_sticky_sessions()
 | 
			
		||||
        {
 | 
			
		||||
            var loadBalancerOptions = new LoadBalancerOptionsBuilder().WithType(nameof(CookieStickySessions)).WithKey("boom").WithExpiryInMs(1).Build();
 | 
			
		||||
            var configuration = new InternalConfiguration(null, "doesnt matter", null, "doesnt matter", loadBalancerOptions, "http", _qoSOptions, _handlerOptions);
 | 
			
		||||
            var configuration = new InternalConfiguration(null, "doesnt matter", null, "doesnt matter", loadBalancerOptions, "http", _qoSOptions, _handlerOptions, new Version("1.1"));
 | 
			
		||||
 | 
			
		||||
            this.Given(_ => GivenTheConfiguration(configuration))
 | 
			
		||||
                .When(_ => WhenICreate())
 | 
			
		||||
@@ -174,7 +175,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
 | 
			
		||||
                .WithTimeoutValue(1)
 | 
			
		||||
                .Build();
 | 
			
		||||
 | 
			
		||||
            var configuration = new InternalConfiguration(null, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", qoSOptions, _handlerOptions);
 | 
			
		||||
            var configuration = new InternalConfiguration(null, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", qoSOptions, _handlerOptions, new Version("1.1"));
 | 
			
		||||
 | 
			
		||||
            this.Given(_ => GivenTheConfiguration(configuration))
 | 
			
		||||
                .And(_ => GivenTheQosCreatorReturns(qoSOptions))
 | 
			
		||||
@@ -186,7 +187,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_create_downstream_route_with_handler_options()
 | 
			
		||||
        {
 | 
			
		||||
            var configuration = new InternalConfiguration(null, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", _qoSOptions, _handlerOptions);
 | 
			
		||||
            var configuration = new InternalConfiguration(null, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", _qoSOptions, _handlerOptions, new Version("1.1"));
 | 
			
		||||
 | 
			
		||||
            this.Given(_ => GivenTheConfiguration(configuration))
 | 
			
		||||
                .When(_ => WhenICreate())
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,6 @@
 | 
			
		||||
namespace Ocelot.UnitTests.DownstreamRouteFinder
 | 
			
		||||
{
 | 
			
		||||
    using System;
 | 
			
		||||
    using Microsoft.AspNetCore.Http;
 | 
			
		||||
    using Moq;
 | 
			
		||||
    using Ocelot.Configuration;
 | 
			
		||||
@@ -48,7 +49,7 @@
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_call_scoped_data_repository_correctly()
 | 
			
		||||
        {
 | 
			
		||||
            var config = new InternalConfiguration(null, null, new ServiceProviderConfigurationBuilder().Build(), "", new LoadBalancerOptionsBuilder().Build(), "", new QoSOptionsBuilder().Build(), new HttpHandlerOptionsBuilder().Build());
 | 
			
		||||
            var config = new InternalConfiguration(null, null, new ServiceProviderConfigurationBuilder().Build(), "", new LoadBalancerOptionsBuilder().Build(), "", new QoSOptionsBuilder().Build(), new HttpHandlerOptionsBuilder().Build(), new Version("1.1"));
 | 
			
		||||
 | 
			
		||||
            var downstreamReRoute = new DownstreamReRouteBuilder()
 | 
			
		||||
                .WithDownstreamPathTemplate("any old string")
 | 
			
		||||
 
 | 
			
		||||
@@ -13,6 +13,8 @@ using Xunit;
 | 
			
		||||
 | 
			
		||||
namespace Ocelot.UnitTests.DownstreamRouteFinder
 | 
			
		||||
{
 | 
			
		||||
    using System;
 | 
			
		||||
 | 
			
		||||
    public class DownstreamRouteFinderTests
 | 
			
		||||
    {
 | 
			
		||||
        private readonly IDownstreamRouteProvider _downstreamRouteFinder;
 | 
			
		||||
@@ -739,7 +741,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
 | 
			
		||||
        private void GivenTheConfigurationIs(List<ReRoute> reRoutesConfig, string adminPath, ServiceProviderConfiguration serviceProviderConfig)
 | 
			
		||||
        {
 | 
			
		||||
            _reRoutesConfig = reRoutesConfig;
 | 
			
		||||
            _config = new InternalConfiguration(_reRoutesConfig, adminPath, serviceProviderConfig, "", new LoadBalancerOptionsBuilder().Build(), "", new QoSOptionsBuilder().Build(), new HttpHandlerOptionsBuilder().Build());
 | 
			
		||||
            _config = new InternalConfiguration(_reRoutesConfig, adminPath, serviceProviderConfig, "", new LoadBalancerOptionsBuilder().Build(), "", new QoSOptionsBuilder().Build(), new HttpHandlerOptionsBuilder().Build(), new Version("1.1"));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void GivenThereIsAnUpstreamUrlPath(string upstreamUrlPath)
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,6 @@
 | 
			
		||||
namespace Ocelot.UnitTests.DownstreamRouteFinder
 | 
			
		||||
{
 | 
			
		||||
    using System;
 | 
			
		||||
    using Microsoft.Extensions.DependencyInjection;
 | 
			
		||||
    using Moq;
 | 
			
		||||
    using Ocelot.Configuration;
 | 
			
		||||
@@ -140,12 +141,12 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
 | 
			
		||||
 | 
			
		||||
        private void GivenTheReRoutes(List<ReRoute> reRoutes)
 | 
			
		||||
        {
 | 
			
		||||
            _config = new InternalConfiguration(reRoutes, "", null, "", new LoadBalancerOptionsBuilder().Build(), "", new QoSOptionsBuilder().Build(), new HttpHandlerOptionsBuilder().Build());
 | 
			
		||||
            _config = new InternalConfiguration(reRoutes, "", null, "", new LoadBalancerOptionsBuilder().Build(), "", new QoSOptionsBuilder().Build(), new HttpHandlerOptionsBuilder().Build(), new Version("1.1"));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void GivenTheReRoutes(List<ReRoute> reRoutes, ServiceProviderConfiguration config)
 | 
			
		||||
        {
 | 
			
		||||
            _config = new InternalConfiguration(reRoutes, "", config, "", new LoadBalancerOptionsBuilder().Build(), "", new QoSOptionsBuilder().Build(), new HttpHandlerOptionsBuilder().Build());
 | 
			
		||||
            _config = new InternalConfiguration(reRoutes, "", config, "", new LoadBalancerOptionsBuilder().Build(), "", new QoSOptionsBuilder().Build(), new HttpHandlerOptionsBuilder().Build(), new Version("1.1"));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -382,7 +382,7 @@
 | 
			
		||||
 | 
			
		||||
        private void GivenTheServiceProviderConfigIs(ServiceProviderConfiguration config)
 | 
			
		||||
        {
 | 
			
		||||
            var configuration = new InternalConfiguration(null, null, config, null, null, null, null, null);
 | 
			
		||||
            var configuration = new InternalConfiguration(null, null, config, null, null, null, null, null, null);
 | 
			
		||||
            _downstreamContext.Configuration = configuration;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -52,7 +52,7 @@ namespace Ocelot.UnitTests.Errors
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void NoDownstreamException()
 | 
			
		||||
        {
 | 
			
		||||
            var config = new InternalConfiguration(null, null, null, null, null, null, null, null);
 | 
			
		||||
            var config = new InternalConfiguration(null, null, null, null, null, null, null, null, null);
 | 
			
		||||
 | 
			
		||||
            this.Given(_ => GivenAnExceptionWillNotBeThrownDownstream())
 | 
			
		||||
                .And(_ => GivenTheConfigurationIs(config))
 | 
			
		||||
@@ -65,7 +65,7 @@ namespace Ocelot.UnitTests.Errors
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void DownstreamException()
 | 
			
		||||
        {
 | 
			
		||||
            var config = new InternalConfiguration(null, null, null, null, null, null, null, null);
 | 
			
		||||
            var config = new InternalConfiguration(null, null, null, null, null, null, null, null, null);
 | 
			
		||||
 | 
			
		||||
            this.Given(_ => GivenAnExceptionWillBeThrownDownstream())
 | 
			
		||||
                .And(_ => GivenTheConfigurationIs(config))
 | 
			
		||||
@@ -77,7 +77,7 @@ namespace Ocelot.UnitTests.Errors
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void ShouldSetRequestId()
 | 
			
		||||
        {
 | 
			
		||||
            var config = new InternalConfiguration(null, null, null, "requestidkey", null, null, null, null);
 | 
			
		||||
            var config = new InternalConfiguration(null, null, null, "requestidkey", null, null, null, null, null);
 | 
			
		||||
 | 
			
		||||
            this.Given(_ => GivenAnExceptionWillNotBeThrownDownstream())
 | 
			
		||||
                .And(_ => GivenTheConfigurationIs(config))
 | 
			
		||||
@@ -90,7 +90,7 @@ namespace Ocelot.UnitTests.Errors
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void ShouldSetAspDotNetRequestId()
 | 
			
		||||
        {
 | 
			
		||||
            var config = new InternalConfiguration(null, null, null, null, null, null, null, null);
 | 
			
		||||
            var config = new InternalConfiguration(null, null, null, null, null, null, null, null, null);
 | 
			
		||||
 | 
			
		||||
            this.Given(_ => GivenAnExceptionWillNotBeThrownDownstream())
 | 
			
		||||
                .And(_ => GivenTheConfigurationIs(config))
 | 
			
		||||
 
 | 
			
		||||
@@ -20,7 +20,7 @@
 | 
			
		||||
        {
 | 
			
		||||
            var configRepo = new Mock<IInternalConfigurationRepository>();
 | 
			
		||||
            configRepo.Setup(x => x.Get())
 | 
			
		||||
                .Returns(new OkResponse<IInternalConfiguration>(new InternalConfiguration(null, null, null, null, null, null, null, null)));
 | 
			
		||||
                .Returns(new OkResponse<IInternalConfiguration>(new InternalConfiguration(null, null, null, null, null, null, null, null, null)));
 | 
			
		||||
            var services = new ServiceCollection();
 | 
			
		||||
            services.AddSingleton<IInternalConfigurationRepository>(configRepo.Object);
 | 
			
		||||
            var sp = services.BuildServiceProvider();
 | 
			
		||||
@@ -35,7 +35,7 @@
 | 
			
		||||
            var client = new Mock<IDiscoveryClient>();
 | 
			
		||||
            var configRepo = new Mock<IInternalConfigurationRepository>();
 | 
			
		||||
            configRepo.Setup(x => x.Get())
 | 
			
		||||
                .Returns(new OkResponse<IInternalConfiguration>(new InternalConfiguration(null, null, serviceProviderConfig, null, null, null, null, null)));
 | 
			
		||||
                .Returns(new OkResponse<IInternalConfiguration>(new InternalConfiguration(null, null, serviceProviderConfig, null, null, null, null, null, null)));
 | 
			
		||||
            var services = new ServiceCollection();
 | 
			
		||||
            services.AddSingleton<IInternalConfigurationRepository>(configRepo.Object);
 | 
			
		||||
            services.AddSingleton<IDiscoveryClient>(client.Object);
 | 
			
		||||
 
 | 
			
		||||
@@ -139,7 +139,7 @@ namespace Ocelot.UnitTests.LoadBalancer
 | 
			
		||||
        private void GivenTheConfigurationIs(ServiceProviderConfiguration config)
 | 
			
		||||
        {
 | 
			
		||||
            _config = config;
 | 
			
		||||
            var configuration = new InternalConfiguration(null, null, config, null, null, null, null, null);
 | 
			
		||||
            var configuration = new InternalConfiguration(null, null, config, null, null, null, null, null, null);
 | 
			
		||||
            _downstreamContext.Configuration = configuration;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,4 @@
 | 
			
		||||
using Ocelot.Middleware;
 | 
			
		||||
 | 
			
		||||
namespace Ocelot.UnitTests.Request
 | 
			
		||||
namespace Ocelot.UnitTests.Request
 | 
			
		||||
{
 | 
			
		||||
    using Microsoft.AspNetCore.Http;
 | 
			
		||||
    using Moq;
 | 
			
		||||
@@ -9,9 +7,12 @@ namespace Ocelot.UnitTests.Request
 | 
			
		||||
    using Ocelot.Request.Creator;
 | 
			
		||||
    using Ocelot.Request.Mapper;
 | 
			
		||||
    using Ocelot.Request.Middleware;
 | 
			
		||||
    using Ocelot.Configuration.Builder;
 | 
			
		||||
    using Ocelot.Middleware;
 | 
			
		||||
    using Ocelot.Responses;
 | 
			
		||||
    using Shouldly;
 | 
			
		||||
    using System.Net.Http;
 | 
			
		||||
    using Ocelot.Configuration;
 | 
			
		||||
    using TestStack.BDDfy;
 | 
			
		||||
    using Xunit;
 | 
			
		||||
 | 
			
		||||
@@ -65,6 +66,20 @@ namespace Ocelot.UnitTests.Request
 | 
			
		||||
                .Then(_ => ThenTheContexRequestIsMappedToADownstreamRequest())
 | 
			
		||||
                .And(_ => ThenTheDownstreamRequestIsStored())
 | 
			
		||||
                .And(_ => ThenTheNextMiddlewareIsInvoked())
 | 
			
		||||
                .And(_ => ThenTheDownstreamRequestMethodIs("GET"))
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void Should_map_downstream_reroute_method_to_downstream_request()
 | 
			
		||||
        {
 | 
			
		||||
            this.Given(_ => GivenTheHttpContextContainsARequest())
 | 
			
		||||
                .And(_ => GivenTheMapperWillReturnAMappedRequest())
 | 
			
		||||
                .When(_ => WhenTheMiddlewareIsInvoked())
 | 
			
		||||
                .Then(_ => ThenTheContexRequestIsMappedToADownstreamRequest())
 | 
			
		||||
                .And(_ => ThenTheDownstreamRequestIsStored())
 | 
			
		||||
                .And(_ => ThenTheNextMiddlewareIsInvoked())
 | 
			
		||||
                .And(_ => ThenTheDownstreamRequestMethodIs("GET"))
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -80,6 +95,11 @@ namespace Ocelot.UnitTests.Request
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void ThenTheDownstreamRequestMethodIs(string expected)
 | 
			
		||||
        {
 | 
			
		||||
            _downstreamContext.DownstreamRequest.Method.ShouldBe(expected);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void GivenTheHttpContextContainsARequest()
 | 
			
		||||
        {
 | 
			
		||||
            _httpContext
 | 
			
		||||
@@ -92,7 +112,7 @@ namespace Ocelot.UnitTests.Request
 | 
			
		||||
            _mappedRequest = new OkResponse<HttpRequestMessage>(new HttpRequestMessage(HttpMethod.Get, "http://www.bbc.co.uk"));
 | 
			
		||||
 | 
			
		||||
            _requestMapper
 | 
			
		||||
                .Setup(rm => rm.Map(It.IsAny<HttpRequest>()))
 | 
			
		||||
                .Setup(rm => rm.Map(It.IsAny<HttpRequest>(), It.IsAny<DownstreamReRoute>()))
 | 
			
		||||
                .ReturnsAsync(_mappedRequest);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -101,7 +121,7 @@ namespace Ocelot.UnitTests.Request
 | 
			
		||||
            _mappedRequest = new ErrorResponse<HttpRequestMessage>(new UnmappableRequestError(new System.Exception("boooom!")));
 | 
			
		||||
 | 
			
		||||
            _requestMapper
 | 
			
		||||
                .Setup(rm => rm.Map(It.IsAny<HttpRequest>()))
 | 
			
		||||
                .Setup(rm => rm.Map(It.IsAny<HttpRequest>(), It.IsAny<DownstreamReRoute>()))
 | 
			
		||||
                .ReturnsAsync(_mappedRequest);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -112,7 +132,7 @@ namespace Ocelot.UnitTests.Request
 | 
			
		||||
 | 
			
		||||
        private void ThenTheContexRequestIsMappedToADownstreamRequest()
 | 
			
		||||
        {
 | 
			
		||||
            _requestMapper.Verify(rm => rm.Map(_httpRequest.Object), Times.Once);
 | 
			
		||||
            _requestMapper.Verify(rm => rm.Map(_httpRequest.Object, _downstreamContext.DownstreamReRoute), Times.Once);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void ThenTheDownstreamRequestIsStored()
 | 
			
		||||
 
 | 
			
		||||
@@ -13,6 +13,8 @@
 | 
			
		||||
    using System.Security.Cryptography;
 | 
			
		||||
    using System.Text;
 | 
			
		||||
    using System.Threading.Tasks;
 | 
			
		||||
    using Ocelot.Configuration;
 | 
			
		||||
    using Ocelot.Configuration.Builder;
 | 
			
		||||
    using TestStack.BDDfy;
 | 
			
		||||
    using Xunit;
 | 
			
		||||
 | 
			
		||||
@@ -27,6 +29,8 @@
 | 
			
		||||
 | 
			
		||||
        private List<KeyValuePair<string, StringValues>> _inputHeaders = null;
 | 
			
		||||
 | 
			
		||||
        private DownstreamReRoute _downstreamReRoute;
 | 
			
		||||
 | 
			
		||||
        public RequestMapperTests()
 | 
			
		||||
        {
 | 
			
		||||
            _httpContext = new DefaultHttpContext();
 | 
			
		||||
@@ -47,6 +51,7 @@
 | 
			
		||||
                .And(_ => GivenTheInputRequestHasHost(host))
 | 
			
		||||
                .And(_ => GivenTheInputRequestHasPath(path))
 | 
			
		||||
                .And(_ => GivenTheInputRequestHasQueryString(queryString))
 | 
			
		||||
                .And(_ => GivenTheDownstreamReRoute())
 | 
			
		||||
                .When(_ => WhenMapped())
 | 
			
		||||
                .Then(_ => ThenNoErrorIsReturned())
 | 
			
		||||
                .And(_ => ThenTheMappedRequestHasUri(expectedUri))
 | 
			
		||||
@@ -76,18 +81,35 @@
 | 
			
		||||
        {
 | 
			
		||||
            this.Given(_ => GivenTheInputRequestHasMethod(method))
 | 
			
		||||
                .And(_ => GivenTheInputRequestHasAValidUri())
 | 
			
		||||
                .And(_ => GivenTheDownstreamReRoute())
 | 
			
		||||
                .When(_ => WhenMapped())
 | 
			
		||||
                .Then(_ => ThenNoErrorIsReturned())
 | 
			
		||||
                .And(_ => ThenTheMappedRequestHasMethod(method))
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Theory]
 | 
			
		||||
        [InlineData("", "GET")]
 | 
			
		||||
        [InlineData(null, "GET")]
 | 
			
		||||
        [InlineData("POST", "POST")]
 | 
			
		||||
        public void Should_use_downstream_reroute_method_if_set(string input, string expected)
 | 
			
		||||
        {
 | 
			
		||||
            this.Given(_ => GivenTheInputRequestHasMethod("GET"))
 | 
			
		||||
                .And(_ => GivenTheDownstreamReRouteMethodIs(input))
 | 
			
		||||
                .And(_ => GivenTheInputRequestHasAValidUri())
 | 
			
		||||
                .When(_ => WhenMapped())
 | 
			
		||||
                .Then(_ => ThenNoErrorIsReturned())
 | 
			
		||||
                .And(_ => ThenTheMappedRequestHasMethod(expected))
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void Should_map_all_headers()
 | 
			
		||||
        {
 | 
			
		||||
            this.Given(_ => GivenTheInputRequestHasHeaders())
 | 
			
		||||
                .And(_ => GivenTheInputRequestHasMethod("GET"))
 | 
			
		||||
                .And(_ => GivenTheInputRequestHasAValidUri())
 | 
			
		||||
                .And(_ => GivenTheDownstreamReRoute())
 | 
			
		||||
                .When(_ => WhenMapped())
 | 
			
		||||
                .Then(_ => ThenNoErrorIsReturned())
 | 
			
		||||
                .And(_ => ThenTheMappedRequestHasEachHeader())
 | 
			
		||||
@@ -100,6 +122,7 @@
 | 
			
		||||
            this.Given(_ => GivenTheInputRequestHasNoHeaders())
 | 
			
		||||
                .And(_ => GivenTheInputRequestHasMethod("GET"))
 | 
			
		||||
                .And(_ => GivenTheInputRequestHasAValidUri())
 | 
			
		||||
                .And(_ => GivenTheDownstreamReRoute())
 | 
			
		||||
                .When(_ => WhenMapped())
 | 
			
		||||
                .Then(_ => ThenNoErrorIsReturned())
 | 
			
		||||
                .And(_ => ThenTheMappedRequestHasNoHeaders())
 | 
			
		||||
@@ -112,6 +135,7 @@
 | 
			
		||||
            this.Given(_ => GivenTheInputRequestHasContent("This is my content"))
 | 
			
		||||
                .And(_ => GivenTheInputRequestHasMethod("GET"))
 | 
			
		||||
                .And(_ => GivenTheInputRequestHasAValidUri())
 | 
			
		||||
                .And(_ => GivenTheDownstreamReRoute())
 | 
			
		||||
                .When(_ => WhenMapped())
 | 
			
		||||
                .Then(_ => ThenNoErrorIsReturned())
 | 
			
		||||
                .And(_ => ThenTheMappedRequestHasContent("This is my content"))
 | 
			
		||||
@@ -124,6 +148,7 @@
 | 
			
		||||
            this.Given(_ => GivenTheInputRequestHasNullContent())
 | 
			
		||||
                .And(_ => GivenTheInputRequestHasMethod("GET"))
 | 
			
		||||
                .And(_ => GivenTheInputRequestHasAValidUri())
 | 
			
		||||
                .And(_ => GivenTheDownstreamReRoute())
 | 
			
		||||
                .When(_ => WhenMapped())
 | 
			
		||||
                .Then(_ => ThenNoErrorIsReturned())
 | 
			
		||||
                .And(_ => ThenTheMappedRequestHasNoContent())
 | 
			
		||||
@@ -136,6 +161,7 @@
 | 
			
		||||
            this.Given(_ => GivenTheInputRequestHasNoContentType())
 | 
			
		||||
                .And(_ => GivenTheInputRequestHasMethod("GET"))
 | 
			
		||||
                .And(_ => GivenTheInputRequestHasAValidUri())
 | 
			
		||||
                .And(_ => GivenTheDownstreamReRoute())
 | 
			
		||||
                .When(_ => WhenMapped())
 | 
			
		||||
                .Then(_ => ThenNoErrorIsReturned())
 | 
			
		||||
                .And(_ => ThenTheMappedRequestHasNoContent())
 | 
			
		||||
@@ -148,22 +174,13 @@
 | 
			
		||||
            this.Given(_ => GivenTheInputRequestHasNoContentLength())
 | 
			
		||||
                .And(_ => GivenTheInputRequestHasMethod("GET"))
 | 
			
		||||
                .And(_ => GivenTheInputRequestHasAValidUri())
 | 
			
		||||
                .And(_ => GivenTheDownstreamReRoute())
 | 
			
		||||
                .When(_ => WhenMapped())
 | 
			
		||||
                .Then(_ => ThenNoErrorIsReturned())
 | 
			
		||||
                .And(_ => ThenTheMappedRequestHasNoContent())
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void GivenTheInputRequestHasNoContentLength()
 | 
			
		||||
        {
 | 
			
		||||
            _inputRequest.ContentLength = null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void GivenTheInputRequestHasNoContentType()
 | 
			
		||||
        {
 | 
			
		||||
            _inputRequest.ContentType = null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void Should_map_content_headers()
 | 
			
		||||
        {
 | 
			
		||||
@@ -183,6 +200,7 @@
 | 
			
		||||
                .And(_ => GivenTheContentMD5Is(md5bytes))
 | 
			
		||||
                .And(_ => GivenTheInputRequestHasMethod("GET"))
 | 
			
		||||
                .And(_ => GivenTheInputRequestHasAValidUri())
 | 
			
		||||
                .And(_ => GivenTheDownstreamReRoute())
 | 
			
		||||
                .When(_ => WhenMapped())
 | 
			
		||||
                .Then(_ => ThenNoErrorIsReturned())
 | 
			
		||||
                .And(_ => ThenTheMappedRequestHasContentTypeHeader("application/json"))
 | 
			
		||||
@@ -204,6 +222,7 @@
 | 
			
		||||
                .And(_ => GivenTheContentTypeIs("application/json"))
 | 
			
		||||
                .And(_ => GivenTheInputRequestHasMethod("POST"))
 | 
			
		||||
                .And(_ => GivenTheInputRequestHasAValidUri())
 | 
			
		||||
                .And(_ => GivenTheDownstreamReRoute())
 | 
			
		||||
                .When(_ => WhenMapped())
 | 
			
		||||
                .Then(_ => ThenNoErrorIsReturned())
 | 
			
		||||
                .And(_ => ThenTheMappedRequestHasContentTypeHeader("application/json"))
 | 
			
		||||
@@ -212,6 +231,30 @@
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void GivenTheDownstreamReRouteMethodIs(string input)
 | 
			
		||||
        {
 | 
			
		||||
            _downstreamReRoute = new DownstreamReRouteBuilder()
 | 
			
		||||
                .WithDownStreamHttpMethod(input)
 | 
			
		||||
                .WithDownstreamHttpVersion(new Version("1.1")).Build();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void GivenTheDownstreamReRoute()
 | 
			
		||||
        {
 | 
			
		||||
            _downstreamReRoute = new DownstreamReRouteBuilder()
 | 
			
		||||
                .WithDownstreamHttpVersion(new Version("1.1")).Build();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void GivenTheInputRequestHasNoContentLength()
 | 
			
		||||
        {
 | 
			
		||||
            _inputRequest.ContentLength = null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void GivenTheInputRequestHasNoContentType()
 | 
			
		||||
        {
 | 
			
		||||
            _inputRequest.ContentType = null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        private void ThenTheContentHeadersAreNotAddedToNonContentHeaders()
 | 
			
		||||
        {
 | 
			
		||||
            _mappedRequest.Data.Headers.ShouldNotContain(x => x.Key == "Content-Disposition");
 | 
			
		||||
@@ -380,7 +423,7 @@
 | 
			
		||||
 | 
			
		||||
        private async Task WhenMapped()
 | 
			
		||||
        {
 | 
			
		||||
            _mappedRequest = await _requestMapper.Map(_inputRequest);
 | 
			
		||||
            _mappedRequest = await _requestMapper.Map(_inputRequest, _downstreamReRoute);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void ThenNoErrorIsReturned()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user