diff options
author | AKalinich-Luxoft <AKalinich@luxoft.com> | 2017-12-26 18:25:27 +0200 |
---|---|---|
committer | AKalinich-Luxoft <AKalinich@luxoft.com> | 2018-01-29 09:06:29 +0200 |
commit | 4ce09f81793c0a2df3826e412831a1ddd0a5ce54 (patch) | |
tree | eb2ed409473b5fc9ece82118b7016e5b2484c0eb | |
parent | 45f6356cc4194a88f5de88e6df88241efcd7c9f3 (diff) | |
download | sdl_core-4ce09f81793c0a2df3826e412831a1ddd0a5ce54.tar.gz |
Minor refactoring in protocol and security manager
Added consts for some methods.
Fixed typos in description.
Renamed some non informative variables names.
18 files changed, 50 insertions, 37 deletions
diff --git a/src/components/application_manager/include/application_manager/application_manager_impl.h b/src/components/application_manager/include/application_manager/application_manager_impl.h index 01503a7794..22ae032a00 100644 --- a/src/components/application_manager/include/application_manager/application_manager_impl.h +++ b/src/components/application_manager/include/application_manager/application_manager_impl.h @@ -923,7 +923,7 @@ class ApplicationManagerImpl #ifdef ENABLE_SECURITY /** * @brief Notification about protection result - * @param connection_key Unique key of session which triggrs handshake + * @param connection_key Unique key of session which triggers handshake * @param result result of connection protection * @return true on success notification handling or false otherwise */ @@ -941,7 +941,7 @@ class ApplicationManagerImpl * @param reference to string where to save certificate data * @return true if listener saved some data to string otherwise false */ - bool GetPolicyCertificateData(std::string& data) OVERRIDE; + bool GetPolicyCertificateData(std::string& data) const OVERRIDE; /** * @brief Get unique handshake context by application id @@ -957,7 +957,7 @@ class ApplicationManagerImpl * @param app_id id of application to check * @return true if application is navi otherwise returns false */ - bool CheckAppIsNavi(const uint32_t app_id) OVERRIDE; + bool CheckAppIsNavi(const uint32_t app_id) const OVERRIDE; #endif // ENABLE_SECURITY /** diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index da11a4ac5b..96e8a1314b 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -1655,7 +1655,7 @@ void ApplicationManagerImpl::OnCertificateUpdateRequired() { GetPolicyHandler().OnPTExchangeNeeded(); } -bool ApplicationManagerImpl::GetPolicyCertificateData(std::string& data) { +bool ApplicationManagerImpl::GetPolicyCertificateData(std::string& data) const { LOG4CXX_AUTO_TRACE(logger_); data = GetPolicyHandler().RetrieveCertificate(); return true; @@ -1673,7 +1673,7 @@ ApplicationManagerImpl::GetHandshakeContext(uint32_t key) const { return SSLContext::HandshakeContext(); } -bool ApplicationManagerImpl::CheckAppIsNavi(const uint32_t app_id) { +bool ApplicationManagerImpl::CheckAppIsNavi(const uint32_t app_id) const { LOG4CXX_AUTO_TRACE(logger_); ApplicationSharedPtr app = application(app_id); if (app) { diff --git a/src/components/connection_handler/include/connection_handler/connection.h b/src/components/connection_handler/include/connection_handler/connection.h index aef1c92f1e..b0f9586046 100644 --- a/src/components/connection_handler/include/connection_handler/connection.h +++ b/src/components/connection_handler/include/connection_handler/connection.h @@ -218,9 +218,9 @@ class Connection { * @param service_type type of service to check * @return true if session contains service with specified service type */ - bool IsSessionServiceExists( + bool SessionServiceExists( const uint8_t session_id, - const protocol_handler::ServiceType& service_type); + const protocol_handler::ServiceType& service_type) const; #endif // ENABLE_SECURITY /** diff --git a/src/components/connection_handler/include/connection_handler/connection_handler_impl.h b/src/components/connection_handler/include/connection_handler/connection_handler_impl.h index 3d5c5900f2..44d9d213bc 100644 --- a/src/components/connection_handler/include/connection_handler/connection_handler_impl.h +++ b/src/components/connection_handler/include/connection_handler/connection_handler_impl.h @@ -356,9 +356,9 @@ class ConnectionHandlerImpl * @param service_type type of service to check * @return true if session contains service with specified service type */ - bool IsSessionServiceExists( + bool SessionServiceExists( const uint32_t connection_key, - const protocol_handler::ServiceType& service_type) OVERRIDE; + const protocol_handler::ServiceType& service_type) const OVERRIDE; security_manager::SSLContext::HandshakeContext GetHandshakeContext( uint32_t key) const OVERRIDE; diff --git a/src/components/connection_handler/src/connection.cc b/src/components/connection_handler/src/connection.cc index 2c8b781b13..d494611643 100644 --- a/src/components/connection_handler/src/connection.cc +++ b/src/components/connection_handler/src/connection.cc @@ -314,19 +314,19 @@ void Connection::SetProtectionFlag( } } -bool Connection::IsSessionServiceExists( +bool Connection::SessionServiceExists( const uint8_t session_id, - const protocol_handler::ServiceType& service_type) { + const protocol_handler::ServiceType& service_type) const { LOG4CXX_AUTO_TRACE(logger_); sync_primitives::AutoLock lock(session_map_lock_); - SessionMap::iterator session_it = session_map_.find(session_id); + SessionMap::const_iterator session_it = session_map_.find(session_id); if (session_it == session_map_.end()) { LOG4CXX_WARN(logger_, "Session not found in this connection!"); return false; } - Session& session = session_it->second; + const Session& session = session_it->second; return session.FindService(service_type); } diff --git a/src/components/connection_handler/src/connection_handler_impl.cc b/src/components/connection_handler/src/connection_handler_impl.cc index 53d2449ede..ac8bad2205 100644 --- a/src/components/connection_handler/src/connection_handler_impl.cc +++ b/src/components/connection_handler/src/connection_handler_impl.cc @@ -436,7 +436,7 @@ void ConnectionHandlerImpl::OnSessionStartedCallback( Connection* connection = it->second; context.is_new_service_ = - !connection->IsSessionServiceExists(session_id, service_type); + !connection->SessionServiceExists(session_id, service_type); if ((0 == session_id) && (protocol_handler::kRpc == service_type)) { context.new_session_id_ = connection->AddNewSession(); @@ -875,22 +875,22 @@ void ConnectionHandlerImpl::SetProtectionFlag( connection.SetProtectionFlag(session_id, service_type); } -bool ConnectionHandlerImpl::IsSessionServiceExists( +bool ConnectionHandlerImpl::SessionServiceExists( const uint32_t connection_key, - const protocol_handler::ServiceType& service_type) { + const protocol_handler::ServiceType& service_type) const { LOG4CXX_AUTO_TRACE(logger_); transport_manager::ConnectionUID connection_handle = 0; uint8_t session_id = 0; PairFromKey(connection_key, &connection_handle, &session_id); sync_primitives::AutoReadLock lock(connection_list_lock_); - ConnectionList::iterator it = connection_list_.find(connection_handle); + ConnectionList::const_iterator it = connection_list_.find(connection_handle); if (connection_list_.end() == it) { LOG4CXX_ERROR(logger_, "Unknown connection!"); return false; } - Connection& connection = *it->second; - return connection.IsSessionServiceExists(session_id, service_type); + const Connection& connection = *it->second; + return connection.SessionServiceExists(session_id, service_type); } security_manager::SSLContext::HandshakeContext diff --git a/src/components/include/connection_handler/connection_handler_observer.h b/src/components/include/connection_handler/connection_handler_observer.h index f2f885d1f4..1bd919f30e 100644 --- a/src/components/include/connection_handler/connection_handler_observer.h +++ b/src/components/include/connection_handler/connection_handler_observer.h @@ -155,7 +155,7 @@ class ConnectionHandlerObserver { * @param app_id id of application to check * @return true if application is navi otherwise returns false */ - virtual bool CheckAppIsNavi(const uint32_t app_id) = 0; + virtual bool CheckAppIsNavi(const uint32_t app_id) const = 0; #endif // ENABLE_SECURITY protected: /** diff --git a/src/components/include/protocol_handler/session_observer.h b/src/components/include/protocol_handler/session_observer.h index 6b16ba1c0f..3a68059b6f 100644 --- a/src/components/include/protocol_handler/session_observer.h +++ b/src/components/include/protocol_handler/session_observer.h @@ -333,9 +333,9 @@ class SessionObserver { * @param service_type type of service to check * @return true if session contains service with specified service type */ - virtual bool IsSessionServiceExists( + virtual bool SessionServiceExists( const uint32_t connection_key, - const protocol_handler::ServiceType& service_type) = 0; + const protocol_handler::ServiceType& service_type) const = 0; virtual security_manager::SSLContext::HandshakeContext GetHandshakeContext( uint32_t key) const = 0; diff --git a/src/components/include/security_manager/security_manager.h b/src/components/include/security_manager/security_manager.h index a95c31432e..8f772f6a13 100644 --- a/src/components/include/security_manager/security_manager.h +++ b/src/components/include/security_manager/security_manager.h @@ -137,7 +137,7 @@ class SecurityManager : public protocol_handler::ProtocolObserver { * @brief Notify all listeners that certificate update required * Allows to notify that certificate should be updated */ - virtual void NotifyOnCertififcateUpdateRequired() = 0; + virtual void NotifyOnCertificateUpdateRequired() = 0; /** * @brief Check if policy certificate data is empty diff --git a/src/components/include/security_manager/security_manager_listener.h b/src/components/include/security_manager/security_manager_listener.h index 37b3a09f91..aeb3334a56 100644 --- a/src/components/include/security_manager/security_manager_listener.h +++ b/src/components/include/security_manager/security_manager_listener.h @@ -57,7 +57,7 @@ class SecurityManagerListener { * @param reference to string where to save certificate data * @return true if listener saved some data to string otherwise false */ - virtual bool GetPolicyCertificateData(std::string& data) = 0; + virtual bool GetPolicyCertificateData(std::string& data) const = 0; virtual ~SecurityManagerListener() {} }; diff --git a/src/components/include/test/connection_handler/mock_connection_handler_observer.h b/src/components/include/test/connection_handler/mock_connection_handler_observer.h index bb5ad7cad0..f1c605eaca 100644 --- a/src/components/include/test/connection_handler/mock_connection_handler_observer.h +++ b/src/components/include/test/connection_handler/mock_connection_handler_observer.h @@ -71,6 +71,7 @@ class MockConnectionHandlerObserver void(const connection_handler::Device& device_from, const connection_handler::Device& device_to)); MOCK_METHOD1(OnDeviceSwitchingFinish, void(const std::string& device_uid)); + MOCK_CONST_METHOD1(CheckAppIsNavi, bool(const uint32_t app_id)); }; } // namespace connection_handler_test diff --git a/src/components/include/test/protocol_handler/mock_session_observer.h b/src/components/include/test/protocol_handler/mock_session_observer.h index 350704ae86..3d54b97fad 100644 --- a/src/components/include/test/protocol_handler/mock_session_observer.h +++ b/src/components/include/test/protocol_handler/mock_session_observer.h @@ -126,6 +126,9 @@ class MockSessionObserver : public ::protocol_handler::SessionObserver { MOCK_METHOD2(SetProtectionFlag, void(const uint32_t& key, const protocol_handler::ServiceType& service_type)); + MOCK_CONST_METHOD2(SessionServiceExists, + bool(const uint32_t connection_key, + const protocol_handler::ServiceType& service_type)); MOCK_CONST_METHOD1( GetHandshakeContext, security_manager::SSLContext::HandshakeContext(uint32_t key)); diff --git a/src/components/include/test/security_manager/mock_security_manager.h b/src/components/include/test/security_manager/mock_security_manager.h index e3d95cd94f..11890cb071 100644 --- a/src/components/include/test/security_manager/mock_security_manager.h +++ b/src/components/include/test/security_manager/mock_security_manager.h @@ -65,6 +65,9 @@ class MockSecurityManager : public ::security_manager::SecurityManager { void(const ::protocol_handler::RawMessagePtr)); MOCK_METHOD1(OnMobileMessageSent, void(const ::protocol_handler::RawMessagePtr)); + MOCK_METHOD0(IsCertificateUpdateRequired, bool()); + MOCK_METHOD0(NotifyOnCertificateUpdateRequired, void()); + MOCK_METHOD0(IsPolicyCertificateDataEmpty, bool()); }; /* diff --git a/src/components/include/test/security_manager/mock_security_manager_listener.h b/src/components/include/test/security_manager/mock_security_manager_listener.h index 9e5dd03698..a06762a09d 100644 --- a/src/components/include/test/security_manager/mock_security_manager_listener.h +++ b/src/components/include/test/security_manager/mock_security_manager_listener.h @@ -48,6 +48,7 @@ class MockSecurityManagerListener bool(uint32_t connection_key, ::security_manager::SSLContext::HandshakeResult result)); MOCK_METHOD0(OnCertificateUpdateRequired, void()); + MOCK_CONST_METHOD1(GetPolicyCertificateData, bool(std::string& data)); }; } // namespace security_manager_test } // namespace components diff --git a/src/components/protocol_handler/include/protocol_handler/handshake_handler.h b/src/components/protocol_handler/include/protocol_handler/handshake_handler.h index 12e617f2a4..0ef40290f2 100644 --- a/src/components/protocol_handler/include/protocol_handler/handshake_handler.h +++ b/src/components/protocol_handler/include/protocol_handler/handshake_handler.h @@ -45,7 +45,7 @@ namespace protocol_handler { class ProtocolHandlerImpl; /** - * \brief HandshakeHandler class for handling SSL handshake and sending + * @brief HandshakeHandler class for handling SSL handshake and sending * Ack/Nack on its success or fail */ class HandshakeHandler : public security_manager::SecurityManagerListener { @@ -77,13 +77,13 @@ class HandshakeHandler : public security_manager::SecurityManagerListener { * @param reference to string where to save certificate data * @return true if listener saved some data to string otherwise false */ - bool GetPolicyCertificateData(std::string& data) OVERRIDE; + bool GetPolicyCertificateData(std::string& data) const OVERRIDE; /** - * \brief Notification about protection result - * \param connection_key Unique key of session which triggrs handshake - * \param result result of connection protection - * \return true on success notification handling or false otherwise + * @brief Notification about protection result + * @param connection_key Unique key of session which triggrs handshake + * @param result result of connection protection + * @return true on success notification handling or false otherwise */ bool OnHandshakeDone( uint32_t connection_key, diff --git a/src/components/protocol_handler/src/handshake_handler.cc b/src/components/protocol_handler/src/handshake_handler.cc index e9c7734189..055ff2cf45 100644 --- a/src/components/protocol_handler/src/handshake_handler.cc +++ b/src/components/protocol_handler/src/handshake_handler.cc @@ -78,7 +78,7 @@ HandshakeHandler::HandshakeHandler( , payload_(payload) {} HandshakeHandler::~HandshakeHandler() { - LOG4CXX_DEBUG(logger_, "Destroying StartSessionHandler: " << this); + LOG4CXX_DEBUG(logger_, "Destroying of HandshakeHandler: " << this); } uint32_t HandshakeHandler::connection_key() const { @@ -86,7 +86,7 @@ uint32_t HandshakeHandler::connection_key() const { context_.new_session_id_); } -bool HandshakeHandler::GetPolicyCertificateData(std::string& data) { +bool HandshakeHandler::GetPolicyCertificateData(std::string& data) const { return false; } @@ -98,7 +98,12 @@ bool HandshakeHandler::OnHandshakeDone( LOG4CXX_AUTO_TRACE(logger_); if (connection_key != this->connection_key()) { - LOG4CXX_DEBUG(logger_, "Notification not for handler " << this); + LOG4CXX_DEBUG(logger_, + "Listener " << this + << " expects notification for connection id: " + << this->connection_key() + << ". Received notification for connection id " + << connection_key << " will be ignored"); return false; } diff --git a/src/components/protocol_handler/src/protocol_handler_impl.cc b/src/components/protocol_handler/src/protocol_handler_impl.cc index c4a2253108..e7ff8d2f2d 100644 --- a/src/components/protocol_handler/src/protocol_handler_impl.cc +++ b/src/components/protocol_handler/src/protocol_handler_impl.cc @@ -1582,7 +1582,7 @@ void ProtocolHandlerImpl::NotifySessionStarted( ptu_pending_handlers_.push_back(handler); is_ptu_triggered_ = true; - security_manager_->NotifyOnCertififcateUpdateRequired(); + security_manager_->NotifyOnCertificateUpdateRequired(); } else { LOG4CXX_DEBUG(logger_, "PTU has been triggered. Added to pending."); ptu_pending_handlers_.push_back(handler); diff --git a/src/components/security_manager/test/security_manager_test.cc b/src/components/security_manager/test/security_manager_test.cc index 1178efbc0d..c8af0aa022 100644 --- a/src/components/security_manager/test/security_manager_test.cc +++ b/src/components/security_manager/test/security_manager_test.cc @@ -250,14 +250,14 @@ TEST_F(SecurityManagerTest, Listeners_Notifying) { security_manager_->AddListener(&mock_listener2); // 1st call security_manager_->NotifyListenersOnHandshakeDone(key, first_call_value); - security_manager_->NotifyOnCertififcateUpdateRequired(); + security_manager_->NotifyOnCertificateUpdateRequired(); // 2nd call security_manager_->NotifyListenersOnHandshakeDone(key, second_call_value); - security_manager_->NotifyOnCertififcateUpdateRequired(); + security_manager_->NotifyOnCertificateUpdateRequired(); // 3nd call security_manager_->NotifyListenersOnHandshakeDone( key, SSLContext::Handshake_Result_Fail); - security_manager_->NotifyOnCertififcateUpdateRequired(); + security_manager_->NotifyOnCertificateUpdateRequired(); } /* |