2 * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @file test_cases.cpp
19 * @author Jan Olszak (j.olszak@samsung.com)
20 * @author Rafal Krypa (r.krypa@samsung.com)
22 * @brief libprivilege-control test runner
25 #include <dpl/test/test_runner.h>
26 #include <tests_common.h>
27 #include <sys/smack.h>
28 #include <privilege-control.h>
29 #include <tests_common.h>
30 #include <libprivilege-control_test_common.h>
34 //////////////////////////////////////////////////////
35 //TEST FOR INCORRECT PARAMS CHECK IN LIBPRIVILEGE APIS
36 //////////////////////////////////////////////////////
38 RUNNER_TEST_GROUP_INIT(libprivilegecontrol_incorrect_params)
40 RUNNER_TEST(privilege_control21c_incorrect_params_perm_app_set_privilege)
42 RUNNER_ASSERT_MSG(perm_app_set_privilege(nullptr, nullptr, APP_SET_PRIV_PATH) == PC_ERR_INVALID_PARAM,
43 "perm_app_set_privilege didn't check if package name isn't nullptr.");
46 RUNNER_TEST(privilege_control21d_incorrect_params_perm_app_install)
48 RUNNER_ASSERT_MSG(perm_app_install(nullptr) == PC_ERR_INVALID_PARAM,
49 "perm_app_install didn't check if pkg_id isn't nullptr.");
50 RUNNER_ASSERT_MSG(perm_app_install("") == PC_ERR_INVALID_PARAM,
51 "perm_app_install didn't check if pkg_id isn't empty.");
54 RUNNER_TEST(privilege_control21e_incorrect_params_perm_app_uninstall)
56 RUNNER_ASSERT_MSG(perm_app_uninstall(nullptr) == PC_ERR_INVALID_PARAM,
57 "perm_app_uninstall didn't check if pkg_id isn't nullptr.");
58 RUNNER_ASSERT_MSG(perm_app_uninstall("") == PC_ERR_INVALID_PARAM,
59 "perm_app_uninstall didn't check if pkg_id isn't empty.");
62 RUNNER_TEST(privilege_control21f_incorrect_params_perm_app_enable_permissions)
64 RUNNER_ASSERT_MSG(perm_app_enable_permissions(APP_ID, APP_TYPE_OTHER, nullptr, 1) == PC_ERR_INVALID_PARAM,
65 "perm_app_enable_permissions didn't check if perm_list isn't nullptr.");
66 RUNNER_ASSERT_MSG(perm_app_enable_permissions(nullptr, APP_TYPE_OTHER, PRIVS2, 1) == PC_ERR_INVALID_PARAM,
67 "perm_app_enable_permissions didn't check if pkg_id isn't nullptr.");
68 RUNNER_ASSERT_MSG(perm_app_enable_permissions("", APP_TYPE_OTHER, PRIVS2, 1) == PC_ERR_INVALID_PARAM,
69 "perm_app_enable_permissions didn't check if pkg_id isn't empty.");
70 RUNNER_ASSERT_MSG(perm_app_enable_permissions("~APP~", APP_TYPE_OTHER, PRIVS2, 1) == PC_ERR_INVALID_PARAM,
71 "perm_app_enable_permissions didn't check if pkg_id is valid");
74 RUNNER_TEST(privilege_control21g_incorrect_params_app_revoke_permissions)
76 RUNNER_ASSERT_MSG(perm_app_revoke_permissions(nullptr) == PC_ERR_INVALID_PARAM,
77 "perm_app_revoke_permissions didn't check if pkg_id isn't nullptr.");
78 RUNNER_ASSERT_MSG(perm_app_revoke_permissions("") == PC_ERR_INVALID_PARAM,
79 "perm_app_revoke_permissions didn't check if pkg_id isn't empty.");
80 RUNNER_ASSERT_MSG(perm_app_revoke_permissions("~APP~") == PC_ERR_INVALID_PARAM,
81 "perm_app_revoke_permissions didn't check if pkg_id is valid.");
84 RUNNER_TEST(privilege_control21h_incorrect_params_app_reset_permissions)
86 RUNNER_ASSERT_MSG(perm_app_reset_permissions(nullptr) == PC_ERR_INVALID_PARAM,
87 "perm_app_reset_permissions didn't check if pkg_id isn't nullptr.");
88 RUNNER_ASSERT_MSG(perm_app_reset_permissions("") == PC_ERR_INVALID_PARAM,
89 "perm_app_reset_permissions didn't check if pkg_id isn't empty.");
90 RUNNER_ASSERT_MSG(perm_app_reset_permissions("~APP~") == PC_ERR_INVALID_PARAM,
91 "perm_app_reset_permissions didn't check if pkg_id is valid.");
94 RUNNER_TEST(privilege_control21i_incorrect_params_app_setup_path)
96 RUNNER_ASSERT_MSG(perm_app_setup_path(APPID_DIR, nullptr, APP_PATH_PRIVATE) == PC_ERR_INVALID_PARAM,
97 "perm_app_setup_path didn't check if path isn't nullptr.");
98 RUNNER_ASSERT_MSG(perm_app_setup_path(nullptr, TEST_APP_DIR, APP_PATH_PRIVATE) == PC_ERR_INVALID_PARAM,
99 "perm_app_setup_path didn't check if pkg_id isn't nullptr.");
100 RUNNER_ASSERT_MSG(perm_app_setup_path("", TEST_APP_DIR, APP_PATH_PRIVATE) == PC_ERR_INVALID_PARAM,
101 "perm_app_setup_path didn't check if pkg_id isn't empty.");
102 RUNNER_ASSERT_MSG(perm_app_setup_path("~APP~", TEST_APP_DIR, APP_PATH_PRIVATE) == PC_ERR_INVALID_PARAM,
103 "perm_app_setup_path didn't check if pkg_id is valid.");
106 RUNNER_TEST(privilege_control21k_incorrect_params_add_api_feature)
108 RUNNER_ASSERT_MSG(perm_add_api_feature(APP_TYPE_OSP, nullptr, nullptr, nullptr, 0) == PC_ERR_INVALID_PARAM,
109 "perm_add_api_feature didn't check if api_feature_name isn't nullptr.");
110 RUNNER_ASSERT_MSG(perm_add_api_feature(APP_TYPE_OSP, "", nullptr, nullptr, 0) == PC_ERR_INVALID_PARAM,
111 "perm_add_api_feature didn't check if api_feature_name isn't empty.");
114 RUNNER_TEST(privilege_control21l_incorrect_params_ignored_disable_permissions)
116 RUNNER_ASSERT_MSG(perm_app_disable_permissions(APP_ID, APP_TYPE_OTHER, nullptr) == PC_ERR_INVALID_PARAM,
117 "perm_app_disable_permissions didn't check if perm_list isn't nullptr.");
118 RUNNER_ASSERT_MSG(perm_app_disable_permissions(nullptr, APP_TYPE_OTHER, PRIVS2) == PC_ERR_INVALID_PARAM,
119 "perm_app_disable_permissions didn't check if pkg_id isn't nullptr.");
120 RUNNER_ASSERT_MSG(perm_app_disable_permissions("", APP_TYPE_OTHER, PRIVS2) == PC_ERR_INVALID_PARAM,
121 "perm_app_disable_permissions didn't check if pkg_id isn't empty.");
122 RUNNER_ASSERT_MSG(perm_app_disable_permissions("~APP~", APP_TYPE_OTHER, PRIVS2) == PC_ERR_INVALID_PARAM,
123 "perm_app_disable_permissions didn't check if pkg_id is valid.");
126 RUNNER_TEST(privilege_control21m_incorrect_params_perm_app_has_permission)
129 const char *app_label = "test_app_label";
131 RUNNER_ASSERT_MSG(perm_app_has_permission(nullptr, APP_TYPE_WGT,
132 PRIVS2[0], &has_permission) == PC_ERR_INVALID_PARAM,
133 "perm_app_has_permission didn't check if pkg_id isn't nullptr.");
134 RUNNER_ASSERT_MSG(perm_app_has_permission(app_label, APP_TYPE_OTHER,
135 PRIVS2[0], &has_permission) == PC_ERR_INVALID_PARAM,
136 "perm_app_has_permission should not accept app_type = OTHER.");
137 RUNNER_ASSERT_MSG(perm_app_has_permission(app_label, APP_TYPE_WGT,
138 nullptr, &has_permission) == PC_ERR_INVALID_PARAM,
139 "perm_app_has_permission didn't check if permission_name isn't nullptr.");
140 RUNNER_ASSERT_MSG(perm_app_has_permission(app_label, APP_TYPE_WGT,
141 PRIVS2[0], nullptr) == PC_ERR_INVALID_PARAM,
142 "perm_app_has_permission didn't check if has_permission isn't nullptr.");