|
14 | 14 |
|
15 | 15 | #include "SecurityTests.hpp"
|
16 | 16 |
|
| 17 | +#include "../../logging/mock/MockConsumer.h" |
| 18 | + |
17 | 19 | const char* const MockIdentity::class_id_ = "MockIdentityHandle";
|
18 | 20 | const char* const MockHandshake::class_id_ = "MockHandshakeHandle";
|
19 | 21 | const char* const SharedSecret::class_id_ = "SharedSecretHandle";
|
@@ -208,3 +210,43 @@ TEST_F(SecurityTest, initialization_ok)
|
208 | 210 |
|
209 | 211 | }
|
210 | 212 |
|
| 213 | +/* Regression test for Redmine 22545. |
| 214 | + * |
| 215 | + * Triggering a throw false in SecurityManager::init() should be logged properly as |
| 216 | + * the error: "Error while configuring security plugin.". |
| 217 | + */ |
| 218 | +TEST_F(SecurityTest, initialization_logging_error) |
| 219 | +{ |
| 220 | + DefaultValue<const GUID_t&>::Set(guid); |
| 221 | + DefaultValue<const ParticipantSecurityAttributes&>::Set(security_attributes_); |
| 222 | + |
| 223 | + EXPECT_CALL(*auth_plugin_, validate_local_identity(_, _, _, _, _, _)).Times(1). |
| 224 | + WillOnce(DoAll(SetArgPointee<0>(&local_identity_handle_), Return(ValidationResult_t::VALIDATION_OK))); |
| 225 | + EXPECT_CALL(crypto_plugin_->cryptokeyfactory_, |
| 226 | + register_local_participant(Ref(local_identity_handle_), _, _, _, _)).Times(1). |
| 227 | + WillOnce(Return(nullptr)); |
| 228 | + |
| 229 | + eprosima::fastdds::dds::MockConsumer* mockConsumer = new eprosima::fastdds::dds::MockConsumer(); |
| 230 | + eprosima::fastdds::dds::Log::RegisterConsumer(std::unique_ptr<eprosima::fastdds::dds::LogConsumer>(mockConsumer)); |
| 231 | + eprosima::fastdds::dds::Log::SetVerbosity(eprosima::fastdds::dds::Log::Error); |
| 232 | + |
| 233 | + security_activated_ = manager_.init(security_attributes_, participant_properties_); |
| 234 | + |
| 235 | + // Check that the error message was logged. |
| 236 | + // First flush the log to make sure the message is there. |
| 237 | + eprosima::fastdds::dds::Log::Flush(); |
| 238 | + |
| 239 | + auto log_entries = mockConsumer->ConsumedEntries(); |
| 240 | + ASSERT_GE(log_entries.size(), 1); |
| 241 | + bool found = false; |
| 242 | + for (auto entry : log_entries) |
| 243 | + { |
| 244 | + if (entry.message.find("Error while configuring security plugin.") != std::string::npos) |
| 245 | + { |
| 246 | + found = true; |
| 247 | + break; |
| 248 | + } |
| 249 | + } |
| 250 | + ASSERT_TRUE(found); |
| 251 | +} |
| 252 | + |
0 commit comments