Prepare service for database corruption handling 21/36221/5
authorPawel Wieczorek <p.wieczorek2@samsung.com>
Wed, 4 Feb 2015 14:05:30 +0000 (15:05 +0100)
committerPawel Wieczorek <p.wieczorek2@samsung.com>
Thu, 5 Mar 2015 10:01:10 +0000 (11:01 +0100)
When database corruption is detected, no administrative actions are
allowed and all responses to check requests are DENY. Administrative API
has to be informed about detected corruption. This patch modifies
protocol so that this information is passed.

Unit tests are also adjusted to the protocol changes this patch
introduces.

Change-Id: If3ab5d6ca1671167890956b986a4768cc828f3f5

src/common/protocol/ProtocolAdmin.cpp
src/common/response/AdminCheckResponse.h
src/common/response/CodeResponse.h
src/common/response/DescriptionListResponse.h
src/common/response/ListResponse.h
src/service/logic/Logic.cpp
src/service/logic/Logic.h
test/common/protocols/admin/admincheckresponse.cpp
test/common/protocols/admin/descriptionlistresponse.cpp
test/common/protocols/admin/listresponse.cpp

index 238374b..35eedd8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *    Licensed under the Apache License, Version 2.0 (the "License");
  *    you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
  * @file        src/common/protocol/ProtocolAdmin.cpp
  * @author      Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
  * @author      Adam Malinowski <a.malinowsk2@partner.samsung.com>
+ * @author      Pawel Wieczorek <p.wieczorek2@samsung.com>
  * @version     1.0
  * @brief       This file implements protocol class for administration
  */
@@ -233,17 +234,20 @@ ResponsePtr ProtocolAdmin::deserializeAdminCheckResponse(void) {
     PolicyType result;
     PolicyResult::PolicyMetadata additionalInfo;
     bool bucketValid;
+    bool dbCorrupted;
 
     ProtocolDeserialization::deserialize(m_frameHeader, result);
     ProtocolDeserialization::deserialize(m_frameHeader, additionalInfo);
     ProtocolDeserialization::deserialize(m_frameHeader, bucketValid);
+    ProtocolDeserialization::deserialize(m_frameHeader, dbCorrupted);
 
     const PolicyResult policyResult(result, additionalInfo);
 
-    LOGD("Deserialized AdminCheckResponse: result [%" PRIu16 "], metadata <%s>, bucketValid [%d]",
-         policyResult.policyType(), policyResult.metadata().c_str(), static_cast<int>(bucketValid));
+    LOGD("Deserialized AdminCheckResponse: result [%" PRIu16 "], metadata <%s>, bucketValid [%d], "
+         "dbCorrupted [%d]", policyResult.policyType(), policyResult.metadata().c_str(),
+         static_cast<int>(bucketValid), static_cast<int>(dbCorrupted));
 
-    return std::make_shared<AdminCheckResponse>(policyResult, bucketValid,
+    return std::make_shared<AdminCheckResponse>(policyResult, bucketValid, dbCorrupted,
                                                 m_frameHeader.sequenceNumber());
 }
 
@@ -269,10 +273,14 @@ ResponsePtr ProtocolAdmin::deserializeDescriptionListResponse(void) {
         ProtocolDeserialization::deserialize(m_frameHeader, descriptions[fields].name);
     }
 
-    LOGD("Deserialized DescriptionListResponse: number of descriptions [%" PRIu16 "]",
-         descriptionsCount);
+    bool dbCorrupted;
+    ProtocolDeserialization::deserialize(m_frameHeader, dbCorrupted);
 
-    return std::make_shared<DescriptionListResponse>(descriptions, m_frameHeader.sequenceNumber());
+    LOGD("Deserialized DescriptionListResponse: number of descriptions [%" PRIu16 "], "
+         "dbCorrupted [%d]", descriptionsCount, static_cast<int>(dbCorrupted));
+
+    return std::make_shared<DescriptionListResponse>(descriptions, dbCorrupted,
+                                                     m_frameHeader.sequenceNumber());
 }
 
 ResponsePtr ProtocolAdmin::deserializeListResponse(void) {
@@ -298,13 +306,18 @@ ResponsePtr ProtocolAdmin::deserializeListResponse(void) {
                                         PolicyResult(policyType, metadata)));
     }
 
-    bool isBucketValid;
-    ProtocolDeserialization::deserialize(m_frameHeader, isBucketValid);
+    bool bucketValid;
+    bool dbCorrupted;
+    ProtocolDeserialization::deserialize(m_frameHeader, bucketValid);
+    ProtocolDeserialization::deserialize(m_frameHeader, dbCorrupted);
+
+    LOGD("Deserialized ListResponse: number of policies [%" PRIu16 "], bucketValid [%d], "
+         "dbCorrupted [%d]", policiesCount, static_cast<int>(bucketValid),
+         static_cast<int>(dbCorrupted));
 
-    LOGD("Deserialized ListResponse: number of policies [%" PRIu16 "], isBucketValid [%d]",
-         policiesCount, isBucketValid);
+    return std::make_shared<ListResponse>(policies, bucketValid, dbCorrupted,
+                                          m_frameHeader.sequenceNumber());
 
