/*
- * 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.
* @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
*/
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());
}
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) {
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) {
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());
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()));
}
= 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());
ProtocolSerialization::serialize(frame, desc.type);
ProtocolSerialization::serialize(frame, desc.name);
}
+ ProtocolSerialization::serialize(frame, response->isDbCorrupted());
+
ProtocolFrameSerializer::finishSerialization(frame, *(context->responseQueue()));
}
= 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());
ProtocolSerialization::serialize(frame, policy.result().metadata());
}
ProtocolSerialization::serialize(frame, response->isBucketValid());
+ ProtocolSerialization::serialize(frame, response->isDbCorrupted());
ProtocolFrameSerializer::finishSerialization(frame, *(context->responseQueue()));
}
/*
- * 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.
/**
* @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
*/
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() {}
return m_bucketValid;
}
+ bool isDbCorrupted(void) const {
+ return m_dbCorrupted;
+ }
+
private:
const PolicyResult m_result;
bool m_bucketValid;
+ bool m_dbCorrupted;
};
} // namespace Cynara
/**
* @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
*/
NO_BUCKET,
NO_POLICY_TYPE,
NOT_ALLOWED,
- FAILED
+ FAILED,
+ DB_CORRUPTED
};
const Code m_code;
/*
- * 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.
/**
* @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
*/
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
/*
- * 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.
/**
* @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
*/
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() {};
return m_bucketValid;
}
+ bool isDbCorrupted(void) const {
+ return m_dbCorrupted;
+ }
+
const std::vector<Policy> &policies(void) const {
return m_policies;
}
private:
std::vector<Policy> m_policies;
bool m_bucketValid;
+ bool m_dbCorrupted;
};
} // namespace Cynara
* @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
*/
namespace Cynara {
-Logic::Logic() {
+Logic::Logic() : m_dbCorrupted(false) {
}
Logic::~Logic() {
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) {
return false;
}
- result = m_storage->checkPolicy(key);
+ result = (m_dbCorrupted ? PredefinedPolicyType::DENY : m_storage->checkPolicy(key));
switch (result.policyType()) {
case PredefinedPolicyType::ALLOW :
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,
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,
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()));
}
* @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
*/
StoragePtr m_storage;
SocketManagerPtr m_socketManager;
AuditLog m_auditLog;
+ bool m_dbCorrupted;
bool check(const RequestContextPtr &context, const PolicyKey &key,
ProtocolFrameSequenceNumber checkId, PolicyResult &result);
/*
- * 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.
/**
* @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
*/
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 */
/* *** 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);
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);
}
/* *** 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);
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);
}
/*
- * 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.
/**
* @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
*/
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;
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
/*
- * 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.
/**
* @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
*/
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 */
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}