PageRenderTime 46ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/test/cyad/policy_collection.cpp

https://gitlab.com/github-cloud-corporation/cynara
C++ | 68 lines | 34 code | 13 blank | 21 comment | 0 complexity | 0993c7d3d02aad26cd76461badceb51e MD5 | raw file
  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. #include <exception>
  23. #include <memory>
  24. #include <gmock/gmock.h>
  25. #include <gtest/gtest.h>
  26. #include <cynara-admin-types.h>
  27. #include <cynara-policy-types.h>
  28. #include <cyad/CynaraAdminPolicies.h>
  29. #include "helpers.h"
  30. TEST(CynaraAdminPolicies, notSealed) {
  31. Cynara::CynaraAdminPolicies policies;
  32. ASSERT_THROW(policies.data(), std::logic_error);
  33. }
  34. TEST(CynaraAdminPolicies, sealEmpty) {
  35. Cynara::CynaraAdminPolicies policies;
  36. policies.seal();
  37. ASSERT_EQ(nullptr, policies.data()[0]);
  38. }
  39. TEST(CynaraAdminPolicies, addToSealed) {
  40. Cynara::CynaraAdminPolicies policies;
  41. policies.seal();
  42. ASSERT_THROW(policies.add("", { CYNARA_ADMIN_ALLOW, "" }, { "", "", ""} ), std::logic_error);
  43. }
  44. TEST(CynaraAdminPolicies, addOne) {
  45. using ::testing::ElementsAreArray;
  46. Cynara::CynaraAdminPolicies policies;
  47. policies.add("test-bucket", { CYNARA_ADMIN_ALLOW, "" }, { "client", "user", "privilege"} );
  48. policies.seal();
  49. ASSERT_NO_THROW(policies.data());
  50. cynara_admin_policy policy = { strdup("test-bucket"), strdup("client"), strdup("user"),
  51. strdup("privilege"), CYNARA_ADMIN_ALLOW, nullptr };
  52. ASSERT_EQ(policy, *policies.data()[0]);
  53. ASSERT_EQ(nullptr, policies.data()[1]);
  54. Cynara::Helpers::freeAdminPolicyMembers(&policy);
  55. }