Remove SM privilege mapping tests 88/58888/2
authorRafal Krypa <r.krypa@samsung.com>
Thu, 4 Feb 2016 11:48:42 +0000 (12:48 +0100)
committerBartlomiej Grzelewski <b.grzelewski@samsung.com>
Wed, 10 Feb 2016 09:43:39 +0000 (01:43 -0800)
Functionality removed from security-manager, now provided by privilege-checker
(which is out of our project scope).

Change-Id: Ica93ab99f2617c97f538e60965a5098d5614acdf

src/security-manager-tests/common/sm_api.cpp
src/security-manager-tests/common/sm_api.h
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 604b1714437cfc95c0636c0fefa4da2854c68a17..697dca9c6eb21c2dcb3259e7bf3c46a62d3a4899 100644 (file)
 
 #include <dpl/test/test_runner.h>
 
-#include <memory>
-
 namespace SecurityManagerTest {
 
 namespace Api {
 
-void free_cstring_list(char **p, size_t count) {
-    for (size_t i = 0; i < count; i++) {
-        free(p[i]);
-    }
-    delete [] p;
-}
-
 void install(const InstallRequest &request, lib_retcode expectedResult)
 {
     int result = security_manager_app_install(request.get());
@@ -200,45 +191,6 @@ void getPolicyForAdmin(const PolicyEntry &filter, std::vector<PolicyEntry> &poli
     getConfiguredPolicy(filter, policyEntries, expectedResult, true);
 }
 
-void getPrivilegesMappings(const char *version_from,
-                           const char *version_to,
-                           const std::vector<std::string> &privileges,
-                           std::vector<std::string> &mappings,
-                           lib_retcode expectedResult)
-{
-    char **mappings_buff = nullptr;
-    size_t mappings_count;
-
-    size_t i = 0;
-
-    std::unique_ptr<char *, std::function<void(char**)>> privileges_buff(new char*[privileges.size()],
-                                                        std::bind(free_cstring_list, std::placeholders::_1, std::ref(i)));
-
-    for (; i < privileges.size(); i++) {
-        if (privileges[i].empty())
-            privileges_buff.get()[i] = nullptr;
-        else
-            privileges_buff.get()[i] = strdup(privileges[i].c_str());
-        RUNNER_ASSERT_MSG(privileges_buff.get()[i], "Couldn't copy string");
-    }
-
-    int result;
-    if (privileges.empty())
-        result = security_manager_get_privileges_mapping(version_from, version_to, nullptr,
-                                                         privileges.size(), &mappings_buff, &mappings_count);
-    else
-        result = security_manager_get_privileges_mapping(version_from, version_to, privileges_buff.get(),
-                                                         privileges.size(), &mappings_buff, &mappings_count);
-    RUNNER_ASSERT_MSG(static_cast<lib_retcode>(result) == expectedResult,
-                      "Unexpected result in security_manager_get_privileges_mapping()" << std::endl
-                      << "For version_from: " << version_from << " version_to: " << version_to << " for set of privileges" << std::endl
-                      << " Result: " << result << " Expected: " << expectedResult);
-    for (size_t i = 0; i < mappings_count; i++) {
-        mappings.push_back(mappings_buff[i]);
-    }
-    security_manager_privilege_mapping_free(mappings_buff, mappings_count);
-}
-
 } // namespace Api
 
 } // namespace SecurityManagerTest
index 2a3711ba94185bbed895b33639cf36267a868b5e..06897b78b5eb129ed9f7ba10c2711494607b9ea1 100644 (file)
@@ -41,11 +41,6 @@ void sendPolicy(const PolicyRequest &request, lib_retcode expectedResult = SECUR
 void getPolicy(const PolicyEntry &filter, std::vector<PolicyEntry> &policyEntries, lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS);
 void getPolicyForSelf(const PolicyEntry &filter, std::vector<PolicyEntry> &policyEntries, lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS);
 void getPolicyForAdmin(const PolicyEntry &filter, std::vector<PolicyEntry> &policyEntries, lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS);
-void getPrivilegesMappings(const char *version_from,
-                           const char *version_to,
-                           const std::vector<std::string> &privileges,
-                           std::vector<std::string> &mappings,
-                           lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS);
 void applySharing(const SharingRequest &req, lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS);
 void dropSharing(const SharingRequest &req, lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS);
 } // namespace Api
index d09703dc54511912a2562081b3d8c123689cb87f..c7d3d000061b7fb2109f8f86905f657a858d3b8a 100644 (file)
@@ -198,50 +198,6 @@ void TestSecurityManagerDatabase::setup_privilege_groups(const std::string &priv
     }
 }
 
