Skip to content

Commit

Permalink
api key auth: fix broken test and use const for config
Browse files Browse the repository at this point in the history
Signed-off-by: wangbaiping(wbpcode) <[email protected]>
  • Loading branch information
wbpcode committed Dec 10, 2024
1 parent d2dbc05 commit d8470c0
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
6 changes: 3 additions & 3 deletions source/extensions/filters/http/api_key_auth/api_key_auth.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions source/extensions/filters/http/api_key_auth/api_key_auth.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ class RouteConfig : public Router::RouteSpecificFilterConfig {
}

private:
ApiKeyAuthConfig override_config_;
absl::flat_hash_set<std::string> allowed_clients_;
const ApiKeyAuthConfig override_config_;
const absl::flat_hash_set<std::string> allowed_clients_;
};

struct AuthResult {
Expand Down Expand Up @@ -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_;
};

Expand Down
2 changes: 1 addition & 1 deletion source/extensions/filters/http/api_key_auth/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Http::FilterFactoryCb ApiKeyAuthFilterFactory::createFilterFactoryFromProtoTyped
};
}

Router::RouteSpecificFilterConfigConstSharedPtr
absl::StatusOr<Router::RouteSpecificFilterConfigConstSharedPtr>
ApiKeyAuthFilterFactory::createRouteSpecificFilterConfigTyped(
const ApiKeyAuthPerRouteProto& proto_config, Server::Configuration::ServerFactoryContext&,
ProtobufMessage::ValidationVisitor&) {
Expand Down
2 changes: 1 addition & 1 deletion source/extensions/filters/http/api_key_auth/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Router::RouteSpecificFilterConfigConstSharedPtr>
createRouteSpecificFilterConfigTyped(const ApiKeyAuthPerRouteProto& proto_config,
Server::Configuration::ServerFactoryContext&,
ProtobufMessage::ValidationVisitor&) override;
Expand Down
6 changes: 4 additions & 2 deletions test/extensions/filters/http/api_key_auth/config_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit d8470c0

Please sign in to comment.