2 * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * @file test/common/protocols/admin/listresponse.cpp
18 * @author Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
19 * @author Pawel Wieczorek <p.wieczorek2@samsung.com>
21 * @brief Tests for Cynara::ListResponse usage in Cynara::ProtocolAdmin
26 #include <gtest/gtest.h>
28 #include <protocol/ProtocolAdmin.h>
29 #include <response/ListResponse.h>
30 #include <types/Policy.h>
32 #include <ResponseTestHelper.h>
33 #include <TestDataCollection.h>
38 void compare(const Cynara::ListResponse &resp1, const Cynara::ListResponse &resp2) {
39 EXPECT_EQ(resp1.policies(), resp2.policies());
40 EXPECT_EQ(resp1.isBucketValid(), resp2.isBucketValid());
41 EXPECT_EQ(resp1.isDbCorrupted(), resp2.isDbCorrupted());
44 static const bool VALID_BUCKET = true;
45 static const bool NO_BUCKET = false;
46 static const bool DB_OK = false;
47 static const bool DB_CORRUPTED = true;
49 } /* namespace anonymous */
51 using namespace Cynara;
52 using namespace ResponseTestHelper;
53 using namespace TestDataCollection;
55 /* *** compare by objects test cases *** */
57 TEST(ProtocolAdmin, ListResponse01) {
58 std::vector<Policy> policies = {
59 Policy(Keys::k_nun, Results::allow),
62 auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, DB_OK, SN::min);
63 auto protocol = std::make_shared<ProtocolAdmin>();
64 testResponse(response, protocol);
67 TEST(ProtocolAdmin, ListResponse02) {
68 std::vector<Policy> policies = {
69 Policy(Keys::k_cup, Results::deny),
72 auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, DB_OK, SN::min_1);
73 auto protocol = std::make_shared<ProtocolAdmin>();
74 testResponse(response, protocol);
77 TEST(ProtocolAdmin, ListResponse03) {
78 std::vector<Policy> policies = {
79 Policy(Keys::k_www, Results::bucket_empty),
82 auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, DB_OK, SN::min_2);
83 auto protocol = std::make_shared<ProtocolAdmin>();
84 testResponse(response, protocol);
87 TEST(ProtocolAdmin, ListResponse04) {
88 std::vector<Policy> policies = {
89 Policy(Keys::k_wuw, Results::bucket_not_empty),
92 auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, DB_OK, SN::max);
93 auto protocol = std::make_shared<ProtocolAdmin>();
94 testResponse(response, protocol);
97 TEST(ProtocolAdmin, ListResponse05) {
98 std::vector<Policy> policies = {
99 Policy(Keys::k_aaa, Results::none),
102 auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, DB_OK, SN::max_1);
103 auto protocol = std::make_shared<ProtocolAdmin>();
104 testResponse(response, protocol);
107 TEST(ProtocolAdmin, ListResponse06) {
108 std::vector<Policy> policies = {
109 Policy(Keys::k_wua, Results::plugin_1),
112 auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, DB_OK, SN::max_2);
113 auto protocol = std::make_shared<ProtocolAdmin>();
114 testResponse(response, protocol);
117 TEST(ProtocolAdmin, ListResponse07) {
118 std::vector<Policy> policies = {
119 Policy(Keys::k_nua, Results::plugin_2),
122 auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, DB_OK, SN::mid);
123 auto protocol = std::make_shared<ProtocolAdmin>();
124 testResponse(response, protocol);
127 TEST(ProtocolAdmin, ListResponseMultiplePolicies) {
128 std::vector<Policy> policies = {
129 Policy(Keys::k_nun, Results::allow),
130 Policy(Keys::k_cup, Results::deny),
131 Policy(Keys::k_www, Results::bucket_empty),
132 Policy(Keys::k_wuw, Results::bucket_not_empty),
133 Policy(Keys::k_aaa, Results::none),
134 Policy(Keys::k_wua, Results::plugin_1),
135 Policy(Keys::k_nua, Results::plugin_2),
138 auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, DB_OK, SN::min);
139 auto protocol = std::make_shared<ProtocolAdmin>();
140 testResponse(response, protocol);
143 TEST(ProtocolAdmin, ListResponseEmptyPolicies) {
144 std::vector<Policy> policies;
146 auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, DB_OK, SN::min_1);
147 auto protocol = std::make_shared<ProtocolAdmin>();
148 testResponse(response, protocol);
151 TEST(ProtocolAdmin, ListResponseNoBucket) {
152 std::vector<Policy> policies;
154 auto response = std::make_shared<ListResponse>(policies, NO_BUCKET, DB_OK, SN::min_2);
155 auto protocol = std::make_shared<ProtocolAdmin>();
156 testResponse(response, protocol);
160 * @brief Verify if ListResponse is properly (de)serialized while database is corrupted
161 * @test Expected result:
162 * - policies vector is empty
163 * - bucketValid flag set to false (NO_BUCKET)
164 * - dbCorrupted flag set to true (DB_CORRUPTED)
166 TEST(ProtocolAdmin, ListResponseDatabaseCorrupted) {
167 std::vector<Policy> policies;
169 auto response = std::make_shared<ListResponse>(policies, NO_BUCKET, DB_CORRUPTED, SN::max);
170 auto protocol = std::make_shared<ProtocolAdmin>();
171 testResponse(response, protocol);
174 /* *** compare by serialized data test cases *** */
176 TEST(ProtocolAdmin, ListResponseBinary01) {
177 std::vector<Policy> policies = {
178 Policy(Keys::k_nun, Results::allow),
181 auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, DB_OK, SN::min);
182 auto protocol = std::make_shared<ProtocolAdmin>();
183 binaryTestResponse(response, protocol);
186 TEST(ProtocolAdmin, ListResponseBinary02) {
187 std::vector<Policy> policies = {
188 Policy(Keys::k_cup, Results::deny),
191 auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, DB_OK, SN::min_1);
192 auto protocol = std::make_shared<ProtocolAdmin>();
193 binaryTestResponse(response, protocol);
196 TEST(ProtocolAdmin, ListResponseBinary03) {
197 std::vector<Policy> policies = {
198 Policy(Keys::k_www, Results::bucket_empty),
201 auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, DB_OK, SN::min_2);
202 auto protocol = std::make_shared<ProtocolAdmin>();
203 binaryTestResponse(response, protocol);
206 TEST(ProtocolAdmin, ListResponseBinary04) {
207 std::vector<Policy> policies = {
208 Policy(Keys::k_wuw, Results::bucket_not_empty),
211 auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, DB_OK, SN::max);
212 auto protocol = std::make_shared<ProtocolAdmin>();
213 binaryTestResponse(response, protocol);
216 TEST(ProtocolAdmin, ListResponseBinary05) {
217 std::vector<Policy> policies = {
218 Policy(Keys::k_aaa, Results::none),
221 auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, DB_OK, SN::max_1);
222 auto protocol = std::make_shared<ProtocolAdmin>();
223 binaryTestResponse(response, protocol);
226 TEST(ProtocolAdmin, ListResponseBinary06) {
227 std::vector<Policy> policies = {
228 Policy(Keys::k_wua, Results::plugin_1),
231 auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, DB_OK, SN::max_2);
232 auto protocol = std::make_shared<ProtocolAdmin>();
233 binaryTestResponse(response, protocol);
236 TEST(ProtocolAdmin, ListResponseBinary07) {
237 std::vector<Policy> policies = {
238 Policy(Keys::k_nua, Results::plugin_2),
241 auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, DB_OK, SN::mid);
242 auto protocol = std::make_shared<ProtocolAdmin>();
243 binaryTestResponse(response, protocol);
246 TEST(ProtocolAdmin, ListResponseBinaryMultiplePolicies) {
247 std::vector<Policy> policies = {
248 Policy(Keys::k_nun, Results::allow),
249 Policy(Keys::k_cup, Results::deny),
250 Policy(Keys::k_www, Results::bucket_empty),
251 Policy(Keys::k_wuw, Results::bucket_not_empty),
252 Policy(Keys::k_aaa, Results::none),
253 Policy(Keys::k_wua, Results::plugin_1),
254 Policy(Keys::k_nua, Results::plugin_2),
257 auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, DB_OK, SN::min);
258 auto protocol = std::make_shared<ProtocolAdmin>();
259 binaryTestResponse(response, protocol);
262 TEST(ProtocolAdmin, ListResponseBinaryEmptyPolicies) {
263 std::vector<Policy> policies;
265 auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, DB_OK, SN::min_1);
266 auto protocol = std::make_shared<ProtocolAdmin>();
267 binaryTestResponse(response, protocol);
270 TEST(ProtocolAdmin, ListResponseBinaryNoBucket) {
271 std::vector<Policy> policies;
273 auto response = std::make_shared<ListResponse>(policies, NO_BUCKET, DB_OK, SN::min_2);
274 auto protocol = std::make_shared<ProtocolAdmin>();
275 binaryTestResponse(response, protocol);
279 * @brief Verify if ListResponse is properly (de)serialized while database is corrupted
280 * @test Expected result:
281 * - policies vector is empty
282 * - bucketValid flag set to false (NO_BUCKET)
283 * - dbCorrupted flag set to true (DB_CORRUPTED)
285 TEST(ProtocolAdmin, ListResponseBinaryDatabaseCorrupted) {
286 std::vector<Policy> policies;
288 auto response = std::make_shared<ListResponse>(policies, NO_BUCKET, DB_CORRUPTED, SN::max);
289 auto protocol = std::make_shared<ProtocolAdmin>();
290 binaryTestResponse(response, protocol);