2 * Copyright (c) 2014 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 policybucket.cpp
18 * @author Aleksander Zdyb <a.zdyb@partner.samsung.com>
20 * @brief Tests for Cynara::PolicyBucket
23 #include <gtest/gtest.h>
24 #include <gmock/gmock.h>
26 #include "common/types/PolicyBucket.h"
27 #include "common/types/PolicyKey.h"
28 #include "common/types/PolicyCollection.h"
30 #include "../../helpers.h"
32 using namespace Cynara;
34 class PolicyBucketFixture : public ::testing::Test {
36 virtual ~PolicyBucketFixture() {}
39 const PolicyKey pk1 = Helpers::generatePolicyKey("1");
40 const PolicyKey otherPk = Helpers::generatePolicyKey("_");
42 const PolicyCollection pk1Policies = {
43 Policy::simpleWithKey(pk1, PredefinedPolicyType::ALLOW),
44 Policy::simpleWithKey(pk1, PredefinedPolicyType::ALLOW),
45 Policy::simpleWithKey(pk1, PredefinedPolicyType::ALLOW)
49 TEST_F(PolicyBucketFixture, filtered) {
50 using ::testing::UnorderedElementsAreArray;
51 using ::testing::UnorderedElementsAre;
52 using ::testing::IsEmpty;
54 PolicyBucket bucket(pk1Policies);
55 bucket.setDefaultPolicy(PredefinedPolicyType::DENY);
56 auto filtered = bucket.filtered(pk1);
59 ASSERT_THAT(filtered.policyCollection(), UnorderedElementsAreArray(pk1Policies));
61 // default policy matches
62 ASSERT_EQ(PredefinedPolicyType::DENY, filtered.defaultPolicy());
65 TEST_F(PolicyBucketFixture, filtered_other) {
66 using ::testing::UnorderedElementsAreArray;
67 using ::testing::UnorderedElementsAre;
68 using ::testing::IsEmpty;
70 PolicyBucket bucket(pk1Policies);
71 bucket.setDefaultPolicy(PredefinedPolicyType::DENY);
72 auto filtered = bucket.filtered(otherPk);
74 // No policies should be found
75 ASSERT_THAT(filtered.policyCollection(), IsEmpty());
77 // default policy should be preserved
78 ASSERT_EQ(PredefinedPolicyType::DENY, filtered.defaultPolicy());