Skip to content

Commit

Permalink
Add test for redirect response from route configuration.
Browse files Browse the repository at this point in the history
Signed-off-by: Constance Caramanolis <ccaramanolis@lyft.com>
  • Loading branch information
ccaraman committed Nov 9, 2017
1 parent 6e3a49c commit 13ced5b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion source/common/router/config_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ RouteMatcher::RouteMatcher(const envoy::api::v2::RouteConfiguration& route_confi
for (const std::string& domain : virtual_host_config.domains()) {
if ("*" == domain) {
if (default_virtual_host_) {
throw EnvoyException(fmt::format("Only a single single wildcard domain is permitted"));
throw EnvoyException(fmt::format("Only a single wildcard domain is permitted"));
}
default_virtual_host_ = virtual_host;
} else if (domain.size() > 0 && '*' == domain[0]) {
Expand Down
33 changes: 33 additions & 0 deletions test/common/router/config_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ envoy::api::v2::RouteConfiguration parseRouteConfigurationFromJson(const std::st
return route_config;
}

envoy::api::v2::RouteConfiguration parseRouteConfigurationFromV2Yaml(const std::string& yaml) {
envoy::api::v2::RouteConfiguration route_config;
MessageUtil::loadFromYaml(yaml, route_config);
return route_config;
}

TEST(RouteMatcherTest, TestRoutes) {
std::string json = R"EOF(
{
Expand Down Expand Up @@ -2942,6 +2948,33 @@ TEST(ConfigUtility, ParseResponseCode) {
}
}

TEST(RouteConfigurationV2, RedirectCode) {
std::string yaml = R"EOF(
name: foo
virtual_hosts:
- name: redirect
domains: [redirect.lyft.com]
routes:
- match: { prefix: "/"}
redirect: { host_redirect: new.lyft.com, response_code: TEMPORARY_REDIRECT }
)EOF";

NiceMock<Runtime::MockLoader> runtime;
NiceMock<Upstream::MockClusterManager> cm;
ConfigImpl config(parseRouteConfigurationFromV2Yaml(yaml), runtime, cm, true);

EXPECT_EQ(nullptr, config.route(genRedirectHeaders("www.foo.com", "/foo", true, true), 0));

{
Http::TestHeaderMapImpl headers = genRedirectHeaders("redirect.lyft.com", "/foo", false, false);
EXPECT_EQ("http://new.lyft.com/foo",
config.route(headers, 0)->redirectEntry()->newPath(headers));
EXPECT_EQ(Http::Code::TemporaryRedirect,
config.route(headers, 0)->redirectEntry()->redirectResponseCode());
}
}

} // namespace
} // namespace Router
} // namespace Envoy

0 comments on commit 13ced5b

Please sign in to comment.