Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
Signed-off-by: Adi Suissa-Peleg <adip@google.com>
  • Loading branch information
adisuissa committed Dec 20, 2024
1 parent a50f1d5 commit 14320a5
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 49 deletions.
2 changes: 2 additions & 0 deletions contrib/hyperscan/matching/input_matchers/source/matcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class Matcher : public Envoy::Regex::CompiledMatcher, public Envoy::Matcher::Inp
// Envoy::Matcher::InputMatcher
bool match(const ::Envoy::Matcher::MatchingDataType& input) override;

const std::string& stringRepresentation() const override { return EMPTY_STRING; }

private:
hs_database_t* database_{};
hs_database_t* start_of_match_database_{};
Expand Down
8 changes: 2 additions & 6 deletions test/extensions/common/aws/utility_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,13 @@ TEST(UtilityTest, CanonicalizeHeadersDropExcludedMatchers) {
for (auto& str : exact_matches) {
envoy::type::matcher::v3::StringMatcher config;
config.set_exact(str);
exclusion_list.emplace_back(
std::make_unique<Matchers::StringMatcherImpl<envoy::type::matcher::v3::StringMatcher>>(
config, context));
exclusion_list.emplace_back(std::make_unique<Matchers::StringMatcherImpl>(config, context));
}
std::vector<std::string> prefixes = {"x-envoy"};
for (auto& match_str : prefixes) {
envoy::type::matcher::v3::StringMatcher config;
config.set_prefix(match_str);
exclusion_list.emplace_back(
std::make_unique<Matchers::StringMatcherImpl<envoy::type::matcher::v3::StringMatcher>>(
config, context));
exclusion_list.emplace_back(std::make_unique<Matchers::StringMatcherImpl>(config, context));
}
const auto map = Utility::canonicalizeHeaders(headers, exclusion_list);
EXPECT_THAT(map,
Expand Down
20 changes: 5 additions & 15 deletions test/extensions/filters/http/cache/cache_headers_utils_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -496,9 +496,7 @@ TEST(GetAllMatchingHeaderNames, EmptyHeaderMap) {

envoy::type::matcher::v3::StringMatcher matcher;
matcher.set_exact("accept");
ruleset.emplace_back(
std::make_unique<Matchers::StringMatcherImpl<envoy::type::matcher::v3::StringMatcher>>(
matcher, context));
ruleset.emplace_back(std::make_unique<Matchers::StringMatcherImpl>(matcher, context));

CacheHeadersUtils::getAllMatchingHeaderNames(headers, ruleset, result);

Expand All @@ -513,9 +511,7 @@ TEST(GetAllMatchingHeaderNames, SingleMatchSingleValue) {

envoy::type::matcher::v3::StringMatcher matcher;
matcher.set_exact("accept");
ruleset.emplace_back(
std::make_unique<Matchers::StringMatcherImpl<envoy::type::matcher::v3::StringMatcher>>(
matcher, context));
ruleset.emplace_back(std::make_unique<Matchers::StringMatcherImpl>(matcher, context));

CacheHeadersUtils::getAllMatchingHeaderNames(headers, ruleset, result);

Expand All @@ -531,9 +527,7 @@ TEST(GetAllMatchingHeaderNames, SingleMatchMultiValue) {

envoy::type::matcher::v3::StringMatcher matcher;
matcher.set_exact("accept");
ruleset.emplace_back(
std::make_unique<Matchers::StringMatcherImpl<envoy::type::matcher::v3::StringMatcher>>(
matcher, context));
ruleset.emplace_back(std::make_unique<Matchers::StringMatcherImpl>(matcher, context));

CacheHeadersUtils::getAllMatchingHeaderNames(headers, ruleset, result);

Expand All @@ -549,13 +543,9 @@ TEST(GetAllMatchingHeaderNames, MultipleMatches) {

envoy::type::matcher::v3::StringMatcher matcher;
matcher.set_exact("accept");
ruleset.emplace_back(
std::make_unique<Matchers::StringMatcherImpl<envoy::type::matcher::v3::StringMatcher>>(
matcher, context));
ruleset.emplace_back(std::make_unique<Matchers::StringMatcherImpl>(matcher, context));
matcher.set_exact("accept-language");
ruleset.emplace_back(
std::make_unique<Matchers::StringMatcherImpl<envoy::type::matcher::v3::StringMatcher>>(
matcher, context));
ruleset.emplace_back(std::make_unique<Matchers::StringMatcherImpl>(matcher, context));

CacheHeadersUtils::getAllMatchingHeaderNames(headers, ruleset, result);

Expand Down
6 changes: 2 additions & 4 deletions test/extensions/filters/http/cors/cors_filter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,14 @@ Matchers::StringMatcherPtr makeExactStringMatcher(const std::string& exact_match
NiceMock<Server::Configuration::MockServerFactoryContext> context;
envoy::type::matcher::v3::StringMatcher config;
config.set_exact(exact_match);
return std::make_unique<Matchers::StringMatcherImpl<envoy::type::matcher::v3::StringMatcher>>(
config, context);
return std::make_unique<Matchers::StringMatcherImpl>(config, context);
}

Matchers::StringMatcherPtr makeStdRegexStringMatcher(const std::string& regex) {
NiceMock<Server::Configuration::MockServerFactoryContext> context;
envoy::type::matcher::v3::StringMatcher config;
config.MergeFrom(TestUtility::createRegexMatcher(regex));
return std::make_unique<Matchers::StringMatcherImpl<envoy::type::matcher::v3::StringMatcher>>(
config, context);
return std::make_unique<Matchers::StringMatcherImpl>(config, context);
}

} // namespace
Expand Down
33 changes: 9 additions & 24 deletions test/extensions/filters/http/ext_proc/mutation_utils_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -337,13 +337,9 @@ TEST_F(MutationUtilsTest, TestAllowHeadersExactCaseSensitive) {
std::vector<Matchers::StringMatcherPtr> disallow_headers;
envoy::type::matcher::v3::StringMatcher string_matcher;
string_matcher.set_exact(":method");
allow_headers.push_back(
std::make_unique<Matchers::StringMatcherImpl<envoy::type::matcher::v3::StringMatcher>>(
string_matcher, context));
allow_headers.push_back(std::make_unique<Matchers::StringMatcherImpl>(string_matcher, context));
string_matcher.set_exact(":Path");
allow_headers.push_back(
std::make_unique<Matchers::StringMatcherImpl<envoy::type::matcher::v3::StringMatcher>>(
string_matcher, context));
allow_headers.push_back(std::make_unique<Matchers::StringMatcherImpl>(string_matcher, context));
MutationUtils::headersToProto(headers, allow_headers, disallow_headers, proto_headers);

Http::TestRequestHeaderMapImpl expected{{":method", "GET"}};
Expand All @@ -364,14 +360,10 @@ TEST_F(MutationUtilsTest, TestAllowHeadersExactIgnoreCase) {
std::vector<Matchers::StringMatcherPtr> disallow_headers;
envoy::type::matcher::v3::StringMatcher string_matcher;
string_matcher.set_exact(":method");
allow_headers.push_back(
std::make_unique<Matchers::StringMatcherImpl<envoy::type::matcher::v3::StringMatcher>>(
string_matcher, context));
allow_headers.push_back(std::make_unique<Matchers::StringMatcherImpl>(string_matcher, context));
string_matcher.set_exact(":Path");
string_matcher.set_ignore_case(true);
allow_headers.push_back(
std::make_unique<Matchers::StringMatcherImpl<envoy::type::matcher::v3::StringMatcher>>(
string_matcher, context));
allow_headers.push_back(std::make_unique<Matchers::StringMatcherImpl>(string_matcher, context));
MutationUtils::headersToProto(headers, allow_headers, disallow_headers, proto_headers);
Http::TestRequestHeaderMapImpl expected{{":method", "GET"}, {":path", "/foo/the/bar?size=123"}};
EXPECT_THAT(proto_headers, HeaderProtosEqual(expected));
Expand All @@ -394,19 +386,14 @@ TEST_F(MutationUtilsTest, TestBothAllowAndDisallowHeadersSet) {

// Set allow_headers.
string_matcher.set_exact(":method");
allow_headers.push_back(
std::make_unique<Matchers::StringMatcherImpl<envoy::type::matcher::v3::StringMatcher>>(
string_matcher, context));
allow_headers.push_back(std::make_unique<Matchers::StringMatcherImpl>(string_matcher, context));
string_matcher.set_exact(":path");
allow_headers.push_back(
std::make_unique<Matchers::StringMatcherImpl<envoy::type::matcher::v3::StringMatcher>>(
string_matcher, context));
allow_headers.push_back(std::make_unique<Matchers::StringMatcherImpl>(string_matcher, context));

// Set disallow_headers
string_matcher.set_exact(":method");
disallow_headers.push_back(
std::make_unique<Matchers::StringMatcherImpl<envoy::type::matcher::v3::StringMatcher>>(
string_matcher, context));
std::make_unique<Matchers::StringMatcherImpl>(string_matcher, context));

MutationUtils::headersToProto(headers, allow_headers, disallow_headers, proto_headers);
Http::TestRequestHeaderMapImpl expected{{":path", "/foo/the/bar?size=123"}};
Expand All @@ -431,12 +418,10 @@ TEST_F(MutationUtilsTest, TestDisallowHeaderSetNotAllowHeader) {
// Set disallow_headers.
string_matcher.set_exact(":method");
disallow_headers.push_back(
std::make_unique<Matchers::StringMatcherImpl<envoy::type::matcher::v3::StringMatcher>>(
string_matcher, context));
std::make_unique<Matchers::StringMatcherImpl>(string_matcher, context));
string_matcher.set_exact(":path");
disallow_headers.push_back(
std::make_unique<Matchers::StringMatcherImpl<envoy::type::matcher::v3::StringMatcher>>(
string_matcher, context));
std::make_unique<Matchers::StringMatcherImpl>(string_matcher, context));

MutationUtils::headersToProto(headers, allow_headers, disallow_headers, proto_headers);
Http::TestRequestHeaderMapImpl expected{{"content-type", "text/plain; encoding=UTF8"},
Expand Down

0 comments on commit 14320a5

Please sign in to comment.