SM : extended installation helpers to support hybrid flag 70/93070/8
authorTomasz Swierczek <t.swierczek@samsung.com>
Mon, 17 Oct 2016 08:10:48 +0000 (10:10 +0200)
committerTomasz Swierczek <t.swierczek@samsung.com>
Thu, 3 Nov 2016 07:48:01 +0000 (08:48 +0100)
ScopedInstaller class and AppInstallHelper class needed relevant support to fully
configure temporary application installation. Cynara admin class extended with
support to retrieve policy types from descriptions.

Change-Id: Ic0808cd911f97151338d515f37b8995abba561c6

src/cynara-tests/common/cynara_test_admin.cpp
src/cynara-tests/common/cynara_test_admin.h
src/security-manager-tests/common/app_install_helper.cpp
src/security-manager-tests/common/app_install_helper.h
src/security-manager-tests/common/scoped_installer.h

index b066e83e82a262a05d286b93325913d61b9998a2..4ff300c39841e02f5f54b81c389a756beeb0bbe0 100644 (file)
@@ -442,4 +442,33 @@ void Admin::listPoliciesDescriptions(CynaraTestPlugins::Descriptions &expectedDe
                          "doesn't match expected. " << dump());
 }
 
+void Admin::getPolicyTypeForDescription(const std::string &description,
+                                        int &policyType, int expectedResult)
+{
+    auto descr_deleter = [](cynara_admin_policy_descr** descr) {
+            if (descr != nullptr)
+                for (int i = 0; descr[i] != nullptr; i++) {
+                    free(descr[i]->name);
+                    free(descr[i]);
+                }
+            free(descr);
+         };
+    struct cynara_admin_policy_descr **descriptions = nullptr;
+    int ret = cynara_admin_list_policies_descriptions(m_admin, &descriptions);
+    std::unique_ptr<cynara_admin_policy_descr*, decltype(descr_deleter)>
+        descrPtr(descriptions, descr_deleter);
+    RUNNER_ASSERT_MSG(ret == expectedResult,
+        "cynara_admin_list_policies_descriptions returned wrong value: " <<
+        ret << " != " << expectedResult);
+    ret = 0;
+    for (int i = 0; descriptions[i] != nullptr; i++) {
+        if (descriptions[i]->name == description) {
+            policyType = descriptions[i]->result;
+            ret = 1;
+        }
+    }
+    if (!ret)
+        RUNNER_FAIL_MSG("Policy type for description " << description << " not found: ");
+}
+
 } // namespace CynaraTestAdmin
index 7920d4dbdf9d794dd7c0d29994a5fc6a64404191..b4f7ffd896b4b0121bf42b082ba0c8d6ae3ff546 100644 (file)
@@ -23,6 +23,7 @@
 #include <cynara-admin.h>
 #include <ostream>
 #include <vector>
+#include <string>
 
 namespace CynaraTestAdmin {
 
@@ -88,6 +89,8 @@ public:
                        int expectedResult = CYNARA_API_SUCCESS);
     void listPoliciesDescriptions(CynaraTestPlugins::Descriptions &expectedDescriptions,
                                   int expectedResult = CYNARA_API_SUCCESS);
+    void getPolicyTypeForDescription(const std::string &description, int &policyType,
+                                     int expectedResult = CYNARA_API_SUCCESS);
 private:
     struct cynara_admin *m_admin;
     bool m_online;
index 90d8ab3059f697f94a27bf084fb80e0d18410ac5..e2436e397a04cb5e6d8a077815d8cc2b388555a5 100644 (file)
@@ -114,6 +114,10 @@ void AppInstallHelper::createPrivateRODir() {
         m_dirTypeMap[SECURITY_MANAGER_PATH_RO].emplace_back(getPrivateRODir());
 }
 
+bool AppInstallHelper::getIsHybrid() const {
+    return m_isHybrid;
+}
+
 void AppInstallHelper::addPrivilege(const std::string &privilege) {
     m_privileges.push_back(privilege);
 }
