diff options
Diffstat (limited to 'src/components')
7 files changed, 128 insertions, 44 deletions
diff --git a/src/components/application_manager/include/application_manager/request_controller.h b/src/components/application_manager/include/application_manager/request_controller.h index d3a5a0b821..c0bae1aac8 100644 --- a/src/components/application_manager/include/application_manager/request_controller.h +++ b/src/components/application_manager/include/application_manager/request_controller.h @@ -289,6 +289,13 @@ class RequestController { */ std::list<RequestPtr> notification_list_; + /** + * @brief Map keeping track of how many duplicate messages were sent for a + * given correlation id, to prevent early termination of a request + */ + std::map<uint32_t, uint32_t> duplicate_message_count_; + sync_primitives::Lock duplicate_message_count_lock_; + /* * timer for checking requests timeout */ diff --git a/src/components/application_manager/src/request_controller.cc b/src/components/application_manager/src/request_controller.cc index 1b9bd7ffb9..f341967842 100644 --- a/src/components/application_manager/src/request_controller.cc +++ b/src/components/application_manager/src/request_controller.cc @@ -50,6 +50,7 @@ RequestController::RequestController(const RequestControlerSettings& settings) : pool_state_(UNDEFINED) , pool_size_(settings.thread_pool_size()) , request_tracker_(settings) + , duplicate_message_count_() , timer_("AM RequestCtrlTimer", new timer::TimerTaskImpl<RequestController>( this, &RequestController::TimeoutThread)) @@ -230,6 +231,21 @@ void RequestController::TerminateRequest(const uint32_t correlation_id, << correlation_id << " connection_key = " << connection_key << " function_id = " << function_id << " force_terminate = " << force_terminate); + { + AutoLock auto_lock(duplicate_message_count_lock_); + auto dup_it = duplicate_message_count_.find(correlation_id); + if (duplicate_message_count_.end() != dup_it) { + duplicate_message_count_[correlation_id]--; + if (0 == duplicate_message_count_[correlation_id]) { + duplicate_message_count_.erase(dup_it); + } + LOG4CXX_DEBUG(logger_, + "Ignoring termination request due to duplicate correlation " + "ID being sent"); + return; + } + } + RequestInfoPtr request = waiting_for_response_.Find(connection_key, correlation_id); if (!request) { @@ -474,7 +490,24 @@ void RequestController::Worker::threadMain() { RequestInfoPtr request_info_ptr = utils::MakeShared<MobileRequestInfo>(request_ptr, timeout_in_mseconds); - request_controller_->waiting_for_response_.Add(request_info_ptr); + if (!request_controller_->waiting_for_response_.Add(request_info_ptr)) { + commands::CommandRequestImpl* cmd_request = + dynamic_cast<commands::CommandRequestImpl*>(request_ptr.get()); + if (cmd_request != NULL) { + uint32_t corr_id = cmd_request->correlation_id(); + request_controller_->duplicate_message_count_lock_.Acquire(); + auto dup_it = + request_controller_->duplicate_message_count_.find(corr_id); + if (request_controller_->duplicate_message_count_.end() == dup_it) { + request_controller_->duplicate_message_count_[corr_id] = 0; + } + request_controller_->duplicate_message_count_[corr_id]++; + request_controller_->duplicate_message_count_lock_.Release(); + cmd_request->SendResponse( + false, mobile_apis::Result::INVALID_ID, "Duplicate correlation_id"); + } + continue; + } LOG4CXX_DEBUG(logger_, "timeout_in_mseconds " << timeout_in_mseconds); if (0 != timeout_in_mseconds) { diff --git a/src/components/application_manager/test/commands/mobile/slider_test.cc b/src/components/application_manager/test/commands/mobile/slider_test.cc index 54ac3cccc0..53764e3fcd 100644 --- a/src/components/application_manager/test/commands/mobile/slider_test.cc +++ b/src/components/application_manager/test/commands/mobile/slider_test.cc @@ -282,9 +282,8 @@ TEST_F(SliderRequestTest, OnEvent_UI_OnResetTimeout_UNSUCCESS) { CommandPtr command(CreateCommand<SliderRequest>(msg_)); EXPECT_TRUE(command->Init()); - EXPECT_CALL( - app_mngr_, - updateRequestTimeout(kConnectionKey, kCorrelationId, kDefaultTimeout)); + EXPECT_CALL(app_mngr_, + updateRequestTimeout(kConnectionKey, kCorrelationId, _)); Event event(hmi_apis::FunctionID::UI_OnResetTimeout); event.set_smart_object(*msg_); diff --git a/src/components/application_manager/test/request_controller/request_controller_test.cc b/src/components/application_manager/test/request_controller/request_controller_test.cc index e053d51c34..c2912fdc0b 100644 --- a/src/components/application_manager/test/request_controller/request_controller_test.cc +++ b/src/components/application_manager/test/request_controller/request_controller_test.cc @@ -62,6 +62,7 @@ using ::application_manager::request_controller::RequestInfo; using ::testing::Return; using ::testing::ReturnRef; using ::testing::NiceMock; +using ::testing::_; typedef NiceMock<application_manager_test::MockRequest> MRequest; typedef utils::SharedPtr<MRequest> RequestPtr; @@ -114,6 +115,7 @@ class RequestControllerTestClass : public ::testing::Test { RequestPtr output = utils::MakeShared<MRequest>(connection_key, correlation_id); ON_CALL(*output, default_timeout()).WillByDefault(Return(default_timeout)); + ON_CALL(*output, CheckPermissions()).WillByDefault(Return(true)); return output; } @@ -159,6 +161,40 @@ class RequestControllerTestClass : public ::testing::Test { }; TEST_F(RequestControllerTestClass, + AddMobileRequest_DuplicateCorrelationId_INVALID_ID) { + RequestPtr request_valid = GetMockRequest(); + TestAsyncWaiter waiter_valid; + ON_CALL(*request_valid, default_timeout()).WillByDefault(Return(0)); + EXPECT_CALL(*request_valid, Init()).WillOnce(Return(true)); + EXPECT_CALL(*request_valid, Run()) + .Times(1) + .WillRepeatedly(NotifyTestAsyncWaiter(&waiter_valid)); + + EXPECT_EQ(RequestController::SUCCESS, + AddRequest(default_settings_, + request_valid, + RequestInfo::RequestType::MobileRequest, + mobile_apis::HMILevel::HMI_NONE)); + EXPECT_TRUE(waiter_valid.WaitFor(1, 1000)); + + // The command should not be run if another command with the same + // correlation_id is waiting for a response + RequestPtr request_dup_corr_id = GetMockRequest(); + TestAsyncWaiter waiter_dup; + ON_CALL(*request_dup_corr_id, default_timeout()).WillByDefault(Return(0)); + EXPECT_CALL(*request_dup_corr_id, Init()).WillOnce(Return(true)); + ON_CALL(*request_dup_corr_id, Run()) + .WillByDefault(NotifyTestAsyncWaiter(&waiter_dup)); + + EXPECT_EQ(RequestController::SUCCESS, + AddRequest(default_settings_, + request_dup_corr_id, + RequestInfo::RequestType::MobileRequest, + mobile_apis::HMILevel::HMI_NONE)); + EXPECT_FALSE(waiter_dup.WaitFor(1, 1000)); +} + +TEST_F(RequestControllerTestClass, CheckPosibilitytoAdd_ZeroValueLimiters_SUCCESS) { // Test case than pending_requests_amount, // app_time_scale_max_requests_ and diff --git a/src/components/security_manager/src/crypto_manager_impl.cc b/src/components/security_manager/src/crypto_manager_impl.cc index 6bee28a976..2cc88c5966 100644 --- a/src/components/security_manager/src/crypto_manager_impl.cc +++ b/src/components/security_manager/src/crypto_manager_impl.cc @@ -137,8 +137,13 @@ bool CryptoManagerImpl::Init() { #endif switch (get_settings().security_manager_protocol_name()) { case SSLv3: +#ifdef OPENSSL_NO_SSL3 + LOG4CXX_WARN(logger_, "OpenSSL does not support SSL3 protocol"); + return false; +#else method = is_server ? SSLv3_server_method() : SSLv3_client_method(); break; +#endif case TLSv1: method = is_server ? TLSv1_server_method() : TLSv1_client_method(); break; diff --git a/src/components/security_manager/test/ssl_context_test.cc b/src/components/security_manager/test/ssl_context_test.cc index 945059e58c..a77cd98b27 100644 --- a/src/components/security_manager/test/ssl_context_test.cc +++ b/src/components/security_manager/test/ssl_context_test.cc @@ -228,7 +228,7 @@ class SSLTestParam : public testing::TestWithParam<ProtocolAndCipher> { GetParam().server_ciphers_list); const bool crypto_manager_initialization = crypto_manager->Init(); - EXPECT_TRUE(crypto_manager_initialization); + ASSERT_TRUE(crypto_manager_initialization); mock_client_manager_settings_ = utils::MakeShared< NiceMock<security_manager_test::MockCryptoManagerSettings> >(); @@ -241,7 +241,7 @@ class SSLTestParam : public testing::TestWithParam<ProtocolAndCipher> { GetParam().client_ciphers_list); const bool client_manager_initialization = client_manager->Init(); - EXPECT_TRUE(client_manager_initialization); + ASSERT_TRUE(client_manager_initialization); server_ctx = crypto_manager->CreateSSLContext(); client_ctx = client_manager->CreateSSLContext(); @@ -261,9 +261,12 @@ class SSLTestParam : public testing::TestWithParam<ProtocolAndCipher> { } void TearDown() OVERRIDE { - crypto_manager->ReleaseSSLContext(server_ctx); - client_manager->ReleaseSSLContext(client_ctx); - + if (crypto_manager) { + crypto_manager->ReleaseSSLContext(server_ctx); + } + if (client_manager) { + client_manager->ReleaseSSLContext(client_ctx); + } delete crypto_manager; delete client_manager; } @@ -303,10 +306,10 @@ class SSLTestParam : public testing::TestWithParam<ProtocolAndCipher> { mock_crypto_manager_settings_; utils::SharedPtr<NiceMock<security_manager_test::MockCryptoManagerSettings> > mock_client_manager_settings_; - security_manager::CryptoManager* crypto_manager; - security_manager::CryptoManager* client_manager; - security_manager::SSLContext* server_ctx; - security_manager::SSLContext* client_ctx; + security_manager::CryptoManager* crypto_manager = NULL; + security_manager::CryptoManager* client_manager = NULL; + security_manager::SSLContext* server_ctx = NULL; + security_manager::SSLContext* client_ctx = NULL; std::string certificate_data_base64_; }; @@ -323,11 +326,15 @@ INSTANTIATE_TEST_CASE_P( ProtocolAndCipher(security_manager::TLSv1_1, security_manager::TLSv1_1, kFordCipher, - kFordCipher), + kFordCipher) +#ifndef OPENSSL_NO_SSL3 + , ProtocolAndCipher(security_manager::SSLv3, security_manager::SSLv3, kFordCipher, - kFordCipher))); + kFordCipher) +#endif + )); INSTANTIATE_TEST_CASE_P( IncorrectProtocolAndCiphers, @@ -336,18 +343,10 @@ INSTANTIATE_TEST_CASE_P( security_manager::TLSv1_1, kFordCipher, kFordCipher), - ProtocolAndCipher(security_manager::TLSv1, - security_manager::SSLv3, - kFordCipher, - kFordCipher), ProtocolAndCipher(security_manager::TLSv1_1, security_manager::TLSv1, kFordCipher, kFordCipher), - ProtocolAndCipher(security_manager::TLSv1_1, - security_manager::SSLv3, - kFordCipher, - kFordCipher), ProtocolAndCipher(security_manager::TLSv1_2, security_manager::TLSv1, kFordCipher, @@ -355,6 +354,16 @@ INSTANTIATE_TEST_CASE_P( ProtocolAndCipher(security_manager::TLSv1_2, security_manager::TLSv1_1, kFordCipher, + kFordCipher) +#ifndef OPENSSL_NO_SSL3 + , + ProtocolAndCipher(security_manager::TLSv1, + security_manager::SSLv3, + kFordCipher, + kFordCipher), + ProtocolAndCipher(security_manager::TLSv1_1, + security_manager::SSLv3, + kFordCipher, kFordCipher), ProtocolAndCipher(security_manager::TLSv1_2, security_manager::SSLv3, @@ -367,7 +376,9 @@ INSTANTIATE_TEST_CASE_P( ProtocolAndCipher(security_manager::SSLv3, security_manager::TLSv1_1, kFordCipher, - kFordCipher))); + kFordCipher) +#endif + )); TEST_F(SSLTest, OnTSL2Protocol_BrokenHandshake) { ASSERT_EQ(security_manager::SSLContext::Handshake_Result_Success, @@ -521,11 +532,15 @@ INSTANTIATE_TEST_CASE_P( ProtocolAndCipher(security_manager::TLSv1_1, security_manager::TLSv1_2, kFordCipher, - kFordCipher), + kFordCipher) +#ifndef OPENSSL_NO_SSL3 + , ProtocolAndCipher(security_manager::SSLv3, security_manager::TLSv1_2, kFordCipher, - kFordCipher))); + kFordCipher) +#endif + )); TEST_P(SSLTestForTLS1_2, HandshakeFailed) { ASSERT_EQ(security_manager::SSLContext::Handshake_Result_Success, diff --git a/src/components/utils/src/file_system.cc b/src/components/utils/src/file_system.cc index 62a91ad1f3..62a090550d 100644 --- a/src/components/utils/src/file_system.cc +++ b/src/components/utils/src/file_system.cc @@ -71,17 +71,14 @@ int64_t file_system::FileSize(const std::string& path) { size_t file_system::DirectorySize(const std::string& path) { size_t size = 0; - int32_t return_code = 0; DIR* directory = NULL; - struct dirent dir_element_; - struct dirent* dir_element = &dir_element_; + struct dirent* result = NULL; struct stat file_info = {0}; directory = opendir(path.c_str()); if (NULL != directory) { - return_code = readdir_r(directory, dir_element, &result); - for (; NULL != result && 0 == return_code; - return_code = readdir_r(directory, dir_element, &result)) { + result = readdir(directory); + for (; NULL != result; result = readdir(directory)) { if (0 == strcmp(result->d_name, "..") || 0 == strcmp(result->d_name, ".")) { continue; @@ -229,19 +226,15 @@ bool file_system::DeleteFile(const std::string& name) { } void file_system::remove_directory_content(const std::string& directory_name) { - int32_t return_code = 0; DIR* directory = NULL; - struct dirent dir_element_; - struct dirent* dir_element = &dir_element_; struct dirent* result = NULL; directory = opendir(directory_name.c_str()); if (NULL != directory) { - return_code = readdir_r(directory, dir_element, &result); + result = readdir(directory); - for (; NULL != result && 0 == return_code; - return_code = readdir_r(directory, dir_element, &result)) { + for (; NULL != result; result = readdir(directory)) { if (0 == strcmp(result->d_name, "..") || 0 == strcmp(result->d_name, ".")) { continue; @@ -295,18 +288,14 @@ std::vector<std::string> file_system::ListFiles( return listFiles; } - int32_t return_code = 0; DIR* directory = NULL; - struct dirent dir_element_; - struct dirent* dir_element = &dir_element_; struct dirent* result = NULL; directory = opendir(directory_name.c_str()); if (NULL != directory) { - return_code = readdir_r(directory, dir_element, &result); + result = readdir(directory); - for (; NULL != result && 0 == return_code; - return_code = readdir_r(directory, dir_element, &result)) { + for (; NULL != result; result = readdir(directory)) { if (0 == strcmp(result->d_name, "..") || 0 == strcmp(result->d_name, ".")) { continue; |