Skip to content

Commit

Permalink
Check for duplicate domains (#50)
Browse files Browse the repository at this point in the history
* Check for duplicate domains

* address prr comments

* Add docs
  • Loading branch information
ccaraman authored Sep 1, 2016
1 parent 2bf238b commit d9a1f1e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docs/configuration/http_conn_man/route_config/vhost.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ domains
*(required, array)* A list of domains (host/authority header) that will be matched to this
virtual host. Currently, wildcard matching of the form "\*.foo.com" is not supported, however
a special entry "\*" is allowed which will match any host/authority header. Only a single virtual
host in the entire route configuration can match on "\*".
host in the entire route configuration can match on "\*". A domain must be unique across all
virtual hosts or the config will fail to load.

:ref:`routes <config_http_conn_man_route_table_route>`
*(required, array)* The list of routes that will be matched, in order, for incoming requests.
Expand Down
5 changes: 5 additions & 0 deletions source/common/router/config_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@ RouteMatcher::RouteMatcher(const Json::Object& config, Runtime::Loader& runtime,
}
default_virtual_host_ = virtual_host;
} else {
if (virtual_hosts_.find(domain) != virtual_hosts_.end()) {
throw EnvoyException(fmt::format(
"Only unique values for domains are permitted. Duplicate entry of domain {}",
domain));
}
virtual_hosts_.emplace(domain, virtual_host);
}
}
Expand Down
34 changes: 34 additions & 0 deletions test/common/router/config_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,40 @@ TEST(RouteMatcherTest, TestBadDefaultConfig) {
EXPECT_THROW(ConfigImpl config(loader, runtime, cm), EnvoyException);
}

TEST(RouteMatcherTest, TestDuplicateDomainConfig) {
std::string json = R"EOF(
{
"virtual_hosts": [
{
"name": "www2",
"domains": ["www.lyft.com"],
"routes": [
{
"prefix": "/",
"cluster": "www2"
}
]
},
{
"name": "www2_staging",
"domains": ["www.lyft.com"],
"routes": [
{
"prefix": "/",
"cluster": "www2_staging"
}
]
}
]
}
)EOF";

Json::StringLoader loader(json);
NiceMock<Runtime::MockLoader> runtime;
NiceMock<Upstream::MockClusterManager> cm;
EXPECT_THROW(ConfigImpl config(loader, runtime, cm), EnvoyException);
}

static Http::HeaderMapImpl genRedirectHeaders(const std::string& host, const std::string& path,
bool ssl, bool internal) {
Http::HeaderMapImpl headers{
Expand Down

0 comments on commit d9a1f1e

Please sign in to comment.