-    return std::make_shared<ListResponse>(policies, isBucketValid, m_frameHeader.sequenceNumber());
 }
 
 ResponsePtr ProtocolAdmin::extractResponseFromBuffer(BinaryQueuePtr bufferQueue) {
@@ -471,9 +484,10 @@ void ProtocolAdmin::execute(RequestContextPtr context, SetPoliciesRequestPtr req
 
 void ProtocolAdmin::execute(RequestContextPtr context, AdminCheckResponsePtr response) {
     LOGD("Serializing AdminCheckResponse: op [%" PRIu8 "], sequenceNumber [%" PRIu16 "], "
-         "policyType [%" PRIu16 "], metadata <%s>, bucketValid [%d]", OpAdminCheckPolicyResponse,
-         response->sequenceNumber(), response->result().policyType(),
-         response->result().metadata().c_str(), static_cast<int>(response->isBucketValid()));
+         "policyType [%" PRIu16 "], metadata <%s>, bucketValid [%d], dbCorrupted [%d]",
+         OpAdminCheckPolicyResponse, response->sequenceNumber(), response->result().policyType(),
+         response->result().metadata().c_str(), static_cast<int>(response->isBucketValid()),
+         static_cast<int>(response->isDbCorrupted()));
 
     ProtocolFrame frame = ProtocolFrameSerializer::startSerialization(
             response->sequenceNumber());
@@ -482,6 +496,7 @@ void ProtocolAdmin::execute(RequestContextPtr context, AdminCheckResponsePtr res
     ProtocolSerialization::serialize(frame, response->result().policyType());
     ProtocolSerialization::serialize(frame, response->result().metadata());
     ProtocolSerialization::serialize(frame, response->isBucketValid());
+    ProtocolSerialization::serialize(frame, response->isDbCorrupted());
 
     ProtocolFrameSerializer::finishSerialization(frame, *(context->responseQueue()));
 }
@@ -504,8 +519,8 @@ void ProtocolAdmin::execute(RequestContextPtr context, DescriptionListResponsePt
         = static_cast<ProtocolFrameFieldsCount>(response->descriptions().size());
 
     LOGD("Serializing DescriptionListResponse: op [%" PRIu8 "], sequenceNumber [%" PRIu16 "], "
-         "number of descriptions [%" PRIu16 "]", OpDescriptionListResponse,
-         response->sequenceNumber(), descriptionsSize);
+         "number of descriptions [%" PRIu16 "], dbCorrupted [%d]", OpDescriptionListResponse,
+         response->sequenceNumber(), descriptionsSize, static_cast<int>(response->isDbCorrupted()));
 
     ProtocolFrame frame = ProtocolFrameSerializer::startSerialization(response->sequenceNumber());
 
@@ -515,6 +530,8 @@ void ProtocolAdmin::execute(RequestContextPtr context, DescriptionListResponsePt
         ProtocolSerialization::serialize(frame, desc.type);
         ProtocolSerialization::serialize(frame, desc.name);
     }
+    ProtocolSerialization::serialize(frame, response->isDbCorrupted());
+
     ProtocolFrameSerializer::finishSerialization(frame, *(context->responseQueue()));
 }
 
@@ -523,8 +540,9 @@ void ProtocolAdmin::execute(RequestContextPtr context, ListResponsePtr response)
         = static_cast<ProtocolFrameFieldsCount>(response->policies().size());
 
     LOGD("Serializing ListResponse: op [%" PRIu8 "], sequenceNumber [%" PRIu16 "], "
-         "number of policies [%" PRIu16 "], isBucketValid [%d]", OpListResponse,
-         response->sequenceNumber(), policiesSize, response->isBucketValid());
+         "number of policies [%" PRIu16 "], bucketValid [%d], dbCorrupted [%d]", OpListResponse,
+         response->sequenceNumber(), policiesSize, static_cast<int>(response->isBucketValid()),
+         static_cast<int>(response->isDbCorrupted()));
 
     ProtocolFrame frame = ProtocolFrameSerializer::startSerialization(response->sequenceNumber());
 
@@ -540,6 +558,7 @@ void ProtocolAdmin::execute(RequestContextPtr context, ListResponsePtr response)
         ProtocolSerialization::serialize(frame, policy.result().metadata());
     }
     ProtocolSerialization::serialize(frame, response->isBucketValid());
+    ProtocolSerialization::serialize(frame, response->isDbCorrupted());
 
     ProtocolFrameSerializer::finishSerialization(frame, *(context->responseQueue()));
 }
index c2bbf30..d553fd9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *    Licensed under the Apache License, Version 2.0 (the "License");
  *    you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
 /**
  * @file        src/common/response/AdminCheckResponse.h
  * @author      Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
+ * @author      Pawel Wieczorek <p.wieczorek2@samsung.com>
  * @version     1.0
  * @brief       This file defines response class for admin check request
  */
@@ -33,9 +34,10 @@ namespace Cynara {
 
 class AdminCheckResponse : public Response {
 public:
-    AdminCheckResponse(const PolicyResult &result, bool bucketValid,
+    AdminCheckResponse(const PolicyResult &result, bool bucketValid, bool dbCorrupted,
                        ProtocolFrameSequenceNumber sequenceNumber) :
-        Response(sequenceNumber), m_result(result), m_bucketValid(bucketValid) {
+        Response(sequenceNumber), m_result(result), m_bucketValid(bucketValid),
+        m_dbCorrupted(dbCorrupted) {
     }
 
     virtual ~AdminCheckResponse() {}
@@ -51,9 +53,14 @@ public:
         return m_bucketValid;
     }
 
+    bool isDbCorrupted(void) const {
+        return m_dbCorrupted;
+    }
+
 private:
     const PolicyResult m_result;
     bool m_bucketValid;
+    bool m_dbCorrupted;
 };
 
 } // namespace Cynara
index f5790f4..78b21c1 100644 (file)
@@ -16,6 +16,7 @@
 /**
  * @file        src/common/response/CodeResponse.h
  * @author      Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
+ * @author      Pawel Wieczorek <p.wieczorek2@samsung.com>
  * @version     1.0
  * @brief       This file defines class for responding to a request with a code
  */
@@ -36,7 +37,8 @@ public:
         NO_BUCKET,
         NO_POLICY_TYPE,
         NOT_ALLOWED,
-        FAILED
+        FAILED,
+        DB_CORRUPTED
     };
 
     const Code m_code;
index a963775..310ee63 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *    Licensed under the Apache License, Version 2.0 (the "License");
  *    you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
 /**
  * @file        src/common/response/DescriptionListResponse.h
  * @author      Zofia Abramowska <z.abramowska@samsung.com>
+ * @author      Pawel Wieczorek <p.wieczorek2@samsung.com>
  * @version     1.0
  * @brief       This file defines response class for plugins description list response
  */
