Remove test of security_server_get_object_name.
[platform/core/test/security-tests.git] / tests / security-server-tests / 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 #define SECURITY_SERVER_MAX_OBJ_NAME 30
17
18 RUNNER_TEST_GROUP_INIT(SECURITY_SERVER_TESTS_WEIRD_ARGUMENTS);
19
20 RUNNER_TEST(tc01_security_server_get_gid_weird_input_case)
21 {
22     int ret = 0;
23     char weird[] = {static_cast <char> (0xe3), 0x79, static_cast <char> (0x82), 0x0};
24
25     /* normal param case */
26     ret = security_server_get_gid("tel_sim");
27     RUNNER_ASSERT_MSG(ret > -1, "ret: " << ret);
28
29     /* wrong param case */
30     ret = security_server_get_gid("elephony_akecall");
31     RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_ERROR_NO_SUCH_OBJECT, "ret: " << ret);
32
33     /* weird param case */
34     ret = security_server_get_gid(weird);
35     RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_ERROR_NO_SUCH_OBJECT, "ret: " << ret);
36
37     /* null param case */
38     ret = security_server_get_gid(NULL);
39     RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_ERROR_INPUT_PARAM, "ret: " << ret);
40
41     /* param too long case */
42     ret = security_server_get_gid("abcdefghijklmnopqrstuvwxyz01234");
43     RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_ERROR_INPUT_PARAM, "ret: " << ret);
44
45     /* empty param case */
46     ret = security_server_get_gid("");
47     RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_ERROR_INPUT_PARAM, "ret: " << ret);
48 }
49
50 /* from security_server_tests_server.cpp */
51
52 RUNNER_TEST(tc03_security_server_request_cookie_weird_input_case)
53 {
54     int ret = 0;
55     size_t cookie_size = security_server_get_cookie_size();
56
57     /* null cookie case */
58     char *cookie = NULL;
59
60     ret = security_server_request_cookie(cookie, cookie_size);
61     RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_ERROR_INPUT_PARAM, "ret: " << ret);
62
63     /* buffer size too small case */
64     cookie_size = 19;
65     char cookie2[cookie_size];
66
67     ret = security_server_request_cookie(cookie2, cookie_size);
68     RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_ERROR_BUFFER_TOO_SMALL, "ret: " << ret);
69 }
70
71 RUNNER_TEST(tc04_security_server_check_privilege_weird_input_case)
72 {
73     int ret = 0;
74     size_t cookie_size = security_server_get_cookie_size();
75     gid_t gid = DB_ALARM_GID;
76
77     /* null cookie case */
78     char *cookie = NULL;
79
80     ret = security_server_check_privilege(cookie, gid);
81     RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_ERROR_INPUT_PARAM, "ret: " << ret);
82
83     char cookie2[cookie_size];
84
85     ret = security_server_request_cookie(cookie2, cookie_size);
86     RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_SUCCESS, "ret: " << ret);
87
88     /* big gid case */
89     gid = 70666;
90
91     ret = security_server_check_privilege(cookie2, gid);
92     RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_ERROR_ACCESS_DENIED, "ret: " << ret);
93 }
94 RUNNER_TEST(tc05_security_server_check_privilege_by_cookie_weird_input_case)
95 {
96     int ret = 0;
97     size_t cookie_size = security_server_get_cookie_size();;
98     const char *object = "telephony_makecall";
99     const char *access_rights = "r";
100
101     /* null cookie case */
102     char *cookie = NULL;
103     ret = security_server_check_privilege_by_cookie(cookie, object, access_rights);
104     RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_ERROR_INPUT_PARAM, "ret: " << ret);
105
106     /* null object case */
107     char *object2 = NULL;
108     char cookie2[cookie_size];
109
110     ret = security_server_request_cookie(cookie2, cookie_size);
111     RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_SUCCESS, "ret: " << ret);
112
113     ret = security_server_check_privilege_by_cookie(cookie2, object2, access_rights);
114     RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_ERROR_INPUT_PARAM, "ret: " << ret);
115
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(ret == SECURITY_SERVER_API_ERROR_INPUT_PARAM, "ret: " << ret);
120 }
121
122 RUNNER_TEST_SMACK(tc06_security_server_check_privilege_by_sockfd_weird_input_case)
123 {
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 = NULL;
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 = NULL;
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 = NULL;
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     int ret = 0;
169     int sockfd = -1;
170     const char* object = "telephony_makecall";
171     const char* access_rights = "r";
172
173     //invalid sockfd case
174     ret = security_server_check_privilege_by_sockfd(sockfd, object, access_rights);
175     RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_SUCCESS,
176             "check_privilege_by_sockfd failed. Result: " << ret);
177     sockfd = 0;
178
179     //null object case
180     char *object2 = NULL;
181     ret = security_server_check_privilege_by_sockfd(sockfd, object2, access_rights);
182     RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_SUCCESS,
183             "check_privilege_by_sockfd failed. Result: " << ret);
184
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(ret == SECURITY_SERVER_API_SUCCESS,
189             "check_privilege_by_sockfd failed. Result: " << ret);
190 }