Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[19769] Add tests for reconnection with same GUID (backport #3953) #3978

Merged
merged 1 commit into from
Nov 13, 2023
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
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 @@ -1331,6 +1331,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 @@ -1138,6 +1138,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 @@ -1284,8 +1291,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 @@ -1142,6 +1142,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 @@ -792,6 +792,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