diff --git a/source/extensions/filters/http/cors/BUILD b/source/extensions/filters/http/cors/BUILD index 5aefb9449c43..4790eb885cf0 100644 --- a/source/extensions/filters/http/cors/BUILD +++ b/source/extensions/filters/http/cors/BUILD @@ -25,6 +25,7 @@ envoy_cc_library( "//source/common/http:header_map_lib", "//source/common/http:headers_lib", "//source/common/http:utility_lib", + "//source/extensions/filters/http/common:pass_through_filter_lib", "@com_google_absl//absl/container:inlined_vector", ], ) diff --git a/source/extensions/filters/http/cors/cors_filter.cc b/source/extensions/filters/http/cors/cors_filter.cc index 7fb1b78bba73..bb0db480d407 100644 --- a/source/extensions/filters/http/cors/cors_filter.cc +++ b/source/extensions/filters/http/cors/cors_filter.cc @@ -206,10 +206,6 @@ Http::FilterHeadersStatus CorsFilter::encodeHeaders(Http::ResponseHeaderMap& hea return Http::FilterHeadersStatus::Continue; } -void CorsFilter::setDecoderFilterCallbacks(Http::StreamDecoderFilterCallbacks& callbacks) { - decoder_callbacks_ = &callbacks; -} - bool CorsFilter::isOriginAllowed(const Http::HeaderString& origin) { for (const auto& allow_origin : allowOrigins()) { if (allow_origin->match("*") || allow_origin->match(origin.getStringView())) { diff --git a/source/extensions/filters/http/cors/cors_filter.h b/source/extensions/filters/http/cors/cors_filter.h index a89a488b3f64..1a3bfc5b6426 100644 --- a/source/extensions/filters/http/cors/cors_filter.h +++ b/source/extensions/filters/http/cors/cors_filter.h @@ -5,6 +5,7 @@ #include "envoy/stats/stats_macros.h" #include "source/common/buffer/buffer_impl.h" +#include "source/extensions/filters/http/common/pass_through_filter.h" #include "absl/container/inlined_vector.h" @@ -44,44 +45,19 @@ class CorsFilterConfig { }; using CorsFilterConfigSharedPtr = std::shared_ptr; -class CorsFilter : public Http::StreamFilter { +class CorsFilter : public Http::PassThroughFilter { public: CorsFilter(CorsFilterConfigSharedPtr config); void initializeCorsPolicies(); - // Http::StreamFilterBase - void onDestroy() override {} - // Http::StreamDecoderFilter Http::FilterHeadersStatus decodeHeaders(Http::RequestHeaderMap& headers, bool end_stream) override; - Http::FilterDataStatus decodeData(Buffer::Instance&, bool) override { - return Http::FilterDataStatus::Continue; - }; - Http::FilterTrailersStatus decodeTrailers(Http::RequestTrailerMap&) override { - return Http::FilterTrailersStatus::Continue; - }; - void setDecoderFilterCallbacks(Http::StreamDecoderFilterCallbacks& callbacks) override; // Http::StreamEncoderFilter - Http::Filter1xxHeadersStatus encode1xxHeaders(Http::ResponseHeaderMap&) override { - return Http::Filter1xxHeadersStatus::Continue; - } Http::FilterHeadersStatus encodeHeaders(Http::ResponseHeaderMap& headers, bool end_stream) override; - Http::FilterDataStatus encodeData(Buffer::Instance&, bool) override { - return Http::FilterDataStatus::Continue; - }; - Http::FilterTrailersStatus encodeTrailers(Http::ResponseTrailerMap&) override { - return Http::FilterTrailersStatus::Continue; - }; - Http::FilterMetadataStatus encodeMetadata(Http::MetadataMap&) override { - return Http::FilterMetadataStatus::Continue; - } - void setEncoderFilterCallbacks(Http::StreamEncoderFilterCallbacks& callbacks) override { - encoder_callbacks_ = &callbacks; - }; const auto& policiesForTest() const { return policies_; } @@ -100,8 +76,6 @@ class CorsFilter : public Http::StreamFilter { bool isOriginAllowed(const Http::HeaderString& origin); bool forwardNotMatchingPreflights(); - Http::StreamDecoderFilterCallbacks* decoder_callbacks_{}; - Http::StreamEncoderFilterCallbacks* encoder_callbacks_{}; absl::InlinedVector, 4> policies_; bool is_cors_request_{}; std::string latched_origin_; diff --git a/test/extensions/filters/http/cors/cors_filter_test.cc b/test/extensions/filters/http/cors/cors_filter_test.cc index 17c1c5818d9f..5d960f6f6fd6 100644 --- a/test/extensions/filters/http/cors/cors_filter_test.cc +++ b/test/extensions/filters/http/cors/cors_filter_test.cc @@ -43,7 +43,9 @@ Matchers::StringMatcherPtr makeStdRegexStringMatcher(const std::string& regex) { class CorsFilterTest : public testing::Test { public: - CorsFilterTest() : config_(new CorsFilterConfig("test.", *stats_.rootScope())), filter_(config_) { + CorsFilterTest() + : config_(new CorsFilterConfig("test.", *stats_.rootScope())), + filter_(std::make_shared(config_)) { cors_policy_ = std::make_unique(); cors_policy_->enabled_ = true; cors_policy_->shadow_enabled_ = false; @@ -60,17 +62,17 @@ class CorsFilterTest : public testing::Test { return {cors_policy_.get(), cors_policy_.get()}; })); - filter_.setDecoderFilterCallbacks(decoder_callbacks_); - filter_.setEncoderFilterCallbacks(encoder_callbacks_); + filter_->setDecoderFilterCallbacks(decoder_callbacks_); + filter_->setEncoderFilterCallbacks(encoder_callbacks_); } - bool isCorsRequest() { return filter_.is_cors_request_; } + bool isCorsRequest() { return filter_->is_cors_request_; } NiceMock decoder_callbacks_; NiceMock encoder_callbacks_; Stats::TestUtil::TestStore stats_; CorsFilterConfigSharedPtr config_; - CorsFilter filter_; + std::shared_ptr filter_; Buffer::OwnedImpl data_; Http::TestRequestHeaderMapImpl request_headers_; Http::TestRequestTrailerMapImpl request_trailers_; @@ -84,34 +86,34 @@ TEST_F(CorsFilterTest, InitializeCorsPoliciesTest) { Http::TestRequestHeaderMapImpl request_headers{{":method", "get"}}; // Cors policies in the 'typed_per_filter_config'. { - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.decodeHeaders(request_headers, true)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->decodeHeaders(request_headers, true)); EXPECT_EQ(false, isCorsRequest()); - EXPECT_EQ(2, filter_.policiesForTest().size()); - EXPECT_EQ(cors_policy_.get(), &filter_.policiesForTest().at(0).get()); - EXPECT_EQ(cors_policy_.get(), &filter_.policiesForTest().at(1).get()); + EXPECT_EQ(2, filter_->policiesForTest().size()); + EXPECT_EQ(cors_policy_.get(), &filter_->policiesForTest().at(0).get()); + EXPECT_EQ(cors_policy_.get(), &filter_->policiesForTest().at(1).get()); } // Only 'typed_per_filter_config' of virtual host has cors policy. { - filter_ = CorsFilter(config_); - filter_.setDecoderFilterCallbacks(decoder_callbacks_); - filter_.setEncoderFilterCallbacks(encoder_callbacks_); + filter_ = std::make_shared(config_); + filter_->setDecoderFilterCallbacks(decoder_callbacks_); + filter_->setEncoderFilterCallbacks(encoder_callbacks_); ON_CALL(decoder_callbacks_, perFilterConfigs()) .WillByDefault(Invoke( [this]() -> Router::RouteSpecificFilterConfigs { return {cors_policy_.get()}; })); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.decodeHeaders(request_headers, true)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->decodeHeaders(request_headers, true)); EXPECT_EQ(false, isCorsRequest()); - EXPECT_EQ(1, filter_.policiesForTest().size()); - EXPECT_EQ(cors_policy_.get(), &filter_.policiesForTest().at(0).get()); + EXPECT_EQ(1, filter_->policiesForTest().size()); + EXPECT_EQ(cors_policy_.get(), &filter_->policiesForTest().at(0).get()); } // No cors policy in the 'typed_per_filter_config'. { - filter_ = CorsFilter(config_); - filter_.setDecoderFilterCallbacks(decoder_callbacks_); - filter_.setEncoderFilterCallbacks(encoder_callbacks_); + filter_ = std::make_shared(config_); + filter_->setDecoderFilterCallbacks(decoder_callbacks_); + filter_->setEncoderFilterCallbacks(encoder_callbacks_); EXPECT_CALL(decoder_callbacks_.route_->route_entry_, corsPolicy()).WillOnce(Return(nullptr)); EXPECT_CALL(decoder_callbacks_.route_->virtual_host_, corsPolicy()).WillOnce(Return(nullptr)); @@ -119,14 +121,14 @@ TEST_F(CorsFilterTest, InitializeCorsPoliciesTest) { ON_CALL(decoder_callbacks_, perFilterConfigs()) .WillByDefault(Invoke([]() -> Router::RouteSpecificFilterConfigs { return {}; })); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.decodeHeaders(request_headers, true)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->decodeHeaders(request_headers, true)); EXPECT_EQ(false, isCorsRequest()); - EXPECT_EQ(0, filter_.policiesForTest().size()); + EXPECT_EQ(0, filter_->policiesForTest().size()); } { - filter_ = CorsFilter(config_); - filter_.setDecoderFilterCallbacks(decoder_callbacks_); - filter_.setEncoderFilterCallbacks(encoder_callbacks_); + filter_ = std::make_shared(config_); + filter_->setDecoderFilterCallbacks(decoder_callbacks_); + filter_->setEncoderFilterCallbacks(encoder_callbacks_); EXPECT_CALL(decoder_callbacks_.route_->route_entry_, corsPolicy()) .WillOnce(Return(cors_policy_.get())); @@ -135,15 +137,15 @@ TEST_F(CorsFilterTest, InitializeCorsPoliciesTest) { ON_CALL(decoder_callbacks_, perFilterConfigs()) .WillByDefault(Invoke([]() -> Router::RouteSpecificFilterConfigs { return {}; })); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.decodeHeaders(request_headers, true)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->decodeHeaders(request_headers, true)); EXPECT_EQ(false, isCorsRequest()); - EXPECT_EQ(1, filter_.policiesForTest().size()); - EXPECT_EQ(cors_policy_.get(), &filter_.policiesForTest().at(0).get()); + EXPECT_EQ(1, filter_->policiesForTest().size()); + EXPECT_EQ(cors_policy_.get(), &filter_->policiesForTest().at(0).get()); } { - filter_ = CorsFilter(config_); - filter_.setDecoderFilterCallbacks(decoder_callbacks_); - filter_.setEncoderFilterCallbacks(encoder_callbacks_); + filter_ = std::make_shared(config_); + filter_->setDecoderFilterCallbacks(decoder_callbacks_); + filter_->setEncoderFilterCallbacks(encoder_callbacks_); EXPECT_CALL(decoder_callbacks_.route_->route_entry_, corsPolicy()).WillOnce(Return(nullptr)); EXPECT_CALL(decoder_callbacks_.route_->virtual_host_, corsPolicy()) @@ -152,10 +154,10 @@ TEST_F(CorsFilterTest, InitializeCorsPoliciesTest) { ON_CALL(decoder_callbacks_, perFilterConfigs()) .WillByDefault(Invoke([]() -> Router::RouteSpecificFilterConfigs { return {}; })); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.decodeHeaders(request_headers, false)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->decodeHeaders(request_headers, false)); EXPECT_EQ(false, isCorsRequest()); - EXPECT_EQ(1, filter_.policiesForTest().size()); - EXPECT_EQ(cors_policy_.get(), &filter_.policiesForTest().at(0).get()); + EXPECT_EQ(1, filter_->policiesForTest().size()); + EXPECT_EQ(cors_policy_.get(), &filter_->policiesForTest().at(0).get()); } } @@ -163,66 +165,66 @@ TEST_F(CorsFilterTest, RequestWithoutOrigin) { Http::TestRequestHeaderMapImpl request_headers{{":method", "get"}}; EXPECT_CALL(decoder_callbacks_, encodeHeaders_(_, false)).Times(0); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.decodeHeaders(request_headers, false)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->decodeHeaders(request_headers, false)); EXPECT_EQ(false, isCorsRequest()); EXPECT_EQ(0, stats_.counter("test.cors.origin_invalid").value()); EXPECT_EQ(0, stats_.counter("test.cors.origin_valid").value()); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.decodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.decodeTrailers(request_trailers_)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->decodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->decodeTrailers(request_trailers_)); Http::MetadataMap metadata_map{{"metadata", "metadata"}}; - EXPECT_EQ(Http::FilterMetadataStatus::Continue, filter_.decodeMetadata(metadata_map)); + EXPECT_EQ(Http::FilterMetadataStatus::Continue, filter_->decodeMetadata(metadata_map)); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.encodeHeaders(response_headers_, false)); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.encodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.encodeTrailers(response_trailers_)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->encodeHeaders(response_headers_, false)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->encodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->encodeTrailers(response_trailers_)); } TEST_F(CorsFilterTest, RequestWithOrigin) { Http::TestRequestHeaderMapImpl request_headers{{":method", "get"}, {"origin", "localhost"}}; EXPECT_CALL(decoder_callbacks_, encodeHeaders_(_, false)).Times(0); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.decodeHeaders(request_headers, false)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->decodeHeaders(request_headers, false)); EXPECT_EQ(true, isCorsRequest()); EXPECT_EQ(0, stats_.counter("test.cors.origin_invalid").value()); EXPECT_EQ(1, stats_.counter("test.cors.origin_valid").value()); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.decodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.decodeTrailers(request_trailers_)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->decodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->decodeTrailers(request_trailers_)); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.encodeHeaders(response_headers_, false)); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.encodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.encodeTrailers(response_trailers_)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->encodeHeaders(response_headers_, false)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->encodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->encodeTrailers(response_trailers_)); } TEST_F(CorsFilterTest, OptionsRequestWithoutOrigin) { Http::TestRequestHeaderMapImpl request_headers{{":method", "OPTIONS"}}; EXPECT_CALL(decoder_callbacks_, encodeHeaders_(_, false)).Times(0); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.decodeHeaders(request_headers, false)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->decodeHeaders(request_headers, false)); EXPECT_EQ(false, isCorsRequest()); EXPECT_EQ(0, stats_.counter("test.cors.origin_invalid").value()); EXPECT_EQ(0, stats_.counter("test.cors.origin_valid").value()); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.decodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.decodeTrailers(request_trailers_)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->decodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->decodeTrailers(request_trailers_)); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.encodeHeaders(response_headers_, false)); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.encodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.encodeTrailers(response_trailers_)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->encodeHeaders(response_headers_, false)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->encodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->encodeTrailers(response_trailers_)); } TEST_F(CorsFilterTest, OptionsRequestWithOrigin) { Http::TestRequestHeaderMapImpl request_headers{{":method", "OPTIONS"}, {"origin", "localhost"}}; EXPECT_CALL(decoder_callbacks_, encodeHeaders_(_, false)).Times(0); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.decodeHeaders(request_headers, false)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->decodeHeaders(request_headers, false)); EXPECT_EQ(true, isCorsRequest()); EXPECT_EQ(0, stats_.counter("test.cors.origin_invalid").value()); EXPECT_EQ(1, stats_.counter("test.cors.origin_valid").value()); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.decodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.decodeTrailers(request_trailers_)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->decodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->decodeTrailers(request_trailers_)); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.encodeHeaders(response_headers_, false)); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.encodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.encodeTrailers(response_trailers_)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->encodeHeaders(response_headers_, false)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->encodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->encodeTrailers(response_trailers_)); } TEST_F(CorsFilterTest, OptionsRequestWithOriginCorsDisabled) { @@ -231,16 +233,16 @@ TEST_F(CorsFilterTest, OptionsRequestWithOriginCorsDisabled) { cors_policy_->enabled_ = false; EXPECT_CALL(decoder_callbacks_, encodeHeaders_(_, false)).Times(0); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.decodeHeaders(request_headers, false)); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.decodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.decodeTrailers(request_trailers_)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->decodeHeaders(request_headers, false)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->decodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->decodeTrailers(request_trailers_)); EXPECT_EQ(0, stats_.counter("test.cors.origin_invalid").value()); EXPECT_EQ(0, stats_.counter("test.cors.origin_valid").value()); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.encodeHeaders(response_headers_, false)); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.encodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.encodeTrailers(response_trailers_)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->encodeHeaders(response_headers_, false)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->encodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->encodeTrailers(response_trailers_)); } TEST_F(CorsFilterTest, OptionsRequestWithOriginCorsDisabledShadowDisabled) { @@ -249,16 +251,16 @@ TEST_F(CorsFilterTest, OptionsRequestWithOriginCorsDisabledShadowDisabled) { cors_policy_->enabled_ = false; EXPECT_CALL(decoder_callbacks_, encodeHeaders_(_, false)).Times(0); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.decodeHeaders(request_headers, false)); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.decodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.decodeTrailers(request_trailers_)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->decodeHeaders(request_headers, false)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->decodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->decodeTrailers(request_trailers_)); EXPECT_EQ(0, stats_.counter("test.cors.origin_invalid").value()); EXPECT_EQ(0, stats_.counter("test.cors.origin_valid").value()); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.encodeHeaders(response_headers_, false)); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.encodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.encodeTrailers(response_trailers_)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->encodeHeaders(response_headers_, false)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->encodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->encodeTrailers(response_trailers_)); } TEST_F(CorsFilterTest, OptionsRequestWithOriginCorsDisabledShadowEnabled) { @@ -268,48 +270,48 @@ TEST_F(CorsFilterTest, OptionsRequestWithOriginCorsDisabledShadowEnabled) { cors_policy_->shadow_enabled_ = true; EXPECT_CALL(decoder_callbacks_, encodeHeaders_(_, false)).Times(0); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.decodeHeaders(request_headers, false)); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.decodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.decodeTrailers(request_trailers_)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->decodeHeaders(request_headers, false)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->decodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->decodeTrailers(request_trailers_)); EXPECT_EQ(0, stats_.counter("test.cors.origin_invalid").value()); EXPECT_EQ(1, stats_.counter("test.cors.origin_valid").value()); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.encodeHeaders(response_headers_, false)); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.encodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.encodeTrailers(response_trailers_)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->encodeHeaders(response_headers_, false)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->encodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->encodeTrailers(response_trailers_)); } TEST_F(CorsFilterTest, OptionsRequestWithOriginCorsEnabled) { Http::TestRequestHeaderMapImpl request_headers{{":method", "OPTIONS"}, {"origin", "localhost"}}; EXPECT_CALL(decoder_callbacks_, encodeHeaders_(_, false)).Times(0); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.decodeHeaders(request_headers, false)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->decodeHeaders(request_headers, false)); EXPECT_EQ(true, isCorsRequest()); EXPECT_EQ(0, stats_.counter("test.cors.origin_invalid").value()); EXPECT_EQ(1, stats_.counter("test.cors.origin_valid").value()); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.decodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.decodeTrailers(request_trailers_)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->decodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->decodeTrailers(request_trailers_)); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.encodeHeaders(response_headers_, false)); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.encodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.encodeTrailers(response_trailers_)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->encodeHeaders(response_headers_, false)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->encodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->encodeTrailers(response_trailers_)); } TEST_F(CorsFilterTest, OptionsRequestWithoutAccessRequestMethod) { Http::TestRequestHeaderMapImpl request_headers{{":method", "OPTIONS"}, {"origin", "localhost"}}; EXPECT_CALL(decoder_callbacks_, encodeHeaders_(_, false)).Times(0); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.decodeHeaders(request_headers, false)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->decodeHeaders(request_headers, false)); EXPECT_EQ(true, isCorsRequest()); EXPECT_EQ(0, stats_.counter("test.cors.origin_invalid").value()); EXPECT_EQ(1, stats_.counter("test.cors.origin_valid").value()); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.decodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.decodeTrailers(request_trailers_)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->decodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->decodeTrailers(request_trailers_)); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.encodeHeaders(response_headers_, false)); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.encodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.encodeTrailers(response_trailers_)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->encodeHeaders(response_headers_, false)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->encodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->encodeTrailers(response_trailers_)); } TEST_F(CorsFilterTest, OptionsRequestMatchingOriginByWildcard) { @@ -326,16 +328,16 @@ TEST_F(CorsFilterTest, OptionsRequestMatchingOriginByWildcard) { EXPECT_CALL(decoder_callbacks_, encodeHeaders_(HeaderMapEqualRef(&response_headers), true)); EXPECT_EQ(Http::FilterHeadersStatus::StopIteration, - filter_.decodeHeaders(request_headers, false)); + filter_->decodeHeaders(request_headers, false)); EXPECT_EQ(true, isCorsRequest()); EXPECT_EQ(0, stats_.counter("test.cors.origin_invalid").value()); EXPECT_EQ(1, stats_.counter("test.cors.origin_valid").value()); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.decodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.decodeTrailers(request_trailers_)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->decodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->decodeTrailers(request_trailers_)); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.encodeHeaders(response_headers_, false)); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.encodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.encodeTrailers(response_trailers_)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->encodeHeaders(response_headers_, false)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->encodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->encodeTrailers(response_trailers_)); ASSERT_TRUE(decoder_callbacks_.stream_info_.responseCodeDetails().has_value()); EXPECT_EQ(decoder_callbacks_.stream_info_.responseCodeDetails().value(), "cors_response"); } @@ -356,16 +358,16 @@ TEST_F(CorsFilterTest, OptionsRequestWithOriginCorsEnabledShadowDisabled) { EXPECT_CALL(decoder_callbacks_, encodeHeaders_(HeaderMapEqualRef(&response_headers), true)); EXPECT_EQ(Http::FilterHeadersStatus::StopIteration, - filter_.decodeHeaders(request_headers, false)); + filter_->decodeHeaders(request_headers, false)); EXPECT_EQ(true, isCorsRequest()); EXPECT_EQ(0, stats_.counter("test.cors.origin_invalid").value()); EXPECT_EQ(1, stats_.counter("test.cors.origin_valid").value()); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.decodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.decodeTrailers(request_trailers_)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->decodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->decodeTrailers(request_trailers_)); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.encodeHeaders(response_headers_, false)); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.encodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.encodeTrailers(response_trailers_)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->encodeHeaders(response_headers_, false)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->encodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->encodeTrailers(response_trailers_)); } TEST_F(CorsFilterTest, OptionsRequestWithOriginCorsEnabledShadowEnabled) { @@ -384,16 +386,16 @@ TEST_F(CorsFilterTest, OptionsRequestWithOriginCorsEnabledShadowEnabled) { EXPECT_CALL(decoder_callbacks_, encodeHeaders_(HeaderMapEqualRef(&response_headers), true)); EXPECT_EQ(Http::FilterHeadersStatus::StopIteration, - filter_.decodeHeaders(request_headers, false)); + filter_->decodeHeaders(request_headers, false)); EXPECT_EQ(true, isCorsRequest()); EXPECT_EQ(0, stats_.counter("test.cors.origin_invalid").value()); EXPECT_EQ(1, stats_.counter("test.cors.origin_valid").value()); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.decodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.decodeTrailers(request_trailers_)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->decodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->decodeTrailers(request_trailers_)); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.encodeHeaders(response_headers_, false)); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.encodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.encodeTrailers(response_trailers_)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->encodeHeaders(response_headers_, false)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->encodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->encodeTrailers(response_trailers_)); } TEST_F(CorsFilterTest, OptionsRequestNotMatchingOrigin) { @@ -404,16 +406,16 @@ TEST_F(CorsFilterTest, OptionsRequestNotMatchingOrigin) { cors_policy_->allow_origins_.emplace_back(makeExactStringMatcher("localhost")); EXPECT_CALL(decoder_callbacks_, encodeHeaders_(_, false)).Times(0); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.decodeHeaders(request_headers, false)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->decodeHeaders(request_headers, false)); EXPECT_EQ(true, isCorsRequest()); EXPECT_EQ(1, stats_.counter("test.cors.origin_invalid").value()); EXPECT_EQ(0, stats_.counter("test.cors.origin_valid").value()); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.decodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.decodeTrailers(request_trailers_)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->decodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->decodeTrailers(request_trailers_)); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.encodeHeaders(response_headers_, false)); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.encodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.encodeTrailers(response_trailers_)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->encodeHeaders(response_headers_, false)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->encodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->encodeTrailers(response_trailers_)); } TEST_F(CorsFilterTest, OptionsRequestNotMatchingOriginDoNotForward) { @@ -426,16 +428,16 @@ TEST_F(CorsFilterTest, OptionsRequestNotMatchingOriginDoNotForward) { EXPECT_CALL(decoder_callbacks_, encodeHeaders_(_, true)); EXPECT_EQ(Http::FilterHeadersStatus::StopIteration, - filter_.decodeHeaders(request_headers, false)); + filter_->decodeHeaders(request_headers, false)); EXPECT_EQ(true, isCorsRequest()); EXPECT_EQ(1, stats_.counter("test.cors.origin_invalid").value()); EXPECT_EQ(0, stats_.counter("test.cors.origin_valid").value()); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.decodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.decodeTrailers(request_trailers_)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->decodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->decodeTrailers(request_trailers_)); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.encodeHeaders(response_headers_, false)); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.encodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.encodeTrailers(response_trailers_)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->encodeHeaders(response_headers_, false)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->encodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->encodeTrailers(response_trailers_)); } TEST_F(CorsFilterTest, OptionsRequestEmptyOriginList) { @@ -445,16 +447,16 @@ TEST_F(CorsFilterTest, OptionsRequestEmptyOriginList) { cors_policy_->allow_origins_.clear(); EXPECT_CALL(decoder_callbacks_, encodeHeaders_(_, false)).Times(0); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.decodeHeaders(request_headers, false)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->decodeHeaders(request_headers, false)); EXPECT_EQ(true, isCorsRequest()); EXPECT_EQ(1, stats_.counter("test.cors.origin_invalid").value()); EXPECT_EQ(0, stats_.counter("test.cors.origin_valid").value()); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.decodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.decodeTrailers(request_trailers_)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->decodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->decodeTrailers(request_trailers_)); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.encodeHeaders(response_headers_, false)); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.encodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.encodeTrailers(response_trailers_)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->encodeHeaders(response_headers_, false)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->encodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->encodeTrailers(response_trailers_)); } TEST_F(CorsFilterTest, ValidOptionsRequestWithAllowCredentialsTrue) { @@ -476,16 +478,16 @@ TEST_F(CorsFilterTest, ValidOptionsRequestWithAllowCredentialsTrue) { EXPECT_CALL(decoder_callbacks_, encodeHeaders_(HeaderMapEqualRef(&response_headers), true)); EXPECT_EQ(Http::FilterHeadersStatus::StopIteration, - filter_.decodeHeaders(request_headers, false)); + filter_->decodeHeaders(request_headers, false)); EXPECT_EQ(true, isCorsRequest()); EXPECT_EQ(0, stats_.counter("test.cors.origin_invalid").value()); EXPECT_EQ(1, stats_.counter("test.cors.origin_valid").value()); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.decodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.decodeTrailers(request_trailers_)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->decodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->decodeTrailers(request_trailers_)); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.encodeHeaders(response_headers_, false)); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.encodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.encodeTrailers(response_trailers_)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->encodeHeaders(response_headers_, false)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->encodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->encodeTrailers(response_trailers_)); } TEST_F(CorsFilterTest, ValidOptionsRequestWithAllowCredentialsFalse) { @@ -502,90 +504,90 @@ TEST_F(CorsFilterTest, ValidOptionsRequestWithAllowCredentialsFalse) { EXPECT_CALL(decoder_callbacks_, encodeHeaders_(HeaderMapEqualRef(&response_headers), true)); EXPECT_EQ(Http::FilterHeadersStatus::StopIteration, - filter_.decodeHeaders(request_headers, false)); + filter_->decodeHeaders(request_headers, false)); EXPECT_EQ(true, isCorsRequest()); EXPECT_EQ(0, stats_.counter("test.cors.origin_invalid").value()); EXPECT_EQ(1, stats_.counter("test.cors.origin_valid").value()); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.decodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.decodeTrailers(request_trailers_)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->decodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->decodeTrailers(request_trailers_)); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.encodeHeaders(response_headers_, false)); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.encodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.encodeTrailers(response_trailers_)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->encodeHeaders(response_headers_, false)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->encodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->encodeTrailers(response_trailers_)); } TEST_F(CorsFilterTest, EncodeWithCorsDisabled) { cors_policy_->enabled_ = false; cors_policy_->shadow_enabled_ = false; - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.decodeHeaders(request_headers_, false)); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.decodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.decodeTrailers(request_trailers_)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->decodeHeaders(request_headers_, false)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->decodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->decodeTrailers(request_trailers_)); Http::TestResponseHeaderMapImpl response_headers{}; - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.encodeHeaders(response_headers, false)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->encodeHeaders(response_headers, false)); EXPECT_EQ("", response_headers.get_("access-control-allow-origin")); EXPECT_EQ("", response_headers.get_("access-control-allow-credentials")); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.encodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.encodeTrailers(response_trailers_)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->encodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->encodeTrailers(response_trailers_)); } TEST_F(CorsFilterTest, EncodeNonCorsRequest) { - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.decodeHeaders(request_headers_, false)); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.decodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.decodeTrailers(request_trailers_)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->decodeHeaders(request_headers_, false)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->decodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->decodeTrailers(request_trailers_)); Http::TestResponseHeaderMapImpl response_headers{}; - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.encodeHeaders(response_headers, false)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->encodeHeaders(response_headers, false)); EXPECT_EQ("", response_headers.get_("access-control-allow-origin")); EXPECT_EQ("", response_headers.get_("access-control-allow-credentials")); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.encodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.encodeTrailers(response_trailers_)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->encodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->encodeTrailers(response_trailers_)); } TEST_F(CorsFilterTest, EncodeWithAllowCredentialsTrue) { Http::TestRequestHeaderMapImpl request_headers{{"origin", "localhost"}}; cors_policy_->allow_credentials_ = true; - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.decodeHeaders(request_headers, false)); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.decodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.decodeTrailers(request_trailers_)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->decodeHeaders(request_headers, false)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->decodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->decodeTrailers(request_trailers_)); Http::TestResponseHeaderMapImpl continue_headers{{":status", "100"}}; - EXPECT_EQ(Http::Filter1xxHeadersStatus::Continue, filter_.encode1xxHeaders(continue_headers)); + EXPECT_EQ(Http::Filter1xxHeadersStatus::Continue, filter_->encode1xxHeaders(continue_headers)); Http::TestResponseHeaderMapImpl response_headers{}; - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.encodeHeaders(response_headers, false)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->encodeHeaders(response_headers, false)); EXPECT_EQ("localhost", response_headers.get_("access-control-allow-origin")); EXPECT_EQ("true", response_headers.get_("access-control-allow-credentials")); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.encodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.encodeTrailers(response_trailers_)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->encodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->encodeTrailers(response_trailers_)); } TEST_F(CorsFilterTest, EncodeWithExposeHeaders) { Http::TestRequestHeaderMapImpl request_headers{{"origin", "localhost"}}; cors_policy_->expose_headers_ = "custom-header-1"; - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.decodeHeaders(request_headers, false)); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.decodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.decodeTrailers(request_trailers_)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->decodeHeaders(request_headers, false)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->decodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->decodeTrailers(request_trailers_)); Http::TestResponseHeaderMapImpl continue_headers{{":status", "100"}}; - EXPECT_EQ(Http::Filter1xxHeadersStatus::Continue, filter_.encode1xxHeaders(continue_headers)); + EXPECT_EQ(Http::Filter1xxHeadersStatus::Continue, filter_->encode1xxHeaders(continue_headers)); Http::MetadataMap metadata_map{{"metadata", "metadata"}}; - EXPECT_EQ(Http::FilterMetadataStatus::Continue, filter_.encodeMetadata(metadata_map)); + EXPECT_EQ(Http::FilterMetadataStatus::Continue, filter_->encodeMetadata(metadata_map)); Http::TestResponseHeaderMapImpl response_headers{}; - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.encodeHeaders(response_headers, false)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->encodeHeaders(response_headers, false)); EXPECT_EQ("localhost", response_headers.get_("access-control-allow-origin")); EXPECT_EQ("custom-header-1", response_headers.get_("access-control-expose-headers")); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.encodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.encodeTrailers(response_trailers_)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->encodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->encodeTrailers(response_trailers_)); } TEST_F(CorsFilterTest, DoNotAddResponseHeadersForNotMatchingOrigins) { @@ -595,39 +597,39 @@ TEST_F(CorsFilterTest, DoNotAddResponseHeadersForNotMatchingOrigins) { cors_policy_->allow_origins_.clear(); cors_policy_->allow_origins_.emplace_back(makeExactStringMatcher("localhost")); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.decodeHeaders(request_headers, false)); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.decodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.decodeTrailers(request_trailers_)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->decodeHeaders(request_headers, false)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->decodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->decodeTrailers(request_trailers_)); Http::TestResponseHeaderMapImpl continue_headers{{":status", "100"}}; - EXPECT_EQ(Http::Filter1xxHeadersStatus::Continue, filter_.encode1xxHeaders(continue_headers)); + EXPECT_EQ(Http::Filter1xxHeadersStatus::Continue, filter_->encode1xxHeaders(continue_headers)); Http::MetadataMap metadata_map{{"metadata", "metadata"}}; - EXPECT_EQ(Http::FilterMetadataStatus::Continue, filter_.encodeMetadata(metadata_map)); + EXPECT_EQ(Http::FilterMetadataStatus::Continue, filter_->encodeMetadata(metadata_map)); Http::TestResponseHeaderMapImpl response_headers{}; - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.encodeHeaders(response_headers, false)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->encodeHeaders(response_headers, false)); // None of the response headers should be added for non-matching origins. EXPECT_EQ("", response_headers.get_("access-control-allow-origin")); EXPECT_EQ("", response_headers.get_("access-control-expose-headers")); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.encodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.encodeTrailers(response_trailers_)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->encodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->encodeTrailers(response_trailers_)); } TEST_F(CorsFilterTest, EncodeWithAllowCredentialsFalse) { Http::TestRequestHeaderMapImpl request_headers{{"origin", "localhost"}}; - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.decodeHeaders(request_headers, false)); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.decodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.decodeTrailers(request_trailers_)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->decodeHeaders(request_headers, false)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->decodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->decodeTrailers(request_trailers_)); Http::TestResponseHeaderMapImpl response_headers{}; - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.encodeHeaders(response_headers, false)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->encodeHeaders(response_headers, false)); EXPECT_EQ("localhost", response_headers.get_("access-control-allow-origin")); EXPECT_EQ("", response_headers.get_("access-control-allow-credentials")); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.encodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.encodeTrailers(response_trailers_)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->encodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->encodeTrailers(response_trailers_)); } TEST_F(CorsFilterTest, EncodeWithNonMatchingOrigin) { @@ -636,67 +638,67 @@ TEST_F(CorsFilterTest, EncodeWithNonMatchingOrigin) { cors_policy_->allow_origins_.clear(); cors_policy_->allow_origins_.emplace_back(makeExactStringMatcher("localhost")); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.decodeHeaders(request_headers, false)); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.decodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.decodeTrailers(request_trailers_)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->decodeHeaders(request_headers, false)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->decodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->decodeTrailers(request_trailers_)); Http::TestResponseHeaderMapImpl response_headers{}; - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.encodeHeaders(response_headers, false)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->encodeHeaders(response_headers, false)); EXPECT_EQ("", response_headers.get_("access-control-allow-origin")); EXPECT_EQ("", response_headers.get_("access-control-allow-credentials")); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.encodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.encodeTrailers(response_trailers_)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->encodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->encodeTrailers(response_trailers_)); } TEST_F(CorsFilterTest, RedirectRoute) { ON_CALL(*decoder_callbacks_.route_, directResponseEntry()) .WillByDefault(Return(&direct_response_entry_)); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.decodeHeaders(request_headers_, false)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->decodeHeaders(request_headers_, false)); EXPECT_EQ(false, isCorsRequest()); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.decodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.decodeTrailers(request_trailers_)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->decodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->decodeTrailers(request_trailers_)); Http::TestResponseHeaderMapImpl response_headers{}; - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.encodeHeaders(response_headers, false)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->encodeHeaders(response_headers, false)); EXPECT_EQ("", response_headers.get_("access-control-allow-origin")); EXPECT_EQ("", response_headers.get_("access-control-allow-credentials")); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.encodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.encodeTrailers(response_trailers_)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->encodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->encodeTrailers(response_trailers_)); } TEST_F(CorsFilterTest, EmptyRoute) { ON_CALL(decoder_callbacks_, route()).WillByDefault(Return(nullptr)); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.decodeHeaders(request_headers_, false)); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.decodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.decodeTrailers(request_trailers_)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->decodeHeaders(request_headers_, false)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->decodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->decodeTrailers(request_trailers_)); Http::TestResponseHeaderMapImpl response_headers{}; - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.encodeHeaders(response_headers, false)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->encodeHeaders(response_headers, false)); EXPECT_EQ("", response_headers.get_("access-control-allow-origin")); EXPECT_EQ("", response_headers.get_("access-control-allow-credentials")); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.encodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.encodeTrailers(response_trailers_)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->encodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->encodeTrailers(response_trailers_)); } TEST_F(CorsFilterTest, EmptyRouteEntry) { ON_CALL(*decoder_callbacks_.route_, routeEntry()).WillByDefault(Return(nullptr)); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.decodeHeaders(request_headers_, false)); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.decodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.decodeTrailers(request_trailers_)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->decodeHeaders(request_headers_, false)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->decodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->decodeTrailers(request_trailers_)); Http::TestResponseHeaderMapImpl response_headers{}; - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.encodeHeaders(response_headers, false)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->encodeHeaders(response_headers, false)); EXPECT_EQ("", response_headers.get_("access-control-allow-origin")); EXPECT_EQ("", response_headers.get_("access-control-allow-credentials")); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.encodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.encodeTrailers(response_trailers_)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->encodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->encodeTrailers(response_trailers_)); } TEST_F(CorsFilterTest, NoCorsEntry) { @@ -710,20 +712,20 @@ TEST_F(CorsFilterTest, NoCorsEntry) { ON_CALL(decoder_callbacks_.route_->route_entry_, corsPolicy()).WillByDefault(Return(nullptr)); ON_CALL(decoder_callbacks_.route_->virtual_host_, corsPolicy()).WillByDefault(Return(nullptr)); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.decodeHeaders(request_headers, false)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->decodeHeaders(request_headers, false)); EXPECT_EQ(false, isCorsRequest()); EXPECT_EQ(0, stats_.counter("test.cors.origin_invalid").value()); EXPECT_EQ(0, stats_.counter("test.cors.origin_valid").value()); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.decodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.decodeTrailers(request_trailers_)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->decodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->decodeTrailers(request_trailers_)); Http::TestResponseHeaderMapImpl response_headers{}; - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.encodeHeaders(response_headers, false)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->encodeHeaders(response_headers, false)); EXPECT_EQ("", response_headers.get_("access-control-allow-origin")); EXPECT_EQ("", response_headers.get_("access-control-allow-credentials")); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.encodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.encodeTrailers(response_trailers_)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->encodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->encodeTrailers(response_trailers_)); } TEST_F(CorsFilterTest, NoRouteCorsEntry) { @@ -744,16 +746,16 @@ TEST_F(CorsFilterTest, NoRouteCorsEntry) { EXPECT_CALL(decoder_callbacks_, encodeHeaders_(HeaderMapEqualRef(&response_headers), true)); EXPECT_EQ(Http::FilterHeadersStatus::StopIteration, - filter_.decodeHeaders(request_headers, false)); + filter_->decodeHeaders(request_headers, false)); EXPECT_EQ(true, isCorsRequest()); EXPECT_EQ(0, stats_.counter("test.cors.origin_invalid").value()); EXPECT_EQ(1, stats_.counter("test.cors.origin_valid").value()); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.decodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.decodeTrailers(request_trailers_)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->decodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->decodeTrailers(request_trailers_)); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.encodeHeaders(response_headers_, false)); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.encodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.encodeTrailers(response_trailers_)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->encodeHeaders(response_headers_, false)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->encodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->encodeTrailers(response_trailers_)); } TEST_F(CorsFilterTest, NoVHostCorsEntry) { @@ -775,16 +777,16 @@ TEST_F(CorsFilterTest, NoVHostCorsEntry) { EXPECT_CALL(decoder_callbacks_, encodeHeaders_(HeaderMapEqualRef(&response_headers), true)); EXPECT_EQ(Http::FilterHeadersStatus::StopIteration, - filter_.decodeHeaders(request_headers, false)); + filter_->decodeHeaders(request_headers, false)); EXPECT_EQ(true, isCorsRequest()); EXPECT_EQ(0, stats_.counter("test.cors.origin_invalid").value()); EXPECT_EQ(1, stats_.counter("test.cors.origin_valid").value()); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.decodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.decodeTrailers(request_trailers_)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->decodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->decodeTrailers(request_trailers_)); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.encodeHeaders(response_headers_, false)); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.encodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.encodeTrailers(response_trailers_)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->encodeHeaders(response_headers_, false)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->encodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->encodeTrailers(response_trailers_)); } TEST_F(CorsFilterTest, OptionsRequestMatchingOriginByRegex) { @@ -806,16 +808,16 @@ TEST_F(CorsFilterTest, OptionsRequestMatchingOriginByRegex) { EXPECT_CALL(decoder_callbacks_, encodeHeaders_(HeaderMapEqualRef(&response_headers), true)); EXPECT_EQ(Http::FilterHeadersStatus::StopIteration, - filter_.decodeHeaders(request_headers, false)); + filter_->decodeHeaders(request_headers, false)); EXPECT_EQ(true, isCorsRequest()); EXPECT_EQ(0, stats_.counter("test.cors.origin_invalid").value()); EXPECT_EQ(1, stats_.counter("test.cors.origin_valid").value()); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.decodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.decodeTrailers(request_trailers_)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->decodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->decodeTrailers(request_trailers_)); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.encodeHeaders(response_headers_, false)); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.encodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.encodeTrailers(response_trailers_)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->encodeHeaders(response_headers_, false)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->encodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->encodeTrailers(response_trailers_)); } TEST_F(CorsFilterTest, OptionsRequestNotMatchingOriginByRegex) { @@ -827,16 +829,16 @@ TEST_F(CorsFilterTest, OptionsRequestNotMatchingOriginByRegex) { cors_policy_->allow_origins_.emplace_back(makeStdRegexStringMatcher(".*.envoyproxy.io")); EXPECT_CALL(decoder_callbacks_, encodeHeaders_(_, false)).Times(0); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.decodeHeaders(request_headers, false)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->decodeHeaders(request_headers, false)); EXPECT_EQ(true, isCorsRequest()); EXPECT_EQ(1, stats_.counter("test.cors.origin_invalid").value()); EXPECT_EQ(0, stats_.counter("test.cors.origin_valid").value()); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.decodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.decodeTrailers(request_trailers_)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->decodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->decodeTrailers(request_trailers_)); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.encodeHeaders(response_headers_, false)); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.encodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.encodeTrailers(response_trailers_)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->encodeHeaders(response_headers_, false)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->encodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->encodeTrailers(response_trailers_)); } TEST_F(CorsFilterTest, OptionsRequestWithWildcardAllowMethods) { @@ -857,13 +859,13 @@ TEST_F(CorsFilterTest, OptionsRequestWithWildcardAllowMethods) { EXPECT_CALL(decoder_callbacks_, encodeHeaders_(HeaderMapEqualRef(&response_headers), true)); EXPECT_EQ(Http::FilterHeadersStatus::StopIteration, - filter_.decodeHeaders(request_headers, false)); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.decodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.decodeTrailers(request_trailers_)); + filter_->decodeHeaders(request_headers, false)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->decodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->decodeTrailers(request_trailers_)); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.encodeHeaders(response_headers_, false)); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.encodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.encodeTrailers(response_trailers_)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->encodeHeaders(response_headers_, false)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->encodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->encodeTrailers(response_trailers_)); } TEST_F(CorsFilterTest, OptionsRequestWithWildcardAllowHeaders) { @@ -885,13 +887,13 @@ TEST_F(CorsFilterTest, OptionsRequestWithWildcardAllowHeaders) { EXPECT_CALL(decoder_callbacks_, encodeHeaders_(HeaderMapEqualRef(&response_headers), true)); EXPECT_EQ(Http::FilterHeadersStatus::StopIteration, - filter_.decodeHeaders(request_headers, false)); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.decodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.decodeTrailers(request_trailers_)); + filter_->decodeHeaders(request_headers, false)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->decodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->decodeTrailers(request_trailers_)); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.encodeHeaders(response_headers_, false)); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.encodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.encodeTrailers(response_trailers_)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->encodeHeaders(response_headers_, false)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->encodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->encodeTrailers(response_trailers_)); } TEST_F(CorsFilterTest, OptionsRequestMatchingOriginByWildcardWithPNA) { @@ -912,16 +914,16 @@ TEST_F(CorsFilterTest, OptionsRequestMatchingOriginByWildcardWithPNA) { EXPECT_CALL(decoder_callbacks_, encodeHeaders_(HeaderMapEqualRef(&response_headers), true)); EXPECT_EQ(Http::FilterHeadersStatus::StopIteration, - filter_.decodeHeaders(request_headers, false)); + filter_->decodeHeaders(request_headers, false)); EXPECT_EQ(true, isCorsRequest()); EXPECT_EQ(0, stats_.counter("test.cors.origin_invalid").value()); EXPECT_EQ(1, stats_.counter("test.cors.origin_valid").value()); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.decodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.decodeTrailers(request_trailers_)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->decodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->decodeTrailers(request_trailers_)); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.encodeHeaders(response_headers_, false)); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.encodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.encodeTrailers(response_trailers_)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->encodeHeaders(response_headers_, false)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->encodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->encodeTrailers(response_trailers_)); ASSERT_TRUE(decoder_callbacks_.stream_info_.responseCodeDetails().has_value()); EXPECT_EQ(decoder_callbacks_.stream_info_.responseCodeDetails().value(), "cors_response"); } @@ -946,16 +948,16 @@ TEST_F(CorsFilterTest, OptionsRequestMatchingOriginByWildcardWithoutPNA) { EXPECT_CALL(decoder_callbacks_, encodeHeaders_(HeaderMapEqualRef(&response_headers), true)); EXPECT_EQ(Http::FilterHeadersStatus::StopIteration, - filter_.decodeHeaders(request_headers, false)); + filter_->decodeHeaders(request_headers, false)); EXPECT_EQ(true, isCorsRequest()); EXPECT_EQ(0, stats_.counter("test.cors.origin_invalid").value()); EXPECT_EQ(1, stats_.counter("test.cors.origin_valid").value()); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.decodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.decodeTrailers(request_trailers_)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->decodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->decodeTrailers(request_trailers_)); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.encodeHeaders(response_headers_, false)); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.encodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.encodeTrailers(response_trailers_)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->encodeHeaders(response_headers_, false)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->encodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->encodeTrailers(response_trailers_)); ASSERT_TRUE(decoder_callbacks_.stream_info_.responseCodeDetails().has_value()); EXPECT_EQ(decoder_callbacks_.stream_info_.responseCodeDetails().value(), "cors_response"); } @@ -978,16 +980,16 @@ TEST_F(CorsFilterTest, OptionsRequestMatchingOriginByWildcardWithInvalidPNA) { EXPECT_CALL(decoder_callbacks_, encodeHeaders_(HeaderMapEqualRef(&response_headers), true)); EXPECT_EQ(Http::FilterHeadersStatus::StopIteration, - filter_.decodeHeaders(request_headers, false)); + filter_->decodeHeaders(request_headers, false)); EXPECT_EQ(true, isCorsRequest()); EXPECT_EQ(0, stats_.counter("test.cors.origin_invalid").value()); EXPECT_EQ(1, stats_.counter("test.cors.origin_valid").value()); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.decodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.decodeTrailers(request_trailers_)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->decodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->decodeTrailers(request_trailers_)); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.encodeHeaders(response_headers_, false)); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.encodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.encodeTrailers(response_trailers_)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->encodeHeaders(response_headers_, false)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->encodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->encodeTrailers(response_trailers_)); ASSERT_TRUE(decoder_callbacks_.stream_info_.responseCodeDetails().has_value()); EXPECT_EQ(decoder_callbacks_.stream_info_.responseCodeDetails().value(), "cors_response"); } @@ -1010,17 +1012,17 @@ TEST_F(CorsFilterTest, CorsFilterLatchesRequestOriginValue) { EXPECT_CALL(decoder_callbacks_, encodeHeaders_(HeaderMapEqualRef(&response_headers), true)); EXPECT_EQ(Http::FilterHeadersStatus::StopIteration, - filter_.decodeHeaders(request_headers, false)); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.decodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.decodeTrailers(request_trailers_)); + filter_->decodeHeaders(request_headers, false)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->decodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->decodeTrailers(request_trailers_)); // Remove the origin request header from the header map. If we don't // latch the value we will have a dangling pointer. request_headers.remove("origin"); - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.encodeHeaders(response_headers_, false)); - EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.encodeData(data_, false)); - EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_.encodeTrailers(response_trailers_)); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->encodeHeaders(response_headers_, false)); + EXPECT_EQ(Http::FilterDataStatus::Continue, filter_->encodeData(data_, false)); + EXPECT_EQ(Http::FilterTrailersStatus::Continue, filter_->encodeTrailers(response_trailers_)); } } // namespace Cors