Add tests to libprivilege-control perm_app_has_permission function.
[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 <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>
31
32
33
34 //////////////////////////////////////////////////////
35 //TEST FOR INCORRECT PARAMS CHECK IN LIBPRIVILEGE APIS
36 //////////////////////////////////////////////////////
37
38 RUNNER_TEST_GROUP_INIT(libprivilegecontrol_incorrect_params)
39
40 RUNNER_TEST(privilege_control21c_incorrect_params_perm_app_set_privilege)
41 {
42     RUNNER_ASSERT_MSG_BT(perm_app_set_privilege(NULL, NULL, APP_SET_PRIV_PATH) == PC_ERR_INVALID_PARAM,
43             "perm_app_set_privilege didn't check if package name isn't NULL.");
44 }
45
46 RUNNER_TEST(privilege_control21d_incorrect_params_perm_app_install)
47 {
48     RUNNER_ASSERT_MSG_BT(perm_app_install(NULL) == PC_ERR_INVALID_PARAM,
49             "perm_app_install didn't check if pkg_id isn't NULL.");
50     RUNNER_ASSERT_MSG_BT(perm_app_install("") == PC_ERR_INVALID_PARAM,
51             "perm_app_install didn't check if pkg_id isn't empty.");
52 }
53
54 RUNNER_TEST(privilege_control21e_incorrect_params_perm_app_uninstall)
55 {
56     RUNNER_ASSERT_MSG_BT(perm_app_uninstall(NULL) == PC_ERR_INVALID_PARAM,
57             "perm_app_uninstall didn't check if pkg_id isn't NULL.");
58     RUNNER_ASSERT_MSG_BT(perm_app_uninstall("") == PC_ERR_INVALID_PARAM,
59             "perm_app_uninstall didn't check if pkg_id isn't empty.");
60 }
61
62 RUNNER_TEST(privilege_control21f_incorrect_params_perm_app_enable_permissions)
63 {
64     RUNNER_ASSERT_MSG_BT(perm_app_enable_permissions(APP_ID, APP_TYPE_OTHER, NULL, 1) == PC_ERR_INVALID_PARAM,
65             "perm_app_enable_permissions didn't check if perm_list isn't NULL.");
66     RUNNER_ASSERT_MSG_BT(perm_app_enable_permissions(NULL, APP_TYPE_OTHER, PRIVS2, 1) == PC_ERR_INVALID_PARAM,
67             "perm_app_enable_permissions didn't check if pkg_id isn't NULL.");
68     RUNNER_ASSERT_MSG_BT(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_BT(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");
72 }
73
74 RUNNER_TEST(privilege_control21g_incorrect_params_app_revoke_permissions)
75 {
76     RUNNER_ASSERT_MSG_BT(perm_app_revoke_permissions(NULL) == PC_ERR_INVALID_PARAM,
77             "perm_app_revoke_permissions didn't check if pkg_id isn't NULL.");
78     RUNNER_ASSERT_MSG_BT(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_BT(perm_app_revoke_permissions("~APP~") == PC_ERR_INVALID_PARAM,
81             "perm_app_revoke_permissions didn't check if pkg_id is valid.");
82 }
83
84 RUNNER_TEST(privilege_control21h_incorrect_params_app_reset_permissions)
85 {
86     RUNNER_ASSERT_MSG_BT(perm_app_reset_permissions(NULL) == PC_ERR_INVALID_PARAM,
87             "perm_app_reset_permissions didn't check if pkg_id isn't NULL.");
88     RUNNER_ASSERT_MSG_BT(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_BT(perm_app_reset_permissions("~APP~") == PC_ERR_INVALID_PARAM,
91             "perm_app_reset_permissions didn't check if pkg_id is valid.");
92 }
93
94 RUNNER_TEST(privilege_control21i_incorrect_params_app_setup_path)
95 {
96     RUNNER_ASSERT_MSG_BT(perm_app_setup_path(APPID_DIR, NULL, APP_PATH_PRIVATE) == PC_ERR_INVALID_PARAM,
97             "perm_app_setup_path didn't check if path isn't NULL.");
98     RUNNER_ASSERT_MSG_BT(perm_app_setup_path(NULL, TEST_APP_DIR, APP_PATH_PRIVATE) == PC_ERR_INVALID_PARAM,
99             "perm_app_setup_path didn't check if pkg_id isn't NULL.");
100     RUNNER_ASSERT_MSG_BT(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_BT(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.");
104 }
105
106 RUNNER_TEST(privilege_control21k_incorrect_params_add_api_feature)
107 {
108     RUNNER_ASSERT_MSG_BT(perm_add_api_feature(APP_TYPE_OSP, NULL, NULL, NULL, 0) == PC_ERR_INVALID_PARAM,
109             "perm_add_api_feature didn't check if api_feature_name isn't NULL.");
110     RUNNER_ASSERT_MSG_BT(perm_add_api_feature(APP_TYPE_OSP, "", NULL, NULL, 0) == PC_ERR_INVALID_PARAM,
111             "perm_add_api_feature didn't check if api_feature_name isn't empty.");
112 }
113
114 RUNNER_TEST(privilege_control21l_incorrect_params_ignored_disable_permissions)
115 {
116     RUNNER_ASSERT_MSG_BT(perm_app_disable_permissions(APP_ID, APP_TYPE_OTHER, NULL) == PC_ERR_INVALID_PARAM,
117             "perm_app_disable_permissions didn't check if perm_list isn't NULL.");
118     RUNNER_ASSERT_MSG_BT(perm_app_disable_permissions(NULL, APP_TYPE_OTHER, PRIVS2) == PC_ERR_INVALID_PARAM,
119             "perm_app_disable_permissions didn't check if pkg_id isn't NULL.");
120     RUNNER_ASSERT_MSG_BT(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_BT(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.");
124 }
125
126 RUNNER_TEST(privilege_control21m_incorrect_params_perm_app_has_permission)
127 {
128     bool has_permission;
129     const char *app_label = "test_app_label";
130
131     RUNNER_ASSERT_MSG_BT(perm_app_has_permission(NULL, 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 NULL.");
134     RUNNER_ASSERT_MSG_BT(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_BT(perm_app_has_permission(app_label, APP_TYPE_WGT,
138                                               NULL, &has_permission) == PC_ERR_INVALID_PARAM,
139             "perm_app_has_permission didn't check if permission_name isn't NULL.");
140     RUNNER_ASSERT_MSG_BT(perm_app_has_permission(app_label, APP_TYPE_WGT,
141                                               PRIVS2[0], NULL) == PC_ERR_INVALID_PARAM,
142             "perm_app_has_permission didn't check if has_permission isn't NULL.");
143 }