Skip to content

Commit

Permalink
Fix/1157 fix UpstreamHost validation (#1169)
Browse files Browse the repository at this point in the history
* #1157: fix reRoute UpstreamHost validation

* change port number
  • Loading branch information
jlukawska authored Apr 13, 2020
1 parent 53d7f56 commit 99a15d8
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private static bool IsNotDuplicateIn(FileReRoute reRoute,
{
var matchingReRoutes = reRoutes
.Where(r => r.UpstreamPathTemplate == reRoute.UpstreamPathTemplate
&& (r.UpstreamHost == reRoute.UpstreamHost || reRoute.UpstreamHost == null))
&& r.UpstreamHost == reRoute.UpstreamHost)
.ToList();

if (matchingReRoutes.Count == 1)
Expand Down
2 changes: 1 addition & 1 deletion test/Ocelot.IntegrationTests/AdministrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ private void ThenTheConfigurationIsSavedCorrectly(FileConfiguration expected)
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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,132 @@ public void configuration_is_valid_with_duplicate_reroutes_different_verbs()
.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()
{
Expand Down

0 comments on commit 99a15d8

Please sign in to comment.