mirror of
				https://github.com/nsnail/Ocelot.git
				synced 2025-11-04 21:10:49 +08:00 
			
		
		
		
	Fix/1157 fix UpstreamHost validation (#1169)
* #1157: fix reRoute UpstreamHost validation * change port number
This commit is contained in:
		@@ -342,7 +342,7 @@ namespace Ocelot.IntegrationTests
 | 
			
		||||
        public void should_get_file_configuration_edit_and_post_updated_version_redirecting_reroute()
 | 
			
		||||
        {
 | 
			
		||||
            var fooPort = 47689;
 | 
			
		||||
            var barPort = 47690;
 | 
			
		||||
            var barPort = 27654;
 | 
			
		||||
 | 
			
		||||
            var initialConfiguration = new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
 
 | 
			
		||||
@@ -1119,6 +1119,132 @@
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void configuration_is_not_valid_with_duplicate_reroutes_with_duplicated_upstreamhosts()
 | 
			
		||||
        {
 | 
			
		||||
            this.Given(x => x.GivenAConfiguration(new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
                {
 | 
			
		||||
                    new FileReRoute
 | 
			
		||||
                    {
 | 
			
		||||
                        DownstreamPathTemplate = "/api/products/",
 | 
			
		||||
                        UpstreamPathTemplate = "/asdf/",
 | 
			
		||||
                        DownstreamHostAndPorts = new List<FileHostAndPort>
 | 
			
		||||
                        {
 | 
			
		||||
                            new FileHostAndPort
 | 
			
		||||
                            {
 | 
			
		||||
                                Host = "bbc.co.uk",
 | 
			
		||||
                            }
 | 
			
		||||
                        },
 | 
			
		||||
                        UpstreamHttpMethod = new List<string>(),
 | 
			
		||||
                        UpstreamHost = "upstreamhost"
 | 
			
		||||
                    },
 | 
			
		||||
                    new FileReRoute
 | 
			
		||||
                    {
 | 
			
		||||
                        DownstreamPathTemplate = "/www/test/",
 | 
			
		||||
                        UpstreamPathTemplate = "/asdf/",
 | 
			
		||||
                        DownstreamHostAndPorts = new List<FileHostAndPort>
 | 
			
		||||
                        {
 | 
			
		||||
                            new FileHostAndPort
 | 
			
		||||
                            {
 | 
			
		||||
                                Host = "bbc.co.uk",
 | 
			
		||||
                            }
 | 
			
		||||
                        },
 | 
			
		||||
                        UpstreamHttpMethod = new List<string>(),
 | 
			
		||||
                        UpstreamHost = "upstreamhost"
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }))
 | 
			
		||||
                .When(x => x.WhenIValidateTheConfiguration())
 | 
			
		||||
                .Then(x => x.ThenTheResultIsNotValid())
 | 
			
		||||
                 .And(x => x.ThenTheErrorMessageAtPositionIs(0, "reRoute /asdf/ has duplicate"))
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void configuration_is_valid_with_duplicate_reroutes_but_different_upstreamhosts()
 | 
			
		||||
        {
 | 
			
		||||
            this.Given(x => x.GivenAConfiguration(new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
                {
 | 
			
		||||
                    new FileReRoute
 | 
			
		||||
                    {
 | 
			
		||||
                        DownstreamPathTemplate = "/api/products/",
 | 
			
		||||
                        UpstreamPathTemplate = "/asdf/",
 | 
			
		||||
                        DownstreamHostAndPorts = new List<FileHostAndPort>
 | 
			
		||||
                        {
 | 
			
		||||
                            new FileHostAndPort
 | 
			
		||||
                            {
 | 
			
		||||
                                Host = "bbc.co.uk",
 | 
			
		||||
                            }
 | 
			
		||||
                        },
 | 
			
		||||
                        UpstreamHttpMethod = new List<string>(),
 | 
			
		||||
                        UpstreamHost = "upstreamhost111"
 | 
			
		||||
                    },
 | 
			
		||||
                    new FileReRoute
 | 
			
		||||
                    {
 | 
			
		||||
                        DownstreamPathTemplate = "/www/test/",
 | 
			
		||||
                        UpstreamPathTemplate = "/asdf/",
 | 
			
		||||
                        DownstreamHostAndPorts = new List<FileHostAndPort>
 | 
			
		||||
                        {
 | 
			
		||||
                            new FileHostAndPort
 | 
			
		||||
                            {
 | 
			
		||||
                                Host = "bbc.co.uk",
 | 
			
		||||
                            }
 | 
			
		||||
                        },
 | 
			
		||||
                        UpstreamHttpMethod = new List<string>(),
 | 
			
		||||
                        UpstreamHost = "upstreamhost222"
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }))
 | 
			
		||||
                .When(x => x.WhenIValidateTheConfiguration())
 | 
			
		||||
                .Then(x => x.ThenTheResultIsValid())
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void configuration_is_valid_with_duplicate_reroutes_but_one_upstreamhost_is_not_set()
 | 
			
		||||
        {
 | 
			
		||||
            this.Given(x => x.GivenAConfiguration(new FileConfiguration
 | 
			
		||||
            {
 | 
			
		||||
                ReRoutes = new List<FileReRoute>
 | 
			
		||||
                {
 | 
			
		||||
                    new FileReRoute
 | 
			
		||||
                    {
 | 
			
		||||
                        DownstreamPathTemplate = "/api/products/",
 | 
			
		||||
                        UpstreamPathTemplate = "/asdf/",
 | 
			
		||||
                        DownstreamHostAndPorts = new List<FileHostAndPort>
 | 
			
		||||
                        {
 | 
			
		||||
                            new FileHostAndPort
 | 
			
		||||
                            {
 | 
			
		||||
                                Host = "bbc.co.uk",
 | 
			
		||||
                            }
 | 
			
		||||
                        },
 | 
			
		||||
                        UpstreamHttpMethod = new List<string>(),
 | 
			
		||||
                        UpstreamHost = "upstreamhost"
 | 
			
		||||
                    },
 | 
			
		||||
                    new FileReRoute
 | 
			
		||||
                    {
 | 
			
		||||
                        DownstreamPathTemplate = "/www/test/",
 | 
			
		||||
                        UpstreamPathTemplate = "/asdf/",
 | 
			
		||||
                        DownstreamHostAndPorts = new List<FileHostAndPort>
 | 
			
		||||
                        {
 | 
			
		||||
                            new FileHostAndPort
 | 
			
		||||
                            {
 | 
			
		||||
                                Host = "bbc.co.uk",
 | 
			
		||||
                            }
 | 
			
		||||
                        },
 | 
			
		||||
                        UpstreamHttpMethod = new List<string>()
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }))
 | 
			
		||||
                .When(x => x.WhenIValidateTheConfiguration())
 | 
			
		||||
                .Then(x => x.ThenTheResultIsValid())
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void configuration_is_invalid_with_invalid_rate_limit_configuration()
 | 
			
		||||
        {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user