Skip to content

Commit

Permalink
kill_request: Use RELEASE_ASSERT instead of raise(SIGABRT) in kill_re…
Browse files Browse the repository at this point in the history
…quest filter (envoyproxy#15999)

Signed-off-by: [email protected] <[email protected]>
Signed-off-by: Gokul Nair <[email protected]>
  • Loading branch information
qqustc authored and Gokul Nair committed May 6, 2021
1 parent 5cc5f04 commit b72b599
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Http::FilterHeadersStatus KillRequestFilter::decodeHeaders(Http::RequestHeaderMa

if (is_kill_request && is_correct_direction && isKillRequestEnabled()) {
// Crash Envoy.
raise(SIGABRT);
RELEASE_ASSERT(false, "KillRequestFilter is crashing Envoy!!!");
}

return Http::FilterHeadersStatus::Continue;
Expand All @@ -81,7 +81,7 @@ Http::FilterHeadersStatus KillRequestFilter::encodeHeaders(Http::ResponseHeaderM

if (isKillRequest(headers) && isKillRequestEnabled()) {
// Crash Envoy.
raise(SIGABRT);
RELEASE_ASSERT(false, "KillRequestFilter is crashing Envoy!!!");
}

return Http::FilterHeadersStatus::Continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ TEST_P(KillRequestFilterIntegrationTestAllProtocols, KillRequestCrashEnvoy) {
{"x-envoy-kill-request", "true"}};

EXPECT_DEATH(sendRequestAndWaitForResponse(request_headers, 0, default_response_headers_, 1024),
"");
"KillRequestFilter is crashing Envoy!!!");
}

// Request crash Envoy controlled via response.
Expand All @@ -70,7 +70,8 @@ TEST_P(KillRequestFilterIntegrationTestAllProtocols, KillRequestCrashEnvoyOnResp
Http::TestResponseHeaderMapImpl kill_response_headers = default_response_headers_;
kill_response_headers.addCopy("x-envoy-kill-request", "true");

EXPECT_DEATH(sendRequestAndWaitForResponse(request_headers, 0, kill_response_headers, 1024), "");
EXPECT_DEATH(sendRequestAndWaitForResponse(request_headers, 0, kill_response_headers, 1024),
"KillRequestFilter is crashing Envoy!!!");
}

TEST_P(KillRequestFilterIntegrationTestAllProtocols, KillRequestCrashEnvoyWithCustomKillHeader) {
Expand All @@ -93,7 +94,7 @@ name: envoy.filters.http.kill_request
{"x-custom-kill-request", "true"}};

EXPECT_DEATH(sendRequestAndWaitForResponse(request_headers, 0, default_response_headers_, 1024),
"");
"KillRequestFilter is crashing Envoy!!!");
}

TEST_P(KillRequestFilterIntegrationTestAllProtocols, KillRequestDisabledWhenHeaderIsMissing) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ TEST_F(KillRequestFilterTest, KillRequestCrashEnvoy) {
request_headers_.addCopy("x-envoy-kill-request", "true");

ON_CALL(random_generator_, random()).WillByDefault(Return(0));
EXPECT_DEATH(filter_->decodeHeaders(request_headers_, false), "");
EXPECT_DEATH(filter_->decodeHeaders(request_headers_, false),
"KillRequestFilter is crashing Envoy!!!");
}

TEST_F(KillRequestFilterTest, KillRequestCrashEnvoyWithCustomKillHeader) {
Expand All @@ -59,7 +60,8 @@ TEST_F(KillRequestFilterTest, KillRequestCrashEnvoyWithCustomKillHeader) {
request_headers_.addCopy("x-custom-kill-request", "true");

ON_CALL(random_generator_, random()).WillByDefault(Return(0));
EXPECT_DEATH(filter_->decodeHeaders(request_headers_, false), "");
EXPECT_DEATH(filter_->decodeHeaders(request_headers_, false),
"KillRequestFilter is crashing Envoy!!!");
}

TEST_F(KillRequestFilterTest, KillRequestWithMillionDenominatorCrashEnvoy) {
Expand All @@ -70,7 +72,8 @@ TEST_F(KillRequestFilterTest, KillRequestWithMillionDenominatorCrashEnvoy) {
request_headers_.addCopy("x-envoy-kill-request", "yes");

ON_CALL(random_generator_, random()).WillByDefault(Return(0));
EXPECT_DEATH(filter_->decodeHeaders(request_headers_, false), "");
EXPECT_DEATH(filter_->decodeHeaders(request_headers_, false),
"KillRequestFilter is crashing Envoy!!!");
}

TEST_F(KillRequestFilterTest, KillRequestDisabledWhenIsKillRequestEnabledReturnsFalse) {
Expand Down Expand Up @@ -184,7 +187,8 @@ TEST_F(KillRequestFilterTest, CanKillOnResponse) {
// We should crash on the OUTBOUND request
ON_CALL(random_generator_, random()).WillByDefault(Return(0));
response_headers_.addCopy("x-envoy-kill-request", "true");
EXPECT_DEATH(filter_->encodeHeaders(response_headers_, false), "");
EXPECT_DEATH(filter_->encodeHeaders(response_headers_, false),
"KillRequestFilter is crashing Envoy!!!");
}

TEST_F(KillRequestFilterTest, KillsBasedOnDirection) {
Expand All @@ -201,7 +205,8 @@ TEST_F(KillRequestFilterTest, KillsBasedOnDirection) {
// We should crash on the RESPONSE kill request
ON_CALL(random_generator_, random()).WillByDefault(Return(0));
response_headers_.addCopy("x-envoy-kill-request", "true");
EXPECT_DEATH(filter_->encodeHeaders(response_headers_, false), "");
EXPECT_DEATH(filter_->encodeHeaders(response_headers_, false),
"KillRequestFilter is crashing Envoy!!!");
}

} // namespace
Expand Down

0 comments on commit b72b599

Please sign in to comment.