Skip to content

Commit

Permalink
Remove tests for special characters that are rejected by Consul 1.0.3…
Browse files Browse the repository at this point in the history
…+ (Fix for #21)

Related consul change: hashicorp/consul#3762
  • Loading branch information
oliora committed Mar 19, 2018
1 parent 7c71242 commit a59048f
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 281 deletions.
62 changes: 0 additions & 62 deletions tests/agent/agent_checks_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,45 +166,6 @@ TEST_CASE("agent.check_registration", "[consul][agent][checks]")
}
}

TEST_CASE("agent.check_registration_special_chars", "[consul][agent][checks][special chars]")
{
const auto spec_name = "check{1}\r\n\t\x0";

auto consul = create_test_consul();
Agent agent(consul);

agent.deregisterCheck(spec_name);
REQUIRE(!agent.checks().count(spec_name));

SECTION("ttl")
{
agent.registerCheck(spec_name, TtlCheck{std::chrono::seconds(100)}, kw::notes = "note\n1\n2\n3\nsummary: bla bla");

REQUIRE(agent.checks().count(spec_name));
auto c = agent.checks().at(spec_name);

CHECK(c.id == spec_name);
CHECK(c.name == spec_name);
CHECK(c.status != CheckStatus::Passing);
CHECK(c.notes == "note\n1\n2\n3\nsummary: bla bla");
}

SECTION("script")
{
agent.registerCheck(spec_name, ScriptCheck{Non_Existing_Script_Name, std::chrono::seconds(100)});
sleep(0.5); // To get updated state and output

REQUIRE(agent.checks().count(spec_name));
auto c = agent.checks().at(spec_name);

CHECK(c.id == spec_name);
CHECK(c.name == spec_name);
CHECK(c.status != CheckStatus::Passing); // because of Non_Existing_Script_Name
// CHECK(!c.output.empty()); // different results on different Consul versions on different platforms
CHECK(c.notes == "");
}
}

TEST_CASE("agent.http_check_registration", "[consul][agent][checks][http_check]")
{
auto consul = create_test_consul();
Expand Down Expand Up @@ -373,26 +334,3 @@ TEST_CASE("agent.check_expired", "[consul][agent][checks][health]")
CHECK(!c.output.empty());
}

TEST_CASE("agent.check_update_special_chars", "[consul][agent][checks][health][special chars]")
{
const auto spec_name = "check{1}\r\n\t\x0";

auto consul = create_test_consul();
Agent agent(consul);

agent.deregisterCheck(spec_name);
REQUIRE(!agent.checks().count(spec_name));

agent.registerCheck("check1", TtlCheck{std::chrono::minutes(5)}, kw::notes = "the check");

ppconsul::CheckInfo c = agent.checks().at("check1");
REQUIRE(c.status != CheckStatus::Passing);
REQUIRE(c.notes == "the check");
REQUIRE(c.output == "");

agent.pass("check1", "status:\neverything passing!!!\n");
c = agent.checks().at("check1");
REQUIRE(c.status == CheckStatus::Passing);
REQUIRE(c.notes == "the check");
REQUIRE(c.output == "status:\neverything passing!!!\n");
}
70 changes: 0 additions & 70 deletions tests/agent/agent_services_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,76 +254,6 @@ TEST_CASE("agent.service_deregistration_with_script", "[consul][agent][services]
REQUIRE(!agent.checks().count(serviceCheckId("service1")));
}

