Add SM tests for app installation constraints 67/65167/6
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Thu, 7 Apr 2016 14:01:27 +0000 (16:01 +0200)
committerRafal Krypa <r.krypa@samsung.com>
Fri, 1 Jul 2016 15:09:09 +0000 (17:09 +0200)
[Problem] Application installation constraints need to be checked.
[Solution] Add test.

[Verification] Run security-manager-tests --regexp=security_manager_50_app_install_constraint_check

Change-Id: I0d00995dac7edf5c0b45e3365bdb77b92470dad1

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

index cc7d791..a31cf2f 100644 (file)
@@ -69,7 +69,7 @@ void TestSecurityManagerDatabase::check_app_and_pkg(const std::string &app_name,
 {
     Sqlite3DBaseSelectResult result;
     std::ostringstream sql;
-    sql << "SELECT app_name, pkg_name FROM app_pkg_view"
+    sql << "SELECT app_name, pkg_name FROM user_app_pkg_view"
            "  WHERE app_name == '" << app_name << "' "
            "    AND pkg_name == '" << pkg_name << "' ;";
     m_base.execute(sql.str(), result);
index a10bcf6..f8f88c6 100644 (file)
@@ -4578,6 +4578,67 @@ RUNNER_CHILD_TEST(security_manager_49f_local_user_set_install_type_preloaded)
     Api::install(requestPrivateUser, (lib_retcode)SECURITY_MANAGER_ERROR_AUTHENTICATION_FAILED);
 }
 
+RUNNER_TEST(security_manager_50_app_install_constraint_check)
+{
+    auto install = [](const TemporaryTestUser& user,
+                      const char *pkgId,
+                      const char *appId,
+                      const char *version,
+                      const char *author,
+                      enum lib_retcode expected,
+                      bool uninstall = true)
+    {
+        InstallRequest request;
+        request.setAppId(appId);
+        request.setPkgId(pkgId);
+        request.setAppTizenVersion(version);
+        request.setAuthorId(author);
+        request.setUid(user.getUid());
+
+        Api::install(request, expected);
+
+        if(expected == SECURITY_MANAGER_SUCCESS) {
+            // TODO add verification once check_app_after_install() supports uid
+            // check_app_after_install(appId, pkgId);
+            if(uninstall)
+                Api::uninstall(request);
+        }
+    };
+
+    std::vector<TemporaryTestUser> users = {
+            {"sm_test_50_user_name_0", GUM_USERTYPE_NORMAL, false},
+            {"sm_test_50_user_name_1", GUM_USERTYPE_NORMAL, false}
+    };
+
+    for(auto& gu : users)
+        gu.create();
+
+    const char *const pkgId[] =   {"sm_test_50_pkg_id_0",  "sm_test_50_pkg_id_1"};
+    const char *const appId[] =   {"sm_test_50_app_id_0",  "sm_test_50_app_id_1"};
+    const char *const version[] = {"sm_test_50_version_0", "sm_test_50_version_1"};
+    const char *const author[] =  {"sm_test_50_author_0",  "sm_test_50_author_1"};
+
+    // uid_0, pkg_0, app_0, version_0, author_0
+    install(users[0], pkgId[0], appId[0], version[0], author[0], SECURITY_MANAGER_SUCCESS, false);
+
+    // uid_1, pkg_0, app_0, version_0, author_0 -> ok (different uid)
+    install(users[1], pkgId[0], appId[0], version[0], author[0], SECURITY_MANAGER_SUCCESS);
+    // uid_1, pkg_0, app_0, version_0, author_1 -> fail (author of app_0 must be the same)
+    install(users[1], pkgId[0], appId[0], version[0], author[1], SECURITY_MANAGER_ERROR_INPUT_PARAM);
+    // uid_1, pkg_0, app_0, version_1, author_0 -> fail (version of app_0 must be the same)
+    install(users[1], pkgId[0], appId[0], version[1], author[0], SECURITY_MANAGER_ERROR_INPUT_PARAM);
+    // uid_1, pkg_1, app_0, version_0, author_0 -> fail (pkg of app_0 must be the same)
+    install(users[1], pkgId[1], appId[0], version[0], author[0], SECURITY_MANAGER_ERROR_INPUT_PARAM);
+    // uid_0, pkg_0, app_0, version_0, author_0 -> ok (the same app again)
+    install(users[0], pkgId[0], appId[0], version[0], author[0], SECURITY_MANAGER_SUCCESS, false);
+    // uid_0, pkg_1, app_0, version_0, author_0 -> fail (app_name + uid must be unique)
+    install(users[0], pkgId[1], appId[0], version[0], author[0], SECURITY_MANAGER_ERROR_INPUT_PARAM);
+    // uid_0, pkg_0, app_0, version_1, author_0 -> fail (app_name + uid must be unique)
+    install(users[0], pkgId[0], appId[0], version[1], author[0], SECURITY_MANAGER_ERROR_INPUT_PARAM);
+    // uid_0, pkg_0, app_0, version_0, author_1 -> fail (app_name + uid must be unique)
+    install(users[0], pkgId[0], appId[0], version[0], author[1], SECURITY_MANAGER_ERROR_INPUT_PARAM);
+}
+
 RUNNER_TEST_GROUP_INIT(SECURITY_MANAGER_REGISTER_PATH)
 
 RUNNER_TEST(security_manager_54_path_req_no_pkg)