From 7cda6a26ddb554fe981d20d9aebf42ffaa2d53f3 Mon Sep 17 00:00:00 2001 From: code Date: Wed, 11 Dec 2024 01:29:45 +0800 Subject: [PATCH] api key auth: fix broken test and use const for config (#37609) Commit Message: api key auth: fix broken test and use const for config Additional Description: Risk Level: Testing: Docs Changes: Release Notes: Platform Specific Features: [Optional Runtime guard:] [Optional Fixes #Issue] [Optional Fixes commit #PR or SHA] [Optional Deprecated:] [Optional [API Considerations](https://github.com/envoyproxy/envoy/blob/main/api/review_checklist.md):] Signed-off-by: wangbaiping(wbpcode) --- source/extensions/filters/http/api_key_auth/api_key_auth.cc | 6 +++--- source/extensions/filters/http/api_key_auth/api_key_auth.h | 6 +++--- source/extensions/filters/http/api_key_auth/config.cc | 2 +- source/extensions/filters/http/api_key_auth/config.h | 2 +- test/extensions/filters/http/api_key_auth/config_test.cc | 6 ++++-- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/source/extensions/filters/http/api_key_auth/api_key_auth.cc b/source/extensions/filters/http/api_key_auth/api_key_auth.cc index 7e19e5e6a285..d1ae12f1220f 100644 --- a/source/extensions/filters/http/api_key_auth/api_key_auth.cc +++ b/source/extensions/filters/http/api_key_auth/api_key_auth.cc @@ -14,9 +14,9 @@ namespace Extensions { namespace HttpFilters { namespace ApiKeyAuth { -RouteConfig::RouteConfig(const ApiKeyAuthPerRouteProto& proto) : override_config_(proto) { - allowed_clients_.insert(proto.allowed_clients().begin(), proto.allowed_clients().end()); -} +RouteConfig::RouteConfig(const ApiKeyAuthPerRouteProto& proto) + : override_config_(proto), + allowed_clients_(proto.allowed_clients().begin(), proto.allowed_clients().end()) {} KeySources::Source::Source(absl::string_view header, absl::string_view query, absl::string_view cookie) { diff --git a/source/extensions/filters/http/api_key_auth/api_key_auth.h b/source/extensions/filters/http/api_key_auth/api_key_auth.h index bf94abbfd127..0793fe620146 100644 --- a/source/extensions/filters/http/api_key_auth/api_key_auth.h +++ b/source/extensions/filters/http/api_key_auth/api_key_auth.h @@ -138,8 +138,8 @@ class RouteConfig : public Router::RouteSpecificFilterConfig { } private: - ApiKeyAuthConfig override_config_; - absl::flat_hash_set allowed_clients_; + const ApiKeyAuthConfig override_config_; + const absl::flat_hash_set allowed_clients_; }; struct AuthResult { @@ -173,7 +173,7 @@ class FilterConfig { return ApiKeyAuthStats{ALL_API_KEY_AUTH_STATS(POOL_COUNTER_PREFIX(scope, prefix))}; } - ApiKeyAuthConfig default_config_; + const ApiKeyAuthConfig default_config_; ApiKeyAuthStats stats_; }; diff --git a/source/extensions/filters/http/api_key_auth/config.cc b/source/extensions/filters/http/api_key_auth/config.cc index ed7c9a69e883..c8e372911612 100644 --- a/source/extensions/filters/http/api_key_auth/config.cc +++ b/source/extensions/filters/http/api_key_auth/config.cc @@ -19,7 +19,7 @@ Http::FilterFactoryCb ApiKeyAuthFilterFactory::createFilterFactoryFromProtoTyped }; } -Router::RouteSpecificFilterConfigConstSharedPtr +absl::StatusOr ApiKeyAuthFilterFactory::createRouteSpecificFilterConfigTyped( const ApiKeyAuthPerRouteProto& proto_config, Server::Configuration::ServerFactoryContext&, ProtobufMessage::ValidationVisitor&) { diff --git a/source/extensions/filters/http/api_key_auth/config.h b/source/extensions/filters/http/api_key_auth/config.h index 461e6c19e6e2..18d130714cc8 100644 --- a/source/extensions/filters/http/api_key_auth/config.h +++ b/source/extensions/filters/http/api_key_auth/config.h @@ -20,7 +20,7 @@ class ApiKeyAuthFilterFactory Http::FilterFactoryCb createFilterFactoryFromProtoTyped(const ApiKeyAuthProto& config, const std::string& stats_prefix, Server::Configuration::FactoryContext& context) override; - Router::RouteSpecificFilterConfigConstSharedPtr + absl::StatusOr createRouteSpecificFilterConfigTyped(const ApiKeyAuthPerRouteProto& proto_config, Server::Configuration::ServerFactoryContext&, ProtobufMessage::ValidationVisitor&) override; diff --git a/test/extensions/filters/http/api_key_auth/config_test.cc b/test/extensions/filters/http/api_key_auth/config_test.cc index 154a01a47ccd..774d7d0928e4 100644 --- a/test/extensions/filters/http/api_key_auth/config_test.cc +++ b/test/extensions/filters/http/api_key_auth/config_test.cc @@ -93,8 +93,10 @@ TEST(ApiKeyAuthFilterFactoryTest, NormalFactory) { status_or.value()(filter_callback); const auto route_config = - factory.createRouteSpecificFilterConfig(scope_proto_config, context.server_factory_context_, - ProtobufMessage::getNullValidationVisitor()); + factory + .createRouteSpecificFilterConfig(scope_proto_config, context.server_factory_context_, + ProtobufMessage::getNullValidationVisitor()) + .value(); EXPECT_TRUE(route_config != nullptr); }