@@ -34,21 +35,26 @@ namespace Cynara {
 
 class DescriptionListResponse : public Response {
 public:
-    DescriptionListResponse(const std::vector<PolicyDescription> &descriptions,
+    DescriptionListResponse(const std::vector<PolicyDescription> &descriptions, bool dbCorrupted,
                             ProtocolFrameSequenceNumber sequenceNumber) :
-        Response(sequenceNumber), m_descriptions(descriptions) {
+        Response(sequenceNumber), m_descriptions(descriptions), m_dbCorrupted(dbCorrupted) {
     }
 
     virtual ~DescriptionListResponse() {};
 
     virtual void execute(ResponsePtr self, ResponseTakerPtr taker, RequestContextPtr context) const;
 
+    bool isDbCorrupted(void) const {
+        return m_dbCorrupted;
+    }
+
     const std::vector<PolicyDescription> &descriptions(void) const {
         return m_descriptions;
     }
 
 private:
     std::vector<PolicyDescription> m_descriptions;
+    bool m_dbCorrupted;
 };
 
 } // namespace Cynara
index ec52736..2a67225 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *    Licensed under the Apache License, Version 2.0 (the "License");
  *    you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
 /**
  * @file        src/common/response/ListResponse.h
  * @author      Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
+ * @author      Pawel Wieczorek <p.wieczorek2@samsung.com>
  * @version     1.0
  * @brief       This file defines response class for policies list request
  */
@@ -35,9 +36,10 @@ namespace Cynara {
 
 class ListResponse : public Response {
 public:
-    ListResponse(const std::vector<Policy> &policies, bool bucketValid,
+    ListResponse(const std::vector<Policy> &policies, bool bucketValid, bool dbCorrupted,
                  ProtocolFrameSequenceNumber sequenceNumber) :
-        Response(sequenceNumber), m_policies(policies), m_bucketValid(bucketValid) {
+        Response(sequenceNumber), m_policies(policies), m_bucketValid(bucketValid),
+        m_dbCorrupted(dbCorrupted) {
     }
 
     virtual ~ListResponse() {};
@@ -48,6 +50,10 @@ public:
         return m_bucketValid;
     }
 
+    bool isDbCorrupted(void) const {
+        return m_dbCorrupted;
+    }
+
     const std::vector<Policy> &policies(void) const {
         return m_policies;
     }
@@ -55,6 +61,7 @@ public:
 private:
     std::vector<Policy> m_policies;
     bool m_bucketValid;
+    bool m_dbCorrupted;
 };
 
 } // namespace Cynara
index 6a1bece..a6e3c12 100644 (file)
@@ -17,6 +17,7 @@
  * @file        src/service/logic/Logic.cpp
  * @author      Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
  * @author      Zofia Abramowska <z.abramowska@samsung.com>
+ * @author      Pawel Wieczorek <p.wieczorek2@samsung.com>
  * @version     1.0
  * @brief       This file implements main class of logic layer in cynara service
  */
@@ -76,7 +77,7 @@
 
 namespace Cynara {
 
-Logic::Logic() {
+Logic::Logic() : m_dbCorrupted(false) {
 }
 
 Logic::~Logic() {
@@ -96,15 +97,20 @@ void Logic::execute(RequestContextPtr context UNUSED, SignalRequestPtr request)
 void Logic::execute(RequestContextPtr context, AdminCheckRequestPtr request) {
     PolicyResult result;
     bool bucketValid = true;
-    try {
-        result = m_storage->checkPolicy(request->key(), request->startBucket(),
-                                        request->recursive());
-    } catch (const BucketNotExistsException &ex) {
+
+    if (m_dbCorrupted) {
         bucketValid = false;
+    } else {
+        try {
+            result = m_storage->checkPolicy(request->key(), request->startBucket(),
+                                            request->recursive());
+        } catch (const BucketNotExistsException &ex) {
+            bucketValid = false;
+        }
     }
 
     context->returnResponse(context, std::make_shared<AdminCheckResponse>(result, bucketValid,
-                            request->sequenceNumber()));
+                            m_dbCorrupted, request->sequenceNumber()));
 }
 
 void Logic::execute(RequestContextPtr context, AgentActionRequestPtr request) {
@@ -183,7 +189,7 @@ bool Logic::check(const RequestContextPtr &context, const PolicyKey &key,
         return false;
     }
 
-    result = m_storage->checkPolicy(key);
+    result = (m_dbCorrupted ? PredefinedPolicyType::DENY : m_storage->checkPolicy(key));
 
     switch (result.policyType()) {
         case PredefinedPolicyType::ALLOW :
@@ -286,19 +292,23 @@ void Logic::execute(RequestContextPtr context, DescriptionListRequestPtr request
     descriptions.insert(descriptions.begin(), predefinedPolicyDescr.begin(),
                         predefinedPolicyDescr.end());
     context->returnResponse(context, std::make_shared<DescriptionListResponse>(descriptions,
-                            request->sequenceNumber()));
+                            m_dbCorrupted, request->sequenceNumber()));
 }
 
 void Logic::execute(RequestContextPtr context, EraseRequestPtr request) {
     auto code = CodeResponse::Code::OK;
 
-    try {
-        m_storage->erasePolicies(request->startBucket(), request->recursive(), request->filter());
-        onPoliciesChanged();
-    } catch (const DatabaseException &ex) {
-        code = CodeResponse::Code::FAILED;
-    } catch (const BucketNotExistsException &ex) {
-        code = CodeResponse::Code::NO_BUCKET;
+    if (m_dbCorrupted) {
+        code = CodeResponse::Code::DB_CORRUPTED;
+    } else {
+        try {
+            m_storage->erasePolicies(request->startBucket(), request->recursive(), request->filter());
+            onPoliciesChanged();
+        } catch (const DatabaseException &ex) {
+            code = CodeResponse::Code::FAILED;
+        } catch (const BucketNotExistsException &ex) {
+            code = CodeResponse::Code::NO_BUCKET;
+        }
     }
 
     context->returnResponse(context, std::make_shared<CodeResponse>(code,
@@ -308,18 +318,22 @@ void Logic::execute(RequestContextPtr context, EraseRequestPtr request) {
 void Logic::execute(RequestContextPtr context, InsertOrUpdateBucketRequestPtr request) {
     auto code = CodeResponse::Code::OK;
 
-    try {
-        checkSinglePolicyType(request->result().policyType(), true, true);
-        m_storage->addOrUpdateBucket(request->bucketId(), request->result());
-        onPoliciesChanged();
-    } catch (const DatabaseException &ex) {
-        code = CodeResponse::Code::FAILED;
-    } catch (const DefaultBucketSetNoneException &ex) {
-        code = CodeResponse::Code::NOT_ALLOWED;
-    } catch (const InvalidBucketIdException &ex) {
-        code = CodeResponse::Code::NOT_ALLOWED;
-    } catch (const UnknownPolicyTypeException &ex) {
-        code = CodeResponse::Code::NO_POLICY_TYPE;
+    if (m_dbCorrupted) {
+        code = CodeResponse::Code::DB_CORRUPTED;
+    } else {
+        try {
+            checkSinglePolicyType(request->result().policyType(), true, true);
+            m_storage->addOrUpdateBucket(request->bucketId(), request->result());
+            onPoliciesChanged();
+        } catch (const DatabaseException &ex) {
+            code = CodeResponse::Code::FAILED;
+        } catch (const DefaultBucketSetNoneException &ex) {
+            code = CodeResponse::Code::NOT_ALLOWED;
+        } catch (const InvalidBucketIdException &ex) {
+            code = CodeResponse::Code::NOT_ALLOWED;
+        } catch (const UnknownPolicyTypeException &ex) {
+            code = CodeResponse::Code::NO_POLICY_TYPE;
+        }
     }
 
     context->returnResponse(context, std::make_shared<CodeResponse>(code,
@@ -328,48 +342,64 @@ void Logic::execute(RequestContextPtr context, InsertOrUpdateBucketRequestPtr re
 
 void Logic::execute(RequestContextPtr context, ListRequestPtr request) {
     bool bucketValid = true;
-
     std::vector<Policy> policies;
-    try {
-        policies = m_storage->listPolicies(request->bucket(), request->filter());
-    } catch (const BucketNotExistsException &ex) {
+
+    if (m_dbCorrupted) {
         bucketValid = false;
+    } else {
+        try {
+            policies = m_storage->listPolicies(request->bucket(), request->filter());
+        } catch (const BucketNotExistsException &ex) {
+            bucketValid = false;
+        }
     }
 
     context->returnResponse(context, std::make_shared<ListResponse>(policies, bucketValid,
-                            request->sequenceNumber()));
+                            m_dbCorrupted, request->sequenceNumber()));
 }
 
 void Logic::execute(RequestContextPtr context, RemoveBucketRequestPtr request) {
     auto code = CodeResponse::Code::OK;
-    try {
-        m_storage->deleteBucket(request->bucketId());
-        onPoliciesChanged();
-    } catch (const DatabaseException &ex) {
-        code = CodeResponse::Code::FAILED;
-    } catch (const BucketNotExistsException &ex) {
-        code = CodeResponse::Code::NO_BUCKET;
-    } catch (const DefaultBucketDeletionException &ex) {
-        code = CodeResponse::Code::NOT_ALLOWED;
+
+    if (m_dbCorrupted) {
+        code = CodeResponse::Code::DB_CORRUPTED;
+    } else {
+        try {
+            m_storage->deleteBucket(request->bucketId());
+            onPoliciesChanged();
+        } catch (const DatabaseException &ex) {
+            code = CodeResponse::Code::FAILED;
+        } catch (const BucketNotExistsException &ex) {
+            code = CodeResponse::Code::NO_BUCKET;
+        } catch (const DefaultBucketDeletionException &ex) {
+            code = CodeResponse::Code::NOT_ALLOWED;
+        }
     }
+
     context->returnResponse(context, std::make_shared<CodeResponse>(code,
                             request->sequenceNumber()));
 }
 
 void Logic::execute(RequestContextPtr context, SetPoliciesRequestPtr request) {
     auto code = CodeResponse::Code::OK;
-    try {
-        checkPoliciesTypes(request->policiesToBeInsertedOrUpdated(), true, false);
-        m_storage->insertPolicies(request->policiesToBeInsertedOrUpdated());
-        m_storage->deletePolicies(request->policiesToBeRemoved());
-        onPoliciesChanged();
-    } catch (const DatabaseException &ex) {
-        code = CodeResponse::Code::FAILED;
-    } catch (const BucketNotExistsException &ex) {
-        code = CodeResponse::Code::NO_BUCKET;
-    } catch (const UnknownPolicyTypeException &ex) {
-        code = CodeResponse::Code::NO_POLICY_TYPE;
+
+    if (m_dbCorrupted) {
+        code = CodeResponse::Code::DB_CORRUPTED;
+    } else {
+        try {
+            checkPoliciesTypes(request->policiesToBeInsertedOrUpdated(), true, false);
+            m_storage->insertPolicies(request->policiesToBeInsertedOrUpdated());
+            m_storage->deletePolicies(request->policiesToBeRemoved());
+            onPoliciesChanged();
+        } catch (const DatabaseException &ex) {
+            code = CodeResponse::Code::FAILED;
+        } catch (const BucketNotExistsException &ex) {
+            code = CodeResponse::Code::NO_BUCKET;
+        } catch (const UnknownPolicyTypeException &ex) {
+            code = CodeResponse::Code::NO_POLICY_TYPE;
+        }
     }
+
     context->returnResponse(context, std::make_shared<CodeResponse>(code,
                             request->sequenceNumber()));
 }
index 2a4ff8a..3e8ee8c 100644 (file)
@@ -17,6 +17,7 @@
  * @file        src/service/logic/Logic.h
  * @author      Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
  * @author      Zofia Abramowska <z.abramowska@samsung.com>
+ * @author      Pawel Wieczorek <p.wieczorek2@samsung.com>
  * @version     1.0
  * @brief       This file defines main class of logic layer in cynara service
  */
@@ -95,6 +96,7 @@ private:
     StoragePtr m_storage;
     SocketManagerPtr m_socketManager;
     AuditLog m_auditLog;
+    bool m_dbCorrupted;
 
     bool check(const RequestContextPtr &context, const PolicyKey &key,
                ProtocolFrameSequenceNumber checkId, PolicyResult &result);
index 666f65e..5aa2386 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *    Licensed under the Apache License, Version 2.0 (the "License");
  *    you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
 /**
  * @file        test/common/protocols/admin/admincheckresponse.cpp
  * @author      Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
+ * @author      Pawel Wieczorek <p.wieczorek2@samsung.com>
  * @version     1.0
  * @brief       Tests for Cynara::AdminCheckResponse usage in Cynara::ProtocolAdmin
  */
@@ -34,10 +35,13 @@ template<>
 void compare(const Cynara::AdminCheckResponse &resp1, const Cynara::AdminCheckResponse &resp2) {
     EXPECT_EQ(resp1.result(), resp2.result());
     EXPECT_EQ(resp1.isBucketValid(), resp2.isBucketValid());
+    EXPECT_EQ(resp1.isDbCorrupted(), resp2.isDbCorrupted());
 }
 
 static const bool VALID_BUCKET = true;
 static const bool NO_BUCKET = false;
+static const bool DB_OK = false;
+static const bool DB_CORRUPTED = true;
 
 } /* anonymous namespace */
 
@@ -48,19 +52,21 @@ using namespace TestDataCollection;
 /* *** compare by objects test cases *** */
 
 TEST(ProtocolAdmin, AdminCheckResponse01) {
-    auto response = std::make_shared<AdminCheckResponse>(Results::allow, VALID_BUCKET, SN::min);
+    auto response = std::make_shared<AdminCheckResponse>(Results::allow, VALID_BUCKET, DB_OK,
+                                                         SN::min);
     auto protocol = std::make_shared<ProtocolAdmin>();
     testResponse(response, protocol);
 }
 
 TEST(ProtocolAdmin, AdminCheckResponse02) {
-    auto response = std::make_shared<AdminCheckResponse>(Results::deny, NO_BUCKET, SN::min_1);
+    auto response = std::make_shared<AdminCheckResponse>(Results::deny, NO_BUCKET, DB_OK,
+                                                         SN::min_1);
     auto protocol = std::make_shared<ProtocolAdmin>();
     testResponse(response, protocol);
 }
 
 TEST(ProtocolAdmin, AdminCheckResponse03) {
-    auto response = std::make_shared<AdminCheckResponse>(Results::bucket_empty, VALID_BUCKET,
+    auto response = std::make_shared<AdminCheckResponse>(Results::bucket_empty, VALID_BUCKET, DB_OK,
                                                          SN::min_2);
     auto protocol = std::make_shared<ProtocolAdmin>();
     testResponse(response, protocol);
@@ -68,25 +74,42 @@ TEST(ProtocolAdmin, AdminCheckResponse03) {
 
 TEST(ProtocolAdmin, AdminCheckResponse04) {
     auto response = std::make_shared<AdminCheckResponse>(Results::bucket_not_empty, NO_BUCKET,
-                                                         SN::max);
+                                                         DB_OK, SN::max);
     auto protocol = std::make_shared<ProtocolAdmin>();
     testResponse(response, protocol);
 }
 
 TEST(ProtocolAdmin, AdminCheckResponse05) {
-    auto response = std::make_shared<AdminCheckResponse>(Results::none, VALID_BUCKET, SN::max_1);
+    auto response = std::make_shared<AdminCheckResponse>(Results::none, VALID_BUCKET, DB_OK,
+                                                         SN::max_1);
     auto protocol = std::make_shared<ProtocolAdmin>();
     testResponse(response, protocol);
 }
 
 TEST(ProtocolAdmin, AdminCheckResponse06) {
-    auto response = std::make_shared<AdminCheckResponse>(Results::plugin_1, NO_BUCKET, SN::max_2);
+    auto response = std::make_shared<AdminCheckResponse>(Results::plugin_1, NO_BUCKET, DB_OK,
+                                                         SN::max_2);
     auto protocol = std::make_shared<ProtocolAdmin>();
     testResponse(response, protocol);
 }
 
 TEST(ProtocolAdmin, AdminCheckResponse07) {
-    auto response = std::make_shared<AdminCheckResponse>(Results::plugin_2, VALID_BUCKET, SN::mid);
+    auto response = std::make_shared<AdminCheckResponse>(Results::plugin_2, VALID_BUCKET, DB_OK,
+                                                         SN::mid);
+    auto protocol = std::make_shared<ProtocolAdmin>();
+    testResponse(response, protocol);
+}
+
+/**
+ * @brief   Verify if AdminCheckResponse is properly (de)serialized while database is corrupted
+ * @test    Expected result:
+ * - PolicyResult set to DENY
+ * - bucketValid flag set to false (NO_BUCKET)
+ * - dbCorrupted flag set to true (DB_CORRUPTED)
+ */
+TEST(ProtocolAdmin, AdminCheckResponse08) {
+    auto response = std::make_shared<AdminCheckResponse>(Results::deny, NO_BUCKET, DB_CORRUPTED,
+                                                         SN::max);
     auto protocol = std::make_shared<ProtocolAdmin>();
     testResponse(response, protocol);
 }
@@ -94,19 +117,21 @@ TEST(ProtocolAdmin, AdminCheckResponse07) {
 /* *** compare by serialized data test cases *** */
 
 TEST(ProtocolAdmin, AdminCheckResponseBinary01) {
-    auto response = std::make_shared<AdminCheckResponse>(Results::allow, VALID_BUCKET, SN::min);
+    auto response = std::make_shared<AdminCheckResponse>(Results::allow, VALID_BUCKET, DB_OK,
+                                                         SN::min);
     auto protocol = std::make_shared<ProtocolAdmin>();
     binaryTestResponse(response, protocol);
 }
 
 TEST(ProtocolAdmin, AdminCheckResponseBinary02) {
-    auto response = std::make_shared<AdminCheckResponse>(Results::deny, NO_BUCKET, SN::min_1);
+    auto response = std::make_shared<AdminCheckResponse>(Results::deny, NO_BUCKET, DB_OK,
+                                                         SN::min_1);
     auto protocol = std::make_shared<ProtocolAdmin>();
     binaryTestResponse(response, protocol);
 }
 
 TEST(ProtocolAdmin, AdminCheckResponseBinary03) {
-    auto response = std::make_shared<AdminCheckResponse>(Results::bucket_empty, VALID_BUCKET,
+    auto response = std::make_shared<AdminCheckResponse>(Results::bucket_empty, VALID_BUCKET, DB_OK,
                                                          SN::min_2);
     auto protocol = std::make_shared<ProtocolAdmin>();
     binaryTestResponse(response, protocol);
@@ -114,25 +139,42 @@ TEST(ProtocolAdmin, AdminCheckResponseBinary03) {
 
 TEST(ProtocolAdmin, AdminCheckResponseBinary04) {
     auto response = std::make_shared<AdminCheckResponse>(Results::bucket_not_empty, NO_BUCKET,
-                                                         SN::max);
+                                                         DB_OK, SN::max);
     auto protocol = std::make_shared<ProtocolAdmin>();
     binaryTestResponse(response, protocol);
 }
 
 TEST(ProtocolAdmin, AdminCheckResponseBinary05) {
-    auto response = std::make_shared<AdminCheckResponse>(Results::none, VALID_BUCKET, SN::max_1);
+    auto response = std::make_shared<AdminCheckResponse>(Results::none, VALID_BUCKET, DB_OK,
+                                                         SN::max_1);
     auto protocol = std::make_shared<ProtocolAdmin>();
     binaryTestResponse(response, protocol);
 }
 
 TEST(ProtocolAdmin, AdminCheckResponseBinary06) {
-    auto response = std::make_shared<AdminCheckResponse>(Results::plugin_1, NO_BUCKET, SN::max_2);
+    auto response = std::make_shared<AdminCheckResponse>(Results::plugin_1, NO_BUCKET, DB_OK,
+                                                         SN::max_2);
     auto protocol = std::make_shared<ProtocolAdmin>();
     binaryTestResponse(response, protocol);
 }
 
 TEST(ProtocolAdmin, AdminCheckResponseBinary07) {
-    auto response = std::make_shared<AdminCheckResponse>(Results::plugin_2, VALID_BUCKET, SN::mid);
+    auto response = std::make_shared<AdminCheckResponse>(Results::plugin_2, VALID_BUCKET, DB_OK,
+                                                         SN::mid);
+    auto protocol = std::make_shared<ProtocolAdmin>();
+    binaryTestResponse(response, protocol);
+}
+
+/**
+ * @brief   Verify if AdminCheckResponse is properly (de)serialized while database is corrupted
+ * @test    Expected result:
+ * - PolicyResult set to DENY
+ * - bucketValid flag set to false (NO_BUCKET)
+ * - dbCorrupted flag set to true (DB_CORRUPTED)
+ */
+TEST(ProtocolAdmin, AdminCheckResponseBinary08) {
+    auto response = std::make_shared<AdminCheckResponse>(Results::deny, NO_BUCKET, DB_CORRUPTED,
+                                                         SN::max);
     auto protocol = std::make_shared<ProtocolAdmin>();
     binaryTestResponse(response, protocol);
 }
index 43acbaa..42e8bae 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *    Licensed under the Apache License, Version 2.0 (the "License");
  *    you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
 /**
  * @file        test/common/protocols/admin/descriptionlistresponse.cpp
  * @author      Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
+ * @author      Pawel Wieczorek <p.wieczorek2@samsung.com>
  * @version     1.0
  * @brief       Tests for Cynara::DescriptionListResponse usage in Cynara::ProtocolAdmin
  */
@@ -42,8 +43,12 @@ void compare(const Cynara::DescriptionListResponse &resp1,
         EXPECT_EQ(resp1.descriptions()[i].name, resp2.descriptions()[i].name);
         EXPECT_EQ(resp1.descriptions()[i].type, resp2.descriptions()[i].type);
     }
+    EXPECT_EQ(resp1.isDbCorrupted(), resp2.isDbCorrupted());
 }
 
+static const bool DB_OK = false;
+static const bool DB_CORRUPTED = true;
+
 } /* namespace anonymous */
 
 using namespace Cynara;
@@ -57,7 +62,7 @@ TEST(ProtocolAdmin, DescriptionListResponse01) {
         PolicyDescription(Types::allow, "allow"),
     };
 
-    auto response = std::make_shared<DescriptionListResponse>(descriptions, SN::min);
+    auto response = std::make_shared<DescriptionListResponse>(descriptions, DB_OK, SN::min);
     auto protocol = std::make_shared<ProtocolAdmin>();
     testResponse(response, protocol);
 }
@@ -67,7 +72,7 @@ TEST(ProtocolAdmin, DescriptionListResponse02) {
         PolicyDescription(Types::bucket, "bucket"),
     };
 
-    auto response = std::make_shared<DescriptionListResponse>(descriptions, SN::min_1);
+    auto response = std::make_shared<DescriptionListResponse>(descriptions, DB_OK, SN::min_1);
     auto protocol = std::make_shared<ProtocolAdmin>();
     testResponse(response, protocol);
 }
@@ -77,7 +82,7 @@ TEST(ProtocolAdmin, DescriptionListResponse03) {
         PolicyDescription(Types::deny, "deny"),
     };
 
-    auto response = std::make_shared<DescriptionListResponse>(descriptions, SN::max);
+    auto response = std::make_shared<DescriptionListResponse>(descriptions, DB_OK, SN::max);
     auto protocol = std::make_shared<ProtocolAdmin>();
     testResponse(response, protocol);
 }
@@ -87,7 +92,7 @@ TEST(ProtocolAdmin, DescriptionListResponse04) {
         PolicyDescription(Types::none, "none"),
     };
 
-    auto response = std::make_shared<DescriptionListResponse>(descriptions, SN::max_1);
+    auto response = std::make_shared<DescriptionListResponse>(descriptions, DB_OK, SN::max_1);
     auto protocol = std::make_shared<ProtocolAdmin>();
     testResponse(response, protocol);
 }
@@ -97,7 +102,7 @@ TEST(ProtocolAdmin, DescriptionListResponse05) {
         PolicyDescription(Types::plugin_type, "plugin"),
     };
 
-    auto response = std::make_shared<DescriptionListResponse>(descriptions, SN::mid);
+    auto response = std::make_shared<DescriptionListResponse>(descriptions, DB_OK, SN::mid);
     auto protocol = std::make_shared<ProtocolAdmin>();
     testResponse(response, protocol);
 }
@@ -113,7 +118,7 @@ TEST(ProtocolAdmin, DescriptionListResponseMultipleDescriptions) {
         PolicyDescription(Types::plugin_type, "plugin"),
     };
 
-    auto response = std::make_shared<DescriptionListResponse>(descriptions, SN::max_2);
+    auto response = std::make_shared<DescriptionListResponse>(descriptions, DB_OK, SN::max_2);
     auto protocol = std::make_shared<ProtocolAdmin>();
     testResponse(response, protocol);
 }
@@ -121,7 +126,24 @@ TEST(ProtocolAdmin, DescriptionListResponseMultipleDescriptions) {
 TEST(ProtocolAdmin, DescriptionListResponseEmptyDescriptions) {
     std::vector<PolicyDescription> descriptions;
 
-    auto response = std::make_shared<DescriptionListResponse>(descriptions, SN::min_2);
+    auto response = std::make_shared<DescriptionListResponse>(descriptions, DB_OK, SN::min_2);
+    auto protocol = std::make_shared<ProtocolAdmin>();
+    testResponse(response, protocol);
+}
+
+/**
+ * @brief   Verify if DescriptionListResponse is properly (de)serialized while database is corrupted
+ * @test    Expected result:
+ * - descriptions vector contains predefined policies ALLOW and DENY
+ * - dbCorrupted flag set to true (DB_CORRUPTED)
+ */
+TEST(ProtocolAdmin, DescriptionListResponseDatabaseCorrupted) {
+    std::vector<PolicyDescription> descriptions = {
+        PolicyDescription(Types::allow, "allow"),
+        PolicyDescription(Types::bucket, "bucket"),
+    };
+
+    auto response = std::make_shared<DescriptionListResponse>(descriptions, DB_CORRUPTED, SN::max);
     auto protocol = std::make_shared<ProtocolAdmin>();
     testResponse(response, protocol);
 }
@@ -133,7 +155,7 @@ TEST(ProtocolAdmin, DescriptionListResponseBinary01) {
         PolicyDescription(Types::allow, "allow"),
     };
 
-    auto response = std::make_shared<DescriptionListResponse>(descriptions, SN::min);
+    auto response = std::make_shared<DescriptionListResponse>(descriptions, DB_OK, SN::min);
     auto protocol = std::make_shared<ProtocolAdmin>();
     binaryTestResponse(response, protocol);
 }
@@ -143,7 +165,7 @@ TEST(ProtocolAdmin, DescriptionListResponseBinary02) {
         PolicyDescription(Types::bucket, "bucket"),
     };
 
-    auto response = std::make_shared<DescriptionListResponse>(descriptions, SN::min_1);
+    auto response = std::make_shared<DescriptionListResponse>(descriptions, DB_OK, SN::min_1);
     auto protocol = std::make_shared<ProtocolAdmin>();
     binaryTestResponse(response, protocol);
 }
@@ -153,7 +175,7 @@ TEST(ProtocolAdmin, DescriptionListResponseBinary03) {
         PolicyDescription(Types::deny, "deny"),
     };
 
-    auto response = std::make_shared<DescriptionListResponse>(descriptions, SN::max);
+    auto response = std::make_shared<DescriptionListResponse>(descriptions, DB_OK, SN::max);
     auto protocol = std::make_shared<ProtocolAdmin>();
     binaryTestResponse(response, protocol);
 }
@@ -163,7 +185,7 @@ TEST(ProtocolAdmin, DescriptionListResponseBinary04) {
         PolicyDescription(Types::none, "none"),
     };
 
-    auto response = std::make_shared<DescriptionListResponse>(descriptions, SN::max_1);
+    auto response = std::make_shared<DescriptionListResponse>(descriptions, DB_OK, SN::max_1);
     auto protocol = std::make_shared<ProtocolAdmin>();
     binaryTestResponse(response, protocol);
 }
@@ -173,7 +195,7 @@ TEST(ProtocolAdmin, DescriptionListResponseBinary05) {
         PolicyDescription(Types::plugin_type, "plugin"),
     };
 
-    auto response = std::make_shared<DescriptionListResponse>(descriptions, SN::mid);
+    auto response = std::make_shared<DescriptionListResponse>(descriptions, DB_OK, SN::mid);
     auto protocol = std::make_shared<ProtocolAdmin>();
     binaryTestResponse(response, protocol);
 }
@@ -189,7 +211,7 @@ TEST(ProtocolAdmin, DescriptionListResponseBinaryMultipleDescriptions) {
         PolicyDescription(Types::plugin_type, "plugin"),
     };
 
-    auto response = std::make_shared<DescriptionListResponse>(descriptions, SN::max_2);
+    auto response = std::make_shared<DescriptionListResponse>(descriptions, DB_OK, SN::max_2);
     auto protocol = std::make_shared<ProtocolAdmin>();
     binaryTestResponse(response, protocol);
 }
@@ -197,7 +219,24 @@ TEST(ProtocolAdmin, DescriptionListResponseBinaryMultipleDescriptions) {
 TEST(ProtocolAdmin, DescriptionListResponseBinaryEmptyDescriptions) {
     std::vector<PolicyDescription> descriptions;
 
-    auto response = std::make_shared<DescriptionListResponse>(descriptions, SN::min_2);
+    auto response = std::make_shared<DescriptionListResponse>(descriptions, DB_OK, SN::min_2);
+    auto protocol = std::make_shared<ProtocolAdmin>();
+    binaryTestResponse(response, protocol);
+}
+
+/**
+ * @brief   Verify if DescriptionListResponse is properly (de)serialized while database is corrupted
+ * @test    Expected result:
+ * - descriptions vector contains predefined policies ALLOW and DENY
+ * - dbCorrupted flag set to true (DB_CORRUPTED)
+ */
+TEST(ProtocolAdmin, DescriptionListResponseBinaryDatabaseCorrupted) {
+    std::vector<PolicyDescription> descriptions = {
+        PolicyDescription(Types::allow, "allow"),
+        PolicyDescription(Types::bucket, "bucket"),
+    };
+
+    auto response = std::make_shared<DescriptionListResponse>(descriptions, DB_CORRUPTED, SN::max);
     auto protocol = std::make_shared<ProtocolAdmin>();
     binaryTestResponse(response, protocol);
 }
index fddd2ca..67ea03d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *    Licensed under the Apache License, Version 2.0 (the "License");
  *    you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
 /**
  * @file        test/common/protocols/admin/listresponse.cpp
  * @author      Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
+ * @author      Pawel Wieczorek <p.wieczorek2@samsung.com>
  * @version     1.0
  * @brief       Tests for Cynara::ListResponse usage in Cynara::ProtocolAdmin
  */
@@ -37,10 +38,13 @@ template<>
 void compare(const Cynara::ListResponse &resp1, const Cynara::ListResponse &resp2) {
     EXPECT_EQ(resp1.policies(), resp2.policies());
     EXPECT_EQ(resp1.isBucketValid(), resp2.isBucketValid());
+    EXPECT_EQ(resp1.isDbCorrupted(), resp2.isDbCorrupted());
 }
 
 static const bool VALID_BUCKET = true;
 static const bool NO_BUCKET = false;
+static const bool DB_OK = false;
+static const bool DB_CORRUPTED = true;
 
 } /* namespace anonymous */
 
@@ -55,7 +59,7 @@ TEST(ProtocolAdmin, ListResponse01) {
         Policy(Keys::k_nun, Results::allow),
     };
 
-    auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, SN::min);
+    auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, DB_OK, SN::min);
     auto protocol = std::make_shared<ProtocolAdmin>();
     testResponse(response, protocol);
 }
@@ -65,7 +69,7 @@ TEST(ProtocolAdmin, ListResponse02) {
         Policy(Keys::k_cup, Results::deny),
     };
 
-    auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, SN::min_1);
+    auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, DB_OK, SN::min_1);
     auto protocol = std::make_shared<ProtocolAdmin>();
     testResponse(response, protocol);
 }
@@ -75,7 +79,7 @@ TEST(ProtocolAdmin, ListResponse03) {
         Policy(Keys::k_www, Results::bucket_empty),
     };
 
-    auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, SN::min_2);
+    auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, DB_OK, SN::min_2);
     auto protocol = std::make_shared<ProtocolAdmin>();
     testResponse(response, protocol);
 }
