--- /dev/null
+/*
+ * Copyright (c) 2014 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file src/cyad/AdminPolicyParser.cpp
+ * @author Aleksander Zdyb <a.zdyb@samsung.com>
+ * @version 1.0
+ * @brief Parses policies from input stream
+ */
+
+#include <exceptions/BucketRecordCorruptedException.h>
+#include <storage/StorageDeserializer.h>
+#include <storage/StorageSerializer.h>
+
+#include "AdminPolicyParser.h"
+
+namespace Cynara {
+
+namespace AdminPolicyParser {
+
+CynaraAdminPolicies parse(const std::shared_ptr<std::istream> &input) {
+ CynaraAdminPolicies policies;
+
+ for (std::size_t lineNum = 1; !input->eof(); ++lineNum) {
+ std::string line;
+ std::getline(*input, line, StorageSerializer::recordSeparator());
+
+ if (line.empty())
+ break;
+
+ try {
+ std::size_t beginToken = 0;
+ auto bucketId = StorageDeserializer::parseBucketId(line, beginToken);
+ auto policyKey = BucketDeserializer::parseKey(line, beginToken);
+ auto policyType = StorageDeserializer::parsePolicyType(line, beginToken);
+ auto metadata = StorageDeserializer::parseMetadata(line, beginToken);
+
+ policies.add(bucketId, PolicyResult(policyType, metadata), policyKey);
+ } catch (const BucketRecordCorruptedException &ex) {
+ throw ex.withLineNumber(lineNum);
+ }
+ }
+
+ policies.seal();
+ return policies;
+}
+
+} /* namespace AdminPolicyParser */
+
+} /* namespace Cynara */
--- /dev/null
+/*
+ * Copyright (c) 2014 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file src/cyad/AdminPolicyParser.h
+ * @author Aleksander Zdyb <a.zdyb@samsung.com>
+ * @version 1.0
+ * @brief Parses policies from input stream
+ */
+
+#ifndef SRC_CYAD_ADMINPOLICYPARSER_H_
+#define SRC_CYAD_ADMINPOLICYPARSER_H_
+
+#include <istream>
+#include <memory>
+
+#include <cyad/CynaraAdminPolicies.h>
+
+namespace Cynara {
+
+namespace AdminPolicyParser {
+
+CynaraAdminPolicies parse(const std::shared_ptr<std::istream> &input);
+
+} /* namespace AdminPolicyParser */
+
+} /* namespace Cynara */
+
+#endif /* SRC_CYAD_ADMINPOLICYPARSER_H_ */
SET(CYAD_SOURCES
${CYAD_PATH}/AdminApiWrapper.cpp
+ ${CYAD_PATH}/AdminPolicyParser.cpp
${CYAD_PATH}/CynaraAdminPolicies.cpp
${CYAD_PATH}/DispatcherIO.cpp
${CYAD_PATH}/main.cpp
${CYNARA_SRC}/common/types/PolicyDescription.cpp
${CYNARA_SRC}/common/types/PolicyResult.cpp
${CYNARA_SRC}/common/types/PolicyType.cpp
+ ${CYNARA_SRC}/cyad/AdminPolicyParser.cpp
${CYNARA_SRC}/cyad/CynaraAdminPolicies.cpp
${CYNARA_SRC}/helpers/creds-commons/CredsCommonsInner.cpp
${CYNARA_SRC}/helpers/creds-commons/creds-commons.cpp
credsCommons/parser/Parser.cpp
cyad/helpers.cpp
cyad/policy_collection.cpp
+ cyad/policy_parser.cpp
helpers.cpp
storage/performance/bucket.cpp
storage/storage/policies.cpp
#ifndef TEST_CYAD_HELPERS_H_
#define TEST_CYAD_HELPERS_H_
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
struct cynara_admin_policy;
bool operator==(const cynara_admin_policy &lhs, const cynara_admin_policy &rhs);
bool operator!=(const cynara_admin_policy &lhs, const cynara_admin_policy &rhs);
+
+MATCHER_P(AdmPolicyListEq, policies, "") {
+ unsigned i = 0;
+ while (policies[i] != nullptr && arg[i] != nullptr) {
+ if (*policies[i] != *arg[i])
+ return false;
+ ++i;
+ }
+ return policies[i] == nullptr && arg[i] == nullptr;
+}
+
namespace Cynara {
namespace Helpers {
--- /dev/null
+/*
+ * Copyright (c) 2014 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file test/cyad/commandline.cpp
+ * @author Aleksander Zdyb <a.zdyb@samsung.com>
+ * @version 1.0
+ * @brief Tests for AdminPolicyParser
+ */
+
+#include <memory>
+#include <sstream>
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#include <common/exceptions/BucketRecordCorruptedException.h>
+#include <common/types/PolicyKey.h>
+#include <cyad/AdminPolicyParser.h>
+
+#include "helpers.h"
+
+TEST(AdminPolicyParser, parseInvalid) {
+ auto input = std::make_shared<std::stringstream>();
+
+ *input << "invalid input" << std::endl;
+
+ ASSERT_THROW(Cynara::AdminPolicyParser::parse(input), Cynara::BucketRecordCorruptedException);
+}
+
+TEST(AdminPolicyParser, parse0) {
+ auto input = std::make_shared<std::stringstream>();
+
+ Cynara::CynaraAdminPolicies expectedPolicies;
+ expectedPolicies.seal();
+
+ auto policies = Cynara::AdminPolicyParser::parse(input);
+
+ ASSERT_TRUE(policies.sealed());
+ ASSERT_THAT(policies.data(), AdmPolicyListEq(expectedPolicies.data()));
+}
+
+TEST(AdminPolicyParser, parse1) {
+ auto input = std::make_shared<std::stringstream>();
+
+ *input << "b;c;u;p;0;m" << std::endl;
+
+ Cynara::CynaraAdminPolicies expectedPolicies;
+ expectedPolicies.add("b", { 0, "m" }, { "c", "u", "p" });
+ expectedPolicies.seal();
+
+ auto policies = Cynara::AdminPolicyParser::parse(input);
+
+ ASSERT_TRUE(policies.sealed());
+ ASSERT_THAT(policies.data(), AdmPolicyListEq(expectedPolicies.data()));
+}
+
+TEST(AdminPolicyParser, parse2) {
+ auto input = std::make_shared<std::stringstream>();
+
+ *input << "b1;c1;u1;p1;0;m1" << std::endl;
+ *input << "b2;c2;u2;p2;0;m2" << std::endl;
+
+ Cynara::CynaraAdminPolicies expectedPolicies;
+ expectedPolicies.add("b1", { 0, "m1" }, { "c1", "u1", "p1" });
+ expectedPolicies.add("b2", { 0, "m2" }, { "c2", "u2", "p2" });
+ expectedPolicies.seal();
+
+ auto policies = Cynara::AdminPolicyParser::parse(input);
+
+ ASSERT_TRUE(policies.sealed());
+ ASSERT_THAT(policies.data(), AdmPolicyListEq(expectedPolicies.data()));
+}