BuildRequires: pkgconfig(libwebappenc)
BuildRequires: cynara-devel
BuildRequires: libcynara-creds-dbus-devel
+BuildRequires: libcynara-creds-gdbus-devel
BuildRequires: pkgconfig(libtzplatform-config)
BuildRequires: boost-devel
BuildRequires: pkgconfig(vconf)
+/*
+ * 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.
+ * 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 MEMORY_H
#define MEMORY_H
#include <sys/smack.h>
#include <dirent.h>
#include <glob.h>
+#include <glib.h>
#define DEFINE_SMARTPTR(func, type, name) \
struct deleter_##func { \
// Defining specializations of unique_ptr
DEFINE_SMARTPTR(free, char, CStringPtr);
+DEFINE_SMARTPTR(g_free, gchar, GStringPtr);
DEFINE_SMARTPTR(closePtr, int, FdUniquePtr);
DEFINE_SMARTPTR(smack_accesses_free, smack_accesses, SmackAccessesPtr);
DEFINE_SMARTPTR(closedir, DIR, DirPtr);
cynara-client
cynara-client-async
cynara-creds-dbus
+ cynara-creds-gdbus
cynara-creds-socket
cynara-plugin
dbus-1
+ glib-2.0
)
#files to compile
#linker directories
TARGET_LINK_LIBRARIES(${CYNARA_TARGET_TEST}
${CYNARA_TARGET_DEP_LIBRARIES}
- dpl-test-framework
tests-common
+ dpl-test-framework
+ gobject-2.0
+ gio-2.0
)
#place for output file
#include <cynara-creds-dbus.h>
#include <cynara-creds-socket.h>
+#include <cynara-creds-gdbus.h>
#include "cynara_test_helpers.h"
return pid;
}
+char *gdbusGetClient(GDBusConnectionPtr connection, const char *uniqueName,
+ cynara_client_creds method, int expectedResult) {
+ char *buff;
+ auto ret = cynara_creds_gdbus_get_client(connection.get(), uniqueName, method, &buff);
+ RUNNER_ASSERT_MSG(ret == expectedResult,
+ "cynara_creds_gdbus_get_client failed, ret = " << ret
+ << "; expected = " << expectedResult);
+ return buff;
+}
+
+char *gdbusGetUser(GDBusConnectionPtr connection, const char *uniqueName, cynara_user_creds method,
+ int expectedResult) {
+ char *buff;
+ auto ret = cynara_creds_gdbus_get_user(connection.get(), uniqueName, method, &buff);
+ RUNNER_ASSERT_MSG(ret == expectedResult,
+ "cynara_creds_gdbus_get_user failed, ret = " << ret
+ << "; expected = " << expectedResult);
+ return buff;
+}
+
+pid_t gdbusGetPid(GDBusConnectionPtr connection, const char *uniqueName) {
+ pid_t pid;
+ auto ret = cynara_creds_gdbus_get_pid(connection.get(), uniqueName, &pid);
+ RUNNER_ASSERT_MSG(ret == CYNARA_API_SUCCESS,
+ "cynara_creds_gdbus_get_pid failed, ret = " << ret);
+ return pid;
+}
+
} //namespace CynaraHelperCredentials
#include <cynara-creds-commons.h>
#include <cynara-error.h>
-
#include <cynara_test_helpers_dbus.h>
namespace CynaraHelperCredentials {
pid_t dbusGetPid(DBusConnectionPtr connection, const char *uniqueName,
int expectedResult = CYNARA_API_SUCCESS);
+char *gdbusGetClient(GDBusConnectionPtr connection, const char *uniqueName,
+ cynara_client_creds method, int expectedResult = CYNARA_API_SUCCESS);
+
+
+char *gdbusGetUser(GDBusConnectionPtr connection, const char *uniqueName, cynara_user_creds method,
+ int expectedResult = CYNARA_API_SUCCESS);
+
+pid_t gdbusGetPid(GDBusConnectionPtr connection, const char *uniqueName);
+
} // namespace CynaraHelperCredentials
#endif // CYNARA_TEST_HELPERS_H_
#include <dbus/dbus.h>
#include <functional>
+#include <gio/gio.h>
#include <memory>
typedef std::function<void(DBusConnection *)> DBusConnectionCloseAndUnref;
+typedef std::function<void(GDBusConnection *)> GDBusConnectionCloseAndUnref;
typedef std::unique_ptr<DBusConnection, DBusConnectionCloseAndUnref> DBusConnectionPtr;
+typedef std::unique_ptr<GDBusConnection, GDBusConnectionCloseAndUnref> GDBusConnectionPtr;
#endif // CYNARA_TEST_HELPERS_DBUS_H_
#include <utility>
#include <dbus/dbus.h>
+#include <glib-object.h>
+#include <gio/gio.h>
#include <tests_common.h>
#include <access_provider.h>
#include <cynara_test_helpers.h>
#include <cynara_test_helpers_dbus.h>
+#include <cynara-creds-gdbus.h>
class ProcessCredentials {
public:
<< "; expected = " << expectedPid);
}, "tccd04");
}
+
+GDBusConnectionPtr createGDBusConnection() {
+ GDBusConnection *conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
+
+ return GDBusConnectionPtr(conn, [] (GDBusConnection *conn) {
+ g_object_unref(G_OBJECT(conn));
+ });
+}
+
+
+typedef std::function<void(GDBusConnectionPtr conn, pid_t pid,
+ const std::string &requestedName,
+ const ProcessCredentials &peerCredentials)> GDBusAssertionFn;
+
+void gdbusTestTemplate(GDBusAssertionFn assertion, const std::string &/*scope*/) {
+ std::string requestedName = "tests.dbus.cynara";
+ const ProcessCredentials peerCredentials;
+
+ SynchronizationPipe pipe;
+ pid_t pid = runInChild(std::bind(dbusServer, std::ref(pipe), std::cref(requestedName),
+ std::cref(peerCredentials)));
+
+ pipe.claimParentEp();
+ pipe.wait();
+
+ auto conn = createGDBusConnection();
+ assertion(std::move(conn), pid, requestedName, peerCredentials);
+ pipe.post();
+}
+
+
+RUNNER_TEST_GROUP_INIT(cynara_creds_gdbus)
+
+RUNNER_TEST_SMACK(tccgd01_gdbus_credentials_client_pid) {
+ gdbusTestTemplate([] (GDBusConnectionPtr conn, pid_t pid, const std::string &requestedName,
+ const ProcessCredentials &) {
+ GStringPtr clientPidStr(CynaraHelperCredentials::gdbusGetClient(std::move(conn),
+ requestedName.c_str(), CLIENT_METHOD_PID));
+ pid_t clientPid = std::stoi(clientPidStr.get());
+ RUNNER_ASSERT_MSG(pid == clientPid, "PIDs don't match ret = " << clientPid
+ << "; expected = " << pid);
+ }, "tccgd01");
+}
+
+RUNNER_TEST_SMACK(tccgd02_gdbus_credentials_client_smack) {
+ gdbusTestTemplate([] (GDBusConnectionPtr conn, pid_t, const std::string &requestedName,
+ const ProcessCredentials &peerCredentials) {
+ GStringPtr label(CynaraHelperCredentials::gdbusGetClient(std::move(conn),
+ requestedName.c_str(), CLIENT_METHOD_SMACK));
+ RUNNER_ASSERT_MSG(peerCredentials.label() == label.get(),
+ "Labels don't match ret = " << label.get()
+ << "; expected = " << peerCredentials.label());
+ }, "tccgd02");
+}
+
+RUNNER_TEST_SMACK(tccgd03_gdbus_credentials_user_uid) {
+ gdbusTestTemplate([] (GDBusConnectionPtr conn, pid_t, const std::string &requestedName,
+ const ProcessCredentials &peerCredentials) {
+ GStringPtr uidStr(CynaraHelperCredentials::gdbusGetUser(std::move(conn),
+ requestedName.c_str(), USER_METHOD_UID));
+ uid_t uid = std::stoul(uidStr.get());
+ RUNNER_ASSERT_MSG(peerCredentials.uid() == uid, "UIDs don't match ret = " << uid
+ << "; expected = "<< peerCredentials.uid());
+ }, "tccgd03");
+}
+
+RUNNER_TEST_SMACK(tccgd04_gdbus_credentials_pid) {
+ gdbusTestTemplate([] (GDBusConnectionPtr conn, pid_t expectedPid,
+ const std::string &requestedName, const ProcessCredentials &) {
+ auto helperPid = CynaraHelperCredentials::gdbusGetPid(std::move(conn),
+ requestedName.c_str());
+ RUNNER_ASSERT_MSG(helperPid == expectedPid, "PIDs don't match ret = " << helperPid
+ << "; expected = " << expectedPid);
+ }, "tccgd04");
+}