@@ -85,7 +89,7 @@ TEST(ProtocolAdmin, ListResponse04) {
         Policy(Keys::k_wuw, Results::bucket_not_empty),
     };
 
-    auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, SN::max);
+    auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, DB_OK, SN::max);
     auto protocol = std::make_shared<ProtocolAdmin>();
     testResponse(response, protocol);
 }
@@ -95,7 +99,7 @@ TEST(ProtocolAdmin, ListResponse05) {
         Policy(Keys::k_aaa, Results::none),
     };
 
-    auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, SN::max_1);
+    auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, DB_OK, SN::max_1);
     auto protocol = std::make_shared<ProtocolAdmin>();
     testResponse(response, protocol);
 }
@@ -105,7 +109,7 @@ TEST(ProtocolAdmin, ListResponse06) {
         Policy(Keys::k_wua, Results::plugin_1),
     };
 
-    auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, SN::max_2);
+    auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, DB_OK, SN::max_2);
     auto protocol = std::make_shared<ProtocolAdmin>();
     testResponse(response, protocol);
 }
@@ -115,7 +119,7 @@ TEST(ProtocolAdmin, ListResponse07) {
         Policy(Keys::k_nua, Results::plugin_2),
     };
 
-    auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, SN::mid);
+    auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, DB_OK, SN::mid);
     auto protocol = std::make_shared<ProtocolAdmin>();
     testResponse(response, protocol);
 }
