2 * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
5 * @file security_server_tests_weird_arguments.cpp
6 * @author Zbigniew Jasinski (z.jasinski@samsung.com)
8 * @brief Test cases for security server
11 #include "tests_common.h"
12 #include "security-server.h"
13 #include <dpl/test/test_runner.h>
14 #include <dpl/log/log.h>
16 RUNNER_TEST_GROUP_INIT(SECURITY_SERVER_TESTS_WEIRD_ARGUMENTS);
18 RUNNER_TEST(tc01_security_server_get_gid_weird_input_case)
21 char weird[] = {static_cast <char> (0xe3), 0x79, static_cast <char> (0x82), 0x0};
23 /* normal param case */
24 ret = security_server_get_gid("tel_sim");
25 RUNNER_ASSERT_MSG(ret > -1, "ret: " << ret);
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);
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);
36 ret = security_server_get_gid(nullptr);
37 RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_ERROR_INPUT_PARAM, "ret: " << ret);
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);
43 /* empty param case */
44 ret = security_server_get_gid("");
45 RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_ERROR_INPUT_PARAM, "ret: " << ret);
48 /* from security_server_tests_server.cpp */
50 RUNNER_TEST(tc03_security_server_request_cookie_weird_input_case)
53 size_t cookie_size = security_server_get_cookie_size();
55 /* null cookie case */
56 char *cookie = nullptr;
58 ret = security_server_request_cookie(cookie, cookie_size);
59 RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_ERROR_INPUT_PARAM, "ret: " << ret);
61 /* buffer size too small case */
63 char cookie2[cookie_size];
65 ret = security_server_request_cookie(cookie2, cookie_size);
66 RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_ERROR_BUFFER_TOO_SMALL, "ret: " << ret);
69 RUNNER_TEST(tc04_security_server_check_privilege_weird_input_case)
72 size_t cookie_size = security_server_get_cookie_size();
73 gid_t gid = DB_ALARM_GID;
75 /* null cookie case */
76 char *cookie = nullptr;
78 ret = security_server_check_privilege(cookie, gid);
79 RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_ERROR_INPUT_PARAM, "ret: " << ret);
81 char cookie2[cookie_size];
83 ret = security_server_request_cookie(cookie2, cookie_size);
84 RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_SUCCESS, "ret: " << ret);
89 ret = security_server_check_privilege(cookie2, gid);
90 RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_ERROR_ACCESS_DENIED, "ret: " << ret);
92 RUNNER_TEST(tc05_security_server_check_privilege_by_cookie_weird_input_case)
94 RUNNER_IGNORED_MSG("security_server_check_privilege_by_cookie is temporarily disabled: always returns success");
96 size_t cookie_size = security_server_get_cookie_size();;
97 const char *object = "telephony_makecall";
98 const char *access_rights = "r";
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);
105 /* null object case */
106 char *object2 = nullptr;
107 char cookie2[cookie_size];
109 ret = security_server_request_cookie(cookie2, cookie_size);
110 RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_SUCCESS, "ret: " << ret);
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);
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);
121 RUNNER_TEST_SMACK(tc06_security_server_check_privilege_by_sockfd_weird_input_case)
123 RUNNER_IGNORED_MSG("security_server_check_privilege_by_sockfd is temporarily disabled: always returns success");
126 const char *object = "telephony_makecall";
127 const char *access_rights = "r";
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);
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);
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);
145 RUNNER_TEST(tc07_security_server_get_cookie_pid_weird_input_case)
148 char *cookie = nullptr;
150 ret = security_server_get_cookie_pid(cookie);
151 RUNNER_ASSERT(ret == SECURITY_SERVER_API_ERROR_INPUT_PARAM);
154 ///////////////////////////
155 /////NOSMACK ENV TESTS/////
156 ///////////////////////////
159 * NOSMACK version of tc06 test.
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
166 RUNNER_TEST_NOSMACK(tc06_security_server_check_privilege_by_sockfd_weird_input_case_nosmack)
168 RUNNER_IGNORED_MSG("security_server_check_privilege_by_sockfd is temporarily disabled: always returns success");
171 const char* object = "telephony_makecall";
172 const char* access_rights = "r";
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);
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);
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);