/test/common/protocols/admin/admincheckresponse.cpp

https://gitlab.com/github-cloud-corporation/cynara · C++ · 180 lines · 116 code · 26 blank · 38 comment · 0 complexity · 03db38687aba8888d5ebcc04565cdb16 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/common/protocols/admin/admincheckresponse.cpp
  18. * @author Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
  19. * @author Pawel Wieczorek <p.wieczorek2@samsung.com>
  20. * @version 1.0
  21. * @brief Tests for Cynara::AdminCheckResponse usage in Cynara::ProtocolAdmin
  22. */
  23. #include <gtest/gtest.h>
  24. #include <protocol/ProtocolAdmin.h>
  25. #include <response/AdminCheckResponse.h>
  26. #include <ResponseTestHelper.h>
  27. #include <TestDataCollection.h>
  28. namespace {
  29. template<>
  30. void compare(const Cynara::AdminCheckResponse &resp1, const Cynara::AdminCheckResponse &resp2) {
  31. EXPECT_EQ(resp1.result(), resp2.result());
  32. EXPECT_EQ(resp1.isBucketValid(), resp2.isBucketValid());
  33. EXPECT_EQ(resp1.isDbCorrupted(), resp2.isDbCorrupted());
  34. }
  35. static const bool VALID_BUCKET = true;
  36. static const bool NO_BUCKET = false;
  37. static const bool DB_OK = false;
  38. static const bool DB_CORRUPTED = true;
  39. } /* anonymous namespace */
  40. using namespace Cynara;
  41. using namespace ResponseTestHelper;
  42. using namespace TestDataCollection;
  43. /* *** compare by objects test cases *** */
  44. TEST(ProtocolAdmin, AdminCheckResponse01) {
  45. auto response = std::make_shared<AdminCheckResponse>(Results::allow, VALID_BUCKET, DB_OK,
  46. SN::min);
  47. auto protocol = std::make_shared<ProtocolAdmin>();
  48. testResponse(response, protocol);
  49. }
  50. TEST(ProtocolAdmin, AdminCheckResponse02) {
  51. auto response = std::make_shared<AdminCheckResponse>(Results::deny, NO_BUCKET, DB_OK,
  52. SN::min_1);
  53. auto protocol = std::make_shared<ProtocolAdmin>();
  54. testResponse(response, protocol);
  55. }
  56. TEST(ProtocolAdmin, AdminCheckResponse03) {
  57. auto response = std::make_shared<AdminCheckResponse>(Results::bucket_empty, VALID_BUCKET, DB_OK,
  58. SN::min_2);
  59. auto protocol = std::make_shared<ProtocolAdmin>();
  60. testResponse(response, protocol);
  61. }
  62. TEST(ProtocolAdmin, AdminCheckResponse04) {
  63. auto response = std::make_shared<AdminCheckResponse>(Results::bucket_not_empty, NO_BUCKET,
  64. DB_OK, SN::max);
  65. auto protocol = std::make_shared<ProtocolAdmin>();
  66. testResponse(response, protocol);
  67. }
  68. TEST(ProtocolAdmin, AdminCheckResponse05) {
  69. auto response = std::make_shared<AdminCheckResponse>(Results::none, VALID_BUCKET, DB_OK,
  70. SN::max_1);
  71. auto protocol = std::make_shared<ProtocolAdmin>();
  72. testResponse(response, protocol);
  73. }
  74. TEST(ProtocolAdmin, AdminCheckResponse06) {
  75. auto response = std::make_shared<AdminCheckResponse>(Results::plugin_1, NO_BUCKET, DB_OK,
  76. SN::max_2);
  77. auto protocol = std::make_shared<ProtocolAdmin>();
  78. testResponse(response, protocol);
  79. }
  80. TEST(ProtocolAdmin, AdminCheckResponse07) {
  81. auto response = std::make_shared<AdminCheckResponse>(Results::plugin_2, VALID_BUCKET, DB_OK,
  82. SN::mid);
  83. auto protocol = std::make_shared<ProtocolAdmin>();
  84. testResponse(response, protocol);
  85. }
  86. /**
  87. * @brief Verify if AdminCheckResponse is properly (de)serialized while database is corrupted
  88. * @test Expected result:
  89. * - PolicyResult set to DENY
  90. * - bucketValid flag set to false (NO_BUCKET)
  91. * - dbCorrupted flag set to true (DB_CORRUPTED)
  92. */
  93. TEST(ProtocolAdmin, AdminCheckResponse08) {
  94. auto response = std::make_shared<AdminCheckResponse>(Results::deny, NO_BUCKET, DB_CORRUPTED,
  95. SN::max);
  96. auto protocol = std::make_shared<ProtocolAdmin>();
  97. testResponse(response, protocol);
  98. }
  99. /* *** compare by serialized data test cases *** */
  100. TEST(ProtocolAdmin, AdminCheckResponseBinary01) {
  101. auto response = std::make_shared<AdminCheckResponse>(Results::allow, VALID_BUCKET, DB_OK,
  102. SN::min);
  103. auto protocol = std::make_shared<ProtocolAdmin>();
  104. binaryTestResponse(response, protocol);
  105. }
  106. TEST(ProtocolAdmin, AdminCheckResponseBinary02) {
  107. auto response = std::make_shared<AdminCheckResponse>(Results::deny, NO_BUCKET, DB_OK,
  108. SN::min_1);
  109. auto protocol = std::make_shared<ProtocolAdmin>();
  110. binaryTestResponse(response, protocol);
  111. }
  112. TEST(ProtocolAdmin, AdminCheckResponseBinary03) {
  113. auto response = std::make_shared<AdminCheckResponse>(Results::bucket_empty, VALID_BUCKET, DB_OK,
  114. SN::min_2);
  115. auto protocol = std::make_shared<ProtocolAdmin>();
  116. binaryTestResponse(response, protocol);
  117. }
  118. TEST(ProtocolAdmin, AdminCheckResponseBinary04) {
  119. auto response = std::make_shared<AdminCheckResponse>(Results::bucket_not_empty, NO_BUCKET,
  120. DB_OK, SN::max);
  121. auto protocol = std::make_shared<ProtocolAdmin>();
  122. binaryTestResponse(response, protocol);
  123. }
  124. TEST(ProtocolAdmin, AdminCheckResponseBinary05) {
  125. auto response = std::make_shared<AdminCheckResponse>(Results::none, VALID_BUCKET, DB_OK,
  126. SN::max_1);
  127. auto protocol = std::make_shared<ProtocolAdmin>();
  128. binaryTestResponse(response, protocol);
  129. }
  130. TEST(ProtocolAdmin, AdminCheckResponseBinary06) {
  131. auto response = std::make_shared<AdminCheckResponse>(Results::plugin_1, NO_BUCKET, DB_OK,
  132. SN::max_2);
  133. auto protocol = std::make_shared<ProtocolAdmin>();
  134. binaryTestResponse(response, protocol);
  135. }
  136. TEST(ProtocolAdmin, AdminCheckResponseBinary07) {
  137. auto response = std::make_shared<AdminCheckResponse>(Results::plugin_2, VALID_BUCKET, DB_OK,
  138. SN::mid);
  139. auto protocol = std::make_shared<ProtocolAdmin>();
  140. binaryTestResponse(response, protocol);
  141. }
  142. /**
  143. * @brief Verify if AdminCheckResponse is properly (de)serialized while database is corrupted
  144. * @test Expected result:
  145. * - PolicyResult set to DENY
  146. * - bucketValid flag set to false (NO_BUCKET)
  147. * - dbCorrupted flag set to true (DB_CORRUPTED)
  148. */
  149. TEST(ProtocolAdmin, AdminCheckResponseBinary08) {
  150. auto response = std::make_shared<AdminCheckResponse>(Results::deny, NO_BUCKET, DB_CORRUPTED,
  151. SN::max);
  152. auto protocol = std::make_shared<ProtocolAdmin>();
  153. binaryTestResponse(response, protocol);
  154. }