@@ -131,7 +135,7 @@ TEST(ProtocolAdmin, ListResponseMultiplePolicies) {
         Policy(Keys::k_nua, Results::plugin_2),
     };
 
-    auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, SN::min);
+    auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, DB_OK, SN::min);
     auto protocol = std::make_shared<ProtocolAdmin>();
     testResponse(response, protocol);
 }
@@ -139,7 +143,7 @@ TEST(ProtocolAdmin, ListResponseMultiplePolicies) {
 TEST(ProtocolAdmin, ListResponseEmptyPolicies) {
     std::vector<Policy> policies;
 
-    auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, SN::min_1);
+    auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, DB_OK, SN::min_1);
     auto protocol = std::make_shared<ProtocolAdmin>();
     testResponse(response, protocol);
 }
@@ -147,7 +151,22 @@ TEST(ProtocolAdmin, ListResponseEmptyPolicies) {
 TEST(ProtocolAdmin, ListResponseNoBucket) {
     std::vector<Policy> policies;
 
-    auto response = std::make_shared<ListResponse>(policies, NO_BUCKET, SN::min_2);
+    auto response = std::make_shared<ListResponse>(policies, NO_BUCKET, DB_OK, SN::min_2);
+    auto protocol = std::make_shared<ProtocolAdmin>();
+    testResponse(response, protocol);
+}
+
+/**
+ * @brief   Verify if ListResponse is properly (de)serialized while database is corrupted
+ * @test    Expected result:
+ * - policies vector is empty
+ * - bucketValid flag set to false (NO_BUCKET)
+ * - dbCorrupted flag set to true (DB_CORRUPTED)
+ */
+TEST(ProtocolAdmin, ListResponseDatabaseCorrupted) {
+    std::vector<Policy> policies;
+
+    auto response = std::make_shared<ListResponse>(policies, NO_BUCKET, DB_CORRUPTED, SN::max);
     auto protocol = std::make_shared<ProtocolAdmin>();
     testResponse(response, protocol);
 }
@@ -159,7 +178,7 @@ TEST(ProtocolAdmin, ListResponseBinary01) {
         Policy(Keys::k_nun, Results::allow),
     };
 
-    auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, SN::min);
+    auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, DB_OK, SN::min);
     auto protocol = std::make_shared<ProtocolAdmin>();
     binaryTestResponse(response, protocol);
 }
