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 #define SECURITY_SERVER_MAX_OBJ_NAME 30
18 RUNNER_TEST_GROUP_INIT(SECURITY_SERVER_TESTS_WEIRD_ARGUMENTS);
20 RUNNER_TEST(tc01_security_server_get_gid_weird_input_case)
23 char weird[] = {static_cast <char> (0xe3), 0x79, static_cast <char> (0x82), 0x0};
25 /* normal param case */
26 ret = security_server_get_gid("tel_sim");
27 RUNNER_ASSERT_MSG_BT(ret > -1, "ret: " << ret);
29 /* wrong param case */
30 ret = security_server_get_gid("elephony_akecall");
31 RUNNER_ASSERT_MSG_BT(ret == SECURITY_SERVER_API_ERROR_NO_SUCH_OBJECT, "ret: " << ret);
33 /* weird param case */
34 ret = security_server_get_gid(weird);
35 RUNNER_ASSERT_MSG_BT(ret == SECURITY_SERVER_API_ERROR_NO_SUCH_OBJECT, "ret: " << ret);
38 ret = security_server_get_gid(NULL);
39 RUNNER_ASSERT_MSG_BT(ret == SECURITY_SERVER_API_ERROR_INPUT_PARAM, "ret: " << ret);
41 /* param too long case */
42 ret = security_server_get_gid("abcdefghijklmnopqrstuvwxyz01234");
43 RUNNER_ASSERT_MSG_BT(ret == SECURITY_SERVER_API_ERROR_INPUT_PARAM, "ret: " << ret);
45 /* empty param case */
46 ret = security_server_get_gid("");
47 RUNNER_ASSERT_MSG_BT(ret == SECURITY_SERVER_API_ERROR_INPUT_PARAM, "ret: " << ret);
50 /* from security_server_tests_server.cpp */
52 RUNNER_TEST(tc03_security_server_request_cookie_weird_input_case)
55 size_t cookie_size = security_server_get_cookie_size();
57 /* null cookie case */
60 ret = security_server_request_cookie(cookie, cookie_size);
61 RUNNER_ASSERT_MSG_BT(ret == SECURITY_SERVER_API_ERROR_INPUT_PARAM, "ret: " << ret);
63 /* buffer size too small case */
65 char cookie2[cookie_size];
67 ret = security_server_request_cookie(cookie2, cookie_size);
68 RUNNER_ASSERT_MSG_BT(ret == SECURITY_SERVER_API_ERROR_BUFFER_TOO_SMALL, "ret: " << ret);
71 RUNNER_TEST(tc04_security_server_check_privilege_weird_input_case)
74 size_t cookie_size = security_server_get_cookie_size();
75 gid_t gid = DB_ALARM_GID;
77 /* null cookie case */
80 ret = security_server_check_privilege(cookie, gid);
81 RUNNER_ASSERT_MSG_BT(ret == SECURITY_SERVER_API_ERROR_INPUT_PARAM, "ret: " << ret);
83 char cookie2[cookie_size];
85 ret = security_server_request_cookie(cookie2, cookie_size);
86 RUNNER_ASSERT_MSG_BT(ret == SECURITY_SERVER_API_SUCCESS, "ret: " << ret);
91 ret = security_server_check_privilege(cookie2, gid);
92 RUNNER_ASSERT_MSG_BT(ret == SECURITY_SERVER_API_ERROR_ACCESS_DENIED, "ret: " << ret);
94 RUNNER_TEST(tc05_security_server_check_privilege_by_cookie_weird_input_case)
97 size_t cookie_size = security_server_get_cookie_size();;
98 const char *object = "telephony_makecall";
99 const char *access_rights = "r";
101 /* null cookie case */
103 ret = security_server_check_privilege_by_cookie(cookie, object, access_rights);
104 RUNNER_ASSERT_MSG_BT(ret == SECURITY_SERVER_API_ERROR_INPUT_PARAM, "ret: " << ret);
106 /* null object case */
107 char *object2 = NULL;
108 char cookie2[cookie_size];
110 ret = security_server_request_cookie(cookie2, cookie_size);
111 RUNNER_ASSERT_MSG_BT(ret == SECURITY_SERVER_API_SUCCESS, "ret: " << ret);
113 ret = security_server_check_privilege_by_cookie(cookie2, object2, access_rights);
114 RUNNER_ASSERT_MSG_BT(ret == SECURITY_SERVER_API_ERROR_INPUT_PARAM, "ret: " << ret);
116 /* null access rights case */
117 access_rights = NULL;
118 ret = security_server_check_privilege_by_cookie(cookie2, object, access_rights);
119 RUNNER_ASSERT_MSG_BT(ret == SECURITY_SERVER_API_ERROR_INPUT_PARAM, "ret: " << ret);
122 RUNNER_TEST_SMACK(tc06_security_server_check_privilege_by_sockfd_weird_input_case)
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_BT(ret == SECURITY_SERVER_API_ERROR_INPUT_PARAM, "ret: " << ret);
134 /* null object case */
135 char *object2 = NULL;
136 ret = security_server_check_privilege_by_sockfd(sockfd, object2, access_rights);
137 RUNNER_ASSERT_MSG_BT(ret == SECURITY_SERVER_API_ERROR_INPUT_PARAM, "ret: " << ret);
139 /* null access rights case */
140 access_rights = NULL;
141 ret = security_server_check_privilege_by_sockfd(sockfd, object, access_rights);
142 RUNNER_ASSERT_MSG_BT(ret == SECURITY_SERVER_API_ERROR_INPUT_PARAM, "ret: " << ret);
145 RUNNER_TEST(tc07_security_server_get_cookie_pid_weird_input_case)
150 ret = security_server_get_cookie_pid(cookie);
151 RUNNER_ASSERT_BT(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)
170 const char* object = "telephony_makecall";
171 const char* access_rights = "r";
173 //invalid sockfd case
174 ret = security_server_check_privilege_by_sockfd(sockfd, object, access_rights);
175 RUNNER_ASSERT_MSG_BT(ret == SECURITY_SERVER_API_SUCCESS,
176 "check_privilege_by_sockfd failed. Result: " << ret);
180 char *object2 = NULL;
181 ret = security_server_check_privilege_by_sockfd(sockfd, object2, access_rights);
182 RUNNER_ASSERT_MSG_BT(ret == SECURITY_SERVER_API_SUCCESS,
183 "check_privilege_by_sockfd failed. Result: " << ret);
185 //null access rights case
186 access_rights = NULL;
187 ret = security_server_check_privilege_by_sockfd(sockfd, object, access_rights);
188 RUNNER_ASSERT_MSG_BT(ret == SECURITY_SERVER_API_SUCCESS,
189 "check_privilege_by_sockfd failed. Result: " << ret);