Introduce 'default' method type for credential helpers
[platform/core/security/cynara.git] / test / cyad / policy_collection.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
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  * @file        test/cyad/policy_collection.cpp
18  * @author      Aleksander Zdyb <a.zdyb@samsung.com>
19  * @version     1.0
20  * @brief       Tests for CynaraAdminPolicies
21  */
22
23 #include <exception>
24 #include <memory>
25
26 #include <gmock/gmock.h>
27 #include <gtest/gtest.h>
28
29 #include <cynara-admin-types.h>
30 #include <cynara-policy-types.h>
31
32 #include <cyad/CynaraAdminPolicies.h>
33
34 #include "helpers.h"
35
36 TEST(CynaraAdminPolicies, notSealed) {
37     Cynara::CynaraAdminPolicies policies;
38     ASSERT_THROW(policies.data(), std::logic_error);
39 }
40
41 TEST(CynaraAdminPolicies, sealEmpty) {
42     Cynara::CynaraAdminPolicies policies;
43     policies.seal();
44     ASSERT_EQ(nullptr, policies.data()[0]);
45 }
46
47 TEST(CynaraAdminPolicies, addToSealed) {
48     Cynara::CynaraAdminPolicies policies;
49     policies.seal();
50     ASSERT_THROW(policies.add("", { CYNARA_ADMIN_ALLOW, "" }, { "", "", ""} ), std::logic_error);
51 }
52
53 TEST(CynaraAdminPolicies, addOne) {
54     using ::testing::ElementsAreArray;
55
56     Cynara::CynaraAdminPolicies policies;
57     policies.add("test-bucket", { CYNARA_ADMIN_ALLOW, "" }, { "client", "user", "privilege"} );
58     policies.seal();
59     ASSERT_NO_THROW(policies.data());
60
61     cynara_admin_policy policy = { strdup("test-bucket"), strdup("client"), strdup("user"),
62                                    strdup("privilege"), CYNARA_ADMIN_ALLOW, nullptr };
63
64     ASSERT_EQ(policy, *policies.data()[0]);
65     ASSERT_EQ(nullptr, policies.data()[1]);
66
67     Cynara::Helpers::freeAdminPolicyMembers(&policy);
68 }