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

router_check_tool: fix ASSERT in path_rewrite test #7106

Merged
merged 2 commits into from
May 31, 2019
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
18 changes: 14 additions & 4 deletions test/tools/router_check/router.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ bool RouterCheckTool::compareEntriesInJson(const std::string& expected_route_jso

bool no_failures = true;
for (const Json::ObjectSharedPtr& check_config : loader->asObjectArray()) {
headers_finalized_ = false;
ToolConfig tool_config = ToolConfig::create(check_config);
tool_config.route_ = config_->route(*tool_config.headers_, tool_config.random_value_);

Expand Down Expand Up @@ -164,6 +165,7 @@ bool RouterCheckTool::compareEntries(const std::string& expected_routes) {
bool no_failures = true;
for (const envoy::RouterCheckToolSchema::ValidationItem& check_config :
validation_config.tests()) {
headers_finalized_ = false;
ToolConfig tool_config = ToolConfig::create(check_config);
tool_config.route_ = config_->route(*tool_config.headers_, tool_config.random_value_);

Expand Down Expand Up @@ -265,8 +267,12 @@ bool RouterCheckTool::compareRewritePath(ToolConfig& tool_config, const std::str
Envoy::StreamInfo::StreamInfoImpl stream_info(Envoy::Http::Protocol::Http11,
factory_context_->dispatcher().timeSource());
if (tool_config.route_->routeEntry() != nullptr) {
tool_config.route_->routeEntry()->finalizeRequestHeaders(*tool_config.headers_, stream_info,
true);
if (!headers_finalized_) {
tool_config.route_->routeEntry()->finalizeRequestHeaders(*tool_config.headers_, stream_info,
true);
headers_finalized_ = true;
}

actual = tool_config.headers_->get_(Http::Headers::get().Path);
}
return compareResults(actual, expected, "path_rewrite");
Expand All @@ -288,8 +294,12 @@ bool RouterCheckTool::compareRewriteHost(ToolConfig& tool_config, const std::str
Envoy::StreamInfo::StreamInfoImpl stream_info(Envoy::Http::Protocol::Http11,
factory_context_->dispatcher().timeSource());
if (tool_config.route_->routeEntry() != nullptr) {
tool_config.route_->routeEntry()->finalizeRequestHeaders(*tool_config.headers_, stream_info,
true);
if (!headers_finalized_) {
tool_config.route_->routeEntry()->finalizeRequestHeaders(*tool_config.headers_, stream_info,
true);
headers_finalized_ = true;
}

actual = tool_config.headers_->get_(Http::Headers::get().Host);
}
return compareResults(actual, expected, "host_rewrite");
Expand Down
2 changes: 2 additions & 0 deletions test/tools/router_check/router.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ class RouterCheckTool : Logger::Loggable<Logger::Id::testing> {
bool compareResults(const std::string& actual, const std::string& expected,
const std::string& test_type);

bool headers_finalized_{false};

bool details_{false};

// TODO(hennna): Switch away from mocks following work done by @rlazarus in github issue #499.
Expand Down
28 changes: 28 additions & 0 deletions test/tools/router_check/test/config/Redirect.golden.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,33 @@
"internal": false
},
"validate": {"path_redirect": "https://new.lyft.com/new_baz"}
},
{
"test_name": "Test_9",
"input": {
":authority": "api.lyft.com",
":path": "/pretest",
"ssl": true
},
"validate": {
"host_rewrite": "api.lyft.com",
"virtual_host_name": "api",
"path_rewrite": "/pre/test",
"cluster_name": "www2"
}
},
{
"test_name": "Test_10",
"input": {
":authority": "api.lyft.com",
":path": "/secondtest",
"ssl": true
},
"validate": {
"host_rewrite": "api.lyft.com",
"virtual_host_name": "api",
"path_rewrite": "/second/test",
"cluster_name": "www2"
}
}
]
30 changes: 30 additions & 0 deletions test/tools/router_check/test/config/Redirect.golden.proto.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,36 @@
"internal": false
},
"validate": {"path_redirect": "https://new.lyft.com/new_baz"}
},
{
"test_name": "Test_9",
"input": {
"authority": "api.lyft.com",
"path": "/pretest",
"method": "GET",
"ssl": true
},
"validate": {
"host_rewrite": "api.lyft.com",
"virtual_host_name": "api",
"path_rewrite": "/pre/test",
"cluster_name": "www2"
}
},
{
"test_name": "Test_9",
"input": {
"authority": "api.lyft.com",
"path": "/secondtest",
"method": "GET",
"ssl": true
},
"validate": {
"host_rewrite": "api.lyft.com",
"virtual_host_name": "api",
"path_rewrite": "/second/test",
"cluster_name": "www2"
}
}
]
}
11 changes: 10 additions & 1 deletion test/tools/router_check/test/config/Redirect.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ virtual_hosts:
- api.lyft.com
require_tls: EXTERNAL_ONLY
routes:
- match:
prefix: /pretest
route:
prefix_rewrite: /pre/test
cluster: www2
- match:
prefix: /secondtest
route:
prefix_rewrite: /second/test
cluster: www2
- match:
prefix: /
route:
Expand All @@ -25,7 +35,6 @@ virtual_hosts:
prefix: /foo
redirect:
host_redirect: new.lyft.com

- match:
prefix: /bar
redirect:
Expand Down