@@ -169,7 +188,7 @@ TEST(ProtocolAdmin, ListResponseBinary02) {
         Policy(Keys::k_cup, Results::deny),
     };
 
-    auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, SN::min_1);
+    auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, DB_OK, SN::min_1);
     auto protocol = std::make_shared<ProtocolAdmin>();
     binaryTestResponse(response, protocol);
 }
@@ -179,7 +198,7 @@ TEST(ProtocolAdmin, ListResponseBinary03) {
         Policy(Keys::k_www, Results::bucket_empty),
     };
 
-    auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, SN::min_2);
+    auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, DB_OK, SN::min_2);
     auto protocol = std::make_shared<ProtocolAdmin>();
     binaryTestResponse(response, protocol);
 }
@@ -189,7 +208,7 @@ TEST(ProtocolAdmin, ListResponseBinary04) {
         Policy(Keys::k_wuw, Results::bucket_not_empty),
     };
 
-    auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, SN::max);
+    auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, DB_OK, SN::max);
     auto protocol = std::make_shared<ProtocolAdmin>();
     binaryTestResponse(response, protocol);
 }
@@ -199,7 +218,7 @@ TEST(ProtocolAdmin, ListResponseBinary05) {
         Policy(Keys::k_aaa, Results::none),
     };
 
