Clean up libprivilege-control test cases
[platform/core/test/security-tests.git] / tests / libprivilege-control-tests / test_cases_incorrect_params.cpp
1 /*
2  * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15 */
16
17 /*
18  * @file        test_cases.cpp
19  * @author      Jan Olszak (j.olszak@samsung.com)
20  * @author      Rafal Krypa (r.krypa@samsung.com)
21  * @version     1.0
22  * @brief       libprivilege-control test runner
23  */
24
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>
30
31
32
33 //////////////////////////////////////////////////////
34 //TEST FOR INCORRECT PARAMS CHECK IN LIBPRIVILEGE APIS
35 //////////////////////////////////////////////////////
36
37 RUNNER_TEST_GROUP_INIT(libprivilegecontrol_incorrect_params)
38
39 RUNNER_TEST(privilege_control21a_incorrect_params_get_smack_label_from_process)
40 {
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.");
43
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.");
47 }
48
49 RUNNER_TEST_SMACK(privilege_control21b_incorrect_params_smack_pid_have_access)
50 {
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.");
59 }
60
61 RUNNER_TEST(privilege_control21c_incorrect_params_perm_app_set_privilege)
62 {
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.");
65 }
66
67 RUNNER_TEST(privilege_control21d_incorrect_params_perm_app_install)
68 {
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.");
73 }
74
75 RUNNER_TEST(privilege_control21e_incorrect_params_perm_app_uninstall)
76 {
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.");
81 }
82
83 RUNNER_TEST(privilege_control21f_incorrect_params_perm_app_enable_permissions)
84 {
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");
93 }
94
95 RUNNER_TEST(privilege_control21g_incorrect_params_app_revoke_permissions)
96 {
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.");
103 }
104
105 RUNNER_TEST(privilege_control21h_incorrect_params_app_reset_permissions)
106 {
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.");
113 }
114
115 RUNNER_TEST(privilege_control21i_incorrect_params_app_setup_path)
116 {
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.");
125 }
126
127 RUNNER_TEST(privilege_control21j_incorrect_params_app_add_friend)
128 {
129     RUNNER_IGNORED_MSG("perm_app_add_friend is not implemented");
130
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.");
143 }
144
145 RUNNER_TEST(privilege_control21k_incorrect_params_add_api_feature)
146 {
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.");
151 }
152
153 RUNNER_TEST(privilege_control21l_incorrect_params_ignored_disable_permissions)
154 {
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.");
163 }
164
165