Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for duplicate domains #50

Merged
merged 3 commits into from
Sep 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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