security-manager: don't check app privileges in security-manager.db 14/77814/1
authorRafal Krypa <r.krypa@samsung.com>
Fri, 1 Jul 2016 07:32:43 +0000 (09:32 +0200)
committerRafal Krypa <r.krypa@samsung.com>
Fri, 1 Jul 2016 07:32:43 +0000 (09:32 +0200)
Security-manager changes to not store application privilege information
in it's own database. The only backend for this information will now
be Cynara.
Adapt tests to not expect privilege information in security-manager
database.

Change-Id: I821ed24cc3dc0e3e69e30ade84bd4f7a5ec42527
Signed-off-by: Rafal Krypa <r.krypa@samsung.com>
src/security-manager-tests/common/sm_db.cpp
src/security-manager-tests/common/sm_db.h
src/security-manager-tests/security_manager_tests.cpp

index c7d3d000061b7fb2109f8f86905f657a858d3b8a..cc7d791a06fc9aba3252806efb9669756a89b22b 100644 (file)
@@ -40,15 +40,6 @@ TestSecurityManagerDatabase::TestSecurityManagerDatabase() : m_base(PRIVILEGE_DB
 
 void TestSecurityManagerDatabase::test_db_after__app_install(const std::string &app_name,
                                                              const std::string &pkg_name)
-{
-    const privileges_t dummy; /* just some empty privileges set */
-
-    test_db_after__app_install(app_name, pkg_name, dummy);
-}
-
-void TestSecurityManagerDatabase::test_db_after__app_install(const std::string &app_name,
-                                                             const std::string &pkg_name,
-                                                             const privileges_t &privileges)
 {
     if (!m_base.is_open())
         m_base.open();
@@ -57,24 +48,10 @@ void TestSecurityManagerDatabase::test_db_after__app_install(const std::string &
     RUNNER_ASSERT_MSG(!pkg_name.empty(), "Request is corrupted, pkgId is empty");
 
     check_app_and_pkg(app_name, pkg_name, NOT_REMOVED);
-
-    if (!privileges.empty()) {
-        check_privileges(app_name, pkg_name, privileges);
-    }
-}
-
-void TestSecurityManagerDatabase::test_db_after__app_uninstall(const std::string &app_name,
-                                                               const std::string &pkg_name,
-                                                               const bool is_pkg_removed)
-{
-    const privileges_t dummy; /* just some empty privileges set */
-
-    test_db_after__app_uninstall(app_name, pkg_name, dummy, is_pkg_removed);
 }
 
 void TestSecurityManagerDatabase::test_db_after__app_uninstall(const std::string &app_name,
                                                                const std::string &pkg_name,
-                                                               const privileges_t &privileges,
                                                                const bool is_pkg_removed)
 {
     if (!m_base.is_open())
@@ -85,44 +62,6 @@ void TestSecurityManagerDatabase::test_db_after__app_uninstall(const std::string
 
     check_app_and_pkg(app_name, pkg_name, REMOVED);
     check_pkg(pkg_name, is_pkg_removed);
-
-    if (!privileges.empty()) {
-        check_privileges_removed(app_name, pkg_name, privileges);
-    }
-}
-
-void TestSecurityManagerDatabase::check_privileges(const std::string &app_name,
-                                                   const std::string &pkg_name,
-                                                   const privileges_t &privileges)
-{
-    bool result;
-
-    RUNNER_ASSERT_MSG(!app_name.empty(), "Request is corrupted, appId is empty");
-    RUNNER_ASSERT_MSG(!pkg_name.empty(), "Request is corrupted, pkgId is empty");
-
-    for (auto it = privileges.begin(); it != privileges.end(); ++it) {
-        result = check_privilege(app_name, pkg_name, *it);
-
-        RUNNER_ASSERT_MSG(result == true, "privilege: <" << *it << "> not added to app: <" <<
-                             app_name << ">  from pkg_id: <" << pkg_name << ">");
-    }
-}
-
-void TestSecurityManagerDatabase::check_privileges_removed(const std::string &app_name,
-                                                           const std::string &pkg_name,
-                                                           const privileges_t &privileges)
-{
-    bool result;
-
-    RUNNER_ASSERT_MSG(!app_name.empty(), "Request is corrupted, appId is empty");
-    RUNNER_ASSERT_MSG(!pkg_name.empty(), "Request is corrupted, pkgId is empty");
-
-    for (auto it = privileges.begin(); it != privileges.end(); ++it) {
-        result = check_privilege(app_name, pkg_name, *it);
-
-        RUNNER_ASSERT_MSG(result == false, "privilege: <" << *it << "> not removed for app: <" <<
-                             app_name << ">  from pkg_id: <" << pkg_name << ">");
-    }
 }
 
 void TestSecurityManagerDatabase::check_app_and_pkg(const std::string &app_name, const std::string &pkg_name,
@@ -158,26 +97,6 @@ void TestSecurityManagerDatabase::check_pkg(const std::string &pkg_name,
                          expected_rows << "] rows");
 }
 
-bool TestSecurityManagerDatabase::check_privilege(const std::string &app_name,
-                                                  const std::string &pkg_name,
-                                                  const std::string &privilege)
-{
-    Sqlite3DBaseSelectResult result;
-    std::ostringstream sql;
-    sql << "SELECT privilege_id FROM app_privilege_view"
-           "  WHERE app_name == '" << app_name << "' "
-           "    AND pkg_name == '" << pkg_name << "' "
-           "    AND privilege_name == '" << privilege << "' "
-           ";";
-    m_base.execute(sql.str(), result);
-
-    /* only 0 or 1 resulting rows are alowed */
-    RUNNER_ASSERT_MSG(result.rows.size() == 0 || result.rows.size() == 1, "query : <" << sql.str() << "> returned [" <<
-                         result.rows.size() << "] rows");
-
-    return result.rows.size() == 1;
-}
-
 void TestSecurityManagerDatabase::setup_privilege_groups(const std::string &privilege,
                                                          const std::vector<std::string> &groups)
 {
@@ -190,7 +109,7 @@ void TestSecurityManagerDatabase::setup_privilege_groups(const std::string &priv
     for (const auto &group : groups) {
         sql.clear();
         sql.str("");
-        sql << "INSERT INTO privilege_group_view (privilege_name, group_name) "
+        sql << "INSERT OR IGNORE INTO privilege_group (privilege_name, group_name) "
                "VALUES ("
                 << "'" << privilege << "'" << ","
                 << "'" << group << "'" << ")";
index 5628c3123b7544be95ab34782edc28ced61c8bfa..1536a57b5cfc6e8ac5e7b611f70130110845a576 100644 (file)
@@ -65,21 +65,6 @@ public:
  */
     void test_db_after__app_install(const std::string &app_name, const std::string &pkg_name);
 
-/**
- * @brief Method for testing database after "security_manager_app_install" was run.
- *
- * It checks existence of proper: - app_name
- *                                - pkg_name
- *                                - privileges
- * TODO: appPaths are currently not handled directly by security-manager, so they are not tested.
- *
- * @param  app_name           name of the app previously used in security_manager_app_install.
- * @param  pkg_name           name of the pkg previously used in security_manager_app_install.
- * @param  privileges         vector of privileges previously used in security_manager_app_install.
- */
-    void test_db_after__app_install(const std::string &app_name, const std::string &pkg_name,
-                                    const privileges_t &privileges);
-
 /**
  * @brief Method for testing database after "security_manager_app_uninstall" was run.
  *
@@ -93,42 +78,6 @@ public:
     void test_db_after__app_uninstall(const std::string &app_name, const std::string &pkg_name,
                                       const bool is_pkg_removed);
 
-/**
- * @brief Method for testing database after "security_manager_app_uninstall" was run.
- *
- * It checks absence of proper: - app_name
- *                              - optionally pkg_name
- *                              - app privileges
- * TODO: appPaths are currently not handled directly by security-manager, so they are not tested.
- *
- * @param  app_name           name of the app previously used in security_manager_app_uninstall.
- * @param  pkg_name           name of the pkg previously used in security_manager_app_uninstall.
- * @param  privileges         vector of privileges previously used in security_manager_app_uninstall.
- * @param  is_pkg_removed     tells if pkg_id is expected to remain in db or not.
- */
-    void test_db_after__app_uninstall(const std::string &app_name, const std::string &pkg_name,
-                                      const privileges_t &privileges, const bool is_pkg_removed);
-
-/**
- * @brief It checks db for existence of a all privileges from install request.
- *
- * @param  app_name           name of the app previously used i.e. in security_manager_app_install.
- * @param  pkg_name           name of the pkg previously used i.e. in security_manager_app_install.
- * @param  privileges         vector of privileges previously used i.e. in security_manager_app_install.
- */
-    void check_privileges(const std::string &app_name, const std::string &pkg_name,
-                          const privileges_t &privileges);
-
-/**
- * @brief It checks in db if all app privileges from install request are removed.
- *
- * @param  app_name           name of the app previously used i.e. in security_manager_app_uninstall.
- * @param  pkg_name           name of the pkg previously used i.e. in security_manager_app_uninstall.
- * @param  privileges         vector of privileges previously used i.e. in security_manager_app_uninstall.
- */
-    void check_privileges_removed(const std::string &app_name, const std::string &pkg_name,
-                                  const privileges_t &privileges);
-
 /**
  * @brief Method for setting privilege to groups mapping in security-manager database
  *
@@ -174,19 +123,6 @@ private:
  */
     void check_pkg(const std::string &pkg_name,
                    const bool is_pkg_removed);
-
-/**
- * @brief Check db for existence of a single privilege.
- *
- * @param  app_name        name of application
- * @param  pkg_name        application's package name
- * @param  privilege       name of the privilege
- *
- * @return true            when privilege present
- *         false           when privilege not present
- */
-    bool check_privilege(const std::string &app_name, const std::string &pkg_name,
-                         const std::string &privilege);
 };
 
 #endif /* SECURITY_MANAGER_TEST_DB_H_ */
index 59a6e7ce0b1be370e6abaf44628c0e6406827d38..a10bcf6ee0e034c3f0d1f7632ac7bd26a83b31e5 100644 (file)
@@ -423,8 +423,7 @@ static void check_app_after_install(const char *const app_id, const char *const
                                     const std::vector<std::string> &allowed_groups)
 {
     TestSecurityManagerDatabase dbtest;
-    dbtest.test_db_after__app_install(app_id, pkg_id, allowed_privs);
-    dbtest.check_privileges_removed(app_id, pkg_id, denied_privs);
+    dbtest.test_db_after__app_install(app_id, pkg_id);
 
     /*Privileges should be granted to all users if root installs app*/
     check_app_permissions(app_id, pkg_id, ANY_USER_REPRESENTATION, allowed_privs, denied_privs);
@@ -457,7 +456,7 @@ static void check_app_after_uninstall(const char *const app_id, const char *cons
                                       const privileges_t &privileges, const bool is_pkg_removed)
 {
     TestSecurityManagerDatabase dbtest;
-    dbtest.test_db_after__app_uninstall(app_id, pkg_id, privileges, is_pkg_removed);
+    dbtest.test_db_after__app_uninstall(app_id, pkg_id, is_pkg_removed);
 
 
     /*Privileges should not be granted anymore to any user*/