Add cynara invalid params tests
[platform/core/test/security-tests.git] / tests / cynara-tests / test_cases.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd
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      Aleksander Zdyb <a.zdyb@partner.samsung.com>
20  * @author      Marcin Niesluchowski <m.niesluchow@samsung.com>
21  * @version     1.1
22  * @brief       Tests for libcynara-client and libcynara-admin
23  */
24
25 #include <tests_common.h>
26 #include <cynara_test_client.h>
27 #include <cynara_test_admin.h>
28
29 #include <climits>
30
31 RUNNER_TEST_GROUP_INIT(cynara_tests)
32
33 RUNNER_TEST(tc01_cynara_initialize) {
34     CynaraTestClient cynara;
35 }
36
37 RUNNER_TEST(tc02_admin_initialize) {
38     CynaraTestAdmin admin;
39 }
40
41 RUNNER_TEST(tc03_cynara_check_invalid_params) {
42     CynaraTestClient cynara;
43
44     const char *client = "client03";
45     const char *user = "user03";
46     const char *privilege = "privilege03";
47     const char *session = "session03";
48
49     cynara.check(nullptr, session, user,    privilege, CYNARA_API_INVALID_PARAM);
50     cynara.check(client,  nullptr, user,    privilege, CYNARA_API_INVALID_PARAM);
51     cynara.check(client,  session, nullptr, privilege, CYNARA_API_INVALID_PARAM);
52     cynara.check(client,  session, user,    nullptr,   CYNARA_API_INVALID_PARAM);
53 }
54
55 void checkInvalidPolicy(CynaraTestAdmin &admin,
56                         const char *bucket,
57                         const char *client,
58                         const char *user,
59                         const char *privilege,
60                         const int result,
61                         const char *resultExtra)
62 {
63     CynaraPoliciesContainer cp;
64     cp.add(bucket, client, user, privilege, result, resultExtra);
65
66     admin.setPolicies(cp, CYNARA_ADMIN_API_INVALID_PARAM);
67 }
68
69 RUNNER_TEST(tc04_admin_set_policies_invalid_params) {
70     CynaraTestAdmin admin;
71
72     const char *bucket = CYNARA_ADMIN_DEFAULT_BUCKET;
73     const char *client = "client04";
74     const char *user = "user04";
75     const char *privilege = "privilege04";
76     const int resultAllow = CYNARA_ADMIN_ALLOW;
77     const int resultBucket = CYNARA_ADMIN_BUCKET;
78     const char *resultExtra = nullptr;
79
80     checkInvalidPolicy(admin, nullptr, client,  user,    privilege, resultAllow,  resultExtra);
81     checkInvalidPolicy(admin, bucket,  nullptr, user,    privilege, resultAllow,  resultExtra);
82     checkInvalidPolicy(admin, bucket,  client,  nullptr, privilege, resultAllow,  resultExtra);
83     checkInvalidPolicy(admin, bucket,  client,  user,    nullptr,   resultAllow,  resultExtra);
84     checkInvalidPolicy(admin, bucket,  client,  user,    privilege, INT_MAX,      resultExtra);
85     checkInvalidPolicy(admin, bucket,  client,  user,    privilege, resultBucket, nullptr    );
86 }
87
88 RUNNER_TEST(tc05_admin_set_bucket_invalid_params) {
89     CynaraTestAdmin admin;
90
91     const char *bucket = CYNARA_ADMIN_DEFAULT_BUCKET;
92     const int operationAllow = CYNARA_ADMIN_ALLOW;
93     const int operationDelete = CYNARA_ADMIN_DELETE;
94     const char *extra = nullptr;
95
96     admin.setBucket(nullptr, operationAllow,   extra, CYNARA_ADMIN_API_INVALID_PARAM);
97     admin.setBucket(bucket,  INT_MAX,          extra, CYNARA_ADMIN_API_INVALID_PARAM);
98     admin.setBucket(bucket,  operationDelete,  extra, CYNARA_ADMIN_API_OPERATION_NOT_ALLOWED);
99 }