summaryrefslogtreecommitdiff
path: root/src/components/security_manager/test/security_manager_test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/security_manager/test/security_manager_test.cc')
-rw-r--r--src/components/security_manager/test/security_manager_test.cc259
1 files changed, 95 insertions, 164 deletions
diff --git a/src/components/security_manager/test/security_manager_test.cc b/src/components/security_manager/test/security_manager_test.cc
index b334e78e19..aff7cbca2d 100644
--- a/src/components/security_manager/test/security_manager_test.cc
+++ b/src/components/security_manager/test/security_manager_test.cc
@@ -44,7 +44,8 @@
#include "security_manager/mock_ssl_context.h"
#include "security_manager/mock_crypto_manager.h"
#include "security_manager/mock_security_manager_listener.h"
-#include "utils/make_shared.h"
+#include "utils/mock_system_time_handler.h"
+
#include "utils/test_async_waiter.h"
namespace test {
@@ -76,11 +77,11 @@ using ::testing::_;
namespace {
// Sample data for handshake data emulation
-const int32_t key = 0x1;
-const int32_t seq_number = 0x2;
-const ServiceType secureServiceType = kControl;
-const uint32_t protocolVersion = PROTOCOL_VERSION_2;
-const bool is_final = false;
+const int32_t kKey = 0x1;
+const int32_t kSeqNumber = 0x2;
+const ServiceType kSecureServiceType = kControl;
+const uint32_t kProtocolVersion = PROTOCOL_VERSION_2;
+const bool kIsFinal = false;
const uint8_t handshake_data[] = {0x1, 0x2, 0x3, 0x4, 0x5};
const size_t handshake_data_size =
@@ -95,8 +96,12 @@ const uint32_t kAsyncExpectationsTimeout = 10000u;
class SecurityManagerTest : public ::testing::Test {
protected:
+ SecurityManagerTest()
+ : mock_system_time_handler(
+ std::unique_ptr<MockSystemTimeHandler>(new MockSystemTimeHandler()))
+ , security_manager_(
+ new SecurityManagerImpl(std::move(mock_system_time_handler))) {}
void SetUp() OVERRIDE {
- security_manager_.reset(new SecurityManagerImpl());
security_manager_->set_session_observer(&mock_session_observer);
security_manager_->set_protocol_handler(&mock_protocol_handler);
mock_sm_listener.reset(new testing::StrictMock<
@@ -105,7 +110,7 @@ class SecurityManagerTest : public ::testing::Test {
}
void SetMockCryptoManager() {
- EXPECT_CALL(mock_crypto_manager, IsCertificateUpdateRequired())
+ EXPECT_CALL(mock_crypto_manager, IsCertificateUpdateRequired(_, _))
.WillRepeatedly(Return(false));
security_manager_->set_crypto_manager(&mock_crypto_manager);
}
@@ -115,8 +120,8 @@ class SecurityManagerTest : public ::testing::Test {
void call_OnMessageReceived(const uint8_t* const data,
uint32_t dataSize,
const ServiceType serviceType) {
- const RawMessagePtr rawMessagePtr(utils::MakeShared<RawMessage>(
- key, protocolVersion, data, dataSize, serviceType));
+ const RawMessagePtr rawMessagePtr(std::make_shared<RawMessage>(
+ kKey, kProtocolVersion, data, dataSize, serviceType));
security_manager_->OnMessageReceived(rawMessagePtr);
}
/*
@@ -147,13 +152,14 @@ class SecurityManagerTest : public ::testing::Test {
const int repeat_count = 1) {
const SecurityQuery::QueryHeader header(SecurityQuery::NOTIFICATION,
SecurityQuery::SEND_HANDSHAKE_DATA,
- seq_number);
+ kSeqNumber);
for (int c = 0; c < repeat_count; ++c) {
EmulateMobileMessage(header, data, data_size);
}
}
- ::utils::SharedPtr<SecurityManagerImpl> security_manager_;
+
// Strict mocks (same as all methods EXPECT_CALL().Times(0))
+
testing::StrictMock<protocol_handler_test::MockSessionObserver>
mock_session_observer;
testing::StrictMock<protocol_handler_test::MockProtocolHandler>
@@ -166,6 +172,8 @@ class SecurityManagerTest : public ::testing::Test {
mock_ssl_context_exists;
std::unique_ptr<testing::StrictMock<
security_manager_test::MockSecurityManagerListener> > mock_sm_listener;
+ std::unique_ptr<MockSystemTimeHandler> mock_system_time_handler;
+ std::shared_ptr<SecurityManagerImpl> security_manager_;
};
// Test Bodies
@@ -174,7 +182,6 @@ class SecurityManagerTest : public ::testing::Test {
* and shall not call any methodes
*/
TEST_F(SecurityManagerTest, SetNULL_Intefaces) {
- security_manager_.reset(new SecurityManagerImpl());
security_manager_->set_session_observer(NULL);
security_manager_->set_protocol_handler(NULL);
security_manager_->set_crypto_manager(NULL);
@@ -209,9 +216,9 @@ TEST_F(SecurityManagerTest, Listeners_NoListeners) {
security_manager_->RemoveListener(&mock_listener2);
security_manager_->NotifyListenersOnHandshakeDone(
- key, SSLContext::Handshake_Result_Success);
+ kKey, SSLContext::Handshake_Result_Success);
security_manager_->NotifyListenersOnHandshakeDone(
- key, SSLContext::Handshake_Result_Fail);
+ kKey, SSLContext::Handshake_Result_Fail);
}
/*
* Notifying two listeners
@@ -228,11 +235,11 @@ TEST_F(SecurityManagerTest, Listeners_Notifying) {
const SSLContext::HandshakeResult first_call_value =
SSLContext::Handshake_Result_Success;
// Expect call both listeners on 1st call
- EXPECT_CALL(*mock_listener1, OnHandshakeDone(key, first_call_value))
+ EXPECT_CALL(*mock_listener1, OnHandshakeDone(kKey, first_call_value))
.
// Emulate false (reject) result
WillOnce(Return(false));
- EXPECT_CALL(*mock_listener2, OnHandshakeDone(key, first_call_value))
+ EXPECT_CALL(*mock_listener2, OnHandshakeDone(kKey, first_call_value))
.
// Emulate true (accept) result
WillOnce(Return(true));
@@ -244,7 +251,7 @@ TEST_F(SecurityManagerTest, Listeners_Notifying) {
const SSLContext::HandshakeResult second_call_value =
SSLContext::Handshake_Result_Fail;
// Expect call last listener on 2d call
- EXPECT_CALL(*mock_listener1, OnHandshakeDone(key, second_call_value))
+ EXPECT_CALL(*mock_listener1, OnHandshakeDone(kKey, second_call_value))
.
// Emulate false (reject) result
WillOnce(Return(true));
@@ -254,14 +261,14 @@ TEST_F(SecurityManagerTest, Listeners_Notifying) {
security_manager_->AddListener(mock_listener1);
security_manager_->AddListener(mock_listener2);
// 1st call
- security_manager_->NotifyListenersOnHandshakeDone(key, first_call_value);
+ security_manager_->NotifyListenersOnHandshakeDone(kKey, first_call_value);
security_manager_->NotifyOnCertificateUpdateRequired();
// 2nd call
- security_manager_->NotifyListenersOnHandshakeDone(key, second_call_value);
+ security_manager_->NotifyListenersOnHandshakeDone(kKey, second_call_value);
security_manager_->NotifyOnCertificateUpdateRequired();
// 3nd call
security_manager_->NotifyListenersOnHandshakeDone(
- key, SSLContext::Handshake_Result_Fail);
+ kKey, SSLContext::Handshake_Result_Fail);
security_manager_->NotifyOnCertificateUpdateRequired();
}
@@ -275,7 +282,7 @@ TEST_F(SecurityManagerTest, SecurityManager_NULLCryptoManager) {
uint8_t session_id = 0;
TestAsyncWaiter waiter;
- EXPECT_CALL(mock_session_observer, PairFromKey(key, _, _));
+ EXPECT_CALL(mock_session_observer, PairFromKey(kKey, _, _));
EXPECT_CALL(mock_session_observer,
ProtocolVersionUsed(connection_id, session_id, _))
.WillOnce(Return(true));
@@ -283,7 +290,7 @@ TEST_F(SecurityManagerTest, SecurityManager_NULLCryptoManager) {
EXPECT_CALL(mock_protocol_handler,
SendMessageToMobileApp(
InternalErrorWithErrId(SecurityManager::ERROR_NOT_SUPPORTED),
- is_final)).WillOnce(NotifyTestAsyncWaiter(&waiter));
+ kIsFinal)).WillOnce(NotifyTestAsyncWaiter(&waiter));
const SecurityQuery::QueryHeader header(SecurityQuery::REQUEST,
// It could be any query id
SecurityQuery::INVALID_QUERY_ID);
@@ -298,7 +305,7 @@ TEST_F(SecurityManagerTest, SecurityManager_NULLCryptoManager) {
TEST_F(SecurityManagerTest, OnMobileMessageSent) {
const uint8_t* data_param = NULL;
const RawMessagePtr rawMessagePtr(
- utils::MakeShared<RawMessage>(key, protocolVersion, data_param, 0));
+ std::make_shared<RawMessage>(kKey, kProtocolVersion, data_param, 0));
security_manager_->OnMobileMessageSent(rawMessagePtr);
}
/*
@@ -319,7 +326,7 @@ TEST_F(SecurityManagerTest, GetEmptyQuery) {
uint32_t connection_id = 0;
uint8_t session_id = 0;
// uint8_t protocol_version = 0;
- EXPECT_CALL(mock_session_observer, PairFromKey(key, _, _));
+ EXPECT_CALL(mock_session_observer, PairFromKey(kKey, _, _));
EXPECT_CALL(mock_session_observer,
ProtocolVersionUsed(connection_id, session_id, _))
.WillOnce(Return(true));
@@ -328,9 +335,9 @@ TEST_F(SecurityManagerTest, GetEmptyQuery) {
mock_protocol_handler,
SendMessageToMobileApp(
InternalErrorWithErrId(SecurityManager::ERROR_INVALID_QUERY_SIZE),
- is_final));
+ kIsFinal));
// Call with NULL data
- call_OnMessageReceived(NULL, 0, secureServiceType);
+ call_OnMessageReceived(NULL, 0, kSecureServiceType);
}
/*
* Shall send InternallError on null data recieved
@@ -340,7 +347,7 @@ TEST_F(SecurityManagerTest, GetWrongJSONSize) {
uint32_t connection_id = 0;
uint8_t session_id = 0;
// uint8_t protocol_version = 0;
- EXPECT_CALL(mock_session_observer, PairFromKey(key, _, _));
+ EXPECT_CALL(mock_session_observer, PairFromKey(kKey, _, _));
EXPECT_CALL(mock_session_observer,
ProtocolVersionUsed(connection_id, session_id, _))
.WillOnce(Return(true));
@@ -349,7 +356,7 @@ TEST_F(SecurityManagerTest, GetWrongJSONSize) {
mock_protocol_handler,
SendMessageToMobileApp(
InternalErrorWithErrId(SecurityManager::ERROR_INVALID_QUERY_SIZE),
- is_final));
+ kIsFinal));
SecurityQuery::QueryHeader header(SecurityQuery::REQUEST,
SecurityQuery::INVALID_QUERY_ID);
header.json_size = 0x0FFFFFFF;
@@ -365,7 +372,7 @@ TEST_F(SecurityManagerTest, GetInvalidQueryId) {
TestAsyncWaiter waiter;
uint32_t times = 0;
- EXPECT_CALL(mock_session_observer, PairFromKey(key, _, _))
+ EXPECT_CALL(mock_session_observer, PairFromKey(kKey, _, _))
.WillOnce(NotifyTestAsyncWaiter(&waiter));
times++;
EXPECT_CALL(mock_session_observer,
@@ -378,7 +385,7 @@ TEST_F(SecurityManagerTest, GetInvalidQueryId) {
mock_protocol_handler,
SendMessageToMobileApp(
InternalErrorWithErrId(SecurityManager::ERROR_INVALID_QUERY_ID),
- is_final)).WillOnce(NotifyTestAsyncWaiter(&waiter));
+ kIsFinal)).WillOnce(NotifyTestAsyncWaiter(&waiter));
times++;
const SecurityQuery::QueryHeader header(SecurityQuery::REQUEST,
SecurityQuery::INVALID_QUERY_ID);
@@ -395,10 +402,12 @@ TEST_F(SecurityManagerTest, CreateSSLContext_ServiceAlreadyProtected) {
SetMockCryptoManager();
// Return mock SSLContext
- EXPECT_CALL(mock_session_observer, GetSSLContext(key, kControl))
+ EXPECT_CALL(mock_session_observer, GetSSLContext(kKey, kControl))
.WillOnce(Return(&mock_ssl_context_new));
- const SSLContext* result = security_manager_->CreateSSLContext(key);
+ const SSLContext* result = security_manager_->CreateSSLContext(
+ kKey,
+ security_manager::SecurityManager::ContextCreationStrategy::kUseExisting);
EXPECT_EQ(&mock_ssl_context_new, result);
}
/*
@@ -410,21 +419,23 @@ TEST_F(SecurityManagerTest, CreateSSLContext_ErrorCreateSSL) {
uint32_t connection_id = 0;
uint8_t session_id = 0;
// uint8_t protocol_version = 0;
- EXPECT_CALL(mock_session_observer, PairFromKey(key, _, _));
+ EXPECT_CALL(mock_session_observer, PairFromKey(kKey, _, _));
EXPECT_CALL(mock_session_observer,
ProtocolVersionUsed(connection_id, session_id, _))
.WillOnce(Return(true));
EXPECT_CALL(
mock_protocol_handler,
SendMessageToMobileApp(
- InternalErrorWithErrId(SecurityManager::ERROR_INTERNAL), is_final));
+ InternalErrorWithErrId(SecurityManager::ERROR_INTERNAL), kIsFinal));
// Emulate SessionObserver and CryptoManager result
- EXPECT_CALL(mock_session_observer, GetSSLContext(key, kControl))
+ EXPECT_CALL(mock_session_observer, GetSSLContext(kKey, kControl))
.WillOnce(ReturnNull());
EXPECT_CALL(mock_crypto_manager, CreateSSLContext()).WillOnce(ReturnNull());
- const SSLContext* result = security_manager_->CreateSSLContext(key);
+ const SSLContext* result = security_manager_->CreateSSLContext(
+ kKey,
+ security_manager::SecurityManager::ContextCreationStrategy::kUseExisting);
EXPECT_EQ(NULL, result);
}
/*
@@ -437,7 +448,7 @@ TEST_F(SecurityManagerTest, CreateSSLContext_SetSSLContextError) {
uint32_t connection_id = 0;
uint8_t session_id = 0;
// uint8_t protocol_version = 0;
- EXPECT_CALL(mock_session_observer, PairFromKey(key, _, _));
+ EXPECT_CALL(mock_session_observer, PairFromKey(kKey, _, _));
EXPECT_CALL(mock_session_observer,
ProtocolVersionUsed(connection_id, session_id, _))
.WillOnce(Return(true));
@@ -446,18 +457,20 @@ TEST_F(SecurityManagerTest, CreateSSLContext_SetSSLContextError) {
mock_protocol_handler,
SendMessageToMobileApp(
InternalErrorWithErrId(SecurityManager::ERROR_UNKNOWN_INTERNAL_ERROR),
- is_final));
+ kIsFinal));
// Emulate SessionObserver and CryptoManager result
- EXPECT_CALL(mock_session_observer, GetSSLContext(key, kControl))
+ EXPECT_CALL(mock_session_observer, GetSSLContext(kKey, kControl))
.WillOnce(ReturnNull());
EXPECT_CALL(mock_crypto_manager, CreateSSLContext())
.WillOnce(Return(&mock_ssl_context_new));
EXPECT_CALL(mock_crypto_manager, ReleaseSSLContext(&mock_ssl_context_new));
- EXPECT_CALL(mock_session_observer, SetSSLContext(key, &mock_ssl_context_new))
+ EXPECT_CALL(mock_session_observer, SetSSLContext(kKey, &mock_ssl_context_new))
.WillOnce(Return(SecurityManager::ERROR_UNKNOWN_INTERNAL_ERROR));
- const SSLContext* result = security_manager_->CreateSSLContext(key);
+ const SSLContext* result = security_manager_->CreateSSLContext(
+ kKey,
+ security_manager::SecurityManager::ContextCreationStrategy::kUseExisting);
EXPECT_EQ(NULL, result);
}
/*
@@ -469,17 +482,17 @@ TEST_F(SecurityManagerTest, CreateSSLContext_Success) {
// Expect no notifying listeners - it will be done after handshake
// Emulate SessionObserver and CryptoManager result
- EXPECT_CALL(mock_session_observer, GetSSLContext(key, kControl))
- .WillOnce(ReturnNull())
- .
- // additional check for debug code
- WillOnce(Return(&mock_ssl_context_exists));
+ EXPECT_CALL(mock_session_observer, GetSSLContext(kKey, kControl))
+ .WillOnce(Return(&mock_ssl_context_exists));
EXPECT_CALL(mock_crypto_manager, CreateSSLContext())
.WillOnce(Return(&mock_ssl_context_new));
- EXPECT_CALL(mock_session_observer, SetSSLContext(key, &mock_ssl_context_new))
+ EXPECT_CALL(mock_session_observer, SetSSLContext(kKey, &mock_ssl_context_new))
.WillOnce(Return(SecurityManager::ERROR_SUCCESS));
- const SSLContext* result = security_manager_->CreateSSLContext(key);
+ const SSLContext* result = security_manager_->CreateSSLContext(
+ kKey,
+ security_manager::SecurityManager::ContextCreationStrategy::
+ kForceRecreation);
EXPECT_EQ(&mock_ssl_context_new, result);
}
/*
@@ -490,7 +503,7 @@ TEST_F(SecurityManagerTest, StartHandshake_ServiceStillUnprotected) {
uint32_t connection_id = 0;
uint8_t session_id = 0;
// uint8_t protocol_version = 0;
- EXPECT_CALL(mock_session_observer, PairFromKey(key, _, _));
+ EXPECT_CALL(mock_session_observer, PairFromKey(kKey, _, _));
EXPECT_CALL(mock_session_observer,
ProtocolVersionUsed(connection_id, session_id, _))
.WillOnce(Return(true));
@@ -498,17 +511,17 @@ TEST_F(SecurityManagerTest, StartHandshake_ServiceStillUnprotected) {
EXPECT_CALL(
mock_protocol_handler,
SendMessageToMobileApp(
- InternalErrorWithErrId(SecurityManager::ERROR_INTERNAL), is_final));
+ InternalErrorWithErrId(SecurityManager::ERROR_INTERNAL), kIsFinal));
// Expect notifying listeners (unsuccess)
EXPECT_CALL(*mock_sm_listener,
- OnHandshakeDone(key, SSLContext::Handshake_Result_Fail))
+ OnHandshakeDone(kKey, SSLContext::Handshake_Result_Fail))
.WillOnce(Return(true));
// Emulate SessionObserver result
- EXPECT_CALL(mock_session_observer, GetSSLContext(key, kControl))
+ EXPECT_CALL(mock_session_observer, GetSSLContext(kKey, kControl))
.WillOnce(ReturnNull());
- security_manager_->StartHandshake(key);
+ security_manager_->StartHandshake(kKey);
// Listener was destroyed after OnHandshakeDone call
mock_sm_listener.release();
@@ -521,109 +534,27 @@ TEST_F(SecurityManagerTest, StartHandshake_SSLInternalError) {
uint32_t connection_id = 0;
uint8_t session_id = 0;
- // uint8_t protocol_version = 0;
- EXPECT_CALL(mock_session_observer, PairFromKey(key, _, _));
- EXPECT_CALL(mock_session_observer, GetHandshakeContext(key))
- .WillOnce(Return(SSLContext::HandshakeContext()));
+
+ EXPECT_CALL(mock_session_observer, PairFromKey(kKey, _, _));
EXPECT_CALL(mock_session_observer,
ProtocolVersionUsed(connection_id, session_id, _))
.WillOnce(Return(true));
-
+ // Expect notifying listeners (unsuccess)
+ EXPECT_CALL(*mock_sm_listener,
+ OnHandshakeDone(kKey, SSLContext::Handshake_Result_Fail))
+ .WillOnce(Return(true));
+ 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), is_final));
- // Expect notifying listeners (unsuccess)
- EXPECT_CALL(*mock_sm_listener,
- OnHandshakeDone(key, SSLContext::Handshake_Result_Fail))
- .WillOnce(Return(true));
-
- // Emulate SessionObserver result
- EXPECT_CALL(mock_session_observer, GetSSLContext(key, kControl))
- .WillOnce(Return(&mock_ssl_context_exists));
- EXPECT_CALL(mock_ssl_context_exists, IsInitCompleted())
- .WillOnce(Return(false));
- EXPECT_CALL(mock_ssl_context_exists, SetHandshakeContext(_));
- EXPECT_CALL(mock_ssl_context_exists, StartHandshake(_, _))
- .WillOnce(DoAll(SetArgPointee<0>(handshake_data_out_pointer),
- SetArgPointee<1>(handshake_data_out_size),
- Return(SSLContext::Handshake_Result_Fail)));
-
- security_manager_->StartHandshake(key);
+ InternalErrorWithErrId(SecurityManager::ERROR_INTERNAL), kIsFinal));
- // Listener was destroyed after OnHandshakeDone call
+ security_manager_->StartHandshake(kKey);
mock_sm_listener.release();
}
-/*
- * Shall send data on call StartHandshake
- */
-TEST_F(SecurityManagerTest, StartHandshake_SSLInitIsNotComplete) {
- SetMockCryptoManager();
- uint32_t connection_id = 0;
- uint8_t session_id = 0;
- // uint8_t protocol_version = 0;
- EXPECT_CALL(mock_session_observer, PairFromKey(key, _, _));
- EXPECT_CALL(mock_session_observer, GetHandshakeContext(key))
- .Times(3)
- .WillRepeatedly(Return(SSLContext::HandshakeContext()));
- EXPECT_CALL(mock_session_observer,
- ProtocolVersionUsed(connection_id, session_id, _))
- .WillOnce(Return(true));
-
- // Expect send one message (with correct pointer and size data)
- EXPECT_CALL(mock_protocol_handler, SendMessageToMobileApp(_, is_final));
-
- // Return mock SSLContext
- EXPECT_CALL(mock_session_observer, GetSSLContext(key, kControl))
- .Times(3)
- .WillRepeatedly(Return(&mock_ssl_context_exists));
- // Expect initialization check on each call StartHandshake
- EXPECT_CALL(mock_ssl_context_exists, IsInitCompleted())
- .Times(3)
- .WillRepeatedly(Return(false));
- EXPECT_CALL(mock_ssl_context_exists, SetHandshakeContext(_)).Times(3);
-
- // Emulate SSLContext::StartHandshake with different parameters
- // Only on both correct - data and size shall be send message to mobile app
- EXPECT_CALL(mock_ssl_context_exists, StartHandshake(_, _))
- .WillOnce(DoAll(SetArgPointee<0>(handshake_data_out_pointer),
- SetArgPointee<1>(0),
- Return(SSLContext::Handshake_Result_Success)))
- .WillOnce(DoAll(SetArgPointee<0>((uint8_t*)NULL),
- SetArgPointee<1>(handshake_data_out_size),
- Return(SSLContext::Handshake_Result_Success)))
- .WillOnce(DoAll(SetArgPointee<0>(handshake_data_out_pointer),
- SetArgPointee<1>(handshake_data_out_size),
- Return(SSLContext::Handshake_Result_Success)));
-
- security_manager_->StartHandshake(key);
- security_manager_->StartHandshake(key);
- security_manager_->StartHandshake(key);
-}
-/*
- * Shall notify listeners on call StartHandshake after SSLContext initialization
- * complete
- */
-TEST_F(SecurityManagerTest, StartHandshake_SSLInitIsComplete) {
- SetMockCryptoManager();
- // Expect no message send
- // Expect notifying listeners (success)
- EXPECT_CALL(*mock_sm_listener,
- OnHandshakeDone(key, SSLContext::Handshake_Result_Success))
- .WillOnce(Return(true));
-
- // Emulate SessionObserver result
- EXPECT_CALL(mock_session_observer, GetSSLContext(key, kControl))
- .WillOnce(Return(&mock_ssl_context_exists));
- EXPECT_CALL(mock_ssl_context_exists, IsInitCompleted())
- .WillOnce(Return(true));
-
- security_manager_->StartHandshake(key);
- // Listener was destroyed after OnHandshakeDone call
- mock_sm_listener.release();
-}
/*
* Shall send InternallError on
* getting SEND_HANDSHAKE_DATA with NULL data
@@ -634,7 +565,7 @@ TEST_F(SecurityManagerTest, ProccessHandshakeData_WrongDataSize) {
uint8_t session_id = 0;
TestAsyncWaiter waiter;
- EXPECT_CALL(mock_session_observer, PairFromKey(key, _, _));
+ EXPECT_CALL(mock_session_observer, PairFromKey(kKey, _, _));
EXPECT_CALL(mock_session_observer,
ProtocolVersionUsed(connection_id, session_id, _))
.WillOnce(Return(true));
@@ -644,7 +575,7 @@ TEST_F(SecurityManagerTest, ProccessHandshakeData_WrongDataSize) {
mock_protocol_handler,
SendMessageToMobileApp(
InternalErrorWithErrId(SecurityManager::ERROR_INVALID_QUERY_SIZE),
- is_final)).WillOnce(NotifyTestAsyncWaiter(&waiter));
+ kIsFinal)).WillOnce(NotifyTestAsyncWaiter(&waiter));
EmulateMobileMessageHandshake(NULL, 0);
@@ -664,7 +595,7 @@ TEST_F(SecurityManagerTest,
TestAsyncWaiter waiter;
uint32_t times = 0;
- EXPECT_CALL(mock_session_observer, PairFromKey(key, _, _))
+ EXPECT_CALL(mock_session_observer, PairFromKey(kKey, _, _))
.WillOnce(NotifyTestAsyncWaiter(&waiter));
times++;
EXPECT_CALL(mock_session_observer,
@@ -675,17 +606,17 @@ TEST_F(SecurityManagerTest,
mock_protocol_handler,
SendMessageToMobileApp(
InternalErrorWithErrId(SecurityManager::ERROR_SERVICE_NOT_PROTECTED),
- is_final)).WillOnce(NotifyTestAsyncWaiter(&waiter));
+ kIsFinal)).WillOnce(NotifyTestAsyncWaiter(&waiter));
times++;
// Expect notifying listeners (unsuccess)
EXPECT_CALL(*mock_sm_listener,
- OnHandshakeDone(key, SSLContext::Handshake_Result_Fail))
+ OnHandshakeDone(kKey, SSLContext::Handshake_Result_Fail))
.WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(true)));
times++;
// Emulate SessionObserver result
- EXPECT_CALL(mock_session_observer, GetSSLContext(key, kControl))
+ EXPECT_CALL(mock_session_observer, GetSSLContext(kKey, kControl))
.WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), ReturnNull()));
times++;
@@ -713,7 +644,7 @@ TEST_F(SecurityManagerTest, ProccessHandshakeData_InvalidData) {
TestAsyncWaiter waiter;
uint32_t times = 0;
- EXPECT_CALL(mock_session_observer, PairFromKey(key, _, _))
+ EXPECT_CALL(mock_session_observer, PairFromKey(kKey, _, _))
.Times(handshake_emulates)
.WillRepeatedly(NotifyTestAsyncWaiter(&waiter));
times += handshake_emulates;
@@ -728,18 +659,18 @@ TEST_F(SecurityManagerTest, ProccessHandshakeData_InvalidData) {
mock_protocol_handler,
SendMessageToMobileApp(
InternalErrorWithErrId(SecurityManager::ERROR_SSL_INVALID_DATA),
- is_final))
+ kIsFinal))
.Times(handshake_emulates)
.WillRepeatedly(NotifyTestAsyncWaiter(&waiter));
times += handshake_emulates;
// Expect notifying listeners (unsuccess)
EXPECT_CALL(*mock_sm_listener,
- OnHandshakeDone(key, SSLContext::Handshake_Result_Fail))
+ OnHandshakeDone(kKey, SSLContext::Handshake_Result_Fail))
.WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(true)));
times++;
// Emulate SessionObserver and CryptoManager result
- EXPECT_CALL(mock_session_observer, GetSSLContext(key, kControl))
+ EXPECT_CALL(mock_session_observer, GetSSLContext(kKey, kControl))
.Times(handshake_emulates)
.WillRepeatedly(Return(&mock_ssl_context_exists));
@@ -794,7 +725,7 @@ TEST_F(SecurityManagerTest, ProccessHandshakeData_Answer) {
TestAsyncWaiter waiter;
uint32_t times = 0;
- EXPECT_CALL(mock_session_observer, PairFromKey(key, _, _))
+ EXPECT_CALL(mock_session_observer, PairFromKey(kKey, _, _))
.Times(handshake_emulates)
.WillRepeatedly(NotifyTestAsyncWaiter(&waiter));
times += handshake_emulates;
@@ -808,14 +739,14 @@ TEST_F(SecurityManagerTest, ProccessHandshakeData_Answer) {
const size_t raw_message_size = 15;
EXPECT_CALL(
mock_protocol_handler,
- SendMessageToMobileApp(RawMessageEqSize(raw_message_size), is_final))
+ SendMessageToMobileApp(RawMessageEqSize(raw_message_size), kIsFinal))
.Times(handshake_emulates)
.WillRepeatedly(NotifyTestAsyncWaiter(&waiter));
times += handshake_emulates;
// Expect notifying listeners (unsuccess)
EXPECT_CALL(*mock_sm_listener,
- OnHandshakeDone(key, SSLContext::Handshake_Result_Fail))
+ OnHandshakeDone(kKey, SSLContext::Handshake_Result_Fail))
.WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(true)));
times++;
@@ -824,7 +755,7 @@ TEST_F(SecurityManagerTest, ProccessHandshakeData_Answer) {
.Times(handshake_emulates)
.WillRepeatedly(DoAll(NotifyTestAsyncWaiter(&waiter), Return(false)));
times += handshake_emulates;
- EXPECT_CALL(mock_session_observer, GetSSLContext(key, kControl))
+ EXPECT_CALL(mock_session_observer, GetSSLContext(kKey, kControl))
.Times(handshake_emulates)
.WillRepeatedly(DoAll(NotifyTestAsyncWaiter(&waiter),
Return(&mock_ssl_context_exists)));
@@ -870,12 +801,12 @@ TEST_F(SecurityManagerTest, ProccessHandshakeData_HandshakeFinished) {
// Expect no errors
// Expect notifying listeners (success)
EXPECT_CALL(*mock_sm_listener,
- OnHandshakeDone(key, SSLContext::Handshake_Result_Success))
+ OnHandshakeDone(kKey, SSLContext::Handshake_Result_Success))
.WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(true)));
times++;
// Emulate SessionObserver and CryptoManager result
- EXPECT_CALL(mock_session_observer, GetSSLContext(key, kControl))
+ EXPECT_CALL(mock_session_observer, GetSSLContext(kKey, kControl))
.Times(handshake_emulates)
.WillRepeatedly(DoAll(NotifyTestAsyncWaiter(&waiter),
Return(&mock_ssl_context_exists)));
@@ -928,14 +859,14 @@ TEST_F(SecurityManagerTest, ProccessHandshakeData_HandshakeFinished) {
uint32_t connection_id = 0;
uint8_t session_id = 0;
// uint8_t protocol_version = 0;
- EXPECT_CALL(mock_session_observer, PairFromKey(key, _, _)).Times(2);
+ EXPECT_CALL(mock_session_observer, PairFromKey(kKey, _, _)).Times(2);
EXPECT_CALL(mock_session_observer,
ProtocolVersionUsed(connection_id, session_id, _))
.Times(2)
.WillRepeatedly(DoAll(NotifyTestAsyncWaiter(&waiter), Return(true)));
times += 2; // matches to the number above
- EXPECT_CALL(mock_protocol_handler, SendMessageToMobileApp(_, is_final))
+ EXPECT_CALL(mock_protocol_handler, SendMessageToMobileApp(_, kIsFinal))
.Times(2)
.WillRepeatedly(NotifyTestAsyncWaiter(&waiter));
times += 2; // matches to the number above