TEST_CASE("agent.service_registration_special_chars", "[consul][agent][service][special chars]")
{
const auto spec_name = "check{1}\r\n\t\x0";

auto consul = create_test_consul();
Agent agent(consul);

agent.deregisterService(spec_name);
REQUIRE(!agent.services().count(spec_name));
REQUIRE(!agent.checks().count(serviceCheckId(spec_name)));

SECTION("ttl")
{
agent.registerService(spec_name, TtlCheck{std::chrono::minutes(5)});

const auto services = agent.services();
REQUIRE(services.count(spec_name));
const auto & s = services.at(spec_name);

CHECK(s.id == spec_name);
CHECK(s.name == spec_name);
CHECK(s.address == "");
CHECK(s.port == 0);
CHECK(s.tags == ppconsul::Tags());

const auto checks = agent.checks();
REQUIRE(checks.count(serviceCheckId(spec_name)));
const auto & c = checks.at(serviceCheckId(spec_name));

CHECK(c.id == serviceCheckId(spec_name));
CHECK(c.node == agent.self().second.name);
CHECK(!c.name.empty());
CHECK(c.status != CheckStatus::Passing);
CHECK(c.notes.empty());
CHECK(c.output.empty());
CHECK(c.serviceId == spec_name);
CHECK(c.serviceName == spec_name);
}

SECTION("script")
{
agent.registerService(spec_name, ScriptCheck{Non_Existing_Script_Name, std::chrono::minutes(1)});

const auto services = agent.services();
REQUIRE(services.count(spec_name));
const auto & s = services.at(spec_name);

CHECK(s.id == spec_name);
CHECK(s.name == spec_name);
CHECK(s.address == "");
CHECK(s.port == 0);
CHECK(s.tags == ppconsul::Tags());

sleep(0.5); // To get updated state and output

const auto checks = agent.checks();
REQUIRE(checks.count(serviceCheckId(spec_name)));
const auto & c = checks.at(serviceCheckId(spec_name));

CHECK(c.id == serviceCheckId(spec_name));
CHECK(c.node == agent.self().second.name);
CHECK(!c.name.empty());
CHECK(c.notes.empty());
CHECK(c.status != CheckStatus::Passing); // because of Non_Existing_Script_Name
// CHECK(!c.output.empty()); // different results on different Consul versions on different platforms
CHECK(c.serviceId == spec_name);
CHECK(c.serviceName == spec_name);
}
}

TEST_CASE("agent.service_check_update", "[consul][agent][service][health]")
{
auto consul = create_test_consul();
Expand Down
97 changes: 0 additions & 97 deletions tests/catalog/catalog_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,103 +301,6 @@ TEST_CASE("catalog.services", "[consul][catalog][services]")
}
}

TEST_CASE("catalog.services_special_chars", "[consul][catalog][services][special chars]")
{
auto consul = create_test_consul();
Catalog catalog(consul);
Agent agent(consul);

const auto selfMember = Agent(consul).self().second;
const auto selfNode = Node{ selfMember.name, selfMember.address };

agent.deregisterService("service1");
agent.deregisterService("service2");
agent.deregisterService("service3");
agent.registerService(
agent::kw::name = Uniq_Name_1_Spec,
agent::kw::port = 1234,
agent::kw::tags = { "print", Tag_Spec },
agent::kw::id = "service1"
);
agent.registerService(
agent::kw::name = Uniq_Name_2_Spec,
agent::kw::port = 2345,
agent::kw::tags = { "copier", Tag_Spec },
agent::kw::id = "service2"
);
agent.registerService(
agent::kw::name = Uniq_Name_1_Spec,
agent::kw::port = 3456,
agent::kw::tags = { "print", "secret" },
agent::kw::id = "service3"
);

sleep(2.0); // Give some time to propogate registered services to the catalog

SECTION("services")
{
auto services = catalog.services();

REQUIRE(services.count(Uniq_Name_1_Spec));
REQUIRE(services.count(Uniq_Name_2_Spec));

CHECK(services.at(Uniq_Name_1_Spec) == ppconsul::Tags({ "print", "secret", Tag_Spec }));
CHECK(services.at(Uniq_Name_2_Spec) == ppconsul::Tags({ "copier", Tag_Spec }));
}

SECTION("service")
{
auto services = catalog.service(Uniq_Name_1_Spec);

REQUIRE(services.size() == 2);

const auto service1Index = services[0].second.id == "service1" ? 0 : 1;

CHECK(services[service1Index].first == selfNode);
CHECK(services[service1Index].second.name == Uniq_Name_1_Spec);
CHECK(services[service1Index].second.port == 1234);
CHECK(services[service1Index].second.tags == ppconsul::Tags({ "print", Tag_Spec }));
CHECK(services[service1Index].second.id == "service1");

CHECK(services[1 - service1Index].first == selfNode);
CHECK(services[1 - service1Index].second.name == Uniq_Name_1_Spec);
CHECK(services[1 - service1Index].second.port == 3456);
CHECK(services[1 - service1Index].second.tags == ppconsul::Tags({ "print", "secret" }));
CHECK(services[1 - service1Index].second.id == "service3");
}

SECTION("service with tag")
{
auto services1 = catalog.service(Uniq_Name_1_Spec, kw::tag = Tag_Spec);

REQUIRE(services1.size() == 1);

CHECK(services1[0].first == selfNode);
CHECK(services1[0].second.name == Uniq_Name_1_Spec);
CHECK(services1[0].second.port == 1234);
CHECK(services1[0].second.tags == ppconsul::Tags({ "print", Tag_Spec }));
CHECK(services1[0].second.id == "service1");

auto services2 = catalog.service(Uniq_Name_1_Spec, kw::tag = "print");

REQUIRE(services2.size() == 2);

const auto service1Index = services2[0].second.id == "service1" ? 0 : 1;

CHECK(services2[service1Index].first == selfNode);
CHECK(services2[service1Index].second.name == Uniq_Name_1_Spec);
CHECK(services2[service1Index].second.port == 1234);
CHECK(services2[service1Index].second.tags == ppconsul::Tags({ "print", Tag_Spec }));
CHECK(services2[service1Index].second.id == "service1");

CHECK(services2[1 - service1Index].first == selfNode);
CHECK(services2[1 - service1Index].second.name == Uniq_Name_1_Spec);
CHECK(services2[1 - service1Index].second.port == 3456);
CHECK(services2[1 - service1Index].second.tags == ppconsul::Tags({ "print", "secret" }));
CHECK(services2[1 - service1Index].second.id == "service3");
}
}

