Rename /tests to /ckm to align with tizen branch
[platform/core/test/security-tests.git] / src / security-server-tests / weird_arguments.cpp
1 /*
2  * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
3  */
4 /*
5  * @file    security_server_tests_weird_arguments.cpp
6  * @author  Zbigniew Jasinski (z.jasinski@samsung.com)
7  * @version 1.0
8  * @brief   Test cases for security server
9  *
10  */
11 #include "tests_common.h"
12 #include "security-server.h"
13 #include <dpl/test/test_runner.h>
14 #include <dpl/log/log.h>
15
16 RUNNER_TEST_GROUP_INIT(SECURITY_SERVER_TESTS_WEIRD_ARGUMENTS);
17
18 RUNNER_TEST(tc01_security_server_get_gid_weird_input_case)
19 {
20     int ret = 0;
21     char weird[] = {static_cast <char> (0xe3), 0x79, static_cast <char> (0x82), 0x0};
22
23     /* normal param case */
24     ret = security_server_get_gid("tel_sim");
25     RUNNER_ASSERT_MSG(ret > -1, "ret: " << ret);
26
27     /* wrong param case */
28     ret = security_server_get_gid("elephony_akecall");
29     RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_ERROR_NO_SUCH_OBJECT, "ret: " << ret);
30
31     /* weird param case */
32     ret = security_server_get_gid(weird);
33     RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_ERROR_NO_SUCH_OBJECT, "ret: " << ret);
34
35     /* null param case */
36     ret = security_server_get_gid(nullptr);
37     RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_ERROR_INPUT_PARAM, "ret: " << ret);
38
39     /* param too long case */
40     ret = security_server_get_gid("abcdefghijklmnopqrstuvwxyz01234");
41     RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_ERROR_INPUT_PARAM, "ret: " << ret);
42
43     /* empty param case */
44     ret = security_server_get_gid("");
45     RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_ERROR_INPUT_PARAM, "ret: " << ret);
46 }
47
48 /* from security_server_tests_server.cpp */
49
50 RUNNER_TEST(tc03_security_server_request_cookie_weird_input_case)
51 {
52     int ret = 0;
53     size_t cookie_size = security_server_get_cookie_size();
54
55     /* null cookie case */
56     char *cookie = nullptr;
57
58     ret = security_server_request_cookie(cookie, cookie_size);
59     RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_ERROR_INPUT_PARAM, "ret: " << ret);
60
61     /* buffer size too small case */
62     cookie_size = 19;
63     char cookie2[cookie_size];
64
65     ret = security_server_request_cookie(cookie2, cookie_size);
66     RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_ERROR_BUFFER_TOO_SMALL, "ret: " << ret);
67 }
68
69 RUNNER_TEST(tc04_security_server_check_privilege_weird_input_case)
70 {
71     int ret = 0;
72     size_t cookie_size = security_server_get_cookie_size();
73     gid_t gid = DB_ALARM_GID;
74
75     /* null cookie case */
76     char *cookie = nullptr;
77
78     ret = security_server_check_privilege(cookie, gid);
79     RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_ERROR_INPUT_PARAM, "ret: " << ret);
80
81     char cookie2[cookie_size];
82
83     ret = security_server_request_cookie(cookie2, cookie_size);
84     RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_SUCCESS, "ret: " << ret);
85
86     /* big gid case */
87     gid = 70666;
88
89     ret = security_server_check_privilege(cookie2, gid);
90     RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_ERROR_ACCESS_DENIED, "ret: " << ret);
91 }
92 RUNNER_TEST(tc05_security_server_check_privilege_by_cookie_weird_input_case)
93 {
94     RUNNER_IGNORED_MSG("security_server_check_privilege_by_cookie is temporarily disabled: always returns success");
95     int ret = 0;
96     size_t cookie_size = security_server_get_cookie_size();;
97     const char *object = "telephony_makecall";
98     const char *access_rights = "r";
99
100     /* null cookie case */
101     char *cookie = nullptr;
102     ret = security_server_check_privilege_by_cookie(cookie, object, access_rights);
103     RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_ERROR_INPUT_PARAM, "ret: " << ret);
104
105     /* null object case */
106     char *object2 = nullptr;
107     char cookie2[cookie_size];
108
109     ret = security_server_request_cookie(cookie2, cookie_size);
110     RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_SUCCESS, "ret: " << ret);
111
112     ret = security_server_check_privilege_by_cookie(cookie2, object2, access_rights);
113     RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_ERROR_INPUT_PARAM, "ret: " << ret);
114
115     /* null access rights case */
116     access_rights = nullptr;
117     ret = security_server_check_privilege_by_cookie(cookie2, object, access_rights);
118     RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_ERROR_INPUT_PARAM, "ret: " << ret);
119 }
120
121 RUNNER_TEST_SMACK(tc06_security_server_check_privilege_by_sockfd_weird_input_case)
122 {
123     RUNNER_IGNORED_MSG("security_server_check_privilege_by_sockfd is temporarily disabled: always returns success");
124     int ret = 0;
125     int sockfd = -1;
126     const char *object = "telephony_makecall";
127     const char *access_rights = "r";
128
129     /* invalid sockfd case */
130     ret = security_server_check_privilege_by_sockfd(sockfd, object, access_rights);
131     RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_ERROR_INPUT_PARAM, "ret: " << ret);
132     sockfd = 0;
133
134     /* null object case */
135     char *object2 = nullptr;
136     ret = security_server_check_privilege_by_sockfd(sockfd, object2, access_rights);
137     RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_ERROR_INPUT_PARAM, "ret: " << ret);
138
139     /* null access rights case */
140     access_rights = nullptr;
141     ret = security_server_check_privilege_by_sockfd(sockfd, object, access_rights);
142     RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_ERROR_INPUT_PARAM, "ret: " << ret);
143 }
144
145 RUNNER_TEST(tc07_security_server_get_cookie_pid_weird_input_case)
146 {
147     int ret = 0;
148     char *cookie = nullptr;
149
150     ret = security_server_get_cookie_pid(cookie);
151     RUNNER_ASSERT(ret == SECURITY_SERVER_API_ERROR_INPUT_PARAM);
152 }
153
154 ///////////////////////////
155 /////NOSMACK ENV TESTS/////
156 ///////////////////////////
157
158 /**
159  * NOSMACK version of tc06 test.
160  *
161  * security_server_check_privilege_by_sockfd at first checks if SMACK exists and then checks if
162  * params are correct. Even with incorrect params we should expect SUCCESS instead of
163  * ERROR_INPUT_PARAM.
164  */
165
166 RUNNER_TEST_NOSMACK(tc06_security_server_check_privilege_by_sockfd_weird_input_case_nosmack)
167 {
168     RUNNER_IGNORED_MSG("security_server_check_privilege_by_sockfd is temporarily disabled: always returns success");
169     int ret = 0;
170     int sockfd = -1;
171     const char* object = "telephony_makecall";
172     const char* access_rights = "r";
173
174     //invalid sockfd case
175     ret = security_server_check_privilege_by_sockfd(sockfd, object, access_rights);
176     RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_SUCCESS,
177             "check_privilege_by_sockfd failed. Result: " << ret);
178     sockfd = 0;
179
180     //null object case
181     char *object2 = nullptr;
182     ret = security_server_check_privilege_by_sockfd(sockfd, object2, access_rights);
183     RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_SUCCESS,
184             "check_privilege_by_sockfd failed. Result: " << ret);
185
186     //null access rights case
187     access_rights = nullptr;
188     ret = security_server_check_privilege_by_sockfd(sockfd, object, access_rights);
189     RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_SUCCESS,
190             "check_privilege_by_sockfd failed. Result: " << ret);
191 }
192