--- /dev/null
+/*
+ * Copyright (c) 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.
+ * 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.
+ */
+
+#include <sm_policy_request.h>
+
+#include <dpl/test/test_runner.h>
+
+namespace SecurityManagerTest {
+
+PolicyEntry::PolicyEntry()
+ : m_appId(true, std::string(SECURITY_MANAGER_ANY))
+ , m_user(true, std::string(SECURITY_MANAGER_ANY))
+ , m_privilege(true, std::string(SECURITY_MANAGER_ANY))
+ , m_currentLevel(false, std::string(""))
+ , m_maxLevel(false, std::string(""))
+{
+ int result = security_manager_policy_entry_new(&m_entry);
+ RUNNER_ASSERT_MSG((lib_retcode)result == SECURITY_MANAGER_SUCCESS,
+ "creation of new policy entry failed. Result: " << result);
+ RUNNER_ASSERT_MSG(m_entry != nullptr, "creation of new policy entry did not allocate memory");
+
+ security_manager_policy_entry_set_application(m_entry, m_appId.second.c_str());
+ security_manager_policy_entry_set_user(m_entry, m_user.second.c_str());
+ security_manager_policy_entry_set_privilege(m_entry, m_privilege.second.c_str());
+}
+
+PolicyEntry::PolicyEntry(const std::string &appId, const std::string &user,
+ const std::string &privilege)
+ : m_appId(true, std::string(appId))
+ , m_user(true, std::string(user))
+ , m_privilege(true, std::string(privilege))
+ , m_currentLevel(false, std::string(""))
+ , m_maxLevel(false, std::string(""))
+{
+ int result = security_manager_policy_entry_new(&m_entry);
+ RUNNER_ASSERT_MSG((lib_retcode)result == SECURITY_MANAGER_SUCCESS,
+ "creation of new policy entry failed. Result: " << result);
+ RUNNER_ASSERT_MSG(m_entry != nullptr, "creation of new policy entry did not allocate memory");
+
+ security_manager_policy_entry_set_user(m_entry, m_user.second.c_str());
+ security_manager_policy_entry_set_application(m_entry, m_appId.second.c_str());
+ security_manager_policy_entry_set_privilege(m_entry, m_privilege.second.c_str());
+}
+
+PolicyEntry::PolicyEntry(policy_entry &entry): m_entry(&entry)
+{
+ m_appId.first = true;
+ m_appId.second = std::string(security_manager_policy_entry_get_application(m_entry));
+
+ m_user.first = true;
+ m_user.second = std::string(security_manager_policy_entry_get_user(m_entry));
+
+ m_privilege.first = true;
+ m_privilege.second = std::string(security_manager_policy_entry_get_privilege(m_entry));
+
+ m_currentLevel.first = true;
+ m_currentLevel.second = std::string(security_manager_policy_entry_get_level(m_entry));
+
+ m_maxLevel.first = true;
+ m_maxLevel.second = std::string(security_manager_policy_entry_get_max_level(m_entry));
+};
+
+void PolicyEntry::setLevel(const std::string &level)
+{
+ m_currentLevel.first = true;
+ m_currentLevel.second = level;
+ security_manager_policy_entry_set_level(m_entry, level.c_str());
+ m_maxLevel.first = true;
+ m_maxLevel.second = std::string(security_manager_policy_entry_get_max_level(m_entry));
+};
+
+void PolicyEntry::setMaxLevel(const std::string &level)
+{
+ m_maxLevel.first = true;
+ m_maxLevel.second = level;
+ security_manager_policy_entry_admin_set_level(m_entry, level.c_str());
+ m_currentLevel.first = true;
+ m_currentLevel.second = std::string(security_manager_policy_entry_get_level(m_entry));
+};
+
+
+std::ostream& operator<<(std::ostream &os, const PolicyEntry &request)
+{
+ if (request.m_appId.first)
+ os << "appId: " << request.m_appId.second << "; ";
+
+ if (request.m_user.first)
+ os << "user: " << request.m_user.second << "; ";
+
+ if (request.m_privilege.first)
+ os << "privilege: " << request.m_privilege.second << "; ";
+
+ if (request.m_currentLevel.first)
+ os << "current: " << request.m_currentLevel.second << "; ";
+
+ if (request.m_maxLevel.first)
+ os << "max: " << request.m_maxLevel.second << "; ";
+
+ return os;
+}
+
+PolicyEntry::~PolicyEntry()
+{
+}
+
+void PolicyEntry::free(void)
+{
+ security_manager_policy_entry_free(m_entry);
+}
+
+
+PolicyRequest::PolicyRequest()
+ : m_req(nullptr),
+ m_entries()
+{
+ int result = security_manager_policy_update_req_new(&m_req);
+ RUNNER_ASSERT_MSG((lib_retcode)result == SECURITY_MANAGER_SUCCESS,
+ "creation of new policy request failed. Result: " << result);
+ RUNNER_ASSERT_MSG(m_req != nullptr, "creation of new policy request did not allocate memory");
+}
+
+PolicyRequest::~PolicyRequest()
+{
+ for(std::vector<PolicyEntry>::iterator it = m_entries.begin(); it != m_entries.end(); ++it) {
+ it->free();
+ }
+ security_manager_policy_update_req_free(m_req);
+}
+
+void PolicyRequest::addEntry(PolicyEntry &entry,
+ lib_retcode expectedResult)
+{
+ int result = 0;
+
+ result = security_manager_policy_update_req_add_entry(m_req, entry.get());
+
+ RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
+ "adding policy entry to request returned wrong value."
+ << " entry: " << entry << ";"
+ << " Result: " << result << ";"
+ << " Expected result: " << expectedResult);
+
+ m_entries.push_back(entry);
+}
+
+std::ostream& operator<<(std::ostream &os, const PolicyRequest &request)
+{
+ if (request.m_entries.size() != 0)
+ {
+ os << "PolicyRequest m_entries size: " << request.m_entries.size() << "; ";
+
+ for(unsigned int i = 0; i != request.m_entries.size(); i++) {
+ os << "entry " << i << ": " << request.m_entries[i] << "; ";
+ }
+ }
+
+ return os;
+}
+
+} // namespace SecurityManagerTest
--- /dev/null
+/*
+ * Copyright (c) 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.
+ * 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.
+ */
+
+#ifndef SECURITY_MANAGER_TEST_POLICYREQUEST
+#define SECURITY_MANAGER_TEST_POLICYREQUEST
+
+#include <iostream>
+#include <sys/types.h>
+#include <utility>
+#include <vector>
+
+#include <security-manager.h>
+
+namespace SecurityManagerTest {
+
+class PolicyEntry
+{
+public:
+ PolicyEntry();
+
+ PolicyEntry(const std::string &appId,
+ const std::string &user,
+ const std::string &privilege
+ );
+ ~PolicyEntry();
+
+ PolicyEntry(policy_entry &entry);
+
+ policy_entry *get() const { return m_entry; }
+ std::string getUser() const { return m_user.second; }
+ std::string getAppId() const { return m_appId.second; }
+ std::string getPrivilege() const { return m_privilege.second; }
+ std::string getCurrentLevel() const { return m_currentLevel.second; }
+ std::string getMaxLevel() const { return m_maxLevel.second; }
+ void setLevel(const std::string &level);
+ void setMaxLevel(const std::string &level);
+ void free(void);
+
+ friend std::ostream& operator<<(std::ostream &, const PolicyEntry&);
+
+private:
+ policy_entry *m_entry;
+ std::pair<bool, std::string> m_appId;
+ std::pair<bool, std::string> m_user;
+ std::pair<bool, std::string> m_privilege;
+ std::pair<bool, std::string> m_currentLevel;
+ std::pair<bool, std::string> m_maxLevel;
+};
+
+std::ostream& operator<<(std::ostream &os, const SecurityManagerTest::PolicyEntry &request);
+
+class PolicyRequest
+{
+public:
+ PolicyRequest();
+ PolicyRequest(const PolicyRequest&) = delete;
+ PolicyRequest& operator=(const PolicyRequest&) = delete;
+ ~PolicyRequest();
+
+ void addEntry(PolicyEntry &entry, lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS);
+
+ policy_update_req *get() const { return m_req; }
+ friend std::ostream& operator<<(std::ostream &, const PolicyRequest&);
+
+private:
+ policy_update_req *m_req;
+ std::vector<PolicyEntry> m_entries;
+};
+
+std::ostream& operator<<(std::ostream &os, const SecurityManagerTest::PolicyRequest &request);
+
+} // namespace SecurityManagerTest
+
+#endif // SECURITY_MANAGER_TEST_USERREQUEST