diff --git a/src/cpp/rtps/builtin/discovery/participant/PDPSimple.cpp b/src/cpp/rtps/builtin/discovery/participant/PDPSimple.cpp index a9e6fb638a3..3c9cf1ff38b 100644 --- a/src/cpp/rtps/builtin/discovery/participant/PDPSimple.cpp +++ b/src/cpp/rtps/builtin/discovery/participant/PDPSimple.cpp @@ -309,27 +309,29 @@ bool PDPSimple::createPDPEndpoints() secure_endpoints->secure_reader.listener_.reset(new PDPListener(this)); endpoints = secure_endpoints; - endpoints->reader.listener_.reset(new PDPSecurityInitiatorListener(this, [this](const ParticipantProxyData& participant_data) - { - auto secure_pdp_endpoints = static_cast(builtin_endpoints_.get()); - std::lock_guard wlock(secure_pdp_endpoints->writer.writer_->getMutex()); + endpoints->reader.listener_.reset(new PDPSecurityInitiatorListener(this, + [this](const ParticipantProxyData& participant_data) + { + auto secure_pdp_endpoints = + static_cast(builtin_endpoints_.get()); + std::lock_guard wlock(secure_pdp_endpoints->writer.writer_->getMutex()); - CacheChange_t* change = nullptr; - secure_pdp_endpoints->writer.history_->get_earliest_change(&change); + CacheChange_t* change = nullptr; + secure_pdp_endpoints->writer.history_->get_earliest_change(&change); - if (change != nullptr) - { - std::vector remote_readers; - LocatorList_t locators; + if (change != nullptr) + { + std::vector remote_readers; + LocatorList_t locators; - // Send discovery information through the non-secure PDP writer - remote_readers.emplace_back(participant_data.m_guid.guidPrefix, c_EntityId_SPDPReader); + // Send discovery information through the non-secure PDP writer + remote_readers.emplace_back(participant_data.m_guid.guidPrefix, c_EntityId_SPDPReader); - fastdds::rtps::FakeWriter writer(getRTPSParticipant(), c_EntityId_SPDPWriter); + fastdds::rtps::FakeWriter writer(getRTPSParticipant(), c_EntityId_SPDPWriter); - direct_send(getRTPSParticipant(), locators, remote_readers, *change, writer); - } - })); + direct_send(getRTPSParticipant(), locators, remote_readers, *change, writer); + } + })); } else #endif // HAVE_SECURITY diff --git a/test/blackbox/common/BlackboxTestsSecurity.cpp b/test/blackbox/common/BlackboxTestsSecurity.cpp index a50d1cff811..fcd2e320b54 100644 --- a/test/blackbox/common/BlackboxTestsSecurity.cpp +++ b/test/blackbox/common/BlackboxTestsSecurity.cpp @@ -5031,7 +5031,7 @@ TEST(Security, security_with_initial_peers_over_tcpv4_correctly_behaves) Locator_t wan_locator; IPFinder::getIP4Address(&all_locators); - for (auto &locator : all_locators) + for (auto& locator : all_locators) { if (!IPLocator::isLocal(locator)) { @@ -5048,8 +5048,8 @@ TEST(Security, security_with_initial_peers_over_tcpv4_correctly_behaves) LocatorList_t initial_peers; initial_peers.push_back(wan_locator); tcp_client.disable_builtin_transport() - .add_user_transport_to_pparams(tcp_client_transport_descriptor) - .initial_peers(initial_peers); + .add_user_transport_to_pparams(tcp_client_transport_descriptor) + .initial_peers(initial_peers); auto tcp_server_transport_descriptor = std::make_shared(); tcp_server_transport_descriptor->listening_ports.push_back(server_listening_port); @@ -5058,7 +5058,7 @@ TEST(Security, security_with_initial_peers_over_tcpv4_correctly_behaves) std::cout << "SETTING WAN address to " << wan_locator << std::endl; tcp_server.disable_builtin_transport() - .add_user_transport_to_pparams(tcp_server_transport_descriptor); + .add_user_transport_to_pparams(tcp_server_transport_descriptor); // Configure security const std::string governance_file("governance_helloworld_all_enable.smime"); @@ -5087,6 +5087,66 @@ TEST(Security, security_with_initial_peers_over_tcpv4_correctly_behaves) tcp_server.block_for_all(std::chrono::seconds(10)); } +//! Regression test for Redmine issue #20181 +TEST(Security, security_with_initial_peers_over_tcpv4_localhost_correctly_behaves) +{ + // Create + PubSubWriter tcp_client("HelloWorldTopic_TCPLocalhost"); + PubSubReader tcp_server("HelloWorldTopic_TCPLocalhost"); + + // Search for a valid WAN address + LocatorList_t all_locators; + Locator_t wan_locator; + + uint16_t server_listening_port = 11810; + wan_locator.port = server_listening_port; + wan_locator.kind = LOCATOR_KIND_TCPv4; + IPLocator::setIPv4(wan_locator, "127.0.0.1"); + + // Need to specify metatraffic locator for localhost + + auto tcp_client_transport_descriptor = std::make_shared(); + LocatorList_t initial_peers; + initial_peers.push_back(wan_locator); + tcp_client.disable_builtin_transport() + .add_user_transport_to_pparams(tcp_client_transport_descriptor) + .initial_peers(initial_peers); + + auto tcp_server_transport_descriptor = std::make_shared(); + tcp_server_transport_descriptor->listening_ports.push_back(server_listening_port); + IPLocator::copyIPv4(wan_locator, tcp_server_transport_descriptor->wan_addr); + + std::cout << "SETTING WAN address to " << wan_locator << std::endl; + + tcp_server.disable_builtin_transport() + .add_user_transport_to_pparams(tcp_server_transport_descriptor); + + // Configure security + const std::string governance_file("governance_helloworld_all_enable.smime"); + const std::string permissions_file("permissions_helloworld.smime"); + CommonPermissionsConfigure(tcp_server, tcp_client, governance_file, permissions_file); + + tcp_server.init(); + tcp_client.init(); + + ASSERT_TRUE(tcp_server.isInitialized()); + ASSERT_TRUE(tcp_client.isInitialized()); + + tcp_server.waitAuthorized(); + tcp_client.waitAuthorized(); + + tcp_server.wait_discovery(); + tcp_client.wait_discovery(); + + ASSERT_TRUE(tcp_server.is_matched()); + ASSERT_TRUE(tcp_client.is_matched()); + + auto data = default_helloworld_data_generator(); + tcp_server.startReception(data); + tcp_client.send(data); + ASSERT_TRUE(data.empty()); + tcp_server.block_for_all(); +} void blackbox_security_init() {