Skip to content

Commit

Permalink
xDS: reject aggregate cluster with empty cluster list (grpc#32238)
Browse files Browse the repository at this point in the history
  • Loading branch information
markdroth authored and XuanWang-Amos committed May 1, 2023
1 parent 5a1858b commit a6c08f8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/core/ext/xds/xds_cluster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,10 @@ XdsClusterResource::Aggregate AggregateClusterParse(
const upb_StringView* clusters =
envoy_extensions_clusters_aggregate_v3_ClusterConfig_clusters(
aggregate_cluster_config, &size);
if (size == 0) {
ValidationErrors::ScopedField field(errors, ".clusters");
errors->AddError("must be non-empty");
}
for (size_t i = 0; i < size; ++i) {
aggregate.prioritized_cluster_names.emplace_back(
UpbStringToStdString(clusters[i]));
Expand Down
23 changes: 23 additions & 0 deletions test/core/xds/xds_cluster_resource_type_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,29 @@ TEST_F(ClusterTypeTest, AggregateClusterUnparseableProto) {
<< decode_result.resource.status();
}

TEST_F(ClusterTypeTest, AggregateClusterEmptyClusterList) {
Cluster cluster;
cluster.set_name("foo");
cluster.mutable_cluster_type()->set_name("envoy.clusters.aggregate");
cluster.mutable_cluster_type()->mutable_typed_config()->PackFrom(
ClusterConfig());
std::string serialized_resource;
ASSERT_TRUE(cluster.SerializeToString(&serialized_resource));
auto* resource_type = XdsClusterResourceType::Get();
auto decode_result =
resource_type->Decode(decode_context_, serialized_resource);
ASSERT_TRUE(decode_result.name.has_value());
EXPECT_EQ(*decode_result.name, "foo");
EXPECT_EQ(decode_result.resource.status().code(),
absl::StatusCode::kInvalidArgument);
EXPECT_EQ(decode_result.resource.status().message(),
"errors validating Cluster resource: ["
"field:cluster_type.typed_config.value["
"envoy.extensions.clusters.aggregate.v3.ClusterConfig].clusters "
"error:must be non-empty]")
<< decode_result.resource.status();
}

//
// LB policy tests
//
Expand Down

0 comments on commit a6c08f8

Please sign in to comment.