diff --git a/src/cpp/rtps/security/SecurityManager.cpp b/src/cpp/rtps/security/SecurityManager.cpp index ad69093ce7..309213ecd6 100644 --- a/src/cpp/rtps/security/SecurityManager.cpp +++ b/src/cpp/rtps/security/SecurityManager.cpp @@ -550,6 +550,12 @@ void SecurityManager::remove_discovered_participant_info( authentication_plugin_->return_identity_handle(auth_ptr->identity_handle_, exception); auth_ptr->identity_handle_ = nullptr; + + if (auth_ptr->change_sequence_number_ != SequenceNumber_t::unknown()) + { + participant_stateless_message_writer_history_->remove_change(auth_ptr->change_sequence_number_); + auth_ptr->change_sequence_number_ = SequenceNumber_t::unknown(); + } } } diff --git a/test/blackbox/api/fastrtps_deprecated/PubSubReader.hpp b/test/blackbox/api/fastrtps_deprecated/PubSubReader.hpp index a5e40ab3df..59cc74e6e1 100644 --- a/test/blackbox/api/fastrtps_deprecated/PubSubReader.hpp +++ b/test/blackbox/api/fastrtps_deprecated/PubSubReader.hpp @@ -459,6 +459,45 @@ class PubSubReader std::cout << "Reader discovery finished..." << std::endl; } + bool wait_participant_discovery( + unsigned int min_participants = 1, + std::chrono::seconds timeout = std::chrono::seconds::zero()) + { + bool ret_value = true; + std::unique_lock lock(mutexDiscovery_); + + std::cout << "Reader is waiting discovery of at least " << min_participants << " participants..." << std::endl; + + if (timeout == std::chrono::seconds::zero()) + { + cvDiscovery_.wait(lock, [&]() + { + return participant_matched_ >= min_participants; + }); + } + else + { + if (!cvDiscovery_.wait_for(lock, timeout, [&]() + { + return participant_matched_ >= min_participants; + })) + { + ret_value = false; + } + } + + if (ret_value) + { + std::cout << "Reader participant discovery finished successfully..." << std::endl; + } + else + { + std::cout << "Reader participant discovery finished unsuccessfully..." << std::endl; + } + + return ret_value; + } + bool wait_participant_undiscovery( std::chrono::seconds timeout = std::chrono::seconds::zero()) { diff --git a/test/blackbox/common/BlackboxTestsSecurity.cpp b/test/blackbox/common/BlackboxTestsSecurity.cpp index 853c214bb3..af2c564268 100644 --- a/test/blackbox/common/BlackboxTestsSecurity.cpp +++ b/test/blackbox/common/BlackboxTestsSecurity.cpp @@ -30,6 +30,8 @@ #include #include +#include + using namespace eprosima::fastrtps; using namespace eprosima::fastrtps::rtps; using test_UDPv4Transport = eprosima::fastdds::rtps::test_UDPv4Transport; @@ -438,6 +440,83 @@ TEST_P(Security, BuiltinAuthenticationPlugin_PKIDH_lossy_conditions) reader.wait_discovery(); } +// Regresion test for Refs #13295, github #2362 +TEST_P(Security, BuiltinAuthenticationPlugin_second_participant_creation_loop) +{ + constexpr size_t n_loops = 101; + + 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::atomicn_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(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 + PubSubReader main_participant("HelloWorldTopic"); + main_participant.property_policy(property_policy).init(); + EXPECT_TRUE(main_participant.isInitialized()); + + // 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 + PubSubParticipant other_participant(0, 0, 0, 0); + EXPECT_TRUE(other_participant.property_policy(property_policy).init_participant()); + + // Wait for the new participant to be discovered by the main one + EXPECT_TRUE(main_participant.wait_participant_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 reader(TEST_TOPIC_NAME); diff --git a/test/unittest/rtps/security/SecurityHandshakeProcessTests.cpp b/test/unittest/rtps/security/SecurityHandshakeProcessTests.cpp index 0889ae7b94..6ebed81a0b 100644 --- a/test/unittest/rtps/security/SecurityHandshakeProcessTests.cpp +++ b/test/unittest/rtps/security/SecurityHandshakeProcessTests.cpp @@ -25,11 +25,11 @@ TEST_F(SecurityTest, discovered_participant_begin_handshake_request_fail_and_the CacheChange_t* change = new CacheChange_t(200); EXPECT_CALL(*auth_plugin_, validate_remote_identity_rvr(_, Ref(local_identity_handle_), _, _, _)).Times(1). - WillOnce(DoAll(SetArgPointee<0>(&remote_identity_handle), + WillOnce(DoAll(SetArgPointee<0>(&remote_identity_handle), Return(ValidationResult_t::VALIDATION_PENDING_HANDSHAKE_REQUEST))); EXPECT_CALL(*auth_plugin_, begin_handshake_request(_, _, Ref(local_identity_handle_), Ref(remote_identity_handle), _, _)).Times(1). - WillOnce(Return(ValidationResult_t::VALIDATION_FAILED)); + WillOnce(Return(ValidationResult_t::VALIDATION_FAILED)); ParticipantProxyData participant_data; fill_participant_key(participant_data.m_guid); @@ -45,26 +45,24 @@ TEST_F(SecurityTest, discovered_participant_begin_handshake_request_fail_and_the EXPECT_CALL(*auth_plugin_, validate_remote_identity_rvr(_, Ref(local_identity_handle_), _, _, _)).Times(0); EXPECT_CALL(*auth_plugin_, begin_handshake_request(_, _, Ref(local_identity_handle_), Ref(remote_identity_handle), _, _)).Times(1). - WillOnce(DoAll(SetArgPointee<0>(&handshake_handle), + WillOnce(DoAll(SetArgPointee<0>(&handshake_handle), SetArgPointee<1>(&handshake_message), Return(ValidationResult_t::VALIDATION_PENDING_HANDSHAKE_MESSAGE))); EXPECT_CALL(*stateless_writer_, new_change(_, _, _)).Times(1). - WillOnce(Return(change)); + WillOnce(Return(change)); EXPECT_CALL(*stateless_writer_->history_, add_change_mock(change)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); EXPECT_CALL(*auth_plugin_, return_identity_handle(&local_identity_handle_, _)).Times(1). - WillRepeatedly(Return(true)); + WillRepeatedly(Return(true)); EXPECT_CALL(*auth_plugin_, return_identity_handle(&remote_identity_handle, _)).Times(1). - WillRepeatedly(Return(true)); + WillRepeatedly(Return(true)); EXPECT_CALL(*auth_plugin_, return_handshake_handle(&handshake_handle, _)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); EXPECT_CALL(participant_, pdpsimple()).Times(1).WillOnce(Return(&pdpsimple_)); EXPECT_CALL(pdpsimple_, get_participant_proxy_data_serialized(BIGEND)).Times(1); ASSERT_TRUE(manager_.discovered_participant(participant_data)); - manager_.destroy(); - - delete change; + destroy_manager_and_change(change); } TEST_F(SecurityTest, discovered_participant_process_message_not_remote_participant_key) @@ -92,9 +90,9 @@ TEST_F(SecurityTest, discovered_participant_process_message_not_remote_participa change->serializedPayload.length = aux_msg.length; EXPECT_CALL(*auth_plugin_, return_identity_handle(&local_identity_handle_, _)).Times(1). - WillRepeatedly(Return(true)); + WillRepeatedly(Return(true)); EXPECT_CALL(*stateless_reader_->history_, remove_change_mock(change)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); stateless_reader_->listener_->onNewCacheChangeAdded(stateless_reader_, change); } @@ -106,7 +104,7 @@ TEST_F(SecurityTest, discovered_participant_process_message_bad_message_class_id MockIdentityHandle remote_identity_handle; EXPECT_CALL(*auth_plugin_, validate_remote_identity_rvr(_, Ref(local_identity_handle_), _, _, _)).Times(1). - WillOnce(DoAll(SetArgPointee<0>(&remote_identity_handle), + WillOnce(DoAll(SetArgPointee<0>(&remote_identity_handle), Return(ValidationResult_t::VALIDATION_PENDING_HANDSHAKE_MESSAGE))); ParticipantProxyData participant_data; @@ -133,11 +131,11 @@ TEST_F(SecurityTest, discovered_participant_process_message_bad_message_class_id change->serializedPayload.length = aux_msg.length; EXPECT_CALL(*auth_plugin_, return_identity_handle(&local_identity_handle_, _)).Times(1). - WillRepeatedly(Return(true)); + WillRepeatedly(Return(true)); EXPECT_CALL(*auth_plugin_, return_identity_handle(&remote_identity_handle, _)).Times(1). - WillRepeatedly(Return(true)); + WillRepeatedly(Return(true)); EXPECT_CALL(*stateless_reader_->history_, remove_change_mock(change)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); stateless_reader_->listener_->onNewCacheChangeAdded(stateless_reader_, change); } @@ -149,7 +147,7 @@ TEST_F(SecurityTest, discovered_participant_process_message_not_expecting_reques MockIdentityHandle remote_identity_handle; EXPECT_CALL(*auth_plugin_, validate_remote_identity_rvr(_, Ref(local_identity_handle_), _, _, _)).Times(1). - WillOnce(DoAll(SetArgPointee<0>(&remote_identity_handle), Return(ValidationResult_t::VALIDATION_OK))); + WillOnce(DoAll(SetArgPointee<0>(&remote_identity_handle), Return(ValidationResult_t::VALIDATION_OK))); ParticipantProxyData participant_data; fill_participant_key(participant_data.m_guid); @@ -188,11 +186,11 @@ TEST_F(SecurityTest, discovered_participant_process_message_not_expecting_reques change->serializedPayload.length = aux_msg.length; EXPECT_CALL(*auth_plugin_, return_identity_handle(&local_identity_handle_, _)).Times(1). - WillRepeatedly(Return(true)); + WillRepeatedly(Return(true)); EXPECT_CALL(*auth_plugin_, return_identity_handle(&remote_identity_handle, _)).Times(1). - WillRepeatedly(Return(true)); + WillRepeatedly(Return(true)); EXPECT_CALL(*stateless_reader_->history_, remove_change_mock(change)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); stateless_reader_->listener_->onNewCacheChangeAdded(stateless_reader_, change); } @@ -204,7 +202,7 @@ TEST_F(SecurityTest, discovered_participant_process_message_fail_begin_handshake MockIdentityHandle remote_identity_handle; EXPECT_CALL(*auth_plugin_, validate_remote_identity_rvr(_, Ref(local_identity_handle_), _, _, _)).Times(1). - WillOnce(DoAll(SetArgPointee<0>(&remote_identity_handle), + WillOnce(DoAll(SetArgPointee<0>(&remote_identity_handle), Return(ValidationResult_t::VALIDATION_PENDING_HANDSHAKE_MESSAGE))); ParticipantProxyData participant_data; @@ -237,13 +235,13 @@ TEST_F(SecurityTest, discovered_participant_process_message_fail_begin_handshake EXPECT_CALL(*auth_plugin_, begin_handshake_reply_rvr(_, _, _, Ref(remote_identity_handle), Ref(local_identity_handle_), _, _)).Times(1). - WillOnce(Return(ValidationResult_t::VALIDATION_FAILED)); + WillOnce(Return(ValidationResult_t::VALIDATION_FAILED)); EXPECT_CALL(*auth_plugin_, return_identity_handle(&local_identity_handle_, _)).Times(1). - WillRepeatedly(Return(true)); + WillRepeatedly(Return(true)); EXPECT_CALL(*auth_plugin_, return_identity_handle(&remote_identity_handle, _)).Times(1). - WillRepeatedly(Return(true)); + WillRepeatedly(Return(true)); EXPECT_CALL(*stateless_reader_->history_, remove_change_mock(change)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); ParticipantAuthenticationInfo info; info.status = ParticipantAuthenticationInfo::UNAUTHORIZED_PARTICIPANT; info.guid = participant_data.m_guid; @@ -261,7 +259,7 @@ TEST_F(SecurityTest, discovered_participant_process_message_ok_begin_handshake_r MockIdentityHandle remote_identity_handle; EXPECT_CALL(*auth_plugin_, validate_remote_identity_rvr(_, Ref(local_identity_handle_), _, _, _)).Times(1). - WillOnce(DoAll(SetArgPointee<0>(&remote_identity_handle), + WillOnce(DoAll(SetArgPointee<0>(&remote_identity_handle), Return(ValidationResult_t::VALIDATION_PENDING_HANDSHAKE_MESSAGE))); ParticipantProxyData participant_data; @@ -298,32 +296,32 @@ TEST_F(SecurityTest, discovered_participant_process_message_ok_begin_handshake_r EXPECT_CALL(*auth_plugin_, begin_handshake_reply_rvr(_, _, _, Ref(remote_identity_handle), Ref(local_identity_handle_), _, _)).Times(1). - WillOnce(DoAll(SetArgPointee<0>(&handshake_handle), + WillOnce(DoAll(SetArgPointee<0>(&handshake_handle), Return(ValidationResult_t::VALIDATION_OK))); EXPECT_CALL(*auth_plugin_, return_identity_handle(&local_identity_handle_, _)).Times(1). - WillRepeatedly(Return(true)); + WillRepeatedly(Return(true)); EXPECT_CALL(*auth_plugin_, return_identity_handle(&remote_identity_handle, _)).Times(1). - WillRepeatedly(Return(true)); + WillRepeatedly(Return(true)); EXPECT_CALL(*auth_plugin_, return_handshake_handle(&handshake_handle, _)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); EXPECT_CALL(*stateless_reader_->history_, remove_change_mock(change)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); EXPECT_CALL(participant_, pdpsimple()).Times(2).WillRepeatedly(Return(&pdpsimple_)); EXPECT_CALL(pdpsimple_, notifyAboveRemoteEndpoints(_)).Times(1); EXPECT_CALL(pdpsimple_, get_participant_proxy_data_serialized(BIGEND)).Times(1); EXPECT_CALL(*auth_plugin_, get_shared_secret(Ref(handshake_handle), _)).Times(1). - WillOnce(Return(&shared_secret_handle)); + WillOnce(Return(&shared_secret_handle)); EXPECT_CALL(*auth_plugin_, return_sharedsecret_handle(&shared_secret_handle, _)).Times(1). - WillRepeatedly(Return(true)); + WillRepeatedly(Return(true)); EXPECT_CALL(crypto_plugin_->cryptokeyfactory_, register_matched_remote_participant(Ref(local_participant_crypto_handle_), Ref(remote_identity_handle), _, Ref(shared_secret_handle), _)).Times(1). - WillOnce(Return(&participant_crypto_handle)); + WillOnce(Return(&participant_crypto_handle)); EXPECT_CALL(crypto_plugin_->cryptokeyexchange_, create_local_participant_crypto_tokens(_, Ref(local_participant_crypto_handle_), Ref(participant_crypto_handle), _)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); EXPECT_CALL(crypto_plugin_->cryptokeyfactory_, unregister_participant(&participant_crypto_handle, _)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); ParticipantAuthenticationInfo info; info.status = ParticipantAuthenticationInfo::AUTHORIZED_PARTICIPANT; @@ -340,7 +338,7 @@ TEST_F(SecurityTest, discovered_participant_process_message_new_change_fail) MockIdentityHandle remote_identity_handle; EXPECT_CALL(*auth_plugin_, validate_remote_identity_rvr(_, Ref(local_identity_handle_), _, _, _)).Times(1). - WillOnce(DoAll(SetArgPointee<0>(&remote_identity_handle), + WillOnce(DoAll(SetArgPointee<0>(&remote_identity_handle), Return(ValidationResult_t::VALIDATION_PENDING_HANDSHAKE_MESSAGE))); ParticipantProxyData participant_data; @@ -376,18 +374,18 @@ TEST_F(SecurityTest, discovered_participant_process_message_new_change_fail) EXPECT_CALL(*auth_plugin_, begin_handshake_reply_rvr(_, _, _, Ref(remote_identity_handle), Ref(local_identity_handle_), _, _)).Times(1). - WillOnce(DoAll(SetArgPointee<0>(&handshake_handle), + WillOnce(DoAll(SetArgPointee<0>(&handshake_handle), SetArgPointee<1>(&handshake_message), Return(ValidationResult_t::VALIDATION_PENDING_HANDSHAKE_MESSAGE))); EXPECT_CALL(*auth_plugin_, return_identity_handle(&local_identity_handle_, _)).Times(1). - WillRepeatedly(Return(true)); + WillRepeatedly(Return(true)); EXPECT_CALL(*auth_plugin_, return_identity_handle(&remote_identity_handle, _)).Times(1). - WillRepeatedly(Return(true)); + WillRepeatedly(Return(true)); EXPECT_CALL(*stateless_writer_, new_change(_, _, _)).Times(1). - WillOnce(Return(nullptr)); + WillOnce(Return(nullptr)); EXPECT_CALL(*auth_plugin_, return_handshake_handle(&handshake_handle, _)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); EXPECT_CALL(*stateless_reader_->history_, remove_change_mock(change)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); EXPECT_CALL(participant_, pdpsimple()).Times(1).WillOnce(Return(&pdpsimple_)); EXPECT_CALL(pdpsimple_, get_participant_proxy_data_serialized(BIGEND)).Times(1); @@ -401,7 +399,7 @@ TEST_F(SecurityTest, discovered_participant_process_message_add_change_fail) MockIdentityHandle remote_identity_handle; EXPECT_CALL(*auth_plugin_, validate_remote_identity_rvr(_, Ref(local_identity_handle_), _, _, _)).Times(1). - WillOnce(DoAll(SetArgPointee<0>(&remote_identity_handle), + WillOnce(DoAll(SetArgPointee<0>(&remote_identity_handle), Return(ValidationResult_t::VALIDATION_PENDING_HANDSHAKE_MESSAGE))); ParticipantProxyData participant_data; @@ -438,63 +436,62 @@ TEST_F(SecurityTest, discovered_participant_process_message_add_change_fail) EXPECT_CALL(*auth_plugin_, begin_handshake_reply_rvr(_, _, _, Ref(remote_identity_handle), Ref(local_identity_handle_), _, _)).Times(1). - WillOnce(DoAll(SetArgPointee<0>(&handshake_handle), + WillOnce(DoAll(SetArgPointee<0>(&handshake_handle), SetArgPointee<1>(&handshake_message), Return(ValidationResult_t::VALIDATION_PENDING_HANDSHAKE_MESSAGE))); EXPECT_CALL(*auth_plugin_, return_identity_handle(&local_identity_handle_, _)).Times(1). - WillRepeatedly(Return(true)); + WillRepeatedly(Return(true)); EXPECT_CALL(*auth_plugin_, return_identity_handle(&remote_identity_handle, _)).Times(1). - WillRepeatedly(Return(true)); + WillRepeatedly(Return(true)); EXPECT_CALL(*stateless_writer_, new_change(_, _, _)).Times(1). - WillOnce(Return(change2)); + WillOnce(Return(change2)); EXPECT_CALL(*stateless_writer_->history_, add_change_mock(change2)).Times(1). - WillOnce(Return(false)); + WillOnce(Return(false)); EXPECT_CALL(*auth_plugin_, return_handshake_handle(&handshake_handle, _)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); EXPECT_CALL(*stateless_reader_->history_, remove_change_mock(change)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); EXPECT_CALL(participant_, pdpsimple()).Times(1).WillOnce(Return(&pdpsimple_)); EXPECT_CALL(pdpsimple_, get_participant_proxy_data_serialized(BIGEND)).Times(1); stateless_reader_->listener_->onNewCacheChangeAdded(stateless_reader_, change); - manager_.destroy(); - - delete change2; + destroy_manager_and_change(change2, false); } TEST_F(SecurityTest, discovered_participant_process_message_pending_handshake_reply_pending_message) { EXPECT_CALL(*auth_plugin_, return_identity_handle(&local_identity_handle_, _)).Times(1). - WillRepeatedly(Return(true)); + WillRepeatedly(Return(true)); EXPECT_CALL(*auth_plugin_, return_identity_handle(&remote_identity_handle_, _)).Times(1). - WillRepeatedly(Return(true)); + WillRepeatedly(Return(true)); EXPECT_CALL(*auth_plugin_, return_handshake_handle(&handshake_handle_, _)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); reply_process_ok(); + + EXPECT_CALL(*stateless_writer_->history_, remove_change(SequenceNumber_t{ 0, 1 })).Times(1). + WillOnce(Return(true)); } TEST_F(SecurityTest, discovered_participant_process_message_pending_handshake_reply_pending_message_resent) { EXPECT_CALL(*auth_plugin_, return_identity_handle(&local_identity_handle_, _)).Times(1). - WillRepeatedly(Return(true)); + WillRepeatedly(Return(true)); EXPECT_CALL(*auth_plugin_, return_identity_handle(&remote_identity_handle_, _)).Times(1). - WillRepeatedly(Return(true)); + WillRepeatedly(Return(true)); EXPECT_CALL(*auth_plugin_, return_handshake_handle(&handshake_handle_, _)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); CacheChange_t* reply_message_change = nullptr; reply_process_ok(&reply_message_change); EXPECT_CALL(*stateless_writer_->history_, remove_change_and_reuse(reply_message_change->sequenceNumber)).Times(1). - WillOnce(Return(reply_message_change)); + WillOnce(Return(reply_message_change)); EXPECT_CALL(*stateless_writer_->history_, add_change_mock(reply_message_change)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); stateless_writer_->history_->wait_for_more_samples_than(1); - manager_.destroy(); - - delete reply_message_change; + destroy_manager_and_change(reply_message_change); } TEST_F(SecurityTest, discovered_participant_process_message_pending_handshake_reply_ok_with_final_message) @@ -504,7 +501,7 @@ TEST_F(SecurityTest, discovered_participant_process_message_pending_handshake_re MockIdentityHandle remote_identity_handle; EXPECT_CALL(*auth_plugin_, validate_remote_identity_rvr(_, Ref(local_identity_handle_), _, _, _)).Times(1). - WillOnce(DoAll(SetArgPointee<0>(&remote_identity_handle), + WillOnce(DoAll(SetArgPointee<0>(&remote_identity_handle), Return(ValidationResult_t::VALIDATION_PENDING_HANDSHAKE_MESSAGE))); ParticipantProxyData participant_data; @@ -543,36 +540,36 @@ TEST_F(SecurityTest, discovered_participant_process_message_pending_handshake_re EXPECT_CALL(*auth_plugin_, begin_handshake_reply_rvr(_, _, _, Ref(remote_identity_handle), Ref(local_identity_handle_), _, _)).Times(1). - WillOnce(DoAll(SetArgPointee<0>(&handshake_handle), + WillOnce(DoAll(SetArgPointee<0>(&handshake_handle), SetArgPointee<1>(&handshake_message), Return(ValidationResult_t::VALIDATION_OK_WITH_FINAL_MESSAGE))); EXPECT_CALL(*auth_plugin_, return_identity_handle(&local_identity_handle_, _)).Times(1). - WillRepeatedly(Return(true)); + WillRepeatedly(Return(true)); EXPECT_CALL(*auth_plugin_, return_identity_handle(&remote_identity_handle, _)).Times(1). - WillRepeatedly(Return(true)); + WillRepeatedly(Return(true)); EXPECT_CALL(*stateless_writer_, new_change(_, _, _)).Times(1). - WillOnce(Return(change2)); + WillOnce(Return(change2)); EXPECT_CALL(*stateless_writer_->history_, add_change_mock(change2)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); EXPECT_CALL(*auth_plugin_, return_handshake_handle(&handshake_handle, _)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); EXPECT_CALL(*stateless_reader_->history_, remove_change_mock(change)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); EXPECT_CALL(participant_, pdpsimple()).Times(2).WillRepeatedly(Return(&pdpsimple_)); EXPECT_CALL(pdpsimple_, notifyAboveRemoteEndpoints(_)).Times(1); EXPECT_CALL(pdpsimple_, get_participant_proxy_data_serialized(BIGEND)).Times(1); EXPECT_CALL(*auth_plugin_, get_shared_secret(Ref(handshake_handle), _)).Times(1). - WillOnce(Return(&shared_secret_handle)); + WillOnce(Return(&shared_secret_handle)); EXPECT_CALL(*auth_plugin_, return_sharedsecret_handle(&shared_secret_handle, _)).Times(1). - WillRepeatedly(Return(true)); + WillRepeatedly(Return(true)); EXPECT_CALL(crypto_plugin_->cryptokeyfactory_, register_matched_remote_participant(Ref(local_participant_crypto_handle_), Ref(remote_identity_handle), _, Ref(shared_secret_handle), _)).Times(1). - WillOnce(Return(&participant_crypto_handle)); + WillOnce(Return(&participant_crypto_handle)); EXPECT_CALL(crypto_plugin_->cryptokeyexchange_, create_local_participant_crypto_tokens(_, Ref(local_participant_crypto_handle_), Ref(participant_crypto_handle), _)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); EXPECT_CALL(crypto_plugin_->cryptokeyfactory_, unregister_participant(&participant_crypto_handle, _)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); ParticipantAuthenticationInfo info; info.status = ParticipantAuthenticationInfo::AUTHORIZED_PARTICIPANT; @@ -581,14 +578,13 @@ TEST_F(SecurityTest, discovered_participant_process_message_pending_handshake_re stateless_reader_->listener_->onNewCacheChangeAdded(stateless_reader_, change); - manager_.destroy(); - - delete change2; + destroy_manager_and_change(change2); } TEST_F(SecurityTest, discovered_participant_process_message_fail_process_handshake_reply) { request_process_ok(); + EXPECT_CALL(*stateless_writer_->history_, remove_change(SequenceNumber_t{0, 1})).Times(1).WillOnce(Return(true)); GUID_t remote_participant_key(participant_data_.m_guid); @@ -619,15 +615,15 @@ TEST_F(SecurityTest, discovered_participant_process_message_fail_process_handsha change->serializedPayload.length = aux_msg.length; EXPECT_CALL(*auth_plugin_, process_handshake_rvr(_, _, Ref(handshake_handle_), _)).Times(1). - WillOnce(Return(ValidationResult_t::VALIDATION_FAILED)); + WillOnce(Return(ValidationResult_t::VALIDATION_FAILED)); EXPECT_CALL(*auth_plugin_, return_identity_handle(&local_identity_handle_, _)).Times(1). - WillRepeatedly(Return(true)); + WillRepeatedly(Return(true)); EXPECT_CALL(*auth_plugin_, return_identity_handle(&remote_identity_handle_, _)).Times(1). - WillRepeatedly(Return(true)); + WillRepeatedly(Return(true)); EXPECT_CALL(*auth_plugin_, return_handshake_handle(&handshake_handle_, _)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); EXPECT_CALL(*stateless_reader_->history_, remove_change_mock(change)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); ParticipantAuthenticationInfo info; info.status = ParticipantAuthenticationInfo::UNAUTHORIZED_PARTICIPANT; info.guid = remote_participant_key; @@ -641,7 +637,7 @@ TEST_F(SecurityTest, discovered_participant_process_message_ok_process_handshake request_process_ok(); EXPECT_CALL(*stateless_writer_->history_, remove_change(SequenceNumber_t{0, 1})).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); GUID_t remote_participant_key(participant_data_.m_guid); @@ -675,30 +671,30 @@ TEST_F(SecurityTest, discovered_participant_process_message_ok_process_handshake MockParticipantCryptoHandle participant_crypto_handle; EXPECT_CALL(*auth_plugin_, process_handshake_rvr(_, _, Ref(handshake_handle_), _)).Times(1). - WillOnce(Return(ValidationResult_t::VALIDATION_OK)); + WillOnce(Return(ValidationResult_t::VALIDATION_OK)); EXPECT_CALL(*auth_plugin_, return_identity_handle(&local_identity_handle_, _)).Times(1). - WillRepeatedly(Return(true)); + WillRepeatedly(Return(true)); EXPECT_CALL(*auth_plugin_, return_identity_handle(&remote_identity_handle_, _)).Times(1). - WillRepeatedly(Return(true)); + WillRepeatedly(Return(true)); EXPECT_CALL(*auth_plugin_, return_handshake_handle(&handshake_handle_, _)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); EXPECT_CALL(*stateless_reader_->history_, remove_change_mock(change)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); EXPECT_CALL(participant_, pdpsimple()).Times(1).WillOnce(Return(&pdpsimple_)); EXPECT_CALL(pdpsimple_, notifyAboveRemoteEndpoints(_)).Times(1); EXPECT_CALL(*auth_plugin_, get_shared_secret(Ref(handshake_handle_), _)).Times(1). - WillOnce(Return(&shared_secret_handle)); + WillOnce(Return(&shared_secret_handle)); EXPECT_CALL(*auth_plugin_, return_sharedsecret_handle(&shared_secret_handle, _)).Times(1). - WillRepeatedly(Return(true)); + WillRepeatedly(Return(true)); EXPECT_CALL(crypto_plugin_->cryptokeyfactory_, register_matched_remote_participant(Ref(local_participant_crypto_handle_), Ref(remote_identity_handle_), _, Ref(shared_secret_handle), _)).Times(1). - WillOnce(Return(&participant_crypto_handle)); + WillOnce(Return(&participant_crypto_handle)); EXPECT_CALL(crypto_plugin_->cryptokeyexchange_, create_local_participant_crypto_tokens(_, Ref(local_participant_crypto_handle_), Ref(participant_crypto_handle), _)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); EXPECT_CALL(crypto_plugin_->cryptokeyfactory_, unregister_participant(&participant_crypto_handle, _)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); ParticipantAuthenticationInfo info; info.status = ParticipantAuthenticationInfo::AUTHORIZED_PARTICIPANT; @@ -713,7 +709,7 @@ TEST_F(SecurityTest, discovered_participant_process_message_process_handshake_re request_process_ok(); EXPECT_CALL(*stateless_writer_->history_, remove_change(SequenceNumber_t{0, 1})).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); GUID_t remote_participant_key(participant_data_.m_guid); @@ -746,18 +742,18 @@ TEST_F(SecurityTest, discovered_participant_process_message_process_handshake_re HandshakeMessageToken handshake_message; EXPECT_CALL(*auth_plugin_, process_handshake_rvr(_, _, Ref(handshake_handle_), _)).Times(1). - WillOnce(DoAll(SetArgPointee<0>(&handshake_message), + WillOnce(DoAll(SetArgPointee<0>(&handshake_message), Return(ValidationResult_t::VALIDATION_PENDING_HANDSHAKE_MESSAGE))); EXPECT_CALL(*auth_plugin_, return_identity_handle(&local_identity_handle_, _)).Times(1). - WillRepeatedly(Return(true)); + WillRepeatedly(Return(true)); EXPECT_CALL(*auth_plugin_, return_identity_handle(&remote_identity_handle_, _)).Times(1). - WillRepeatedly(Return(true)); + WillRepeatedly(Return(true)); EXPECT_CALL(*stateless_writer_, new_change(_, _, _)).Times(1). - WillOnce(Return(nullptr)); + WillOnce(Return(nullptr)); EXPECT_CALL(*auth_plugin_, return_handshake_handle(&handshake_handle_, _)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); EXPECT_CALL(*stateless_reader_->history_, remove_change_mock(change)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); stateless_reader_->listener_->onNewCacheChangeAdded(stateless_reader_, change); } @@ -767,7 +763,7 @@ TEST_F(SecurityTest, discovered_participant_process_message_process_handshake_re request_process_ok(); EXPECT_CALL(*stateless_writer_->history_, remove_change(SequenceNumber_t{0, 1})).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); GUID_t remote_participant_key(participant_data_.m_guid); @@ -801,48 +797,49 @@ TEST_F(SecurityTest, discovered_participant_process_message_process_handshake_re CacheChange_t* change2 = new CacheChange_t(200); EXPECT_CALL(*auth_plugin_, process_handshake_rvr(_, _, Ref(handshake_handle_), _)).Times(1). - WillOnce(DoAll(SetArgPointee<0>(&handshake_message), + WillOnce(DoAll(SetArgPointee<0>(&handshake_message), Return(ValidationResult_t::VALIDATION_PENDING_HANDSHAKE_MESSAGE))); EXPECT_CALL(*auth_plugin_, return_identity_handle(&local_identity_handle_, _)).Times(1). - WillRepeatedly(Return(true)); + WillRepeatedly(Return(true)); EXPECT_CALL(*auth_plugin_, return_identity_handle(&remote_identity_handle_, _)).Times(1). - WillRepeatedly(Return(true)); + WillRepeatedly(Return(true)); EXPECT_CALL(*stateless_writer_, new_change(_, _, _)).Times(1). - WillOnce(Return(change2)); + WillOnce(Return(change2)); EXPECT_CALL(*stateless_writer_->history_, add_change_mock(change2)).Times(1). - WillOnce(Return(false)); + WillOnce(Return(false)); EXPECT_CALL(*auth_plugin_, return_handshake_handle(&handshake_handle_, _)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); EXPECT_CALL(*stateless_reader_->history_, remove_change_mock(change)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); stateless_reader_->listener_->onNewCacheChangeAdded(stateless_reader_, change); - manager_.destroy(); - - delete change2; + destroy_manager_and_change(change2, false); } TEST_F(SecurityTest, discovered_participant_process_message_process_handshake_reply_ok_with_final_message) { EXPECT_CALL(*auth_plugin_, return_identity_handle(&local_identity_handle_, _)).Times(1). - WillRepeatedly(Return(true)); + WillRepeatedly(Return(true)); EXPECT_CALL(*auth_plugin_, return_identity_handle(&remote_identity_handle_, _)).Times(1). - WillRepeatedly(Return(true)); + WillRepeatedly(Return(true)); EXPECT_CALL(*auth_plugin_, return_handshake_handle(&handshake_handle_, _)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); final_message_process_ok(); + + EXPECT_CALL(*stateless_writer_->history_, remove_change(SequenceNumber_t{0, 2})).Times(1). + WillOnce(Return(true)); } TEST_F(SecurityTest, discovered_participant_process_message_process_handshake_reply_ok_with_final_message_resent) { EXPECT_CALL(*auth_plugin_, return_identity_handle(&local_identity_handle_, _)).Times(1). - WillRepeatedly(Return(true)); + WillRepeatedly(Return(true)); EXPECT_CALL(*auth_plugin_, return_identity_handle(&remote_identity_handle_, _)).Times(1). - WillRepeatedly(Return(true)); + WillRepeatedly(Return(true)); EXPECT_CALL(*auth_plugin_, return_handshake_handle(&handshake_handle_, _)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); CacheChange_t* final_message_change = nullptr; final_message_process_ok(&final_message_change); @@ -876,22 +873,21 @@ TEST_F(SecurityTest, discovered_participant_process_message_process_handshake_re change->serializedPayload.length = aux_msg.length; EXPECT_CALL(*stateless_writer_->history_, remove_change_and_reuse(final_message_change->sequenceNumber)).Times(1). - WillOnce(Return(final_message_change)); + WillOnce(Return(final_message_change)); EXPECT_CALL(*stateless_writer_->history_, add_change_mock(final_message_change)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); EXPECT_CALL(*stateless_reader_->history_, remove_change_mock(change)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); stateless_reader_->listener_->onNewCacheChangeAdded(stateless_reader_, change); - manager_.destroy(); - - delete final_message_change; + destroy_manager_and_change(final_message_change); } TEST_F(SecurityTest, discovered_participant_process_message_bad_related_guid) { reply_process_ok(); + EXPECT_CALL(*stateless_writer_->history_, remove_change(SequenceNumber_t{ 0, 1 })).Times(1).WillOnce(Return(true)); GUID_t remote_participant_key(participant_data_.m_guid); remote_participant_key.guidPrefix.value[0] = 0xFF; @@ -923,13 +919,13 @@ TEST_F(SecurityTest, discovered_participant_process_message_bad_related_guid) change->serializedPayload.length = aux_msg.length; EXPECT_CALL(*auth_plugin_, return_identity_handle(&local_identity_handle_, _)).Times(1). - WillRepeatedly(Return(true)); + WillRepeatedly(Return(true)); EXPECT_CALL(*auth_plugin_, return_identity_handle(&remote_identity_handle_, _)).Times(1). - WillRepeatedly(Return(true)); + WillRepeatedly(Return(true)); EXPECT_CALL(*auth_plugin_, return_handshake_handle(&handshake_handle_, _)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); EXPECT_CALL(*stateless_reader_->history_, remove_change_mock(change)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); stateless_reader_->listener_->onNewCacheChangeAdded(stateless_reader_, change); } @@ -937,6 +933,7 @@ TEST_F(SecurityTest, discovered_participant_process_message_bad_related_guid) TEST_F(SecurityTest, discovered_participant_process_message_bad_related_sequence_number) { reply_process_ok(); + EXPECT_CALL(*stateless_writer_->history_, remove_change(SequenceNumber_t{ 0, 1 })).Times(1).WillOnce(Return(true)); GUID_t remote_participant_key(participant_data_.m_guid); @@ -967,13 +964,13 @@ TEST_F(SecurityTest, discovered_participant_process_message_bad_related_sequence change->serializedPayload.length = aux_msg.length; EXPECT_CALL(*auth_plugin_, return_identity_handle(&local_identity_handle_, _)).Times(1). - WillRepeatedly(Return(true)); + WillRepeatedly(Return(true)); EXPECT_CALL(*auth_plugin_, return_identity_handle(&remote_identity_handle_, _)).Times(1). - WillRepeatedly(Return(true)); + WillRepeatedly(Return(true)); EXPECT_CALL(*auth_plugin_, return_handshake_handle(&handshake_handle_, _)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); EXPECT_CALL(*stateless_reader_->history_, remove_change_mock(change)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); stateless_reader_->listener_->onNewCacheChangeAdded(stateless_reader_, change); } @@ -981,6 +978,7 @@ TEST_F(SecurityTest, discovered_participant_process_message_bad_related_sequence TEST_F(SecurityTest, discovered_participant_process_message_fail_process_handshake_final) { reply_process_ok(); + EXPECT_CALL(*stateless_writer_->history_, remove_change(SequenceNumber_t{ 0, 1 })).Times(1).WillOnce(Return(true)); GUID_t remote_participant_key(participant_data_.m_guid); @@ -1011,15 +1009,15 @@ TEST_F(SecurityTest, discovered_participant_process_message_fail_process_handsha change->serializedPayload.length = aux_msg.length; EXPECT_CALL(*auth_plugin_, process_handshake_rvr(_, _, Ref(handshake_handle_), _)).Times(1). - WillOnce(Return(ValidationResult_t::VALIDATION_FAILED)); + WillOnce(Return(ValidationResult_t::VALIDATION_FAILED)); EXPECT_CALL(*auth_plugin_, return_identity_handle(&local_identity_handle_, _)).Times(1). - WillRepeatedly(Return(true)); + WillRepeatedly(Return(true)); EXPECT_CALL(*auth_plugin_, return_identity_handle(&remote_identity_handle_, _)).Times(1). - WillRepeatedly(Return(true)); + WillRepeatedly(Return(true)); EXPECT_CALL(*auth_plugin_, return_handshake_handle(&handshake_handle_, _)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); EXPECT_CALL(*stateless_reader_->history_, remove_change_mock(change)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); ParticipantAuthenticationInfo info; info.status = ParticipantAuthenticationInfo::UNAUTHORIZED_PARTICIPANT; info.guid = remote_participant_key; @@ -1033,7 +1031,7 @@ TEST_F(SecurityTest, discovered_participant_process_message_ok_process_handshake reply_process_ok(); EXPECT_CALL(*stateless_writer_->history_, remove_change(SequenceNumber_t{0, 1})).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); GUID_t remote_participant_key(participant_data_.m_guid); @@ -1067,30 +1065,30 @@ TEST_F(SecurityTest, discovered_participant_process_message_ok_process_handshake MockParticipantCryptoHandle participant_crypto_handle; EXPECT_CALL(*auth_plugin_, process_handshake_rvr(_, _, Ref(handshake_handle_), _)).Times(1). - WillOnce(Return(ValidationResult_t::VALIDATION_OK)); + WillOnce(Return(ValidationResult_t::VALIDATION_OK)); EXPECT_CALL(*auth_plugin_, return_identity_handle(&local_identity_handle_, _)).Times(1). - WillRepeatedly(Return(true)); + WillRepeatedly(Return(true)); EXPECT_CALL(*auth_plugin_, return_identity_handle(&remote_identity_handle_, _)).Times(1). - WillRepeatedly(Return(true)); + WillRepeatedly(Return(true)); EXPECT_CALL(*auth_plugin_, return_handshake_handle(&handshake_handle_, _)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); EXPECT_CALL(*stateless_reader_->history_, remove_change_mock(change)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); EXPECT_CALL(participant_, pdpsimple()).Times(1).WillOnce(Return(&pdpsimple_)); EXPECT_CALL(pdpsimple_, notifyAboveRemoteEndpoints(_)).Times(1); EXPECT_CALL(*auth_plugin_, get_shared_secret(Ref(handshake_handle_), _)).Times(1). - WillOnce(Return(&shared_secret_handle)); + WillOnce(Return(&shared_secret_handle)); EXPECT_CALL(*auth_plugin_, return_sharedsecret_handle(&shared_secret_handle, _)).Times(1). - WillRepeatedly(Return(true)); + WillRepeatedly(Return(true)); EXPECT_CALL(crypto_plugin_->cryptokeyfactory_, register_matched_remote_participant(Ref(local_participant_crypto_handle_), Ref(remote_identity_handle_), _, Ref(shared_secret_handle), _)).Times(1). - WillOnce(Return(&participant_crypto_handle)); + WillOnce(Return(&participant_crypto_handle)); EXPECT_CALL(crypto_plugin_->cryptokeyexchange_, create_local_participant_crypto_tokens(_, Ref(local_participant_crypto_handle_), Ref(participant_crypto_handle), _)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); EXPECT_CALL(crypto_plugin_->cryptokeyfactory_, unregister_participant(&participant_crypto_handle, _)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); ParticipantAuthenticationInfo info; info.status = ParticipantAuthenticationInfo::AUTHORIZED_PARTICIPANT; diff --git a/test/unittest/rtps/security/SecurityTests.cpp b/test/unittest/rtps/security/SecurityTests.cpp index 4ea1289643..4e7759eaff 100644 --- a/test/unittest/rtps/security/SecurityTests.cpp +++ b/test/unittest/rtps/security/SecurityTests.cpp @@ -25,19 +25,19 @@ void SecurityTest::initialization_ok() volatile_reader_ = new ::testing::NiceMock(); EXPECT_CALL(*auth_plugin_, validate_local_identity(_, _, _, _, _, _)).Times(1). - WillOnce(DoAll(SetArgPointee<0>(&local_identity_handle_), Return(ValidationResult_t::VALIDATION_OK))); + WillOnce(DoAll(SetArgPointee<0>(&local_identity_handle_), Return(ValidationResult_t::VALIDATION_OK))); EXPECT_CALL(crypto_plugin_->cryptokeyfactory_, register_local_participant(Ref(local_identity_handle_), _, _, _, _)).Times(1). - WillOnce(Return(&local_participant_crypto_handle_)); + WillOnce(Return(&local_participant_crypto_handle_)); EXPECT_CALL(crypto_plugin_->cryptokeyfactory_, unregister_participant(&local_participant_crypto_handle_, _)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); EXPECT_CALL(participant_, createWriter_mock(_, _, _, _, _, _)).Times(2). - WillOnce(DoAll(SetArgPointee<0>(stateless_writer_), Return(true))). - WillOnce(DoAll(SetArgPointee<0>(volatile_writer_), Return(true))); + WillOnce(DoAll(SetArgPointee<0>(stateless_writer_), Return(true))). + WillOnce(DoAll(SetArgPointee<0>(volatile_writer_), Return(true))); EXPECT_CALL(participant_, createReader_mock(_, _, _, _, _, _, _)).Times(2). - WillOnce(DoAll(SetArgPointee<0>(stateless_reader_), Return(true))). - WillOnce(DoAll(SetArgPointee<0>(volatile_reader_), Return(true))); + WillOnce(DoAll(SetArgPointee<0>(stateless_reader_), Return(true))). + WillOnce(DoAll(SetArgPointee<0>(volatile_reader_), Return(true))); ASSERT_TRUE(manager_.init(security_attributes_, participant_properties_, security_activated_)); ASSERT_TRUE(!security_activated_ || manager_.create_entities()); @@ -54,11 +54,11 @@ void SecurityTest::initialization_auth_ok() stateless_reader_ = new ::testing::NiceMock(); EXPECT_CALL(*auth_plugin_, validate_local_identity(_, _, _, _, _, _)).Times(1). - WillOnce(DoAll(SetArgPointee<0>(&local_identity_handle_), Return(ValidationResult_t::VALIDATION_OK))); + WillOnce(DoAll(SetArgPointee<0>(&local_identity_handle_), Return(ValidationResult_t::VALIDATION_OK))); EXPECT_CALL(participant_, createWriter_mock(_, _, _, _, _, _)).Times(1). - WillOnce(DoAll(SetArgPointee<0>(stateless_writer_), Return(true))); + WillOnce(DoAll(SetArgPointee<0>(stateless_writer_), Return(true))); EXPECT_CALL(participant_, createReader_mock(_, _, _, _, _, _, _)).Times(1). - WillOnce(DoAll(SetArgPointee<0>(stateless_reader_), Return(true))); + WillOnce(DoAll(SetArgPointee<0>(stateless_reader_), Return(true))); ASSERT_TRUE(manager_.init(security_attributes_, participant_properties_, security_activated_)); ASSERT_TRUE(!security_activated_ || manager_.create_entities()); @@ -73,16 +73,16 @@ void SecurityTest::request_process_ok( CacheChange_t* change = new CacheChange_t(200); EXPECT_CALL(*auth_plugin_, validate_remote_identity_rvr(_, Ref(local_identity_handle_), _, _, _)).Times(1). - WillOnce(DoAll(SetArgPointee<0>(&remote_identity_handle_), + WillOnce(DoAll(SetArgPointee<0>(&remote_identity_handle_), Return(ValidationResult_t::VALIDATION_PENDING_HANDSHAKE_REQUEST))); EXPECT_CALL(*auth_plugin_, begin_handshake_request(_, _, Ref(local_identity_handle_), Ref(remote_identity_handle_), _, _)).Times(1). - WillOnce(DoAll(SetArgPointee<0>(&handshake_handle_), + WillOnce(DoAll(SetArgPointee<0>(&handshake_handle_), SetArgPointee<1>(&handshake_message), Return(ValidationResult_t::VALIDATION_PENDING_HANDSHAKE_MESSAGE))); EXPECT_CALL(*stateless_writer_, new_change(_, _, _)).Times(1). - WillOnce(Return(change)); + WillOnce(Return(change)); EXPECT_CALL(*stateless_writer_->history_, add_change_mock(change)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); EXPECT_CALL(participant_, pdpsimple()).Times(1).WillOnce(Return(&pdpsimple_)); EXPECT_CALL(pdpsimple_, get_participant_proxy_data_serialized(BIGEND)).Times(1); @@ -105,7 +105,7 @@ void SecurityTest::reply_process_ok( initialization_ok(); EXPECT_CALL(*auth_plugin_, validate_remote_identity_rvr(_, Ref(local_identity_handle_), _, _, _)).Times(1). - WillOnce(DoAll(SetArgPointee<0>(&remote_identity_handle_), + WillOnce(DoAll(SetArgPointee<0>(&remote_identity_handle_), Return(ValidationResult_t::VALIDATION_PENDING_HANDSHAKE_MESSAGE))); fill_participant_key(participant_data_.m_guid); @@ -140,14 +140,14 @@ void SecurityTest::reply_process_ok( EXPECT_CALL(*auth_plugin_, begin_handshake_reply_rvr(_, _, _, Ref(remote_identity_handle_), Ref(local_identity_handle_), _, _)).Times(1). - WillOnce(DoAll(SetArgPointee<0>(&handshake_handle_), + WillOnce(DoAll(SetArgPointee<0>(&handshake_handle_), SetArgPointee<1>(&handshake_message), Return(ValidationResult_t::VALIDATION_PENDING_HANDSHAKE_MESSAGE))); EXPECT_CALL(*stateless_writer_, new_change(_, _, _)).Times(1). - WillOnce(Return(change2)); + WillOnce(Return(change2)); EXPECT_CALL(*stateless_writer_->history_, add_change_mock(change2)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); EXPECT_CALL(*stateless_reader_->history_, remove_change_mock(change)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); EXPECT_CALL(participant_, pdpsimple()).Times(1).WillOnce(Return(&pdpsimple_)); EXPECT_CALL(pdpsimple_, get_participant_proxy_data_serialized(BIGEND)).Times(1); @@ -169,7 +169,7 @@ void SecurityTest::final_message_process_ok( request_process_ok(); EXPECT_CALL(*stateless_writer_->history_, remove_change(SequenceNumber_t{ 0, 1 })).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); GUID_t remote_participant_key(participant_data_.m_guid); @@ -205,29 +205,30 @@ void SecurityTest::final_message_process_ok( MockParticipantCryptoHandle participant_crypto_handle; EXPECT_CALL(*auth_plugin_, process_handshake_rvr(_, _, Ref(handshake_handle_), _)).Times(1). - WillOnce(DoAll(SetArgPointee<0>(&handshake_message), Return(ValidationResult_t::VALIDATION_OK_WITH_FINAL_MESSAGE))); + WillOnce(DoAll(SetArgPointee<0>(&handshake_message), + Return(ValidationResult_t::VALIDATION_OK_WITH_FINAL_MESSAGE))); EXPECT_CALL(*stateless_writer_, new_change(_, _, _)).Times(1). - WillOnce(Return(change2)); + WillOnce(Return(change2)); EXPECT_CALL(*stateless_writer_->history_, add_change_mock(change2)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); EXPECT_CALL(*stateless_reader_->history_, remove_change_mock(change)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); //TODO(Ricardo) Verify parameter passed to notifyAboveRemoteEndpoints EXPECT_CALL(participant_, pdpsimple()).Times(1).WillOnce(Return(&pdpsimple_)); EXPECT_CALL(pdpsimple_, notifyAboveRemoteEndpoints(_)).Times(1); EXPECT_CALL(*auth_plugin_, get_shared_secret(Ref(handshake_handle_), _)).Times(1). - WillOnce(Return(&shared_secret_handle)); + WillOnce(Return(&shared_secret_handle)); EXPECT_CALL(*auth_plugin_, return_sharedsecret_handle(&shared_secret_handle, _)).Times(1). - WillRepeatedly(Return(true)); + WillRepeatedly(Return(true)); EXPECT_CALL(crypto_plugin_->cryptokeyfactory_, register_matched_remote_participant(Ref(local_participant_crypto_handle_), Ref(remote_identity_handle_), _, Ref(shared_secret_handle), _)).Times(1). - WillOnce(Return(&participant_crypto_handle)); + WillOnce(Return(&participant_crypto_handle)); EXPECT_CALL(crypto_plugin_->cryptokeyexchange_, create_local_participant_crypto_tokens(_, Ref(local_participant_crypto_handle_), Ref(participant_crypto_handle), _)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); EXPECT_CALL(crypto_plugin_->cryptokeyfactory_, unregister_participant(&participant_crypto_handle, _)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); ParticipantAuthenticationInfo info; info.status = ParticipantAuthenticationInfo::AUTHORIZED_PARTICIPANT; @@ -245,3 +246,18 @@ void SecurityTest::final_message_process_ok( *final_message_change = change2; } } + +void SecurityTest::destroy_manager_and_change( + CacheChange_t*& change, + bool was_added) +{ + if (was_added) + { + EXPECT_CALL(*stateless_writer_->history_, + remove_change(change->sequenceNumber)).Times(1).WillOnce(Return(true)); + } + + manager_.destroy(); + delete change; + change = nullptr; +} diff --git a/test/unittest/rtps/security/SecurityTests.hpp b/test/unittest/rtps/security/SecurityTests.hpp index 84b1ebf879..70ee983cb1 100644 --- a/test/unittest/rtps/security/SecurityTests.hpp +++ b/test/unittest/rtps/security/SecurityTests.hpp @@ -39,18 +39,18 @@ using namespace ::testing; class MockIdentity { - public: +public: - static const char* const class_id_; + static const char* const class_id_; }; typedef HandleImpl MockIdentityHandle; class MockHandshake { - public: +public: - static const char* const class_id_; + static const char* const class_id_; }; typedef HandleImpl MockHandshakeHandle; @@ -59,102 +59,117 @@ typedef HandleImpl MockSharedSecretHandle; class MockParticipantCrypto { - public: +public: - static const char* const class_id_; + static const char* const class_id_; }; typedef HandleImpl MockParticipantCryptoHandle; class SecurityTest : public ::testing::Test { - protected: - - virtual void SetUp() - { - ::testing::DefaultValue::Set(network); - SecurityPluginFactory::set_auth_plugin(auth_plugin_); - SecurityPluginFactory::set_crypto_plugin(crypto_plugin_); - fill_participant_key(guid); - } - - virtual void TearDown() - { - SecurityPluginFactory::release_auth_plugin(); - SecurityPluginFactory::release_crypto_plugin(); - - ::testing::DefaultValue::Clear(); - ::testing::DefaultValue::Clear(); - ::testing::DefaultValue::Clear(); - } - - void fill_participant_key(GUID_t& participant_key) - { - participant_key.guidPrefix.value[0] = 1; - participant_key.guidPrefix.value[1] = 2; - participant_key.guidPrefix.value[2] = 3; - participant_key.guidPrefix.value[3] = 4; - participant_key.guidPrefix.value[4] = 5; - participant_key.guidPrefix.value[5] = 6; - participant_key.guidPrefix.value[6] = 7; - participant_key.guidPrefix.value[7] = 8; - participant_key.guidPrefix.value[8] = 9; - participant_key.guidPrefix.value[9] = 10; - participant_key.guidPrefix.value[10] = 11; - participant_key.guidPrefix.value[11] = 12; - participant_key.entityId.value[0] = 0x0; - participant_key.entityId.value[1] = 0x0; - participant_key.entityId.value[2] = 0x1; - participant_key.entityId.value[3] = 0xc1; - } - - void initialization_ok(); - - void initialization_auth_ok(); - - void request_process_ok(CacheChange_t** request_message_change = nullptr); - - void reply_process_ok(CacheChange_t** reply_message_change = nullptr); - - void final_message_process_ok(CacheChange_t** final_message_change = nullptr); - - public: - - SecurityTest() : auth_plugin_(new MockAuthenticationPlugin()), - crypto_plugin_(new MockCryptographyPlugin()), - stateless_writer_(nullptr), stateless_reader_(nullptr), - volatile_writer_(nullptr), volatile_reader_(nullptr), - manager_(&participant_), participant_data_(c_default_RTPSParticipantAllocationAttributes), - default_cdr_message(RTPSMESSAGE_DEFAULT_SIZE){} - - ~SecurityTest() - { - } - - MockAuthenticationPlugin* auth_plugin_; - MockCryptographyPlugin* crypto_plugin_; - ::testing::NiceMock participant_; - ::testing::NiceMock* stateless_writer_; - ::testing::NiceMock* stateless_reader_; - ::testing::NiceMock* volatile_writer_; - ::testing::NiceMock* volatile_reader_; - PDPSimple pdpsimple_; - SecurityManager manager_; - - MockIdentityHandle local_identity_handle_; - MockIdentityHandle remote_identity_handle_; - MockHandshakeHandle handshake_handle_; - MockParticipantCryptoHandle local_participant_crypto_handle_; - ParticipantProxyData participant_data_; - ParticipantSecurityAttributes security_attributes_; - PropertyPolicy participant_properties_; - bool security_activated_; - - - // Default Values - NetworkFactory network; - GUID_t guid; - CDRMessage_t default_cdr_message; +protected: + + virtual void SetUp() + { + ::testing::DefaultValue::Set(network); + SecurityPluginFactory::set_auth_plugin(auth_plugin_); + SecurityPluginFactory::set_crypto_plugin(crypto_plugin_); + fill_participant_key(guid); + } + + virtual void TearDown() + { + SecurityPluginFactory::release_auth_plugin(); + SecurityPluginFactory::release_crypto_plugin(); + + ::testing::DefaultValue::Clear(); + ::testing::DefaultValue::Clear(); + ::testing::DefaultValue::Clear(); + } + + void fill_participant_key( + GUID_t& participant_key) + { + participant_key.guidPrefix.value[0] = 1; + participant_key.guidPrefix.value[1] = 2; + participant_key.guidPrefix.value[2] = 3; + participant_key.guidPrefix.value[3] = 4; + participant_key.guidPrefix.value[4] = 5; + participant_key.guidPrefix.value[5] = 6; + participant_key.guidPrefix.value[6] = 7; + participant_key.guidPrefix.value[7] = 8; + participant_key.guidPrefix.value[8] = 9; + participant_key.guidPrefix.value[9] = 10; + participant_key.guidPrefix.value[10] = 11; + participant_key.guidPrefix.value[11] = 12; + participant_key.entityId.value[0] = 0x0; + participant_key.entityId.value[1] = 0x0; + participant_key.entityId.value[2] = 0x1; + participant_key.entityId.value[3] = 0xc1; + } + + void initialization_ok(); + + void initialization_auth_ok(); + + void request_process_ok( + CacheChange_t** request_message_change = nullptr); + + void reply_process_ok( + CacheChange_t** reply_message_change = nullptr); + + void final_message_process_ok( + CacheChange_t** final_message_change = nullptr); + + void destroy_manager_and_change( + CacheChange_t*& change, + bool was_added = true); + +public: + + SecurityTest() + : auth_plugin_(new MockAuthenticationPlugin()) + , crypto_plugin_(new MockCryptographyPlugin()) + , stateless_writer_(nullptr) + , stateless_reader_(nullptr) + , volatile_writer_(nullptr) + , volatile_reader_(nullptr) + , manager_(&participant_) + , participant_data_(c_default_RTPSParticipantAllocationAttributes) + , default_cdr_message(RTPSMESSAGE_DEFAULT_SIZE) + { + } + + ~SecurityTest() + { + } + + MockAuthenticationPlugin* auth_plugin_; + MockCryptographyPlugin* crypto_plugin_; + ::testing::NiceMock participant_; + ::testing::NiceMock* stateless_writer_; + ::testing::NiceMock* stateless_reader_; + ::testing::NiceMock* volatile_writer_; + ::testing::NiceMock* volatile_reader_; + PDPSimple pdpsimple_; + SecurityManager manager_; + + MockIdentityHandle local_identity_handle_; + MockIdentityHandle remote_identity_handle_; + MockHandshakeHandle handshake_handle_; + MockParticipantCryptoHandle local_participant_crypto_handle_; + ParticipantProxyData participant_data_; + ParticipantSecurityAttributes security_attributes_; + PropertyPolicy participant_properties_; + bool security_activated_; + + + // Default Values + NetworkFactory network; + GUID_t guid; + CDRMessage_t default_cdr_message; + }; struct SecurityTestsGlobalDefaultValues @@ -166,6 +181,7 @@ struct SecurityTestsGlobalDefaultValues { ::testing::DefaultValue::Set(pattr); } + }; static SecurityTestsGlobalDefaultValues g_security_default_values_; diff --git a/test/unittest/rtps/security/SecurityValidationRemoteTests.cpp b/test/unittest/rtps/security/SecurityValidationRemoteTests.cpp index 41422f8b20..55ec165dcc 100644 --- a/test/unittest/rtps/security/SecurityValidationRemoteTests.cpp +++ b/test/unittest/rtps/security/SecurityValidationRemoteTests.cpp @@ -18,10 +18,10 @@ TEST_F(SecurityTest, discovered_participant_validation_remote_identity_fail) { initialization_ok(); - EXPECT_CALL(*auth_plugin_, validate_remote_identity_rvr(_, Ref(local_identity_handle_),_,_,_)).Times(1). - WillOnce(Return(ValidationResult_t::VALIDATION_FAILED)); - EXPECT_CALL(*auth_plugin_, return_identity_handle(&local_identity_handle_,_)).Times(1). - WillOnce(Return(true)); + EXPECT_CALL(*auth_plugin_, validate_remote_identity_rvr(_, Ref(local_identity_handle_), _, _, _)).Times(1). + WillOnce(Return(ValidationResult_t::VALIDATION_FAILED)); + EXPECT_CALL(*auth_plugin_, return_identity_handle(&local_identity_handle_, _)).Times(1). + WillOnce(Return(true)); ParticipantProxyData participant_data; fill_participant_key(participant_data.m_guid); @@ -41,12 +41,12 @@ TEST_F(SecurityTest, discovered_participant_validation_remote_identity_ok) ParticipantProxyData participant_data; fill_participant_key(participant_data.m_guid); - EXPECT_CALL(*auth_plugin_, validate_remote_identity_rvr(_, Ref(local_identity_handle_),_,_,_)).Times(1). - WillOnce(DoAll(SetArgPointee<0>(&remote_identity_handle), Return(ValidationResult_t::VALIDATION_OK))); - EXPECT_CALL(*auth_plugin_, return_identity_handle(&local_identity_handle_,_)).Times(1). - WillOnce(Return(true)); - EXPECT_CALL(*auth_plugin_, return_identity_handle(&remote_identity_handle,_)).Times(1). - WillOnce(Return(true)); + EXPECT_CALL(*auth_plugin_, validate_remote_identity_rvr(_, Ref(local_identity_handle_), _, _, _)).Times(1). + WillOnce(DoAll(SetArgPointee<0>(&remote_identity_handle), Return(ValidationResult_t::VALIDATION_OK))); + EXPECT_CALL(*auth_plugin_, return_identity_handle(&local_identity_handle_, _)).Times(1). + WillOnce(Return(true)); + EXPECT_CALL(*auth_plugin_, return_identity_handle(&remote_identity_handle, _)).Times(1). + WillOnce(Return(true)); EXPECT_CALL(participant_, pdpsimple()).Times(1).WillOnce(Return(&pdpsimple_)); EXPECT_CALL(pdpsimple_, notifyAboveRemoteEndpoints(_)).Times(1); @@ -64,12 +64,13 @@ TEST_F(SecurityTest, discovered_participant_validation_remote_identity_pending_h MockIdentityHandle remote_identity_handle; - EXPECT_CALL(*auth_plugin_, validate_remote_identity_rvr(_, Ref(local_identity_handle_),_,_,_)).Times(1). - WillOnce(DoAll(SetArgPointee<0>(&remote_identity_handle), Return(ValidationResult_t::VALIDATION_PENDING_HANDSHAKE_MESSAGE))); - EXPECT_CALL(*auth_plugin_, return_identity_handle(&local_identity_handle_,_)).Times(1). - WillOnce(Return(true)); - EXPECT_CALL(*auth_plugin_, return_identity_handle(&remote_identity_handle,_)).Times(1). - WillOnce(Return(true)); + EXPECT_CALL(*auth_plugin_, validate_remote_identity_rvr(_, Ref(local_identity_handle_), _, _, _)).Times(1). + WillOnce(DoAll(SetArgPointee<0>(&remote_identity_handle), + Return(ValidationResult_t::VALIDATION_PENDING_HANDSHAKE_MESSAGE))); + EXPECT_CALL(*auth_plugin_, return_identity_handle(&local_identity_handle_, _)).Times(1). + WillOnce(Return(true)); + EXPECT_CALL(*auth_plugin_, return_identity_handle(&remote_identity_handle, _)).Times(1). + WillOnce(Return(true)); ParticipantProxyData participant_data; fill_participant_key(participant_data.m_guid); @@ -82,15 +83,16 @@ TEST_F(SecurityTest, discovered_participant_validation_remote_identity_pending_h MockIdentityHandle remote_identity_handle; - EXPECT_CALL(*auth_plugin_, validate_remote_identity_rvr(_, Ref(local_identity_handle_),_,_,_)).Times(1). - WillOnce(DoAll(SetArgPointee<0>(&remote_identity_handle), Return(ValidationResult_t::VALIDATION_PENDING_HANDSHAKE_REQUEST))); - EXPECT_CALL(*auth_plugin_, begin_handshake_request(_,_, Ref(local_identity_handle_), - Ref(remote_identity_handle),_,_)).Times(1). - WillOnce(Return(ValidationResult_t::VALIDATION_FAILED)); - EXPECT_CALL(*auth_plugin_, return_identity_handle(&local_identity_handle_,_)).Times(1). - WillOnce(Return(true)); - EXPECT_CALL(*auth_plugin_, return_identity_handle(&remote_identity_handle,_)).Times(1). - WillOnce(Return(true)); + EXPECT_CALL(*auth_plugin_, validate_remote_identity_rvr(_, Ref(local_identity_handle_), _, _, _)).Times(1). + WillOnce(DoAll(SetArgPointee<0>(&remote_identity_handle), + Return(ValidationResult_t::VALIDATION_PENDING_HANDSHAKE_REQUEST))); + EXPECT_CALL(*auth_plugin_, begin_handshake_request(_, _, Ref(local_identity_handle_), + Ref(remote_identity_handle), _, _)).Times(1). + WillOnce(Return(ValidationResult_t::VALIDATION_FAILED)); + EXPECT_CALL(*auth_plugin_, return_identity_handle(&local_identity_handle_, _)).Times(1). + WillOnce(Return(true)); + EXPECT_CALL(*auth_plugin_, return_identity_handle(&remote_identity_handle, _)).Times(1). + WillOnce(Return(true)); EXPECT_CALL(participant_, pdpsimple()).Times(1).WillOnce(Return(&pdpsimple_)); EXPECT_CALL(pdpsimple_, get_participant_proxy_data_serialized(BIGEND)).Times(1); @@ -115,33 +117,35 @@ TEST_F(SecurityTest, discovered_participant_validation_remote_identity_pending_h ParticipantProxyData participant_data; fill_participant_key(participant_data.m_guid); - EXPECT_CALL(*auth_plugin_, validate_remote_identity_rvr(_, Ref(local_identity_handle_),_,_,_)).Times(1). - WillOnce(DoAll(SetArgPointee<0>(&remote_identity_handle), Return(ValidationResult_t::VALIDATION_PENDING_HANDSHAKE_REQUEST))); - EXPECT_CALL(*auth_plugin_, begin_handshake_request(_,_, Ref(local_identity_handle_), - Ref(remote_identity_handle),_,_)).Times(1). - WillOnce(DoAll(SetArgPointee<0>(&handshake_handle), - Return(ValidationResult_t::VALIDATION_OK))); - EXPECT_CALL(*auth_plugin_, return_identity_handle(&local_identity_handle_,_)).Times(1). - WillRepeatedly(Return(true)); - EXPECT_CALL(*auth_plugin_, return_identity_handle(&remote_identity_handle,_)).Times(1). - WillRepeatedly(Return(true)); - EXPECT_CALL(*auth_plugin_, return_handshake_handle(&handshake_handle,_)).Times(1). - WillRepeatedly(Return(true)); + EXPECT_CALL(*auth_plugin_, validate_remote_identity_rvr(_, Ref(local_identity_handle_), _, _, _)).Times(1). + WillOnce(DoAll(SetArgPointee<0>(&remote_identity_handle), + Return(ValidationResult_t::VALIDATION_PENDING_HANDSHAKE_REQUEST))); + EXPECT_CALL(*auth_plugin_, begin_handshake_request(_, _, Ref(local_identity_handle_), + Ref(remote_identity_handle), _, _)).Times(1). + WillOnce(DoAll(SetArgPointee<0>(&handshake_handle), + Return(ValidationResult_t::VALIDATION_OK))); + EXPECT_CALL(*auth_plugin_, return_identity_handle(&local_identity_handle_, _)).Times(1). + WillRepeatedly(Return(true)); + EXPECT_CALL(*auth_plugin_, return_identity_handle(&remote_identity_handle, _)).Times(1). + WillRepeatedly(Return(true)); + EXPECT_CALL(*auth_plugin_, return_handshake_handle(&handshake_handle, _)).Times(1). + WillRepeatedly(Return(true)); EXPECT_CALL(participant_, pdpsimple()).Times(2).WillRepeatedly(Return(&pdpsimple_)); EXPECT_CALL(pdpsimple_, notifyAboveRemoteEndpoints(_)).Times(1); EXPECT_CALL(pdpsimple_, get_participant_proxy_data_serialized(BIGEND)).Times(1); - EXPECT_CALL(*auth_plugin_, get_shared_secret(Ref(handshake_handle),_)).Times(1). - WillOnce(Return(&shared_secret_handle)); - EXPECT_CALL(*auth_plugin_, return_sharedsecret_handle(&shared_secret_handle,_)).Times(1). - WillRepeatedly(Return(true)); - EXPECT_CALL(crypto_plugin_->cryptokeyfactory_, register_matched_remote_participant(Ref(local_participant_crypto_handle_), - Ref(remote_identity_handle),_,Ref(shared_secret_handle),_)).Times(1). - WillOnce(Return(&participant_crypto_handle)); + EXPECT_CALL(*auth_plugin_, get_shared_secret(Ref(handshake_handle), _)).Times(1). + WillOnce(Return(&shared_secret_handle)); + EXPECT_CALL(*auth_plugin_, return_sharedsecret_handle(&shared_secret_handle, _)).Times(1). + WillRepeatedly(Return(true)); + EXPECT_CALL(crypto_plugin_->cryptokeyfactory_, + register_matched_remote_participant(Ref(local_participant_crypto_handle_), + Ref(remote_identity_handle), _, Ref(shared_secret_handle), _)).Times(1). + WillOnce(Return(&participant_crypto_handle)); EXPECT_CALL(crypto_plugin_->cryptokeyexchange_, create_local_participant_crypto_tokens(_, - Ref(local_participant_crypto_handle_), Ref(participant_crypto_handle),_)).Times(1). - WillOnce(Return(true)); - EXPECT_CALL(crypto_plugin_->cryptokeyfactory_, unregister_participant(&participant_crypto_handle,_)).Times(1). - WillOnce(Return(true)); + Ref(local_participant_crypto_handle_), Ref(participant_crypto_handle), _)).Times(1). + WillOnce(Return(true)); + EXPECT_CALL(crypto_plugin_->cryptokeyfactory_, unregister_participant(&participant_crypto_handle, _)).Times(1). + WillOnce(Return(true)); ParticipantAuthenticationInfo info; info.status = ParticipantAuthenticationInfo::AUTHORIZED_PARTICIPANT; @@ -159,20 +163,21 @@ TEST_F(SecurityTest, discovered_participant_validation_remote_identity_new_chang MockHandshakeHandle handshake_handle; HandshakeMessageToken handshake_message; - EXPECT_CALL(*auth_plugin_, validate_remote_identity_rvr(_, Ref(local_identity_handle_),_,_,_)).Times(1). - WillOnce(DoAll(SetArgPointee<0>(&remote_identity_handle), Return(ValidationResult_t::VALIDATION_PENDING_HANDSHAKE_REQUEST))); - EXPECT_CALL(*auth_plugin_, begin_handshake_request(_,_, Ref(local_identity_handle_), - Ref(remote_identity_handle),_,_)).Times(1). - WillOnce(DoAll(SetArgPointee<0>(&handshake_handle), - SetArgPointee<1>(&handshake_message), Return(ValidationResult_t::VALIDATION_PENDING_HANDSHAKE_MESSAGE))); - EXPECT_CALL(*stateless_writer_, new_change(_,_,_)).Times(1). - WillOnce(Return(nullptr)); - EXPECT_CALL(*auth_plugin_, return_identity_handle(&local_identity_handle_,_)).Times(1). - WillRepeatedly(Return(true)); - EXPECT_CALL(*auth_plugin_, return_identity_handle(&remote_identity_handle,_)).Times(1). - WillRepeatedly(Return(true)); - EXPECT_CALL(*auth_plugin_, return_handshake_handle(&handshake_handle,_)).Times(1). - WillOnce(Return(true)); + EXPECT_CALL(*auth_plugin_, validate_remote_identity_rvr(_, Ref(local_identity_handle_), _, _, _)).Times(1). + WillOnce(DoAll(SetArgPointee<0>(&remote_identity_handle), + Return(ValidationResult_t::VALIDATION_PENDING_HANDSHAKE_REQUEST))); + EXPECT_CALL(*auth_plugin_, begin_handshake_request(_, _, Ref(local_identity_handle_), + Ref(remote_identity_handle), _, _)).Times(1). + WillOnce(DoAll(SetArgPointee<0>(&handshake_handle), + SetArgPointee<1>(&handshake_message), Return(ValidationResult_t::VALIDATION_PENDING_HANDSHAKE_MESSAGE))); + EXPECT_CALL(*stateless_writer_, new_change(_, _, _)).Times(1). + WillOnce(Return(nullptr)); + EXPECT_CALL(*auth_plugin_, return_identity_handle(&local_identity_handle_, _)).Times(1). + WillRepeatedly(Return(true)); + EXPECT_CALL(*auth_plugin_, return_identity_handle(&remote_identity_handle, _)).Times(1). + WillRepeatedly(Return(true)); + EXPECT_CALL(*auth_plugin_, return_handshake_handle(&handshake_handle, _)).Times(1). + WillOnce(Return(true)); EXPECT_CALL(participant_, pdpsimple()).Times(1).WillOnce(Return(&pdpsimple_)); EXPECT_CALL(pdpsimple_, get_participant_proxy_data_serialized(BIGEND)).Times(1); @@ -190,22 +195,23 @@ TEST_F(SecurityTest, discovered_participant_validation_remote_identity_add_chang HandshakeMessageToken handshake_message; CacheChange_t* change = new CacheChange_t(200); - EXPECT_CALL(*auth_plugin_, validate_remote_identity_rvr(_, Ref(local_identity_handle_),_,_,_)).Times(1). - WillOnce(DoAll(SetArgPointee<0>(&remote_identity_handle), Return(ValidationResult_t::VALIDATION_PENDING_HANDSHAKE_REQUEST))); - EXPECT_CALL(*auth_plugin_, begin_handshake_request(_,_, Ref(local_identity_handle_), - Ref(remote_identity_handle),_,_)).Times(1). - WillOnce(DoAll(SetArgPointee<0>(&handshake_handle), - SetArgPointee<1>(&handshake_message), Return(ValidationResult_t::VALIDATION_PENDING_HANDSHAKE_MESSAGE))); - EXPECT_CALL(*stateless_writer_, new_change(_,_,_)).Times(1). - WillOnce(Return(change)); + EXPECT_CALL(*auth_plugin_, validate_remote_identity_rvr(_, Ref(local_identity_handle_), _, _, _)).Times(1). + WillOnce(DoAll(SetArgPointee<0>(&remote_identity_handle), + Return(ValidationResult_t::VALIDATION_PENDING_HANDSHAKE_REQUEST))); + EXPECT_CALL(*auth_plugin_, begin_handshake_request(_, _, Ref(local_identity_handle_), + Ref(remote_identity_handle), _, _)).Times(1). + WillOnce(DoAll(SetArgPointee<0>(&handshake_handle), + SetArgPointee<1>(&handshake_message), Return(ValidationResult_t::VALIDATION_PENDING_HANDSHAKE_MESSAGE))); + EXPECT_CALL(*stateless_writer_, new_change(_, _, _)).Times(1). + WillOnce(Return(change)); EXPECT_CALL(*stateless_writer_->history_, add_change_mock(change)).Times(1). - WillOnce(Return(false)); - EXPECT_CALL(*auth_plugin_, return_identity_handle(&local_identity_handle_,_)).Times(1). - WillRepeatedly(Return(true)); - EXPECT_CALL(*auth_plugin_, return_identity_handle(&remote_identity_handle,_)).Times(1). - WillRepeatedly(Return(true)); - EXPECT_CALL(*auth_plugin_, return_handshake_handle(&handshake_handle,_)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(false)); + EXPECT_CALL(*auth_plugin_, return_identity_handle(&local_identity_handle_, _)).Times(1). + WillRepeatedly(Return(true)); + EXPECT_CALL(*auth_plugin_, return_identity_handle(&remote_identity_handle, _)).Times(1). + WillRepeatedly(Return(true)); + EXPECT_CALL(*auth_plugin_, return_handshake_handle(&handshake_handle, _)).Times(1). + WillOnce(Return(true)); EXPECT_CALL(participant_, pdpsimple()).Times(1).WillOnce(Return(&pdpsimple_)); EXPECT_CALL(pdpsimple_, get_participant_proxy_data_serialized(BIGEND)).Times(1); @@ -213,44 +219,43 @@ TEST_F(SecurityTest, discovered_participant_validation_remote_identity_add_chang fill_participant_key(participant_data.m_guid); ASSERT_FALSE(manager_.discovered_participant(participant_data)); - manager_.destroy(); - - delete change; + destroy_manager_and_change(change, false); } TEST_F(SecurityTest, discovered_participant_validation_remote_identity_pending_handshake_request_pending_message) { - EXPECT_CALL(*auth_plugin_, return_identity_handle(&local_identity_handle_,_)).Times(1). - WillRepeatedly(Return(true)); - EXPECT_CALL(*auth_plugin_, return_identity_handle(&remote_identity_handle_,_)).Times(1). - WillRepeatedly(Return(true)); - EXPECT_CALL(*auth_plugin_, return_handshake_handle(&handshake_handle_,_)).Times(1). - WillOnce(Return(true)); + EXPECT_CALL(*auth_plugin_, return_identity_handle(&local_identity_handle_, _)).Times(1). + WillRepeatedly(Return(true)); + EXPECT_CALL(*auth_plugin_, return_identity_handle(&remote_identity_handle_, _)).Times(1). + WillRepeatedly(Return(true)); + EXPECT_CALL(*auth_plugin_, return_handshake_handle(&handshake_handle_, _)).Times(1). + WillOnce(Return(true)); request_process_ok(); + + EXPECT_CALL(*stateless_writer_->history_, remove_change(SequenceNumber_t{ 0, 1 })).Times(1). + WillOnce(Return(true)); } TEST_F(SecurityTest, discovered_participant_validation_remote_identity_pending_handshake_request_pending_message_resent) { - EXPECT_CALL(*auth_plugin_, return_identity_handle(&local_identity_handle_,_)).Times(1). - WillRepeatedly(Return(true)); - EXPECT_CALL(*auth_plugin_, return_identity_handle(&remote_identity_handle_,_)).Times(1). - WillRepeatedly(Return(true)); - EXPECT_CALL(*auth_plugin_, return_handshake_handle(&handshake_handle_,_)).Times(1). - WillOnce(Return(true)); + EXPECT_CALL(*auth_plugin_, return_identity_handle(&local_identity_handle_, _)).Times(1). + WillRepeatedly(Return(true)); + EXPECT_CALL(*auth_plugin_, return_identity_handle(&remote_identity_handle_, _)).Times(1). + WillRepeatedly(Return(true)); + EXPECT_CALL(*auth_plugin_, return_handshake_handle(&handshake_handle_, _)).Times(1). + WillOnce(Return(true)); CacheChange_t* request_message_change = nullptr; request_process_ok(&request_message_change); EXPECT_CALL(*stateless_writer_->history_, remove_change_and_reuse(request_message_change->sequenceNumber)).Times(1). - WillOnce(Return(request_message_change)); + WillOnce(Return(request_message_change)); EXPECT_CALL(*stateless_writer_->history_, add_change_mock(request_message_change)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); stateless_writer_->history_->wait_for_more_samples_than(1); - manager_.destroy(); - - delete request_message_change; + destroy_manager_and_change(request_message_change); } TEST_F(SecurityTest, discovered_participant_validation_remote_identity_pending_handshake_request_ok_with_final_message) @@ -266,37 +271,39 @@ TEST_F(SecurityTest, discovered_participant_validation_remote_identity_pending_h ParticipantProxyData participant_data; fill_participant_key(participant_data.m_guid); - EXPECT_CALL(*auth_plugin_, validate_remote_identity_rvr(_, Ref(local_identity_handle_),_,_,_)).Times(1). - WillOnce(DoAll(SetArgPointee<0>(&remote_identity_handle), Return(ValidationResult_t::VALIDATION_PENDING_HANDSHAKE_REQUEST))); - EXPECT_CALL(*auth_plugin_, begin_handshake_request(_,_, Ref(local_identity_handle_), - Ref(remote_identity_handle),_,_)).Times(1). - WillOnce(DoAll(SetArgPointee<0>(&handshake_handle), - SetArgPointee<1>(&handshake_message), Return(ValidationResult_t::VALIDATION_OK_WITH_FINAL_MESSAGE))); - EXPECT_CALL(*stateless_writer_, new_change(_,_,_)).Times(1). - WillOnce(Return(change)); + EXPECT_CALL(*auth_plugin_, validate_remote_identity_rvr(_, Ref(local_identity_handle_), _, _, _)).Times(1). + WillOnce(DoAll(SetArgPointee<0>(&remote_identity_handle), + Return(ValidationResult_t::VALIDATION_PENDING_HANDSHAKE_REQUEST))); + EXPECT_CALL(*auth_plugin_, begin_handshake_request(_, _, Ref(local_identity_handle_), + Ref(remote_identity_handle), _, _)).Times(1). + WillOnce(DoAll(SetArgPointee<0>(&handshake_handle), + SetArgPointee<1>(&handshake_message), Return(ValidationResult_t::VALIDATION_OK_WITH_FINAL_MESSAGE))); + EXPECT_CALL(*stateless_writer_, new_change(_, _, _)).Times(1). + WillOnce(Return(change)); EXPECT_CALL(*stateless_writer_->history_, add_change_mock(change)).Times(1). - WillOnce(Return(true)); - EXPECT_CALL(*auth_plugin_, return_identity_handle(&local_identity_handle_,_)).Times(1). - WillRepeatedly(Return(true)); - EXPECT_CALL(*auth_plugin_, return_identity_handle(&remote_identity_handle,_)).Times(1). - WillRepeatedly(Return(true)); - EXPECT_CALL(*auth_plugin_, return_handshake_handle(&handshake_handle,_)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); + EXPECT_CALL(*auth_plugin_, return_identity_handle(&local_identity_handle_, _)).Times(1). + WillRepeatedly(Return(true)); + EXPECT_CALL(*auth_plugin_, return_identity_handle(&remote_identity_handle, _)).Times(1). + WillRepeatedly(Return(true)); + EXPECT_CALL(*auth_plugin_, return_handshake_handle(&handshake_handle, _)).Times(1). + WillOnce(Return(true)); EXPECT_CALL(participant_, pdpsimple()).Times(2).WillRepeatedly(Return(&pdpsimple_)); EXPECT_CALL(pdpsimple_, notifyAboveRemoteEndpoints(_)).Times(1); EXPECT_CALL(pdpsimple_, get_participant_proxy_data_serialized(BIGEND)).Times(1); - EXPECT_CALL(*auth_plugin_, get_shared_secret(Ref(handshake_handle),_)).Times(1). - WillOnce(Return(&shared_secret_handle)); - EXPECT_CALL(*auth_plugin_, return_sharedsecret_handle(&shared_secret_handle,_)).Times(1). - WillRepeatedly(Return(true)); - EXPECT_CALL(crypto_plugin_->cryptokeyfactory_, register_matched_remote_participant(Ref(local_participant_crypto_handle_), - Ref(remote_identity_handle),_,Ref(shared_secret_handle),_)).Times(1). - WillOnce(Return(&participant_crypto_handle)); + EXPECT_CALL(*auth_plugin_, get_shared_secret(Ref(handshake_handle), _)).Times(1). + WillOnce(Return(&shared_secret_handle)); + EXPECT_CALL(*auth_plugin_, return_sharedsecret_handle(&shared_secret_handle, _)).Times(1). + WillRepeatedly(Return(true)); + EXPECT_CALL(crypto_plugin_->cryptokeyfactory_, + register_matched_remote_participant(Ref(local_participant_crypto_handle_), + Ref(remote_identity_handle), _, Ref(shared_secret_handle), _)).Times(1). + WillOnce(Return(&participant_crypto_handle)); EXPECT_CALL(crypto_plugin_->cryptokeyexchange_, create_local_participant_crypto_tokens(_, - Ref(local_participant_crypto_handle_), Ref(participant_crypto_handle),_)).Times(1). - WillOnce(Return(true)); - EXPECT_CALL(crypto_plugin_->cryptokeyfactory_, unregister_participant(&participant_crypto_handle,_)).Times(1). - WillOnce(Return(true)); + Ref(local_participant_crypto_handle_), Ref(participant_crypto_handle), _)).Times(1). + WillOnce(Return(true)); + EXPECT_CALL(crypto_plugin_->cryptokeyfactory_, unregister_participant(&participant_crypto_handle, _)).Times(1). + WillOnce(Return(true)); ParticipantAuthenticationInfo info; info.status = ParticipantAuthenticationInfo::AUTHORIZED_PARTICIPANT; @@ -305,9 +312,7 @@ TEST_F(SecurityTest, discovered_participant_validation_remote_identity_pending_h ASSERT_TRUE(manager_.discovered_participant(participant_data)); - manager_.destroy(); - - delete change; + destroy_manager_and_change(change); } TEST_F(SecurityTest, discovered_participant_ok) @@ -319,22 +324,23 @@ TEST_F(SecurityTest, discovered_participant_ok) HandshakeMessageToken handshake_message; CacheChange_t* change = new CacheChange_t(200); - EXPECT_CALL(*auth_plugin_, validate_remote_identity_rvr(_, Ref(local_identity_handle_),_,_,_)).Times(1). - WillOnce(DoAll(SetArgPointee<0>(&remote_identity_handle), Return(ValidationResult_t::VALIDATION_PENDING_HANDSHAKE_REQUEST))); - EXPECT_CALL(*auth_plugin_, begin_handshake_request(_,_, Ref(local_identity_handle_), - Ref(remote_identity_handle),_,_)).Times(1). - WillOnce(DoAll(SetArgPointee<0>(&handshake_handle), - SetArgPointee<1>(&handshake_message), Return(ValidationResult_t::VALIDATION_PENDING_HANDSHAKE_MESSAGE))); - EXPECT_CALL(*stateless_writer_, new_change(_,_,_)).Times(1). - WillOnce(Return(change)); + EXPECT_CALL(*auth_plugin_, validate_remote_identity_rvr(_, Ref(local_identity_handle_), _, _, _)).Times(1). + WillOnce(DoAll(SetArgPointee<0>(&remote_identity_handle), + Return(ValidationResult_t::VALIDATION_PENDING_HANDSHAKE_REQUEST))); + EXPECT_CALL(*auth_plugin_, begin_handshake_request(_, _, Ref(local_identity_handle_), + Ref(remote_identity_handle), _, _)).Times(1). + WillOnce(DoAll(SetArgPointee<0>(&handshake_handle), + SetArgPointee<1>(&handshake_message), Return(ValidationResult_t::VALIDATION_PENDING_HANDSHAKE_MESSAGE))); + EXPECT_CALL(*stateless_writer_, new_change(_, _, _)).Times(1). + WillOnce(Return(change)); EXPECT_CALL(*stateless_writer_->history_, add_change_mock(change)).Times(1). - WillOnce(Return(true)); - EXPECT_CALL(*auth_plugin_, return_identity_handle(&local_identity_handle_,_)).Times(1). - WillRepeatedly(Return(true)); - EXPECT_CALL(*auth_plugin_, return_identity_handle(&remote_identity_handle,_)).Times(1). - WillRepeatedly(Return(true)); - EXPECT_CALL(*auth_plugin_, return_handshake_handle(&handshake_handle,_)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); + EXPECT_CALL(*auth_plugin_, return_identity_handle(&local_identity_handle_, _)).Times(1). + WillRepeatedly(Return(true)); + EXPECT_CALL(*auth_plugin_, return_identity_handle(&remote_identity_handle, _)).Times(1). + WillRepeatedly(Return(true)); + EXPECT_CALL(*auth_plugin_, return_handshake_handle(&handshake_handle, _)).Times(1). + WillOnce(Return(true)); EXPECT_CALL(participant_, pdpsimple()).Times(1).WillOnce(Return(&pdpsimple_)); EXPECT_CALL(pdpsimple_, get_participant_proxy_data_serialized(BIGEND)).Times(1); @@ -342,9 +348,7 @@ TEST_F(SecurityTest, discovered_participant_ok) fill_participant_key(participant_data.m_guid); ASSERT_TRUE(manager_.discovered_participant(participant_data)); - manager_.destroy(); - - delete change; + destroy_manager_and_change(change); } TEST_F(SecurityTest, discovered_participant_validate_remote_fail_and_then_ok) @@ -356,8 +360,8 @@ TEST_F(SecurityTest, discovered_participant_validate_remote_fail_and_then_ok) HandshakeMessageToken handshake_message; CacheChange_t* change = new CacheChange_t(200); - EXPECT_CALL(*auth_plugin_, validate_remote_identity_rvr(_, Ref(local_identity_handle_),_,_,_)).Times(1). - WillOnce(Return(ValidationResult_t::VALIDATION_FAILED)); + EXPECT_CALL(*auth_plugin_, validate_remote_identity_rvr(_, Ref(local_identity_handle_), _, _, _)).Times(1). + WillOnce(Return(ValidationResult_t::VALIDATION_FAILED)); ParticipantProxyData participant_data; fill_participant_key(participant_data.m_guid); @@ -368,28 +372,27 @@ TEST_F(SecurityTest, discovered_participant_validate_remote_fail_and_then_ok) ASSERT_FALSE(manager_.discovered_participant(participant_data)); - EXPECT_CALL(*auth_plugin_, validate_remote_identity_rvr(_, Ref(local_identity_handle_),_,_,_)).Times(1). - WillOnce(DoAll(SetArgPointee<0>(&remote_identity_handle), Return(ValidationResult_t::VALIDATION_PENDING_HANDSHAKE_REQUEST))); - EXPECT_CALL(*auth_plugin_, begin_handshake_request(_,_, Ref(local_identity_handle_), - Ref(remote_identity_handle),_,_)).Times(1). - WillOnce(DoAll(SetArgPointee<0>(&handshake_handle), - SetArgPointee<1>(&handshake_message), Return(ValidationResult_t::VALIDATION_PENDING_HANDSHAKE_MESSAGE))); - EXPECT_CALL(*stateless_writer_, new_change(_,_,_)).Times(1). - WillOnce(Return(change)); + EXPECT_CALL(*auth_plugin_, validate_remote_identity_rvr(_, Ref(local_identity_handle_), _, _, _)).Times(1). + WillOnce(DoAll(SetArgPointee<0>(&remote_identity_handle), + Return(ValidationResult_t::VALIDATION_PENDING_HANDSHAKE_REQUEST))); + EXPECT_CALL(*auth_plugin_, begin_handshake_request(_, _, Ref(local_identity_handle_), + Ref(remote_identity_handle), _, _)).Times(1). + WillOnce(DoAll(SetArgPointee<0>(&handshake_handle), + SetArgPointee<1>(&handshake_message), Return(ValidationResult_t::VALIDATION_PENDING_HANDSHAKE_MESSAGE))); + EXPECT_CALL(*stateless_writer_, new_change(_, _, _)).Times(1). + WillOnce(Return(change)); EXPECT_CALL(*stateless_writer_->history_, add_change_mock(change)).Times(1). - WillOnce(Return(true)); - EXPECT_CALL(*auth_plugin_, return_identity_handle(&local_identity_handle_,_)).Times(1). - WillRepeatedly(Return(true)); - EXPECT_CALL(*auth_plugin_, return_identity_handle(&remote_identity_handle,_)).Times(1). - WillRepeatedly(Return(true)); - EXPECT_CALL(*auth_plugin_, return_handshake_handle(&handshake_handle,_)).Times(1). - WillOnce(Return(true)); + WillOnce(Return(true)); + EXPECT_CALL(*auth_plugin_, return_identity_handle(&local_identity_handle_, _)).Times(1). + WillRepeatedly(Return(true)); + EXPECT_CALL(*auth_plugin_, return_identity_handle(&remote_identity_handle, _)).Times(1). + WillRepeatedly(Return(true)); + EXPECT_CALL(*auth_plugin_, return_handshake_handle(&handshake_handle, _)).Times(1). + WillOnce(Return(true)); EXPECT_CALL(participant_, pdpsimple()).Times(1).WillOnce(Return(&pdpsimple_)); EXPECT_CALL(pdpsimple_, get_participant_proxy_data_serialized(BIGEND)).Times(1); ASSERT_TRUE(manager_.discovered_participant(participant_data)); - manager_.destroy(); - - delete change; + destroy_manager_and_change(change); }