/test/storage/inmemorystoragebackend/search.cpp

https://gitlab.com/admin-github-cloud/cynara · C++ · 65 lines · 31 code · 12 blank · 22 comment · 0 complexity · b39d5d3b149e688b670424b85e88895e MD5 · raw file

  1. /*
  2. * Copyright (c) 2014-2015 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/storage/inmemorystoragebackend/search.cpp
  18. * @author Aleksander Zdyb <a.zdyb@samsung.com>
  19. * @version 1.0
  20. * @brief Tests of search in InMemoryStorageBackend
  21. */
  22. #include <memory>
  23. #include "gmock/gmock.h"
  24. #include "gtest/gtest.h"
  25. #include "types/PolicyBucket.h"
  26. #include "../../helpers.h"
  27. #include "fakeinmemorystoragebackend.h"
  28. #include "inmemorystoragebackendfixture.h"
  29. using namespace Cynara;
  30. TEST_F(InMemoryStorageBackendFixture, searchDefault) {
  31. using ::testing::ReturnRef;
  32. using ::testing::UnorderedElementsAreArray;
  33. using ::testing::IsEmpty;
  34. auto pk1 = Helpers::generatePolicyKey("1");
  35. auto pk2 = Helpers::generatePolicyKey("2");
  36. auto pk3 = PolicyKey(PolicyKeyFeature::createWildcard(), pk1.user(), pk1.privilege());
  37. auto otherPk = Helpers::generatePolicyKey("-");
  38. PolicyCollection policies = {
  39. Policy::simpleWithKey(pk1, PredefinedPolicyType::ALLOW),
  40. Policy::simpleWithKey(pk2, PredefinedPolicyType::DENY),
  41. Policy::simpleWithKey(pk3, PredefinedPolicyType::DENY),
  42. };
  43. createBucket(defaultPolicyBucketId, policies);
  44. // Just override buckets() accessor
  45. FakeInMemoryStorageBackend backend(m_fakeDbPath);
  46. EXPECT_CALL(backend, buckets())
  47. .WillRepeatedly(ReturnRef(m_buckets));
  48. auto policiesToStay1 = Helpers::pickFromCollection(policies, { 0, 2 });
  49. auto policiesToStay2 = Helpers::pickFromCollection(policies, { 1 });
  50. ASSERT_THAT(backend.searchDefaultBucket(pk1), UnorderedElementsAreArray(policiesToStay1));
  51. ASSERT_THAT(backend.searchDefaultBucket(pk2), UnorderedElementsAreArray(policiesToStay2));
  52. ASSERT_THAT(backend.searchDefaultBucket(otherPk), IsEmpty());
  53. }