-    auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, SN::max_1);
+    auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, DB_OK, SN::max_1);
     auto protocol = std::make_shared<ProtocolAdmin>();
     binaryTestResponse(response, protocol);
 }
@@ -209,7 +228,7 @@ TEST(ProtocolAdmin, ListResponseBinary06) {
         Policy(Keys::k_wua, Results::plugin_1),
     };
 
-    auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, SN::max_2);
+    auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, DB_OK, SN::max_2);
     auto protocol = std::make_shared<ProtocolAdmin>();
     binaryTestResponse(response, protocol);
 }
@@ -219,7 +238,7 @@ TEST(ProtocolAdmin, ListResponseBinary07) {
         Policy(Keys::k_nua, Results::plugin_2),
     };
 
-    auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, SN::mid);
+    auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, DB_OK, SN::mid);
     auto protocol = std::make_shared<ProtocolAdmin>();
     binaryTestResponse(response, protocol);
 }
@@ -235,7 +254,7 @@ TEST(ProtocolAdmin, ListResponseBinaryMultiplePolicies) {
         Policy(Keys::k_nua, Results::plugin_2),
     };
 
-    auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, SN::min);
+    auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, DB_OK, SN::min);
     auto protocol = std::make_shared<ProtocolAdmin>();
     binaryTestResponse(response, protocol);
 }
