Skip to content
Merged
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
1 change: 1 addition & 0 deletions docs/configuration/cluster_manager/cluster.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Cluster
name
*(required, string)* Supplies the name of the cluster which must be unique across all clusters.
The cluster name is used when emitting :ref:`statistics <config_cluster_manager_cluster_stats>`.
The cluster name can be at most 60 characters long, and must **not** contain ``:``.

type
*(required, string)* The :ref:`service discovery type <arch_overview_service_discovery_types>` to
Expand Down
7 changes: 6 additions & 1 deletion source/common/json/config_schemas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,12 @@ const std::string Json::Schema::CLUSTER_SCHEMA(R"EOF(
},
"type" : "object",
"properties" : {
"name" : {"type" : "string"},
"name" : {
"type" : "string",
"pattern" : "^[^:]+$",
"minLength" : 1,
"maxLength" : 60
},
"type" : {
"type" : "string",
"enum" : ["static", "strict_dns", "logical_dns", "sds"]
Expand Down
34 changes: 34 additions & 0 deletions test/common/upstream/cluster_manager_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,40 @@ TEST_F(ClusterManagerImplTest, UnknownHcType) {
EXPECT_THROW(create(*loader), EnvoyException);
}

TEST_F(ClusterManagerImplTest, MaxClusterName) {
std::string json = R"EOF(
{
"clusters": [
{
"name": "clusterwithareallyreallylongnamemorethanmaxcharsallowedbyschema"
}]
}
)EOF";

Json::ObjectPtr loader = Json::Factory::LoadFromString(json);
EXPECT_THROW_WITH_MESSAGE(create(*loader), Json::Exception,
"JSON object doesn't conform to schema.\n Invalid schema: "
"#/properties/name.\n Invalid keyword: maxLength.\n Invalid document "
"key: #/name");
}

TEST_F(ClusterManagerImplTest, InvalidClusterNameChars) {
std::string json = R"EOF(
{
"clusters": [
{
"name": "cluster:"
}]
}
)EOF";

Json::ObjectPtr loader = Json::Factory::LoadFromString(json);
EXPECT_THROW_WITH_MESSAGE(create(*loader), Json::Exception,
"JSON object doesn't conform to schema.\n Invalid schema: "
"#/properties/name.\n Invalid keyword: pattern.\n Invalid document "
"key: #/name");
}

TEST_F(ClusterManagerImplTest, TcpHealthChecker) {
std::string json = R"EOF(
{
Expand Down
8 changes: 8 additions & 0 deletions test/test_common/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@

#include "common/http/header_map_impl.h"

#define EXPECT_THROW_WITH_MESSAGE(statement, expected_exception, message) \
try { \
statement; \
ADD_FAILURE() << "Exception should take place. It did not."; \
} catch (expected_exception & e) { \
EXPECT_EQ(message, std::string(e.what())); \
}

class TestUtility {
public:
/**
Expand Down