Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ bool isApiNameValid(absl::string_view api_name) {

// Creates and returns a CEL matcher.
MatchTreeHttpMatchingDataSharedPtr
getCelMatcher(Envoy::Server::Configuration::ServerFactoryContext& server_factory_context,
const xds::type::matcher::v3::Matcher& matcher) {
getMatcher(Envoy::Server::Configuration::ServerFactoryContext& server_factory_context,
const xds::type::matcher::v3::Matcher& matcher) {
ProtoApiScrubberRemoveFieldAction remove_field_action;
MatcherInputValidatorVisitor validation_visitor;
Matcher::MatchTreeFactory<HttpMatchingData, ProtoApiScrubberRemoveFieldAction> matcher_factory(
Expand Down Expand Up @@ -118,7 +118,7 @@ absl::Status ProtoApiScrubberFilterConfig::initializeMethodLevelRestrictions(
Envoy::Server::Configuration::FactoryContext& context) {
if (method_config.has_method_restriction()) {
method_level_restrictions_[method_name] =
getCelMatcher(context.serverFactoryContext(), method_config.method_restriction().matcher());
getMatcher(context.serverFactoryContext(), method_config.method_restriction().matcher());
}
return absl::OkStatus();
}
Expand All @@ -135,7 +135,7 @@ absl::Status ProtoApiScrubberFilterConfig::initializeMessageRestrictions(
}
if (message_config.has_config()) {
message_level_restrictions_[message_name] =
getCelMatcher(context.serverFactoryContext(), message_config.config().matcher());
getMatcher(context.serverFactoryContext(), message_config.config().matcher());
}
}
return absl::OkStatus();
Expand Down Expand Up @@ -264,7 +264,7 @@ absl::Status ProtoApiScrubberFilterConfig::initializeMethodFieldRestrictions(
absl::string_view field_mask = restriction.first;
RETURN_IF_ERROR(validateFieldMask(field_mask));
field_restrictions[std::make_pair(std::string(method_name), std::string(field_mask))] =
getCelMatcher(context.serverFactoryContext(), restriction.second.matcher());
getMatcher(context.serverFactoryContext(), restriction.second.matcher());
}

return absl::OkStatus();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,11 @@ class ProtoApiScrubberFilterConfig : public Logger::Loggable<Logger::Id::filter>
class MatcherInputValidatorVisitor : public Matcher::MatchTreeValidationVisitor<HttpMatchingData> {
public:
// Validates whether the input type for the matcher is in the list of supported input types.
// Currently, only CEL input type (i.e., HttpAttributesCelMatchInput) is supported.
// ProtoApiScrubber filter supports all types of data inputs and hence, it returns
// `absl::OkStatus()` by default.
absl::Status performDataInputValidation(const Matcher::DataInputFactory<HttpMatchingData>&,
absl::string_view type_url) override {
if (type_url == TypeUtil::descriptorFullNameToTypeUrl(
HttpAttributesCelMatchInput::descriptor()->full_name())) {
return absl::OkStatus();
}

return absl::InvalidArgumentError(
fmt::format("ProtoApiScrubber filter does not support matching on '{}'", type_url));
absl::string_view) override {
return absl::OkStatus();
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -907,41 +907,6 @@ TEST_F(ProtoApiScrubberFilterConfigTest, FilteringModeValidations) {
}
}

TEST_F(ProtoApiScrubberFilterConfigTest, MatcherInputTypeValidations) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What will happen now if a non-supported matcher will be used?
Are there tests that cover that? Would adding an integration test for this use-case make sense?

NiceMock<Server::Configuration::MockFactoryContext> factory_context;
absl::StatusOr<std::shared_ptr<const ProtoApiScrubberFilterConfig>> filter_config;

{
EXPECT_THROW_WITH_MESSAGE(
filter_config = ProtoApiScrubberFilterConfig::create(
getConfigWithInputType(
"type.googleapis.com/envoy.type.matcher.v3.HttpRequestHeaderMatchInput"),
factory_context),
EnvoyException,
"Unsupported data input type: string. The matcher supports input type: cel_data_input");
}

{
EXPECT_THROW_WITH_MESSAGE(
filter_config = ProtoApiScrubberFilterConfig::create(
getConfigWithInputType(
"type.googleapis.com/"
"envoy.extensions.matching.common_inputs.network.v3.ServerNameInput"),
factory_context),
EnvoyException,
"Unsupported data input type: string. The matcher supports input type: cel_data_input");
}

{
filter_config = ProtoApiScrubberFilterConfig::create(
getConfigWithInputType(
"type.googleapis.com/xds.type.matcher.v3.HttpAttributesCelMatchInput"),
factory_context);
EXPECT_EQ(filter_config.status().code(), absl::StatusCode::kOk);
EXPECT_EQ(filter_config.status().message(), "");
}
}

TEST_F(ProtoApiScrubberFilterConfigTest, GetRequestType) {
// 1. Initialize the config
absl::StatusOr<std::shared_ptr<const ProtoApiScrubberFilterConfig>> config_or_status =
Expand Down