@@ -133,7 +137,7 @@ void AppInstallHelper::revokeRules() const {
 }
 
 std::string AppInstallHelper::generateAppLabel() const {
-    return generateProcessLabel(getAppId(), getPkgId());
+    return generateProcessLabel(getAppId(), getPkgId(), getIsHybrid());
 }
 
 std::string AppInstallHelper::generatePkgLabel() const {
index 776486b85b3b4456c7e93d77bfc44444336d13a0..08d8126769fe72b67314cb62bb3628708f806662 100644 (file)
@@ -30,27 +30,34 @@ const std::string TIZEN_VERSION = "3.0";
 struct AppInstallHelper {
 
     using TypePathsMap = std::map<app_install_path_type, std::vector<std::string>>;
-    AppInstallHelper(const std::string &appName,
-                     const std::string &pkgName,
+    AppInstallHelper(const std::string &appNamePrefix,
+                     const std::string &pkgNamePrefix,
                      bool isLocal,
                      uid_t uid,
-                     std::string version)
-      : m_appName(appName), m_pkgName(pkgName), m_isLocal(isLocal), m_uidGid(uid), m_version(version),
-        m_installType(SM_APP_INSTALL_NONE)
+                     std::string version,
+                     bool isHybrid = false)
+      : m_appName(appNamePrefix), m_pkgName(pkgNamePrefix), m_isLocal(isLocal), m_uidGid(uid), m_version(version),
+        m_installType(SM_APP_INSTALL_NONE), m_isHybrid(isHybrid)
     {
         setInstallPath();
     }
 
-    AppInstallHelper(const std::string &name)
-      : AppInstallHelper(name, name, false, geteuid(), TIZEN_VERSION)
+    AppInstallHelper(const std::string &appNamePrefix,
+                     const std::string &pkgNamePrefix,
+                     uid_t uid)
+      : AppInstallHelper(appNamePrefix, pkgNamePrefix, false, uid, TIZEN_VERSION)
     {}
 
-    AppInstallHelper(const std::string &appName, const std::string &pkgName)
-      : AppInstallHelper(appName, pkgName, false, geteuid(), TIZEN_VERSION)
+    AppInstallHelper(const std::string &namePrefix)
+      : AppInstallHelper(namePrefix, namePrefix, false, geteuid(), TIZEN_VERSION)
     {}
 
-    AppInstallHelper(const std::string &appName, uid_t uid)
-      : AppInstallHelper(appName, appName, true, uid, TIZEN_VERSION)
+    AppInstallHelper(const std::string &appNamePrefix, const std::string &pkgNamePrefix)
+      : AppInstallHelper(appNamePrefix, pkgNamePrefix, false, geteuid(), TIZEN_VERSION)
+    {}
+
+    AppInstallHelper(const std::string &namePrefix, uid_t uid)
+      : AppInstallHelper(namePrefix, namePrefix, true, uid, TIZEN_VERSION)
     {}
 
     // App info getters and setters
@@ -63,6 +70,7 @@ struct AppInstallHelper {
     std::string getAuthor() const;
     void setInstallType(app_install_type type);
     app_install_type getInstallType();
+    bool getIsHybrid() const;
 
     // Path types creation and removal on file system
     void createInstallDir();
@@ -94,7 +102,6 @@ struct AppInstallHelper {
     std::string generateAppLabel() const;
     std::string generatePkgLabel() const;
     void revokeRules() const;
-
     virtual ~AppInstallHelper() {
         removePaths();
     }
@@ -108,7 +115,7 @@ protected:
     int m_uidGid;
     std::string m_version;
     app_install_type m_installType;
-
+    bool m_isHybrid;
     std::string m_installDir;
     TypePathsMap m_dirTypeMap;
     TypePathsMap m_fileTypeMap;
index 26f05d4aee28890cc2a7cdb0ab3aa0f82e436595..27b96ee30b2abb2694c604252a5362cb4bd42965 100644 (file)
@@ -39,6 +39,9 @@ public:
         : m_appInstallHelper(appInstallHelper), m_shouldUninstall(true)
     {
         SecurityManagerTest::InstallRequest instReq;
+
+        if (m_appInstallHelper.getIsHybrid())
+            instReq.setHybrid();
         instReq.setAppId(m_appInstallHelper.getAppId());
         instReq.setPkgId(m_appInstallHelper.getPkgId());
         if (m_appInstallHelper.getInstallType() != SM_APP_INSTALL_NONE)