-void TestSecurityManagerDatabase::setup_privilege_mapping(const std::string &version_from,
-                                                          const std::string &version_to,
-                                                          const std::string &privilege,
-                                                          const std::string &mapping)
-{
-    Sqlite3DBaseSelectResult result;
-    std::ostringstream sql;
-
-    if (!m_base.is_open())
-        m_base.open();
-
-    sql.clear();
-    sql.str("");
-    sql << "INSERT INTO privilege_mapping_view (version_from_name, version_to_name, privilege_name, privilege_mapping_name) "
-           "VALUES ("
-            << "'" << version_from << "'" << ","
-            << "'" << version_to << "'" << ","
-            << "'" << privilege << "'" << ","
-            << "'" << mapping << "'" << ")";
-    m_base.execute(sql.str(), result);
-}
-
-void TestSecurityManagerDatabase::setup_default_version_privilege(const std::string &version_from,
-                                                                  const std::string &version_to,
-                                                                  const std::string &privilege)
-{
-    Sqlite3DBaseSelectResult result;
-    std::ostringstream sql;
-
-    if (!m_base.is_open())
-        m_base.open();
-
-        sql.clear();
-        sql.str("");
-        sql << "INSERT INTO privilege_mapping_view (version_from_name, version_to_name, privilege_name, privilege_mapping_name) "
-               "VALUES ("
-                << "'" << version_from << "'" << ","
-                << "'" << version_to << "'" << ","
-                << "NULL,"
-                << "'" << privilege << "'" << ")";
-        m_base.execute(sql.str(), result);
-
-}
-
 int64_t TestSecurityManagerDatabase::get_author_id(const std::string &authorName)
 {
     Sqlite3DBaseSelectResult result;
index 454996efad9b690232eabccd59946390ef9f0898..5628c3123b7544be95ab34782edc28ced61c8bfa 100644 (file)
@@ -138,34 +138,6 @@ public:
     void setup_privilege_groups(const std::string &privilege,
                                 const std::vector<std::string> &groups);
 
-/**
- * @brief Method for setting privilege to privilege mappings from one version to another
- *        in security-manager database
- *
- * @param version_from version which mapping is from
- * @param version_to version which mapping is to
- * @param privilege privilege for which mapping is set
- * @param mappings mapping of given privielege
- *
- */
-    void setup_privilege_mapping(const std::string &version_from,
-                                 const std::string &version_to,
-                                 const std::string &privilege,
-                                 const std::string &mapping);
-/**
- * @brief Method for setting privilege to privilege mappings from one version to another
- *        in security-manager database
- *
- * @param version_from version which mapping is from
- * @param version_to version which mapping is to
- * @param privilege privilege for which mapping is set
- * @param mappings default privilege
- *
- */
-    void setup_default_version_privilege(const std::string &version_from,
-                                         const std::string &version_to,
-                                         const std::string &privilege);
-
 /**
  * @brief Method for getting author id from database.
  */
index 1fa100ebda7d515ec290d6f2b8fe8a72a5dfc395..b89c43020661db28f63d9767968c82243d232714 100644 (file)
@@ -153,26 +153,6 @@ static const std::vector<privileges_t> MANY_APPS_PRIVILEGES = {
     }
 };
 
