Add security_manager_get_client_privilege_license() tests 22/129022/2
authorDariusz Michaluk <d.michaluk@samsung.com>
Fri, 12 May 2017 07:22:24 +0000 (09:22 +0200)
committerDariusz Michaluk <d.michaluk@samsung.com>
Fri, 12 May 2017 11:56:07 +0000 (13:56 +0200)
Change-Id: I4270f58a8731010593c097252370b98200798edf

src/security-manager-tests/test_cases_app_defined_privilege.cpp

index d0bcf96d0f1ddb4eadb31591faaba6aa96205bf6..7828f8b48672c31619e9a1c050dcc62df93414e8 100644 (file)
@@ -406,3 +406,82 @@ RUNNER_CHILD_TEST(app_defined_07_get_provider_license)
     free(license);
     license = nullptr;
 }
+
+RUNNER_CHILD_TEST(app_defined_08_add_get_client_license)
+{
+    int result;
+    char *license = nullptr;
+    const std::string privilegeA = "http://tizen.org/applicationDefinedPrivilege/app_defined_08a";
+    const std::string privilegeB = "http://tizen.org/applicationDefinedPrivilege/app_defined_08b";
+    const std::string privilegeC = "http://tizen.org/applicationDefinedPrivilege/app_defined_08c";
+    const std::string licenseA = "/opt/data/app_defined_08a/res/license";
+    const std::string licenseB = "/opt/data/app_defined_08b/res/license";
+    const std::string licenseC = "/opt/data/app_defined_08c/res/license";
+    const std::string clientId = "app_def_08_client";
+    uid_t uid = 5001;
+
+    AppInstallHelper clientGlobal(clientId);
+    AppInstallHelper clientLocal(clientId, uid);
+    clientGlobal.addClientPrivilege(std::make_pair(privilegeB, licenseB));
+    clientGlobal.addClientPrivilege(std::make_pair(privilegeC, licenseC));
+    clientLocal.addClientPrivilege(std::make_pair(privilegeA, licenseA));
+    clientLocal.addClientPrivilege(std::make_pair(privilegeC, ""));
+    ScopedInstaller req1(clientGlobal);
+    ScopedInstaller req2(clientLocal);
+
+    result = security_manager_get_client_privilege_license(nullptr,
+                                                           clientLocal.getAppId().c_str(),
+                                                           uid, &license);
+    RUNNER_ASSERT(result == SECURITY_MANAGER_ERROR_INPUT_PARAM);
+    RUNNER_ASSERT(license == nullptr);
+
+    result = security_manager_get_client_privilege_license(privilegeA.c_str(), nullptr,
+                                                           uid, &license);
+    RUNNER_ASSERT(result == SECURITY_MANAGER_ERROR_INPUT_PARAM);
+    RUNNER_ASSERT(license == nullptr);
+
+    result = security_manager_get_client_privilege_license(privilegeA.c_str(),
+                                                           clientLocal.getAppId().c_str(),
+                                                           uid, nullptr);
+    RUNNER_ASSERT(result == SECURITY_MANAGER_ERROR_INPUT_PARAM);
+
+    result = security_manager_get_client_privilege_license("noExistingPrivilege",
+                                                           clientLocal.getAppId().c_str(),
+                                                           uid, &license);
+    RUNNER_ASSERT(result == SECURITY_MANAGER_ERROR_NO_SUCH_OBJECT);
+    RUNNER_ASSERT(license == nullptr);
+
+    result = security_manager_get_client_privilege_license(privilegeA.c_str(), "noExistingApp",
+                                                           uid, &license);
+    RUNNER_ASSERT(result == SECURITY_MANAGER_ERROR_NO_SUCH_OBJECT);
+    RUNNER_ASSERT(license == nullptr);
+
+    result = security_manager_get_client_privilege_license(privilegeC.c_str(),
+                                                           clientLocal.getAppId().c_str(),
+                                                           uid, &license);
+    RUNNER_ASSERT(result == SECURITY_MANAGER_ERROR_NO_SUCH_OBJECT);
+    RUNNER_ASSERT(license == nullptr);
+
+    result = security_manager_get_client_privilege_license(privilegeA.c_str(),
+                                                           clientLocal.getAppId().c_str(),
+                                                           uid+1, &license);
+    RUNNER_ASSERT(result == SECURITY_MANAGER_ERROR_NO_SUCH_OBJECT);
+    RUNNER_ASSERT(license == nullptr);
+
+    result = security_manager_get_client_privilege_license(privilegeA.c_str(),
+                                                           clientLocal.getAppId().c_str(),
+                                                           uid, &license);
+    RUNNER_ASSERT_MSG(result == SECURITY_MANAGER_SUCCESS, "getting privilege license failed");
+    RUNNER_ASSERT(license && std::string(license) == licenseA);
+    free(license);
+    license = nullptr;
+
+    req2.uninstallApp();
+    result = security_manager_get_client_privilege_license(privilegeB.c_str(),
+                                                           clientGlobal.getAppId().c_str(),
+                                                           uid, &license);
+    RUNNER_ASSERT_MSG(result == SECURITY_MANAGER_SUCCESS, "getting privilege license failed");
+    RUNNER_ASSERT(license && std::string(license) == licenseB);
+    free(license);
+    license = nullptr;
+}