@@ -243,7 +262,7 @@ TEST(ProtocolAdmin, ListResponseBinaryMultiplePolicies) {
 TEST(ProtocolAdmin, ListResponseBinaryEmptyPolicies) {
     std::vector<Policy> policies;
 
-    auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, SN::min_1);
+    auto response = std::make_shared<ListResponse>(policies, VALID_BUCKET, DB_OK, SN::min_1);
     auto protocol = std::make_shared<ProtocolAdmin>();
     binaryTestResponse(response, protocol);
 }
@@ -251,7 +270,22 @@ TEST(ProtocolAdmin, ListResponseBinaryEmptyPolicies) {
 TEST(ProtocolAdmin, ListResponseBinaryNoBucket) {
     std::vector<Policy> policies;
 
-    auto response = std::make_shared<ListResponse>(policies, NO_BUCKET, SN::min_2);
+    auto response = std::make_shared<ListResponse>(policies, NO_BUCKET, DB_OK, SN::min_2);
+    auto protocol = std::make_shared<ProtocolAdmin>();
+    binaryTestResponse(response, protocol);
+}
+
+/**
+ * @brief   Verify if ListResponse is properly (de)serialized while database is corrupted
+ * @test    Expected result:
+ * - policies vector is empty
+ * - bucketValid flag set to false (NO_BUCKET)
+ * - dbCorrupted flag set to true (DB_CORRUPTED)
+ */
+TEST(ProtocolAdmin, ListResponseBinaryDatabaseCorrupted) {
+    std::vector<Policy> policies;
+
+    auto response = std::make_shared<ListResponse>(policies, NO_BUCKET, DB_CORRUPTED, SN::max);
     auto protocol = std::make_shared<ProtocolAdmin>();
     binaryTestResponse(response, protocol);
 }