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 <sys/smack.h>
27 #include <privilege-control.h>
28 #include <tests_common.h>
29 #include <libprivilege-control_test_common.h>
33 //////////////////////////////////////////////////////
34 //TEST FOR INCORRECT PARAMS CHECK IN LIBPRIVILEGE APIS
35 //////////////////////////////////////////////////////
37 RUNNER_TEST_GROUP_INIT(libprivilegecontrol_incorrect_params)
39 RUNNER_TEST(privilege_control21a_incorrect_params_get_smack_label_from_process)
41 RUNNER_ASSERT_MSG(get_smack_label_from_process(PID_CORRECT, NULL) == PC_ERR_INVALID_PARAM,
42 "get_smack_label_from_process didn't check if smack_label isn't NULL.");
44 char aquired_smack_label[SMACK_LABEL_LEN+1];
45 RUNNER_ASSERT_MSG(get_smack_label_from_process(PID_INCORRECT, aquired_smack_label) == PC_ERR_INVALID_PARAM,
46 "get_smack_label_from_process didn't check for correct pid.");
49 RUNNER_TEST_SMACK(privilege_control21b_incorrect_params_smack_pid_have_access)
51 RUNNER_ASSERT_MSG(smack_pid_have_access(PID_CORRECT, "some_object", NULL) == -1,
52 "smack_pid_have_access didn't check if access_type isn't NULL.");
53 RUNNER_ASSERT_MSG(smack_pid_have_access(PID_CORRECT, NULL, "rw") == -1,
54 "smack_pid_have_access didn't check if object isn't NULL.");
55 RUNNER_ASSERT_MSG(smack_pid_have_access(PID_CORRECT, "", "rw") == -1,
56 "smack_pid_have_access didn't check if object isn't empty.");
57 RUNNER_ASSERT_MSG(smack_pid_have_access(PID_INCORRECT, "some_object", "rw") == -1,
58 "smack_pid_have_access didn't check for correct pid.");
61 RUNNER_TEST(privilege_control21c_incorrect_params_perm_app_set_privilege)
63 RUNNER_ASSERT_MSG(perm_app_set_privilege(NULL, NULL, APP_SET_PRIV_PATH) == PC_ERR_INVALID_PARAM,
64 "perm_app_set_privilege didn't check if package name isn't NULL.");
67 RUNNER_TEST(privilege_control21d_incorrect_params_perm_app_install)
69 RUNNER_ASSERT_MSG(perm_app_install(NULL) == PC_ERR_INVALID_PARAM,
70 "perm_app_install didn't check if pkg_id isn't NULL.");
71 RUNNER_ASSERT_MSG(perm_app_install("") == PC_ERR_INVALID_PARAM,
72 "perm_app_install didn't check if pkg_id isn't empty.");
75 RUNNER_TEST(privilege_control21e_incorrect_params_perm_app_uninstall)
77 RUNNER_ASSERT_MSG(perm_app_uninstall(NULL) == PC_ERR_INVALID_PARAM,
78 "perm_app_uninstall didn't check if pkg_id isn't NULL.");
79 RUNNER_ASSERT_MSG(perm_app_uninstall("") == PC_ERR_INVALID_PARAM,
80 "perm_app_uninstall didn't check if pkg_id isn't empty.");
83 RUNNER_TEST(privilege_control21f_incorrect_params_perm_app_enable_permissions)
85 RUNNER_ASSERT_MSG(perm_app_enable_permissions(APP_ID, APP_TYPE_OTHER, NULL, 1) == PC_ERR_INVALID_PARAM,
86 "perm_app_enable_permissions didn't check if perm_list isn't NULL.");
87 RUNNER_ASSERT_MSG(perm_app_enable_permissions(NULL, APP_TYPE_OTHER, PRIVS2, 1) == PC_ERR_INVALID_PARAM,
88 "perm_app_enable_permissions didn't check if pkg_id isn't NULL.");
89 RUNNER_ASSERT_MSG(perm_app_enable_permissions("", APP_TYPE_OTHER, PRIVS2, 1) == PC_ERR_INVALID_PARAM,
90 "perm_app_enable_permissions didn't check if pkg_id isn't empty.");
91 RUNNER_ASSERT_MSG(perm_app_enable_permissions("~APP~", APP_TYPE_OTHER, PRIVS2, 1) == PC_ERR_INVALID_PARAM,
92 "perm_app_enable_permissions didn't check if pkg_id is valid");
95 RUNNER_TEST(privilege_control21g_incorrect_params_app_revoke_permissions)
97 RUNNER_ASSERT_MSG(perm_app_revoke_permissions(NULL) == PC_ERR_INVALID_PARAM,
98 "perm_app_revoke_permissions didn't check if pkg_id isn't NULL.");
99 RUNNER_ASSERT_MSG(perm_app_revoke_permissions("") == PC_ERR_INVALID_PARAM,
100 "perm_app_revoke_permissions didn't check if pkg_id isn't empty.");
101 RUNNER_ASSERT_MSG(perm_app_revoke_permissions("~APP~") == PC_ERR_INVALID_PARAM,
102 "perm_app_revoke_permissions didn't check if pkg_id is valid.");
105 RUNNER_TEST(privilege_control21h_incorrect_params_app_reset_permissions)
107 RUNNER_ASSERT_MSG(perm_app_reset_permissions(NULL) == PC_ERR_INVALID_PARAM,
108 "perm_app_reset_permissions didn't check if pkg_id isn't NULL.");
109 RUNNER_ASSERT_MSG(perm_app_reset_permissions("") == PC_ERR_INVALID_PARAM,
110 "perm_app_reset_permissions didn't check if pkg_id isn't empty.");
111 RUNNER_ASSERT_MSG(perm_app_reset_permissions("~APP~") == PC_ERR_INVALID_PARAM,
112 "perm_app_reset_permissions didn't check if pkg_id is valid.");
115 RUNNER_TEST(privilege_control21i_incorrect_params_app_setup_path)
117 RUNNER_ASSERT_MSG(perm_app_setup_path(APPID_DIR, NULL, APP_PATH_PRIVATE) == PC_ERR_INVALID_PARAM,
118 "perm_app_setup_path didn't check if path isn't NULL.");
119 RUNNER_ASSERT_MSG(perm_app_setup_path(NULL, TEST_APP_DIR, APP_PATH_PRIVATE) == PC_ERR_INVALID_PARAM,
120 "perm_app_setup_path didn't check if pkg_id isn't NULL.");
121 RUNNER_ASSERT_MSG(perm_app_setup_path("", TEST_APP_DIR, APP_PATH_PRIVATE) == PC_ERR_INVALID_PARAM,
122 "perm_app_setup_path didn't check if pkg_id isn't empty.");
123 RUNNER_ASSERT_MSG(perm_app_setup_path("~APP~", TEST_APP_DIR, APP_PATH_PRIVATE) == PC_ERR_INVALID_PARAM,
124 "perm_app_setup_path didn't check if pkg_id is valid.");
127 RUNNER_TEST(privilege_control21j_incorrect_params_app_add_friend)
129 RUNNER_IGNORED_MSG("perm_app_add_friend is not implemented");
131 RUNNER_ASSERT_MSG(perm_app_add_friend(NULL, APP_FRIEND_2) == PC_ERR_INVALID_PARAM,
132 "perm_app_add_friend didin't check if pkg_id1 isn't NULL.");
133 RUNNER_ASSERT_MSG(perm_app_add_friend("", APP_FRIEND_2) == PC_ERR_INVALID_PARAM,
134 "perm_app_add_friend didin't check if pkg_id1 isn't empty.");
135 RUNNER_ASSERT_MSG(perm_app_add_friend(APP_FRIEND_1, NULL) == PC_ERR_INVALID_PARAM,
136 "perm_app_add_friend didin't check if pkg_id2 isn't NULL.");
137 RUNNER_ASSERT_MSG(perm_app_add_friend(APP_FRIEND_1, "") == PC_ERR_INVALID_PARAM,
138 "perm_app_add_friend didin't check if pkg_id2 isn't empty.");
139 RUNNER_ASSERT_MSG(perm_app_add_friend("~APP~", APP_FRIEND_2) == PC_ERR_INVALID_PARAM,
140 "perm_app_add_friend didin't check if pkg_id1 is valid.");
141 RUNNER_ASSERT_MSG(perm_app_add_friend(APP_FRIEND_1, "~APP~") == PC_ERR_INVALID_PARAM,
142 "perm_app_add_friend didin't check if pkg_id2 is valid.");
145 RUNNER_TEST(privilege_control21k_incorrect_params_add_api_feature)
147 RUNNER_ASSERT_MSG(perm_add_api_feature(APP_TYPE_OSP, NULL, NULL, NULL, 0) == PC_ERR_INVALID_PARAM,
148 "perm_add_api_feature didn't check if api_feature_name isn't NULL.");
149 RUNNER_ASSERT_MSG(perm_add_api_feature(APP_TYPE_OSP, "", NULL, NULL, 0) == PC_ERR_INVALID_PARAM,
150 "perm_add_api_feature didn't check if api_feature_name isn't empty.");
153 RUNNER_TEST(privilege_control21l_incorrect_params_ignored_disable_permissions)
155 RUNNER_ASSERT_MSG(perm_app_disable_permissions(APP_ID, APP_TYPE_OTHER, NULL) == PC_ERR_INVALID_PARAM,
156 "perm_app_disable_permissions didn't check if perm_list isn't NULL.");
157 RUNNER_ASSERT_MSG(perm_app_disable_permissions(NULL, APP_TYPE_OTHER, PRIVS2) == PC_ERR_INVALID_PARAM,
158 "perm_app_disable_permissions didn't check if pkg_id isn't NULL.");
159 RUNNER_ASSERT_MSG(perm_app_disable_permissions("", APP_TYPE_OTHER, PRIVS2) == PC_ERR_INVALID_PARAM,
160 "perm_app_disable_permissions didn't check if pkg_id isn't empty.");
161 RUNNER_ASSERT_MSG(perm_app_disable_permissions("~APP~", APP_TYPE_OTHER, PRIVS2) == PC_ERR_INVALID_PARAM,
162 "perm_app_disable_permissions didn't check if pkg_id is valid.");
165 RUNNER_TEST(privilege_control21m_incorrect_params_perm_app_has_permission)
169 RUNNER_ASSERT_MSG(perm_app_has_permission(NULL, APP_TYPE_WGT,
170 PRIVS2[0], &has_permission) == PC_ERR_INVALID_PARAM,
171 "perm_app_has_permission didn't check if pkg_id isn't NULL.");
172 RUNNER_ASSERT_MSG(perm_app_has_permission(APP_ID, APP_TYPE_OTHER,
173 PRIVS2[0], &has_permission) == PC_ERR_INVALID_PARAM,
174 "perm_app_has_permission should not accept app_type = OTHER.");
175 RUNNER_ASSERT_MSG(perm_app_has_permission(APP_ID, APP_TYPE_WGT,
176 NULL, &has_permission) == PC_ERR_INVALID_PARAM,
177 "perm_app_has_permission didn't check if permission_name isn't NULL.");
178 RUNNER_ASSERT_MSG(perm_app_has_permission(APP_ID, APP_TYPE_WGT,
179 PRIVS2[0], NULL) == PC_ERR_INVALID_PARAM,
180 "perm_app_has_permission didn't check if has_permission isn't NULL.");
183 RUNNER_TEST(privilege_control21n_incorrect_params_perm_app_setup_permissions)
185 RUNNER_ASSERT_MSG(perm_app_setup_permissions(APP_ID, APP_TYPE_OTHER,
186 NULL) == PC_ERR_INVALID_PARAM,
187 "perm_app_setup_permissions didn't check if perm_list isn't NULL");
188 RUNNER_ASSERT_MSG(perm_app_setup_permissions(NULL, APP_TYPE_OTHER,
189 PRIVS2) == PC_ERR_INVALID_PARAM,
190 "perm_app_setup_permissions didn't check if pkg_id isn't NULL.");
191 RUNNER_ASSERT_MSG(perm_app_setup_permissions("", APP_TYPE_OTHER,
192 PRIVS2) == PC_ERR_INVALID_PARAM,
193 "perm_app_setup_permissions didn't check if pkg_id isn't empty.");
194 RUNNER_ASSERT_MSG(perm_app_setup_permissions(APP_ID, (app_type_t)-1,
195 PRIVS2) == PC_ERR_INVALID_PARAM,
196 "perm_app_setup_permissions didn't check if app type is valid.");
197 RUNNER_ASSERT_MSG(perm_app_setup_permissions("~APP~", APP_TYPE_OTHER,
198 PRIVS2) == PC_ERR_INVALID_PARAM,
199 "perm_app_setup_permissions didn't check if pkg_id is valid");
202 RUNNER_TEST(privilege_control22n_incorrect_params_perm_app_get_paths)
206 RUNNER_ASSERT_MSG(perm_app_get_paths(NULL, PERM_APP_PATH_PUBLIC,
207 &pp_paths) == PC_ERR_INVALID_PARAM,
208 "perm_app_get_paths didn't check if pkg_id isn't NULL.");
210 RUNNER_ASSERT_MSG(perm_app_get_paths(APP_ID, PERM_APP_PATH_PUBLIC,
211 NULL) == PC_ERR_INVALID_PARAM,
212 "perm_app_get_paths didn't check if ppp_paths isn't NULL.");
214 RUNNER_ASSERT_MSG(perm_app_get_paths(APP_ID, PERM_APP_PATH_PRIVATE,
215 &pp_paths) == PC_ERR_INVALID_PARAM,
216 "perm_app_get_paths shouldn't accept paths of type PERM_APP_PATH_PRIVATE");
217 RUNNER_ASSERT_MSG(perm_app_get_paths(APP_ID, PERM_APP_PATH_ANY_LABEL,
218 &pp_paths) == PC_ERR_INVALID_PARAM,
219 "perm_app_get_paths should not accept paths of type PERM_APP_PATH_ANY_LABEL");