<filesystem path="/usr/bin/cynara-tests" exec_label="_" />
<filesystem path="/usr/bin/ckm-tests" exec_label="User" />
<filesystem path="/usr/bin/ckm-privileged-tests" exec_label="System::Privileged" />
+ <filesystem path="/usr/bin/nether-tests" exec_label="System::Privileged" />
+ <filesystem path="/usr/bin/libteec-tests" exec_label="System::Privileged" />
+ <filesystem path="/usr/bin/yaca-test" exec_label="System::Privileged" />
</assign>
<request>
<domain name="_" />
cynara-creds-gdbus
cynara-creds-self
cynara-creds-socket
+ cynara-monitor
cynara-plugin
dbus-1
glib-2.0
${PROJECT_SOURCE_DIR}/src/cynara-tests/common/cynara_test_cynara_mask.cpp
${PROJECT_SOURCE_DIR}/src/cynara-tests/common/cynara_test_env.cpp
${PROJECT_SOURCE_DIR}/src/cynara-tests/common/cynara_test_file_operations.cpp
+ ${PROJECT_SOURCE_DIR}/src/cynara-tests/common/cynara_test_monitor.cpp
${PROJECT_SOURCE_DIR}/src/cynara-tests/plugins/plugins.cpp
${PROJECT_SOURCE_DIR}/src/cynara-tests/cynara-test.cpp
${PROJECT_SOURCE_DIR}/src/cynara-tests/test_cases.cpp
${PROJECT_SOURCE_DIR}/src/cynara-tests/test_cases_async.cpp
${PROJECT_SOURCE_DIR}/src/cynara-tests/test_cases_db.cpp
${PROJECT_SOURCE_DIR}/src/cynara-tests/test_cases_helpers.cpp
+ ${PROJECT_SOURCE_DIR}/src/cynara-tests/test_cases_monitor.cpp
)
#header directories
<< "response = " << response);
}
+void Agent::cancelWaiting(int expectedResult) {
+ int ret = cynara_agent_cancel_waiting(m_agent);
+ RUNNER_ASSERT_MSG(ret == expectedResult,
+ "cynara_agent_cancel_waiting returned wrong value: "
+ << ret << " != " << expectedResult << ".");
+}
+
} // namespace CynaraTestAgent
void getRequest(AgentRequest &request, int expectedResult = CYNARA_API_SUCCESS);
void putResponse(const AgentResponse &response, int expectedResult = CYNARA_API_SUCCESS);
+ void cancelWaiting(int expectedResult = CYNARA_API_SUCCESS);
private:
struct cynara_agent *m_agent;
{
cynara_finish(m_cynara);
}
+void Client::check(const char *client, const char *session, const char *user,
+ const char *privilege, int expectedResult)
+{
+ int ret = cynara_check(m_cynara, client, session, user, privilege);
+ RUNNER_ASSERT_MSG(ret == expectedResult,
+ "cynara_check returned wrong value: "
+ << ret << " != " << expectedResult << "."
+ << " client: " << formatCstr(client) << ","
+ << " session: " << formatCstr(session) << ","
+ << " user: " << formatCstr(user) << ","
+ << " privilege: " << formatCstr(privilege));
+}
void Client::check(const std::string &client, const std::string &session,
const std::string &user, const std::string &privilege,
int expectedResult)
{
- int ret = cynara_check(m_cynara, client.c_str(), session.c_str(), user.c_str(), privilege.c_str());
- RUNNER_ASSERT_MSG(ret == expectedResult,
- "cynara_check returned wrong value: "
- << ret << " != " << expectedResult << "."
- << " client: " << formatCstr(client.c_str()) << ","
- << " session: " << formatCstr(session.c_str()) << ","
- << " user: " << formatCstr(user.c_str()) << ","
- << " privilege: " << formatCstr(privilege.c_str()));
+ check(client.c_str(), session.c_str(), user.c_str(), privilege.c_str(), expectedResult);
}
} //namespace CynaraTestClient
Client();
virtual ~Client();
+ void check(const char *client, const char *session, const char *user, const char *privilege,
+ int expectedResult = CYNARA_API_ACCESS_ALLOWED);
void check(const std::string &client, const std::string &session,
const std::string &user, const std::string &privilege,
int expectedResult = CYNARA_API_ACCESS_ALLOWED);
-
private:
struct cynara *m_cynara;
};
--- /dev/null
+/*
+ * Copyright (c) 2016 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 <cynara_test_monitor.h>
+
+#include <tests_common.h>
+
+namespace CynaraTestMonitor {
+
+MonitorEntries::MonitorEntries(cynara_monitor_entry **entries)
+ : m_entries(entries)
+{
+}
+
+MonitorEntries::~MonitorEntries()
+{
+ cynara_monitor_entries_free(m_entries);
+}
+
+size_t MonitorEntries::count()
+{
+ size_t count = 0;
+
+ while (m_entries[count]) {
+ ++count;
+ }
+
+ return count;
+}
+
+const MonitorEntries& MonitorEntries::operator=(cynara_monitor_entry **other)
+{
+ m_entries = other;
+
+ return *this;
+}
+
+const cynara_monitor_entry* MonitorEntries::operator[](size_t i) const
+{
+ return m_entries[i];
+}
+
+Monitor::Monitor(size_t entries)
+ : m_monitor(nullptr)
+{
+ int ret;
+ struct cynara_monitor_configuration *cfg = nullptr;
+
+ if (entries > 0) {
+ ret = cynara_monitor_configuration_create(&cfg);
+ RUNNER_ASSERT_MSG(ret == CYNARA_API_SUCCESS,
+ "cynara_monitor_configuration_create failed. "
+ "ret: " << ret);
+ RUNNER_ASSERT_MSG(cfg != nullptr, "cynara_monitor_configuration struct "
+ "was not initialized");
+
+ ret = cynara_monitor_configuration_set_buffer_size(cfg, entries);
+ RUNNER_ASSERT_MSG(ret == CYNARA_API_SUCCESS,
+ "cynara_monitor_configuration_set_buffer_size failed. "
+ "ret: " << ret);
+ }
+
+ ret = cynara_monitor_initialize(&m_monitor, cfg);
+ RUNNER_ASSERT_MSG(ret == CYNARA_API_SUCCESS,
+ "cynara_monitor_initialize failed. ret: " << ret);
+ RUNNER_ASSERT_MSG(m_monitor != nullptr, "cynara_monitor struct was not initialized");
+}
+
+Monitor::~Monitor()
+{
+ cynara_monitor_finish(m_monitor);
+}
+
+cynara_monitor_entry** Monitor::get()
+{
+ struct cynara_monitor_entry **entries;
+ int ret = cynara_monitor_entries_get(m_monitor, &entries);
+ RUNNER_ASSERT_MSG(ret == CYNARA_API_SUCCESS,
+ "cynara_monitor_entries_get failed. ret: " << ret);
+ RUNNER_ASSERT_MSG(entries != nullptr, "cynara_monitor_entry table was not initialized");
+
+ return entries;
+}
+
+void Monitor::flush()
+{
+ cynara_monitor_entries_flush(m_monitor);
+}
+
+} //namespace CynaraTestMonitor
--- /dev/null
+/*
+ * Copyright (c) 2016 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 CYNARA_TEST_MONITOR_H
+#define CYNARA_TEST_MONITOR_H
+
+#include <cynara-monitor.h>
+
+namespace CynaraTestMonitor {
+
+class MonitorEntries
+{
+public:
+ MonitorEntries(cynara_monitor_entry **entries = NULL);
+ MonitorEntries(const MonitorEntries& that) = delete;
+ virtual ~MonitorEntries();
+
+ const MonitorEntries& operator=(const MonitorEntries &other) = delete;
+ const MonitorEntries& operator=(cynara_monitor_entry **other);
+ const cynara_monitor_entry* operator[](size_t i) const;
+
+ size_t count();
+
+private:
+ cynara_monitor_entry **m_entries;
+};
+
+class Monitor
+{
+public:
+ Monitor(size_t entries = 0);
+ Monitor(const Monitor &that) = delete;
+ virtual ~Monitor();
+
+ const Monitor& operator=(const Monitor &other) = delete;
+
+ cynara_monitor_entry** get();
+ void flush();
+
+private:
+ cynara_monitor *m_monitor;
+};
+
+} //namespace CynaraTestMonitor
+
+#endif // CYNARA_TEST_MONITOR_H
client.process(CYNARA_API_SUCCESS, Client::TimeoutExpectation::EXPECT_NO_TIMEOUT, 2);
}
+void tcag16_agent_cancel_waiting_func()
+{
+ Agent agent;
+ AgentRequest request;
+
+ auto testTimeLimit = std::chrono::seconds(2);
+ auto cancelRequest = [&agent]() {
+ agent.cancelWaiting();
+ };
+ auto hangOnGetRequest = [&agent, &request]() {
+ agent.getRequest(request, CYNARA_API_INTERRUPTED);
+ };
+
+ Timeout::callAndWait(testTimeLimit, Timeout::ExpectMode::TIMEOUT,
+ cancelRequest, hangOnGetRequest);
+}
+
RUNNER_TEST_GROUP_INIT(cynara_agent_tests)
RUN_CYNARA_TEST(tcag01_set_agent_type_policy_without_plugin)
RUN_CYNARA_TEST(tcag13_create_many_requests)
RUN_CYNARA_TEST(tcag14_client_disconnects)
RUN_CYNARA_TEST(tcag15_agent_disconnects)
+RUN_CYNARA_TEST(tcag16_agent_cancel_waiting)
--- /dev/null
+/*
+ * Copyright (c) 2016 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_cases_monitor.cpp
+ * @author Lukasz Pawelczyk <l.pawelczyk@partner.samsung.com>
+ * @version 1.0
+ * @brief Tests for libcynara-monitor
+ */
+
+#include <cynara-error.h>
+#include <cynara-client.h>
+#include <cynara-monitor.h>
+
+#include <dpl/test/test_runner.h>
+#include <cynara_test_commons.h>
+#include <cynara_test_client.h>
+#include <cynara_test_monitor.h>
+#include <timeout.h>
+
+using namespace CynaraTestClient;
+using namespace CynaraTestMonitor;
+
+namespace {
+
+inline void assertResult(int ret, int expectedResult)
+{
+ RUNNER_ASSERT_MSG(ret == expectedResult,"Expected result: " << expectedResult
+ << ", got: " << ret);
+}
+
+void clientChecks(size_t num, size_t start = 0)
+{
+ Client cynaraClient;
+
+ for (size_t i = 0; i < num; ++i) {
+ std::string index = std::to_string(i + start);
+ std::string client = "client" + index;
+ std::string session = "session" + index;
+ std::string user = "user" + index;
+ std::string privilege = "privilege" + index;
+
+ cynaraClient.check(client.c_str(), session.c_str(), user.c_str(),
+ privilege.c_str(), CYNARA_API_ACCESS_DENIED);
+ }
+}
+
+bool validateEntries(const MonitorEntries &entries, size_t num, size_t start = 0)
+{
+ for (size_t i = 0; i < num; ++i) {
+ std::string index = std::to_string(i + start);
+ std::string client = "client" + index;
+ std::string user = "user" + index;
+ std::string privilege = "privilege" + index;
+
+ if (client != std::string(cynara_monitor_entry_get_client(entries[i])) ||
+ user != std::string(cynara_monitor_entry_get_user(entries[i])) ||
+ privilege != std::string(cynara_monitor_entry_get_privilege(entries[i]))) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+} // namespace
+
+void tcm01_config_invalid_param_func()
+{
+ int ret = cynara_monitor_configuration_create(nullptr);
+ assertResult(ret, CYNARA_API_INVALID_PARAM);
+}
+
+void tcm02_config_buffer_oversize_func()
+{
+ int ret;
+ struct cynara_monitor_configuration *cfg;
+
+ ret = cynara_monitor_configuration_create(&cfg);
+ assertResult(ret, CYNARA_API_SUCCESS);
+
+ ret = cynara_monitor_configuration_set_buffer_size(cfg, CYNARA_MAX_MONITOR_BUFFER_SIZE);
+ assertResult(ret, CYNARA_API_SUCCESS);
+
+ ret = cynara_monitor_configuration_set_buffer_size(cfg, CYNARA_MAX_MONITOR_BUFFER_SIZE + 1);
+ assertResult(ret, CYNARA_API_INVALID_PARAM);
+}
+
+void tcm03_init_invalid_param_func()
+{
+ int ret = cynara_monitor_initialize(nullptr, nullptr);
+ assertResult(ret, CYNARA_API_INVALID_PARAM);
+}
+
+void tcm04_entries_get_flush_no_entries_func()
+{
+ auto timeLimit = std::chrono::milliseconds(10);
+ Monitor monitor(100);
+ MonitorEntries entries;
+
+ auto getMonitorEntries = [&monitor, &entries]() {
+ entries = monitor.get();
+ };
+
+ auto flush = [&monitor]() {
+ monitor.flush();
+ };
+
+ Timeout::callAndWait(timeLimit, Timeout::ExpectMode::TIMEOUT,
+ flush, getMonitorEntries);
+
+ // TODO: system's cynara checks might increase this number
+ if (entries.count() != 0)
+ RUNNER_IGNORED_MSG("no entries should've been returned");
+}
+
+void tcm05_entries_get_no_flush_func()
+{
+ auto timeLimit = std::chrono::milliseconds(10);
+ Monitor monitor(100);
+ MonitorEntries entries;
+
+ auto getMonitorEntries = [&monitor, &entries]() {
+ entries = monitor.get();
+ };
+
+ auto client = [&monitor]() {
+ clientChecks(100);
+ };
+
+ Timeout::callAndWait(timeLimit, Timeout::ExpectMode::TIMEOUT,
+ client, getMonitorEntries);
+
+ RUNNER_ASSERT_MSG(entries.count() == 100, "100 entries should've been returned");
+
+ // TODO: system's cynara checks might cause the entries to differ
+ if (!validateEntries(entries, 100))
+ RUNNER_IGNORED_MSG("Entries received from monitor are not as expected");
+}
+
+void tcm06_entries_get_flush_func()
+{
+ auto getLimit = std::chrono::milliseconds(10);
+ Monitor monitor(200);
+ MonitorEntries entries;
+
+ auto getMonitorEntries = [&monitor, &entries]() {
+ entries = monitor.get();
+ };
+
+ auto clientAndFlush = [&monitor]() {
+ clientChecks(10);
+ monitor.flush();
+ };
+
+ Timeout::callAndWait(getLimit, Timeout::ExpectMode::TIMEOUT,
+ clientAndFlush, getMonitorEntries);
+
+ // TODO: system's cynara checks might increase this number
+ if (entries.count() != 10)
+ RUNNER_IGNORED_MSG("10 entries should've been returned");
+
+ // TODO: system's cynara checks might cause the entries to differ
+ if (!validateEntries(entries, 10))
+ RUNNER_IGNORED_MSG("Entries received from monitor are not as expected");
+}
+
+void tcm07_entries_get_two_func()
+{
+ auto get1Limit = std::chrono::milliseconds(10);
+ Monitor monitor1(200);
+ Monitor monitor2(100);
+ MonitorEntries entries1;
+ MonitorEntries entries2;
+
+ auto getMonitor1Entries = [&monitor1, &entries1]() {
+ entries1 = monitor1.get();
+ };
+
+ auto clientAndGetMonitor2Entries = [&monitor2, &entries2]() {
+ auto get2Limit = std::chrono::milliseconds(10);
+
+ clientChecks(100);
+
+ auto getMonitor2Entries = [&monitor2, &entries2]() {
+ entries2 = monitor2.get();
+ };
+
+ auto client = []() {
+ clientChecks(100, 100);
+ };
+
+ Timeout::callAndWait(get2Limit, Timeout::ExpectMode::TIMEOUT,
+ client, getMonitor2Entries);
+ };
+
+ Timeout::callAndWait(get1Limit, Timeout::ExpectMode::TIMEOUT,
+ clientAndGetMonitor2Entries, getMonitor1Entries);
+
+ RUNNER_ASSERT_MSG(entries1.count() == 200, "200 entries should've been returned by the first monitor");
+ RUNNER_ASSERT_MSG(entries2.count() == 100, "100 entries should've been returned by the second monitor");
+
+ // TODO: system's cynara checks might cause the entries to differ
+ if (!validateEntries(entries1, 200))
+ RUNNER_IGNORED_MSG("Entries received from the first monitor are not as expected");
+ if (!validateEntries(entries2, 100, 100))
+ RUNNER_IGNORED_MSG("Entries received from the second monitor are not as expected");
+}
+
+RUNNER_TEST_GROUP_INIT(cynara_monitor_tests)
+
+RUN_CYNARA_TEST(tcm01_config_invalid_param)
+RUN_CYNARA_TEST(tcm02_config_buffer_oversize)
+RUN_CYNARA_TEST(tcm03_init_invalid_param)
+RUN_CYNARA_TEST(tcm04_entries_get_flush_no_entries)
+RUN_CYNARA_TEST(tcm05_entries_get_no_flush)
+RUN_CYNARA_TEST(tcm06_entries_get_flush)
+RUN_CYNARA_TEST(tcm07_entries_get_two)