-/* PRIVILEGE MAPPING TEST CONSTS */
-
-static const std::string OLD_VERSION = "2.4";
-static const std::string NEW_VERSION = "3.0";
-
-static const std::vector<std::string> OLD_PRIVILEGES = {
-        "http://tizen.org/privilege/internet.old",
-        "http://tizen.org/privilege/telephony.old",
-        "http://tizen.org/privilege/contact.old",
-        "http://tizen.org/privilege/led.old",
-        "http://tizen.org/privilege/email.old"
-};
-
-static const std::vector<privileges_t> &NEW_PRIVILEGES = MANY_APPS_PRIVILEGES;
-
-static const privileges_t DEFAULT_PRIVILEGES = {
-        "http://tizen.org/privilege/led",
-        "http://tizen.org/privilege/internet"
-};
-
 static std::string generateAppLabel(const std::string &appId)
 {
     return "User::App::" + appId;
@@ -2449,135 +2429,6 @@ RUNNER_MULTIPROCESS_TEST(security_manager_21_security_manager_admin_deny_user_pr
     }
 }
 
-void saveMappingsToDb(const std::string &version_from, const std::string &version_to,
-                      const privileges_t &privileges, const std::vector<privileges_t> &mappings) {
-    TestSecurityManagerDatabase db;
-    RUNNER_ASSERT_MSG(privileges.size() == mappings.size(), "Wrong given privileges and mappings size");
-    auto privIt = privileges.begin();
-    auto mappIt = mappings.begin();
-    for (; privIt != privileges.end() && mappIt != mappings.end(); privIt++, mappIt++) {
-        for (const auto &mapping : *mappIt) {
-            db.setup_privilege_mapping(version_from, version_to, *privIt, mapping);
-        }
-    }
-}
-
-void saveDefaultMappingsToDb(const std::string &version_from, const std::string &version_to,
-                             const privileges_t &privileges) {
-    TestSecurityManagerDatabase db;
-    for (auto &privilege : privileges) {
-        db.setup_default_version_privilege(version_from, version_to, privilege);
-    }
-}
-
-void concatUnique(privileges_t &to, const privileges_t &from) {
-    to.reserve(to.size() + from.size());
-    for (auto &new_priv : from) {
-        if (std::find(to.begin(), to.end(), new_priv) == to.end())
-            to.push_back(new_priv);
-    }
-}
-
-RUNNER_TEST(security_manager_22_get_privilege_mappings)
-{
-    saveMappingsToDb(OLD_VERSION, NEW_VERSION, OLD_PRIVILEGES, NEW_PRIVILEGES);
-    saveDefaultMappingsToDb(OLD_VERSION, NEW_VERSION, DEFAULT_PRIVILEGES);
-    privileges_t retrievedMapping;
-    std::string current;
-    auto expectedIt = NEW_PRIVILEGES.begin();
-    for (const auto &privilege : OLD_PRIVILEGES) {
-        retrievedMapping.clear();
-        std::vector<std::string> privilegeToMap = {privilege};
-        Api::getPrivilegesMappings(OLD_VERSION.c_str(), NEW_VERSION.c_str(),
-                                   privilegeToMap, retrievedMapping);
-        std::vector<std::string> expectedPrivileges = *expectedIt;
-        concatUnique(expectedPrivileges, DEFAULT_PRIVILEGES);
-        RUNNER_ASSERT_MSG(retrievedMapping.size() == expectedPrivileges.size(),
-                          "Wrong count of mappings returned for " << privilege << "."
-                          " Got " << retrievedMapping.size()
-                          << " expected " << expectedPrivileges.size());
-        RUNNER_ASSERT_MSG(std::is_permutation(retrievedMapping.begin(), retrievedMapping.end(), expectedPrivileges.begin()),
-                          "Wrong mapping returned for " << privilege);
-        ++expectedIt;
-    }
-}
-
-RUNNER_TEST(security_manager_23_get_privileges_mappings)
-{
-    saveMappingsToDb(OLD_VERSION, NEW_VERSION, OLD_PRIVILEGES, NEW_PRIVILEGES);
-    saveDefaultMappingsToDb(OLD_VERSION, NEW_VERSION, DEFAULT_PRIVILEGES);
-
-    std::vector<std::string> retrievedMapping;
-    std::vector<std::string> expectedPrivileges = DEFAULT_PRIVILEGES;
-    for(auto &expected : NEW_PRIVILEGES) {
-        concatUnique(expectedPrivileges, expected);
-    }
-    const std::vector<std::string> &privilegesToMap = OLD_PRIVILEGES;
-
-    Api::getPrivilegesMappings(OLD_VERSION.c_str(), NEW_VERSION.c_str(), privilegesToMap, retrievedMapping);
-    RUNNER_ASSERT_MSG(retrievedMapping.size() == expectedPrivileges.size(),
-                      "Wrong count of mappings returned. Got " << retrievedMapping.size()
-                      << " expected " << expectedPrivileges.size());
-    RUNNER_ASSERT_MSG(std::is_permutation(retrievedMapping.begin(), retrievedMapping.end(), expectedPrivileges.begin()),
-                      "Wrong mapping returned for privileges set");
-}
-
-RUNNER_TEST(security_manager_24_get_privileges_mappings_default_version)
-{
-    saveMappingsToDb(OLD_VERSION, NEW_VERSION, OLD_PRIVILEGES, NEW_PRIVILEGES);
-    saveDefaultMappingsToDb(OLD_VERSION, NEW_VERSION, DEFAULT_PRIVILEGES);
-
-    std::vector<std::string> retrievedMapping;
-    std::vector<std::string> expectedPrivileges = DEFAULT_PRIVILEGES;
-    for(auto &expected : NEW_PRIVILEGES) {
-        concatUnique(expectedPrivileges, expected);
-    }
-    const std::vector<std::string> &privilegesToMap = OLD_PRIVILEGES;
-
-    Api::getPrivilegesMappings(OLD_VERSION.c_str(), nullptr, privilegesToMap, retrievedMapping);
-    RUNNER_ASSERT_MSG(retrievedMapping.size() == expectedPrivileges.size(),
-                      "Wrong count of mappings returned. Got " << retrievedMapping.size()
-                      << " expected " << expectedPrivileges.size());
-    RUNNER_ASSERT_MSG(std::is_permutation(retrievedMapping.begin(), retrievedMapping.end(), expectedPrivileges.begin()),
-                      "Wrong mapping returned for privileges set");
-}
-
-RUNNER_TEST(security_manager_25_get_default_mappings)
-{
-    saveDefaultMappingsToDb(OLD_VERSION, NEW_VERSION, DEFAULT_PRIVILEGES);
-
-    std::vector<std::string> retrievedMapping;
-    std::vector<std::string> expectedPrivileges = DEFAULT_PRIVILEGES;
-
-    // Empty privilege to map vector will indicate nullptr privilege array in security-manager API
-    std::vector<std::string> privilegeToMap;
-
-    Api::getPrivilegesMappings(OLD_VERSION.c_str(), NEW_VERSION.c_str(), privilegeToMap, retrievedMapping);
-    RUNNER_ASSERT_MSG(retrievedMapping.size() == expectedPrivileges.size(),
-                      "Wrong count of mappings returned. Got " << retrievedMapping.size()
-                      << " expected " << expectedPrivileges.size());
-    RUNNER_ASSERT_MSG(std::is_permutation(retrievedMapping.begin(), retrievedMapping.end(), expectedPrivileges.begin()),
-                      "Wrong default mapping returned");
-}
-
-RUNNER_TEST(security_manager_26_get_default_mappings_default_version)
-{
-    saveDefaultMappingsToDb(OLD_VERSION, NEW_VERSION, DEFAULT_PRIVILEGES);
-
-    std::vector<std::string> retrievedMapping;
-    std::vector<std::string> expectedPrivileges = DEFAULT_PRIVILEGES;
-
-    // Empty privilege to map vector will indicate nullptr privilege array in security-manager API
-    std::vector<std::string> privilegeToMap;
-
-    Api::getPrivilegesMappings(OLD_VERSION.c_str(), nullptr, privilegeToMap, retrievedMapping);
-    RUNNER_ASSERT_MSG(retrievedMapping.size() == expectedPrivileges.size(),
-                      "Wrong count of mappings returned. Got " << retrievedMapping.size()
-                      << " expected " << expectedPrivileges.size());
-    RUNNER_ASSERT_MSG(std::is_permutation(retrievedMapping.begin(), retrievedMapping.end(), expectedPrivileges.begin()),
-                      "Wrong default mapping returned");
-}
-
 namespace {
 const int sm_app_shared_test_id = 27;
 const char *const sm_app_shared_id = "sm_test_27_app_id_full";