Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix policy validation of OnVehicleData message #3568

Merged
merged 2 commits into from
Nov 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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