Skip to content

Commit

Permalink
Improving filter test coverage (#2491)
Browse files Browse the repository at this point in the history
Signed-off-by: Alyssa Wilk <[email protected]>
  • Loading branch information
alyssawilk authored and mattklein123 committed Jan 31, 2018
1 parent e7ee2b9 commit 7f4089a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test/common/http/filter/cors_filter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,23 @@ TEST_F(CorsFilterTest, OptionsRequestNotMatchingOrigin) {
EXPECT_EQ(FilterTrailersStatus::Continue, filter_.encodeTrailers(request_headers_));
}

TEST_F(CorsFilterTest, OptionsRequestEmptyOriginList) {
Http::TestHeaderMapImpl request_headers{
{":method", "OPTIONS"}, {"origin", "test-host"}, {"access-control-request-method", "GET"}};

cors_policy_->allow_origin_.clear();

EXPECT_CALL(decoder_callbacks_, encodeHeaders_(_, false)).Times(0);
EXPECT_EQ(FilterHeadersStatus::Continue, filter_.decodeHeaders(request_headers, false));
EXPECT_EQ(false, IsCorsRequest());
EXPECT_EQ(FilterDataStatus::Continue, filter_.decodeData(data_, false));
EXPECT_EQ(FilterTrailersStatus::Continue, filter_.decodeTrailers(request_headers_));

EXPECT_EQ(FilterHeadersStatus::Continue, filter_.encodeHeaders(request_headers_, false));
EXPECT_EQ(FilterDataStatus::Continue, filter_.encodeData(data_, false));
EXPECT_EQ(FilterTrailersStatus::Continue, filter_.encodeTrailers(request_headers_));
}

TEST_F(CorsFilterTest, ValidOptionsRequestWithAllowCredentialsTrue) {
Http::TestHeaderMapImpl request_headers{
{":method", "OPTIONS"}, {"origin", "localhost"}, {"access-control-request-method", "GET"}};
Expand Down
1 change: 1 addition & 0 deletions test/server/config/http/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ envoy_cc_test(
"//source/server/config/http:lua_lib",
"//source/server/config/http:ratelimit_lib",
"//source/server/config/http:router_lib",
"//source/server/config/http:squash_lib",
"//source/server/config/http:zipkin_lib",
"//source/server/http:health_check_lib",
"//test/mocks/access_log:access_log_mocks",
Expand Down
21 changes: 21 additions & 0 deletions test/server/config/http/config_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "server/config/http/lua.h"
#include "server/config/http/ratelimit.h"
#include "server/config/http/router.h"
#include "server/config/http/squash.h"
#include "server/config/http/zipkin_http_tracer.h"
#include "server/config/network/http_connection_manager.h"
#include "server/http/health_check.h"
Expand Down Expand Up @@ -441,6 +442,26 @@ TEST(HttpFilterConfigTest, DoubleRegistrationTest) {
fmt::format("Double registration for name: '{}'", Config::HttpFilterNames::get().ROUTER));
}

TEST(HttpFilterConfigTest, SquashFilterCorrectJson) {
std::string json_string = R"EOF(
{
"cluster" : "fake_cluster",
"attachment_template" : {"a":"b"},
"request_timeout_ms" : 1001,
"attachment_poll_period_ms" : 2002,
"attachment_timeout_ms" : 3003
}
)EOF";

Json::ObjectSharedPtr json_config = Json::Factory::loadFromString(json_string);
NiceMock<MockFactoryContext> context;
SquashFilterConfig factory;
HttpFilterFactoryCb cb = factory.createFilterFactory(*json_config, "stats", context);
Http::MockFilterChainFactoryCallbacks filter_callback;
EXPECT_CALL(filter_callback, addStreamDecoderFilter(_));
cb(filter_callback);
}

TEST(HttpTracerConfigTest, ZipkinHttpTracer) {
NiceMock<Upstream::MockClusterManager> cm;
EXPECT_CALL(cm, get("fake_cluster")).WillRepeatedly(Return(&cm.thread_local_cluster_));
Expand Down

0 comments on commit 7f4089a

Please sign in to comment.