From: Bartlomiej Grzelewski Date: Fri, 3 Feb 2017 15:48:45 +0000 (+0100) Subject: Add support for Application Defined Privileges X-Git-Tag: security-manager_5.5_testing~15^2~7^2~17 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=06349217a5fe79e2913546f8f3940c3029d0450d;p=platform%2Fcore%2Ftest%2Fsecurity-tests.git Add support for Application Defined Privileges Change-Id: I51122a50ac1b6f0c169659c07fcc9da02bd3ef36 --- diff --git a/src/security-manager-tests/common/app_install_helper.cpp b/src/security-manager-tests/common/app_install_helper.cpp index 0436241..cd352f6 100644 --- a/src/security-manager-tests/common/app_install_helper.cpp +++ b/src/security-manager-tests/common/app_install_helper.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2016 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2014-2017 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -153,6 +153,14 @@ std::vector AppInstallHelper::getPrivileges() const { return m_privileges; } +void AppInstallHelper::addAppDefinedPrivilege(const std::string &privilege) { + m_appDefinedPrivileges.push_back(privilege); +} + +std::vector AppInstallHelper::getAppDefinedPrivileges() const { + return m_appDefinedPrivileges; +} + void AppInstallHelper::revokeRules() const { RUNNER_ASSERT_MSG( 0 == smack_revoke_subject(generateAppLabel().c_str()), diff --git a/src/security-manager-tests/common/app_install_helper.h b/src/security-manager-tests/common/app_install_helper.h index 883dd0e..c4d083e 100644 --- a/src/security-manager-tests/common/app_install_helper.h +++ b/src/security-manager-tests/common/app_install_helper.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2016 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2014-2017 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -110,6 +110,9 @@ struct AppInstallHelper { void addPrivileges(const std::vector &privileges); std::vector getPrivileges() const; + void addAppDefinedPrivilege(const std::string &privilege); + std::vector getAppDefinedPrivileges() const; + // Smack std::string generateAppLabel() const; std::string generatePkgLabel() const; @@ -134,6 +137,7 @@ protected: TypePathsMap m_dirTypeMap; TypePathsMap m_fileTypeMap; std::vector m_privileges; + std::vector m_appDefinedPrivileges; std::string m_author; pid_t m_creatorPid; diff --git a/src/security-manager-tests/common/scoped_installer.h b/src/security-manager-tests/common/scoped_installer.h index 639aa11..6ec37c2 100644 --- a/src/security-manager-tests/common/scoped_installer.h +++ b/src/security-manager-tests/common/scoped_installer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -60,9 +60,11 @@ public: for (const auto& typePaths : app.getFilesMap()) for (const auto& path : typePaths.second) instReq.addPath(path, typePaths.first); - for (const auto &priv : app.getPrivileges()) { + for (const auto &priv : app.getPrivileges()) instReq.addPrivilege(priv.c_str()); - } + for (const auto &priv : app.getAppDefinedPrivileges()) + instReq.addAppDefinedPrivilege(priv); + SecurityManagerTest::Api::install(instReq); } diff --git a/src/security-manager-tests/common/sm_request.cpp b/src/security-manager-tests/common/sm_request.cpp index 2bba17c..5f5f5a2 100644 --- a/src/security-manager-tests/common/sm_request.cpp +++ b/src/security-manager-tests/common/sm_request.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2016 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2014-2017 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -95,6 +95,17 @@ void InstallRequest::addPrivilege(const std::string &privilege, lib_retcode expe m_privileges.push_back(privilege); } +void InstallRequest::addAppDefinedPrivilege(const std::string &privilege, lib_retcode expectedResult) +{ + int result = security_manager_app_inst_req_add_app_defined_privilege(m_req, privilege.c_str()); + RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult, + "adding app defined privilege returned wrong value." + << " Privilege: " << privilege << ";" + << " Result: " << result << ";" + << " Expected result: " << expectedResult); + m_appDefinedPrivileges.push_back(privilege); +} + void InstallRequest::addPath(std::string path, app_install_path_type pathType, lib_retcode expectedResult) { int result = security_manager_app_inst_req_add_path(m_req, path.c_str(), pathType); @@ -162,6 +173,13 @@ std::ostream& operator<<(std::ostream &os, const InstallRequest &request) } os << " ]"; } + if (!request.m_appDefinedPrivileges.empty()) { + os << "app defined privileges: [ " << request.m_appDefinedPrivileges[0]; + for (size_t i = 1; i < request.m_appDefinedPrivileges.size(); ++i) + os << "; " << request.m_appDefinedPrivileges[i]; + os << " ]"; + } + if (!request.m_paths.empty()) { os << "paths: [ " << "< " << request.m_paths[0].first << "; " << request.m_paths[0].second << " >"; diff --git a/src/security-manager-tests/common/sm_request.h b/src/security-manager-tests/common/sm_request.h index ee72521..abdbb42 100644 --- a/src/security-manager-tests/common/sm_request.h +++ b/src/security-manager-tests/common/sm_request.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2016 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2014-2017 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -59,6 +59,7 @@ public: void setAppId(std::string appId, lib_retcode expectedresult = SECURITY_MANAGER_SUCCESS); void setPkgId(std::string pkgId, lib_retcode expectedresult = SECURITY_MANAGER_SUCCESS); void addPrivilege(const std::string &privilege, lib_retcode expectedresult = SECURITY_MANAGER_SUCCESS); + void addAppDefinedPrivilege(const std::string &privilege, lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS); void addPath(std::string path, app_install_path_type pathType, lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS); void setUid(const uid_t uid, lib_retcode expectedresult = SECURITY_MANAGER_SUCCESS); @@ -78,6 +79,7 @@ private: std::string m_pkgId; std::string m_authorId; std::vector m_privileges; + std::vector m_appDefinedPrivileges; std::vector > m_paths; std::pair m_uid; };