diff options
author | collin <collin+i@collinmcqueen.com> | 2020-05-13 14:15:31 -0400 |
---|---|---|
committer | collin <collin+i@collinmcqueen.com> | 2020-05-13 14:15:31 -0400 |
commit | 236bdbaa283147044a6144f8c96cc43b82ff1014 (patch) | |
tree | ba76d0566cb98b9b726ba7a78834e55f2f5dcf02 | |
parent | bfacfcb45b067b987cc38b98fe70657559c330ed (diff) | |
download | sdl_core-236bdbaa283147044a6144f8c96cc43b82ff1014.tar.gz |
RAI reply DUPLICATE_NAME when app has same id and name as existing app
3 files changed, 69 insertions, 8 deletions
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/register_app_interface_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/register_app_interface_request.h index d59964bbc7..1321285bde 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/register_app_interface_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/register_app_interface_request.h @@ -140,7 +140,7 @@ class RegisterAppInterfaceRequest * * return TRUE if ID is known already, otherwise - FALSE */ - bool IsApplicationWithSameAppIdRegistered(); + bool IsApplicationWithSameAppIdOrAppNameRegistered(); /** * @brief Check new application parameters (name, tts, vr) for diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/register_app_interface_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/register_app_interface_request.cc index 54649980c6..bdb648d815 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/register_app_interface_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/register_app_interface_request.cc @@ -248,6 +248,11 @@ void RegisterAppInterfaceRequest::Run() { logger_, "device_handle: " << device_handle_ << " device_id: " << device_id_); + if (IsApplicationWithSameAppIdOrAppNameRegistered()) { + SendResponse(false, mobile_apis::Result::DUPLICATE_NAME); + return; + } + if (IsApplicationSwitched()) { return; } @@ -282,11 +287,6 @@ void RegisterAppInterfaceRequest::Run() { (*message_)[strings::msg_params][strings::full_app_id] = new_app_id_full; } - if (IsApplicationWithSameAppIdRegistered()) { - SendResponse(false, mobile_apis::Result::DISALLOWED); - return; - } - mobile_apis::Result::eType policy_result = CheckWithPolicyData(); if (Compare<mobile_apis::Result::eType, NEQ, ALL>( @@ -1236,11 +1236,13 @@ void RegisterAppInterfaceRequest::FillDeviceInfo( } } -bool RegisterAppInterfaceRequest::IsApplicationWithSameAppIdRegistered() { +bool RegisterAppInterfaceRequest::IsApplicationWithSameAppIdOrAppNameRegistered() { LOG4CXX_AUTO_TRACE(logger_); const custom_string::CustomString mobile_app_id( application_manager_.GetCorrectMobileIDFromMessage(message_)); + const custom_str::CustomString& app_name = + (*message_)[strings::msg_params][strings::app_name].asCustomString(); const auto& applications = application_manager_.applications().GetData(); @@ -1257,6 +1259,9 @@ bool RegisterAppInterfaceRequest::IsApplicationWithSameAppIdRegistered() { } return true; } + if (app_name.CompareIgnoreCase(app->name())) { + return true; + } } return false; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/register_app_interface_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/register_app_interface_request_test.cc index 6376570106..74c292efa7 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/register_app_interface_request_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/register_app_interface_request_test.cc @@ -530,6 +530,10 @@ TEST_F(RegisterAppInterfaceRequestTest, const std::string request_hash_id = "abc123"; (*msg_)[am::strings::msg_params][am::strings::hash_id] = request_hash_id; + ON_CALL(app_mngr_, applications()) + .WillByDefault( + Return(DataAccessor<am::ApplicationSet>(app_set_, lock_ptr_))); + MockAppPtr mock_app = CreateBasicMockedApp(); app_set_.insert(mock_app); EXPECT_CALL(app_mngr_, reregister_application_by_policy_id(kAppId1)) @@ -543,7 +547,7 @@ TEST_F(RegisterAppInterfaceRequestTest, ON_CALL(mock_session_observer_, GetDataOnDeviceID(device_id, _, _, _, _)) .WillByDefault(DoAll(SetArgPointee<3>(kMacAddress1), Return(0))); - EXPECT_CALL(*mock_app, device()).WillOnce(Return(kDeviceHandle)); + ON_CALL(*mock_app, device()).WillByDefault(Return(kDeviceHandle)); EXPECT_CALL(app_mngr_, ProcessReconnection(_, kConnectionKey)); @@ -577,6 +581,10 @@ TEST_F(RegisterAppInterfaceRequestTest, const std::string request_hash_id = "abc123"; (*msg_)[am::strings::msg_params][am::strings::hash_id] = request_hash_id; + ON_CALL(app_mngr_, applications()) + .WillByDefault( + Return(DataAccessor<am::ApplicationSet>(app_set_, lock_ptr_))); + connection_handler::DeviceHandle device_id = 1; ON_CALL(mock_connection_handler_, GetDataOnSessionKey(kConnectionKey, _, _, _)) @@ -620,6 +628,10 @@ TEST_F(RegisterAppInterfaceRequestTest, SwitchApplication_NoHash_ExpectCleanupResumeFailed) { InitBasicMessage(); + ON_CALL(app_mngr_, applications()) + .WillByDefault( + Return(DataAccessor<am::ApplicationSet>(app_set_, lock_ptr_))); + connection_handler::DeviceHandle device_id = 1; ON_CALL(mock_connection_handler_, GetDataOnSessionKey(kConnectionKey, _, _, _)) @@ -654,6 +666,50 @@ TEST_F(RegisterAppInterfaceRequestTest, } TEST_F(RegisterAppInterfaceRequestTest, + Run_Other_App_With_Same_App_Name_DUPLICATE_NAME) { + InitBasicMessage(); + + app_set_.insert(CreateBasicMockedApp()); + + const uint32_t kConnection_key_ = 2u; + const std::string kApp_Id = "other_app_id"; + (*msg_)[am::strings::params][am::strings::connection_key] = kConnection_key_; + (*msg_)[am::strings::msg_params][am::strings::app_id] = kApp_Id; + + ON_CALL(app_mngr_, applications()) + .WillByDefault( + Return(DataAccessor<am::ApplicationSet>(app_set_, lock_ptr_))); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::DUPLICATE_NAME), _)); + + command_->Run(); +} + +TEST_F(RegisterAppInterfaceRequestTest, + Run_Other_App_With_Same_App_ID_DUPLICATE_NAME) { + InitBasicMessage(); + + app_set_.insert(CreateBasicMockedApp()); + + const uint32_t kConnection_key_ = 2u; + const std::string kApp_Name = "other_app_name"; + (*msg_)[am::strings::params][am::strings::connection_key] = kConnection_key_; + (*msg_)[am::strings::msg_params][am::strings::app_name] = kApp_Name; + + ON_CALL(app_mngr_, applications()) + .WillByDefault( + Return(DataAccessor<am::ApplicationSet>(app_set_, lock_ptr_))); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::DUPLICATE_NAME), _)); + + command_->Run(); +} + +TEST_F(RegisterAppInterfaceRequestTest, RegisterApp_SameAppId_SameDeviceFailed) { using namespace am; |