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 2 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
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