Update tests to work with group names instead of gids 55/29255/10
authorKrzysztof Sasiak <k.sasiak@samsung.com>
Thu, 23 Oct 2014 11:53:58 +0000 (13:53 +0200)
committerKrzysztof Sasiak <k.sasiak@samsung.com>
Thu, 13 Nov 2014 14:30:23 +0000 (15:30 +0100)
Change-Id: Ia6ac604ca4d5369a486772d1f9f39fd57e1c3ecd

tests/security-manager-tests/common/sm_db.cpp
tests/security-manager-tests/common/sm_db.h
tests/security-manager-tests/security_manager_tests.cpp

index d4498e6..2f420bf 100644 (file)
@@ -178,8 +178,8 @@ bool TestSecurityManagerDatabase::check_privilege(const std::string &app_name,
     return result.rows.size() == 1;
 }
 
-void TestSecurityManagerDatabase::setup_privilege_gids(const std::string &privilege,
-                                                       const std::vector<gid_t> &gids)
+void TestSecurityManagerDatabase::setup_privilege_groups(const std::string &privilege,
+                                                         const std::vector<std::string> &groups)
 {
     Sqlite3DBaseSelectResult result;
     std::ostringstream sql;
@@ -190,12 +190,12 @@ void TestSecurityManagerDatabase::setup_privilege_gids(const std::string &privil
     sql << "INSERT OR IGNORE INTO privilege (name) VALUES ('" << privilege << "')";
     m_base.execute(sql.str(), result);
 
-    for (const auto &gid : gids) {
+    for (const auto &group : groups) {
         sql.clear();
         sql.str("");
-        sql << "INSERT OR IGNORE INTO privilege_gid (privilege_id, gid) "
+        sql << "INSERT OR IGNORE INTO privilege_group (privilege_id, name) "
                "VALUES ((SELECT privilege_id FROM privilege WHERE name = '"
-                << privilege << "')," << (int) gid << ")";
+                << privilege << "'), '" << group << "')";
         m_base.execute(sql.str(), result);
     }
 }
index e73558c..25ca91a 100644 (file)
@@ -133,9 +133,10 @@ public:
  * @brief Method for setting privilege to groups mapping in security-manager database
  *
  * @param privilege name of the privilege
- * @param gids vector of group ids
+ * @param groups vector of group names
  */
-    void setup_privilege_gids(const std::string &privilege, const std::vector<gid_t> &gids);
+    void setup_privilege_groups(const std::string &privilege,
+                                const std::vector<std::string> &groups);
 
 private:
 /**
index d40e34e..afe4c18 100644 (file)
@@ -47,7 +47,7 @@ static const privileges_t SM_DENIED_PRIVILEGES  = {
 static const privileges_t SM_NO_PRIVILEGES  = {
 };
 
-static const std::vector<gid_t> SM_ALLOWED_GIDS = {6001, 6002};
+static const std::vector<std::string> SM_ALLOWED_GROUPS = {"db_browser", "db_alarm"};
 
 static const char *const SM_PRIVATE_PATH = "/etc/smack/test_DIR/app_dir";
 static const char *const SM_PUBLIC_PATH = "/etc/smack/test_DIR/app_dir_public";
@@ -234,7 +234,7 @@ static void check_app_gids(const char *const app_id, const std::vector<gid_t> &a
 static void check_app_after_install(const char *const app_id, const char *const pkg_id,
                                     const privileges_t &allowed_privs,
                                     const privileges_t &denied_privs,
-                                    const std::vector<gid_t> &allowed_gids)
+                                    const std::vector<std::string> &allowed_groups)
 {
     TestSecurityManagerDatabase dbtest;
     dbtest.test_db_after__app_install(app_id, pkg_id, allowed_privs);
@@ -246,7 +246,16 @@ static void check_app_after_install(const char *const app_id, const char *const
     /* Setup mapping of gids to privileges */
     /* Do this for each privilege for extra check */
     for (const auto &privilege : allowed_privs) {
-        dbtest.setup_privilege_gids(privilege, allowed_gids);
+        dbtest.setup_privilege_groups(privilege, allowed_groups);
+    }
+
+    std::vector<gid_t> allowed_gids;
+
+    for (const auto &groupName : allowed_groups) {
+        errno = 0;
+        struct group* grp = getgrnam(groupName.c_str());
+        RUNNER_ASSERT_ERRNO_MSG(grp, "Group: " << groupName << " not found");
+        allowed_gids.push_back(grp->gr_gid);
     }
 
     check_app_gids(app_id, allowed_gids);
@@ -409,7 +418,7 @@ RUNNER_TEST(security_manager_02_app_install_uninstall_full)
 
     /* Check records in the security-manager database */
     check_app_after_install(SM_APP_ID2, SM_PKG_ID2,
-                            SM_ALLOWED_PRIVILEGES, SM_DENIED_PRIVILEGES, SM_ALLOWED_GIDS);
+                            SM_ALLOWED_PRIVILEGES, SM_DENIED_PRIVILEGES, SM_ALLOWED_GROUPS);
 
     /* TODO: add parameters to this function */
     check_app_path_after_install();