summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbsolonenko <bsolonenko@luxoft.com>2019-03-27 17:20:56 +0200
committerMaksym Ked (GitHub) <mked@luxoft.com>2019-06-25 13:58:39 +0300
commitb47c0411da705698dbfa04c28c24299909f1a0c4 (patch)
treee70be9bb829006b912093c18c4c7d3fef83f7b20
parente7f9a870b7a724428b17181af86393a55a9d111e (diff)
downloadsdl_core-b47c0411da705698dbfa04c28c24299909f1a0c4.tar.gz
Fixed UTs after implementation feature RPC message protection.
-rw-r--r--src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/rc_get_interior_vehicle_data_consent_test.cc1
-rw-r--r--src/components/application_manager/test/include/application_manager/mock_rpc_protection_mediator.h22
-rw-r--r--src/components/include/test/application_manager/policies/mock_policy_handler_interface.h6
-rw-r--r--src/components/include/test/policy/policy_external/policy/mock_cache_manager.h13
-rw-r--r--src/components/include/test/policy/policy_regular/policy/mock_cache_manager.h12
-rw-r--r--src/components/include/test/protocol_handler/mock_protocol_handler.h4
-rw-r--r--src/components/policy/policy_external/src/sql_pt_representation.cc4
-rw-r--r--src/components/protocol_handler/test/protocol_handler_tm_test.cc6
-rw-r--r--src/components/security_manager/test/security_manager_test.cc55
9 files changed, 90 insertions, 33 deletions
diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/rc_get_interior_vehicle_data_consent_test.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/rc_get_interior_vehicle_data_consent_test.cc
index 4a5a0fb977..48b067c3c5 100644
--- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/rc_get_interior_vehicle_data_consent_test.cc
+++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/rc_get_interior_vehicle_data_consent_test.cc
@@ -248,6 +248,7 @@ TEST_F(RCGetInteriorVehicleDataConsentTest,
EXPECT_CALL(mock_command_factory, CreateCommand(_, _))
.WillOnce(Return(rc_consent_response));
auto command = CreateRCCommand<commands::ButtonPressRequest>(mobile_message);
+
// Act
ASSERT_TRUE(command->Init());
command->Run();
diff --git a/src/components/application_manager/test/include/application_manager/mock_rpc_protection_mediator.h b/src/components/application_manager/test/include/application_manager/mock_rpc_protection_mediator.h
new file mode 100644
index 0000000000..32b17aabea
--- /dev/null
+++ b/src/components/application_manager/test/include/application_manager/mock_rpc_protection_mediator.h
@@ -0,0 +1,22 @@
+#pragma once
+
+#include "gmock/gmock.h"
+#include "application_manager/rpc_protection_mediator.h"
+
+namespace application_manager {
+class MockRPCProtectionMediator : public RPCProtectionMediator {
+ public:
+ MOCK_METHOD4(DoesRPCNeedEncryption,
+ bool(const uint32_t function_id,
+ std::shared_ptr<Application> app,
+ const uint32_t conrrelation_id,
+ const bool is_rpc_service_secure));
+ MOCK_METHOD1(DoesRPCNeedEncryption, bool(const uint32_t conrrelation_id));
+ MOCK_METHOD1(EncryptResponseByForce, void(const uint32_t conrrelation_id));
+ MOCK_METHOD3(CreateNegativeResponse,
+ std::shared_ptr<smart_objects::SmartObject>(
+ const uint32_t connection_key,
+ const uint32_t function_id,
+ const uint32_t conrrelation_id));
+};
+}
diff --git a/src/components/include/test/application_manager/policies/mock_policy_handler_interface.h b/src/components/include/test/application_manager/policies/mock_policy_handler_interface.h
index 6dfeea7212..d44a65a934 100644
--- a/src/components/include/test/application_manager/policies/mock_policy_handler_interface.h
+++ b/src/components/include/test/application_manager/policies/mock_policy_handler_interface.h
@@ -38,7 +38,7 @@
#include "gmock/gmock.h"
#include "policy/policy_types.h"
#include "smart_objects/smart_object.h"
-#include "application_manager/policies/rpc_encryption_data_accessor_interface.h"
+#include "application_manager/policies/policy_encryption_flag_getter.h"
namespace test {
namespace components {
@@ -47,8 +47,8 @@ namespace policy_test {
class MockPolicyHandlerInterface : public policy::PolicyHandlerInterface {
public:
MOCK_METHOD0(LoadPolicyLibrary, bool());
- MOCK_CONST_METHOD0(RPCEncryptionDataAccessor,
- policy::RPCEncryptionDataAccessorInterface&());
+ MOCK_CONST_METHOD0(PolicyEncryptionFlagGetter,
+ policy::PolicyEncryptionFlagGetterInterfaceSPtr());
MOCK_CONST_METHOD0(PolicyEnabled, bool());
MOCK_METHOD0(InitPolicyTable, bool());
MOCK_METHOD0(ResetPolicyTable, bool());
diff --git a/src/components/include/test/policy/policy_external/policy/mock_cache_manager.h b/src/components/include/test/policy/policy_external/policy/mock_cache_manager.h
index 6f754ad2c9..89f4a69514 100644
--- a/src/components/include/test/policy/policy_external/policy/mock_cache_manager.h
+++ b/src/components/include/test/policy/policy_external/policy/mock_cache_manager.h
@@ -57,6 +57,7 @@ class MockCacheManagerInterface : public ::policy::CacheManagerInterface {
const PTString& hmi_level,
const PTString& rpc,
CheckPermissionResult& result));
+ MOCK_CONST_METHOD0(pt, std::shared_ptr<policy_table::Table>());
MOCK_METHOD0(IsPTPreloaded, bool());
MOCK_METHOD0(IgnitionCyclesBeforeExchange, int());
MOCK_METHOD1(KilometersBeforeExchange, int(int current));
@@ -292,6 +293,18 @@ class MockCacheManagerInterface : public ::policy::CacheManagerInterface {
RequestType::State(const std::string& policy_app_id));
MOCK_CONST_METHOD1(GetAppRequestSubTypesState,
RequestSubType::State(const std::string& policy_app_id));
+
+ MOCK_CONST_METHOD1(
+ GetAppEncryptionRequiredFlag,
+ rpc::Optional<rpc::Boolean>(const std::string& application_policy_name));
+
+ MOCK_CONST_METHOD1(
+ GetFunctionalGroupingEncryptionRequiredFlag,
+ rpc::Optional<rpc::Boolean>(const std::string& functional_group));
+
+ MOCK_CONST_METHOD2(GetApplicationParams,
+ void(const std::string& application_name,
+ policy_table::ApplicationParams& application_params));
};
} // namespace policy_test
diff --git a/src/components/include/test/policy/policy_regular/policy/mock_cache_manager.h b/src/components/include/test/policy/policy_regular/policy/mock_cache_manager.h
index dacdaf202f..b0259d3e07 100644
--- a/src/components/include/test/policy/policy_regular/policy/mock_cache_manager.h
+++ b/src/components/include/test/policy/policy_regular/policy/mock_cache_manager.h
@@ -254,6 +254,18 @@ class MockCacheManagerInterface : public CacheManagerInterface {
RequestType::State(const std::string& policy_app_id));
MOCK_CONST_METHOD1(GetAppRequestSubTypesState,
RequestSubType::State(const std::string& policy_app_id));
+
+ MOCK_CONST_METHOD1(
+ GetAppEncryptionRequiredFlag,
+ rpc::Optional<rpc::Boolean>(const std::string& application_policy_name));
+
+ MOCK_CONST_METHOD1(
+ GetFunctionalGroupingEncryptionRequiredFlag,
+ rpc::Optional<rpc::Boolean>(const std::string& functional_group));
+
+ MOCK_CONST_METHOD2(GetApplicationParams,
+ void(const std::string& application_name,
+ policy_table::ApplicationParams& application_params));
};
} // namespace policy_test
diff --git a/src/components/include/test/protocol_handler/mock_protocol_handler.h b/src/components/include/test/protocol_handler/mock_protocol_handler.h
index 4468914a26..772b63b582 100644
--- a/src/components/include/test/protocol_handler/mock_protocol_handler.h
+++ b/src/components/include/test/protocol_handler/mock_protocol_handler.h
@@ -44,8 +44,9 @@ namespace protocol_handler_test {
class MockProtocolHandler : public ::protocol_handler::ProtocolHandler {
public:
- MOCK_METHOD2(SendMessageToMobileApp,
+ MOCK_METHOD3(SendMessageToMobileApp,
void(const ::protocol_handler::RawMessagePtr message,
+ bool needs_encryption,
bool final_message));
MOCK_METHOD1(AddProtocolObserver,
void(::protocol_handler::ProtocolObserver* observer));
@@ -67,6 +68,7 @@ class MockProtocolHandler : public ::protocol_handler::ProtocolHandler {
void(const ::protocol_handler::SessionContext& context,
std::vector<std::string>& rejected_params));
MOCK_METHOD0(NotifyOnFailedHandshake, void());
+ MOCK_CONST_METHOD1(IsRPCServiceSecure, bool(const uint32_t connection_key));
};
} // namespace protocol_handler_test
} // namespace components
diff --git a/src/components/policy/policy_external/src/sql_pt_representation.cc b/src/components/policy/policy_external/src/sql_pt_representation.cc
index b6d63bb7bf..12b3b9c22b 100644
--- a/src/components/policy/policy_external/src/sql_pt_representation.cc
+++ b/src/components/policy/policy_external/src/sql_pt_representation.cc
@@ -908,8 +908,8 @@ bool SQLPTRepresentation::SaveFunctionalGroupings(
groups_it->second.user_consent_prompt.is_initialized()
? query.Bind(2, *(groups_it->second.user_consent_prompt))
: query.Bind(2);
- it->second.encryption_required.is_initialized()
- ? query.Bind(3, *(it->second.encryption_required))
+ groups_it->second.encryption_required.is_initialized()
+ ? query.Bind(3, *(groups_it->second.encryption_required))
: query.Bind(3);
if (!query.Exec() || !query.Reset()) {
LOG4CXX_WARN(logger_, "Incorrect insert into functional groups");
diff --git a/src/components/protocol_handler/test/protocol_handler_tm_test.cc b/src/components/protocol_handler/test/protocol_handler_tm_test.cc
index d22cf13270..692b1a7134 100644
--- a/src/components/protocol_handler/test/protocol_handler_tm_test.cc
+++ b/src/components/protocol_handler/test/protocol_handler_tm_test.cc
@@ -3688,7 +3688,7 @@ TEST_F(ProtocolHandlerImplTest,
times++;
// Act
- protocol_handler_impl->SendMessageToMobileApp(message, is_final);
+ protocol_handler_impl->SendMessageToMobileApp(message, false, is_final);
EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout));
}
@@ -3735,7 +3735,7 @@ TEST_F(ProtocolHandlerImplTest,
times++;
// Act
- protocol_handler_impl->SendMessageToMobileApp(message, is_final);
+ protocol_handler_impl->SendMessageToMobileApp(message, false, is_final);
EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout));
}
@@ -3794,7 +3794,7 @@ TEST_F(ProtocolHandlerImplTest, SendMessageToMobileApp_SendMultiframeMessage) {
times++;
// Act
- protocol_handler_impl->SendMessageToMobileApp(message, is_final);
+ protocol_handler_impl->SendMessageToMobileApp(message, false, is_final);
EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout));
}
diff --git a/src/components/security_manager/test/security_manager_test.cc b/src/components/security_manager/test/security_manager_test.cc
index 3b4100ea76..5472e7d49c 100644
--- a/src/components/security_manager/test/security_manager_test.cc
+++ b/src/components/security_manager/test/security_manager_test.cc
@@ -292,8 +292,8 @@ TEST_F(SecurityManagerTest, SecurityManager_NULLCryptoManager) {
EXPECT_CALL(mock_protocol_handler,
SendMessageToMobileApp(
InternalErrorWithErrId(SecurityManager::ERROR_NOT_SUPPORTED),
- kIsFinal))
- .WillOnce(NotifyTestAsyncWaiter(&waiter));
+ false,
+ kIsFinal)).WillOnce(NotifyTestAsyncWaiter(&waiter));
const SecurityQuery::QueryHeader header(SecurityQuery::REQUEST,
// It could be any query id
SecurityQuery::INVALID_QUERY_ID);
@@ -338,6 +338,7 @@ TEST_F(SecurityManagerTest, GetEmptyQuery) {
mock_protocol_handler,
SendMessageToMobileApp(
InternalErrorWithErrId(SecurityManager::ERROR_INVALID_QUERY_SIZE),
+ false,
kIsFinal));
// Call with NULL data
call_OnMessageReceived(NULL, 0, kSecureServiceType);
@@ -359,6 +360,7 @@ TEST_F(SecurityManagerTest, GetWrongJSONSize) {
mock_protocol_handler,
SendMessageToMobileApp(
InternalErrorWithErrId(SecurityManager::ERROR_INVALID_QUERY_SIZE),
+ false,
kIsFinal));
SecurityQuery::QueryHeader header(SecurityQuery::REQUEST,
SecurityQuery::INVALID_QUERY_ID);
@@ -388,8 +390,8 @@ TEST_F(SecurityManagerTest, GetInvalidQueryId) {
mock_protocol_handler,
SendMessageToMobileApp(
InternalErrorWithErrId(SecurityManager::ERROR_INVALID_QUERY_ID),
- kIsFinal))
- .WillOnce(NotifyTestAsyncWaiter(&waiter));
+ false,
+ kIsFinal)).WillOnce(NotifyTestAsyncWaiter(&waiter));
times++;
const SecurityQuery::QueryHeader header(SecurityQuery::REQUEST,
SecurityQuery::INVALID_QUERY_ID);
@@ -427,10 +429,11 @@ TEST_F(SecurityManagerTest, CreateSSLContext_ErrorCreateSSL) {
EXPECT_CALL(mock_session_observer,
ProtocolVersionUsed(connection_id, session_id, _))
.WillOnce(Return(true));
- EXPECT_CALL(
- mock_protocol_handler,
- SendMessageToMobileApp(
- InternalErrorWithErrId(SecurityManager::ERROR_INTERNAL), kIsFinal));
+ EXPECT_CALL(mock_protocol_handler,
+ SendMessageToMobileApp(
+ InternalErrorWithErrId(SecurityManager::ERROR_INTERNAL),
+ false,
+ kIsFinal));
// Emulate SessionObserver and CryptoManager result
EXPECT_CALL(mock_session_observer, GetSSLContext(kKey, kControl))
@@ -461,6 +464,7 @@ TEST_F(SecurityManagerTest, CreateSSLContext_SetSSLContextError) {
mock_protocol_handler,
SendMessageToMobileApp(
InternalErrorWithErrId(SecurityManager::ERROR_UNKNOWN_INTERNAL_ERROR),
+ false,
kIsFinal));
// Emulate SessionObserver and CryptoManager result
@@ -512,10 +516,11 @@ TEST_F(SecurityManagerTest, StartHandshake_ServiceStillUnprotected) {
ProtocolVersionUsed(connection_id, session_id, _))
.WillOnce(Return(true));
// Expect InternalError with ERROR_INTERNAL
- EXPECT_CALL(
- mock_protocol_handler,
- SendMessageToMobileApp(
- InternalErrorWithErrId(SecurityManager::ERROR_INTERNAL), kIsFinal));
+ EXPECT_CALL(mock_protocol_handler,
+ SendMessageToMobileApp(
+ InternalErrorWithErrId(SecurityManager::ERROR_INTERNAL),
+ false,
+ kIsFinal));
// Expect notifying listeners (unsuccess)
EXPECT_CALL(*mock_sm_listener,
OnHandshakeDone(kKey, SSLContext::Handshake_Result_Fail))
@@ -550,10 +555,11 @@ TEST_F(SecurityManagerTest, StartHandshake_SSLInternalError) {
EXPECT_CALL(mock_session_observer, GetSSLContext(kKey, kControl))
.WillOnce(ReturnNull());
// Expect InternalError with ERROR_ID
- EXPECT_CALL(
- mock_protocol_handler,
- SendMessageToMobileApp(
- InternalErrorWithErrId(SecurityManager::ERROR_INTERNAL), kIsFinal));
+ EXPECT_CALL(mock_protocol_handler,
+ SendMessageToMobileApp(
+ InternalErrorWithErrId(SecurityManager::ERROR_INTERNAL),
+ false,
+ kIsFinal));
security_manager_->StartHandshake(kKey);
mock_sm_listener.release();
@@ -579,8 +585,8 @@ TEST_F(SecurityManagerTest, ProccessHandshakeData_WrongDataSize) {
mock_protocol_handler,
SendMessageToMobileApp(
InternalErrorWithErrId(SecurityManager::ERROR_INVALID_QUERY_SIZE),
- kIsFinal))
- .WillOnce(NotifyTestAsyncWaiter(&waiter));
+ false,
+ kIsFinal)).WillOnce(NotifyTestAsyncWaiter(&waiter));
EmulateMobileMessageHandshake(NULL, 0);
@@ -611,8 +617,8 @@ TEST_F(SecurityManagerTest,
mock_protocol_handler,
SendMessageToMobileApp(
InternalErrorWithErrId(SecurityManager::ERROR_SERVICE_NOT_PROTECTED),
- kIsFinal))
- .WillOnce(NotifyTestAsyncWaiter(&waiter));
+ false,
+ kIsFinal)).WillOnce(NotifyTestAsyncWaiter(&waiter));
times++;
// Expect notifying listeners (unsuccess)
@@ -665,6 +671,7 @@ TEST_F(SecurityManagerTest, ProccessHandshakeData_InvalidData) {
mock_protocol_handler,
SendMessageToMobileApp(
InternalErrorWithErrId(SecurityManager::ERROR_SSL_INVALID_DATA),
+ false,
kIsFinal))
.Times(handshake_emulates)
.WillRepeatedly(NotifyTestAsyncWaiter(&waiter));
@@ -743,9 +750,9 @@ TEST_F(SecurityManagerTest, ProccessHandshakeData_Answer) {
// Get size of raw message after
const size_t raw_message_size = 15;
- EXPECT_CALL(
- mock_protocol_handler,
- SendMessageToMobileApp(RawMessageEqSize(raw_message_size), kIsFinal))
+ EXPECT_CALL(mock_protocol_handler,
+ SendMessageToMobileApp(
+ RawMessageEqSize(raw_message_size), false, kIsFinal))
.Times(handshake_emulates)
.WillRepeatedly(NotifyTestAsyncWaiter(&waiter));
times += handshake_emulates;
@@ -872,7 +879,7 @@ TEST_F(SecurityManagerTest, ProccessHandshakeData_HandshakeFinished) {
.WillRepeatedly(DoAll(NotifyTestAsyncWaiter(&waiter), Return(true)));
times += 2; // matches to the number above
- EXPECT_CALL(mock_protocol_handler, SendMessageToMobileApp(_, kIsFinal))
+ EXPECT_CALL(mock_protocol_handler, SendMessageToMobileApp(_, false, kIsFinal))
.Times(2)
.WillRepeatedly(NotifyTestAsyncWaiter(&waiter));
times += 2; // matches to the number above