Skip to content

Commit

Permalink
Add tests for reconnection with same GUID (#3953)
Browse files Browse the repository at this point in the history
* Refs #19769. Added regression test.

Signed-off-by: Miguel Company <[email protected]>

* Refs #19769. Added regression test on PubSubBasic.

Signed-off-by: Miguel Company <[email protected]>

* Refs #19769. Fix build of old-api blackbox test.

Signed-off-by: Miguel Company <[email protected]>

---------

Signed-off-by: Miguel Company <[email protected]>
  • Loading branch information
MiguelCompany authored Oct 31, 2023
1 parent 467216b commit 16e7d90
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 2 deletions.
7 changes: 7 additions & 0 deletions test/blackbox/api/dds-pim/PubSubWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1401,6 +1401,13 @@ class PubSubWriter
return *this;
}

PubSubWriter& guid_prefix(
const eprosima::fastrtps::rtps::GuidPrefix_t& prefix)
{
participant_qos_.wire_protocol().prefix = prefix;
return *this;
}

PubSubWriter& participant_id(
int32_t participantId)
{
Expand Down
9 changes: 7 additions & 2 deletions test/blackbox/api/fastrtps_deprecated/PubSubReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,13 @@ class PubSubReader
return *this;
}

PubSubReader& guid_prefix(
const eprosima::fastrtps::rtps::GuidPrefix_t& prefix)
{
participant_attr_.rtps.prefix = prefix;
return *this;
}

PubSubReader& participant_id(
int32_t participantId)
{
Expand Down Expand Up @@ -1291,8 +1298,6 @@ class PubSubReader
return matched_;
}

private:

const eprosima::fastrtps::rtps::GUID_t& participant_guid() const
{
return participant_guid_;
Expand Down
7 changes: 7 additions & 0 deletions test/blackbox/api/fastrtps_deprecated/PubSubWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,13 @@ class PubSubWriter
return *this;
}

PubSubWriter& guid_prefix(
const eprosima::fastrtps::rtps::GuidPrefix_t& prefix)
{
participant_attr_.rtps.prefix = prefix;
return *this;
}

PubSubWriter& participant_id(
int32_t participantId)
{
Expand Down
19 changes: 19 additions & 0 deletions test/blackbox/common/BlackboxTestsPubSubBasic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,25 @@ TEST_P(PubSubBasic, ReliableVolatileTwoWritersConsecutives)
}
}

TEST_P(PubSubBasic, ReliableVolatileTwoWritersConsecutivesSameGuid)
{
PubSubReader<HelloWorldPubSubType> reader(TEST_TOPIC_NAME);

reader.history_depth(10).reliability(RELIABLE_RELIABILITY_QOS).init();
EXPECT_TRUE(reader.isInitialized());

auto reader_prefix = reader.participant_guid().guidPrefix;
auto writer_prefix = reader_prefix;
writer_prefix.value[11] = 0xFF;

for (int i = 0; i < 2; ++i)
{
PubSubWriter<HelloWorldPubSubType> writer(TEST_TOPIC_NAME);
writer.history_depth(10).durability_kind(VOLATILE_DURABILITY_QOS).guid_prefix(writer_prefix);
two_consecutive_writers(reader, writer, true);
}
}

TEST_P(PubSubBasic, ReliableTransientLocalTwoWritersConsecutives)
{
PubSubReader<HelloWorldPubSubType> reader(TEST_TOPIC_NAME);
Expand Down
81 changes: 81 additions & 0 deletions test/blackbox/common/BlackboxTestsSecurity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,87 @@ TEST_P(Security, BuiltinAuthenticationPlugin_second_participant_creation_loop)
EXPECT_EQ(0u, n_logs);
}

TEST_P(Security, BuiltinAuthenticationPlugin_ensure_same_guid_reconnection)
{
constexpr size_t n_loops = 10;

using Log = eprosima::fastdds::dds::Log;
using LogConsumer = eprosima::fastdds::dds::LogConsumer;

// A LogConsumer that just counts the number of entries consumed
struct TestConsumer : public LogConsumer
{
TestConsumer(
std::atomic_size_t& n_logs_ref)
: n_logs_(n_logs_ref)
{
}

void Consume(
const Log::Entry&) override
{
++n_logs_;
}

private:

std::atomic_size_t& n_logs_;
};

// Counter for log entries
std::atomic<size_t>n_logs{};

// Prepare Log module to check that no SECURITY errors are produced
Log::SetCategoryFilter(std::regex("SECURITY"));
Log::SetVerbosity(Log::Kind::Error);
Log::ClearConsumers();
Log::RegisterConsumer(std::unique_ptr<LogConsumer>(new TestConsumer(n_logs)));

// Prepare participant properties
PropertyPolicy property_policy;
property_policy.properties().emplace_back(Property("dds.sec.auth.plugin", "builtin.PKI-DH"));
property_policy.properties().emplace_back(Property("dds.sec.auth.builtin.PKI-DH.identity_ca",
"file://" + std::string(certs_path) + "/maincacert.pem"));
property_policy.properties().emplace_back(Property("dds.sec.auth.builtin.PKI-DH.identity_certificate",
"file://" + std::string(certs_path) + "/mainpubcert.pem"));
property_policy.properties().emplace_back(Property("dds.sec.auth.builtin.PKI-DH.private_key",
"file://" + std::string(certs_path) + "/mainpubkey.pem"));

// Create the participant being checked
PubSubWriter<HelloWorldPubSubType> main_participant("HelloWorldTopic");
main_participant.property_policy(property_policy).init();
EXPECT_TRUE(main_participant.isInitialized());

eprosima::fastrtps::rtps::GuidPrefix_t guid_prefix;
memset(guid_prefix.value, 0xBB, sizeof(guid_prefix.value));

// Perform a loop in which we create another participant, and destroy it just after it has been discovered.
// This is the best reproducer of the issue, as authentication messages should be sent when a remote participant
// is discovered.
for (size_t n = 1; n <= n_loops; ++n)
{
std::cout << "Iteration " << n << std::endl;

// Wait for undiscovery so we can wait for discovery below
EXPECT_TRUE(main_participant.wait_participant_undiscovery());

// Create another participant with authentication enabled and custom GUID
PubSubReader<HelloWorldPubSubType> other_participant("HelloWorldTopic");
other_participant.property_policy(property_policy).guid_prefix(guid_prefix).init();
EXPECT_TRUE(other_participant.isInitialized());

// Wait for mutual discovery and authentication
main_participant.wait_discovery();
other_participant.wait_discovery();

// The created participant gets out of scope here, and is destroyed
}

// No SECURITY error logs should have been produced
Log::Flush();
EXPECT_EQ(0u, n_logs);
}

TEST_P(Security, BuiltinAuthenticationAndCryptoPlugin_besteffort_rtps_ok)
{
PubSubReader<HelloWorldPubSubType> reader(TEST_TOPIC_NAME);
Expand Down

0 comments on commit 16e7d90

Please sign in to comment.