TEST_CASE("catalog.services_blocking", "[consul][catalog][services][blocking]")
{
auto consul = create_test_consul();
Expand Down
52 changes: 0 additions & 52 deletions tests/kv/kv_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -646,58 +646,6 @@ TEST_CASE("kv.special chars", "[consul][kv][special chars]")
kv.clear();
REQUIRE(kv.empty());

SECTION("get1")
{
kv.set("key{1}/&23\x03", "value1");
KeyValue v = kv.item("key{1}/&23\x03");
REQUIRE(v.valid());
CHECK(v.key == "key{1}/&23\x03");
CHECK(v.value == "value1");
}

SECTION("get2")
{
const auto key = std::string("key\x0-1-\x0", 8);
kv.set(key, "value2");
KeyValue v = kv.item(key);
REQUIRE(v.valid());
CHECK(v.key == key);
CHECK(v.value == "value2");
}

SECTION("getSubKeys1")
{
kv.set("key{1}\x2-1\x2&2-\x03", "value1");
kv.set("key{1}\x2-2\x2&2-\x04", "value2");
kv.set("key{1}\x2-3\x2&2-\x05", "value3");
kv.set("key{1}\x2-3\x2&2-\x06", "value4");
REQUIRE(kv.size() == 4);

auto keys = kv.subKeys("key{1}\x2", "\x2");
REQUIRE(keys.size() == 3);
CHECK(keys[0] == "key{1}\x2-1\x2");
CHECK(keys[1] == "key{1}\x2-2\x2");
CHECK(keys[2] == "key{1}\x2-3\x2");
}

SECTION("getSubKeys2")
{
const auto keyPart = std::string("key{1}\r\n\t\x0", 10);
const auto null = std::string("\x0", 1);

kv.set(keyPart + "-1\t" + null + "&2-\x03", "value1");
kv.set(keyPart + "-2" + null + "&2-\x04", "value2");
kv.set(keyPart + "-3" + null + "&2-\x05", "value3");
kv.set(keyPart + "-3" + null + "&2-\x06", "value4");
REQUIRE(kv.size() == 4);

auto keys = kv.subKeys(keyPart, null);
REQUIRE(keys.size() == 3);
CHECK(keys[0] == keyPart + "-1\t" + null);
CHECK(keys[1] == keyPart + "-2" + null);
CHECK(keys[2] == keyPart + "-3" + null);
}

SECTION("value1")
{
const auto value = std::string("\x2-1\x2&2-\x03", 8);
Expand Down

0 comments on commit a59048f

Please sign in to comment.