Skip to content

Commit

Permalink
Fix policy validation of OnVehicleData message (#3568)
Browse files Browse the repository at this point in the history
* Fix policy validation of OnVehicleData message

* Fix unit tests

Co-authored-by: Mykola Korniichuk <[email protected]>
  • Loading branch information
jacobkeeler and mkorniichuk authored Nov 16, 2020
1 parent 7871541 commit 9dc3c07
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,34 @@ void OnVehicleDataNotification::Run() {
}
}

SDL_LOG_DEBUG("Number of Notifications to be send: " << notify_apps.size());

for (size_t idx = 0; idx < notify_apps.size(); idx++) {
SDL_LOG_INFO("Send OnVehicleData PRNDL notification to "
CommandParametersPermissions params_permissions;
application_manager_.CheckPolicyPermissions(
notify_apps[idx],
window_id(),
MessageHelper::StringifiedFunctionID(
mobile_api::FunctionID::OnVehicleDataID),
appSO[idx].enumerate(),
&params_permissions);

for (const auto& param : appSO[idx].enumerate()) {
const auto& allowed_params = params_permissions.allowed_params;
auto param_allowed = allowed_params.find(param);
if (allowed_params.end() == param_allowed) {
SDL_LOG_DEBUG("Param " << param << " is not allowed by policy for app "
<< notify_apps[idx]->app_id()
<< ". It will be ignored.");
appSO[idx].erase(param);
}
}

if (appSO[idx].empty()) {
SDL_LOG_DEBUG("App " << notify_apps[idx]->app_id()
<< " will be skipped: there is nothing to notify.");
continue;
}

SDL_LOG_INFO("Send OnVehicleData notification to "
<< notify_apps[idx]->name().c_str() << " application id "
<< notify_apps[idx]->app_id());
(*message_)[strings::params][strings::connection_key] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ namespace on_vehicle_data_notification {
namespace am = ::application_manager;

using ::testing::_;
using ::testing::ContainerEq;
using ::testing::Return;
using ::testing::ReturnRef;
using ::testing::SetArgPointee;

using am::commands::MessageSharedPtr;
using vehicle_info_plugin::commands::OnVehicleDataNotification;
Expand Down Expand Up @@ -119,6 +121,15 @@ TEST_F(OnVehicleDataNotificationTest, OnVehicleDataNotification_SUCCESS) {
VehicleInfoAppExtensionUID))
.WillByDefault(Return(vi_app_extention_ptr));

am::CommandParametersPermissions params_permissions;
params_permissions.allowed_params.insert(am::strings::gps);
params_permissions.allowed_params.insert(am::strings::speed);
EXPECT_CALL(app_mngr_,
CheckPolicyPermissions(
_, _, _, ContainerEq(params_permissions.allowed_params), _))
.WillOnce(DoAll(SetArgPointee<4>(params_permissions),
Return(mobile_apis::Result::SUCCESS)));

MessageSharedPtr message(CreateMessage(smart_objects::SmartType_Map));
smart_objects::SmartObject gps_data;
gps_data[am::strings::longitude_degrees] = 1.0;
Expand Down

0 comments on commit 9dc3c07

Please sign in to comment.