From cf2e8335f71676f77fc92b46817526e3b5b82a4b Mon Sep 17 00:00:00 2001 From: Zofia Abramowska Date: Wed, 10 Aug 2016 12:11:23 +0200 Subject: [PATCH] Cynara: Redo gdbus helpers tests Change-Id: I7317d9921b3498a8cb8ecd32ada9b13b79da5f8e --- src/cynara-tests/test_cases_helpers.cpp | 94 +++++++++++++++++++++++++++------ 1 file changed, 79 insertions(+), 15 deletions(-) diff --git a/src/cynara-tests/test_cases_helpers.cpp b/src/cynara-tests/test_cases_helpers.cpp index 320dfd0..5e0f1cd 100644 --- a/src/cynara-tests/test_cases_helpers.cpp +++ b/src/cynara-tests/test_cases_helpers.cpp @@ -430,47 +430,111 @@ void gdbusTestTemplate(GDBusAssertionFn assertion, const std::string &/*scope*/) 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 &) { +void testGdbusClientPid(cynara_client_creds method = CLIENT_METHOD_PID) { + gdbusTestTemplate([method] (GDBusConnectionPtr conn, pid_t pid, + const std::string &requestedName, + const ProcessCredentials &) { GStringPtr clientPidStr(CynaraHelperCredentials::gdbusGetClient(std::move(conn), - requestedName.c_str(), CLIENT_METHOD_PID)); + requestedName.c_str(), method)); 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) { +void testGdbusClientSmack(cynara_client_creds method = CLIENT_METHOD_SMACK) { + gdbusTestTemplate([method] (GDBusConnectionPtr conn, pid_t, + const std::string &requestedName, + const ProcessCredentials &peerCredentials) { GStringPtr label(CynaraHelperCredentials::gdbusGetClient(std::move(conn), - requestedName.c_str(), CLIENT_METHOD_SMACK)); + requestedName.c_str(), method)); 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) { +RUNNER_MULTIPROCESS_TEST(tccgd01_gdbus_credentials_client_pid) +{ + testGdbusClientPid(); +} + +RUNNER_MULTIPROCESS_TEST_SMACK(tccgd02_gdbus_credentials_client_smack) +{ + testGdbusClientSmack(); +} + +RUNNER_MULTIPROCESS_TEST_SMACK(tccgd03_gdbus_credentials_client_default) +{ + auto method = getClientDefaultMethod(); + switch(method) { + case CLIENT_METHOD_SMACK: + testGdbusClientSmack(CLIENT_METHOD_DEFAULT); + break; + case CLIENT_METHOD_PID: + testGdbusClientPid(CLIENT_METHOD_DEFAULT); + break; + default: + RUNNER_FAIL_MSG("cynara_creds_get_default_client_method returned unexpected value " + << method); + } +} + +void testGdbusUserUid(cynara_user_creds method = USER_METHOD_UID) { + gdbusTestTemplate([method] (GDBusConnectionPtr conn, pid_t, + const std::string &requestedName, + const ProcessCredentials &peerCredentials) { GStringPtr uidStr(CynaraHelperCredentials::gdbusGetUser(std::move(conn), - requestedName.c_str(), USER_METHOD_UID)); + requestedName.c_str(), method)); uid_t uid = std::stoul(uidStr.get()); RUNNER_ASSERT_MSG(peerCredentials.uid() == uid, "UIDs don't match ret = " << uid << "; expected = "<< peerCredentials.uid()); - }, "tccgd03"); + }, "tccgd04"); +} + +void testGdbusUserGid(cynara_user_creds method = USER_METHOD_GID) { + // Getting gid for gdbus connection is not yet implemented in cynara helpers + gdbusTestTemplate([method] (GDBusConnectionPtr conn, pid_t, + const std::string &requestedName, + const ProcessCredentials &) { + GStringPtr gidStr(CynaraHelperCredentials::gdbusGetUser(std::move(conn), + requestedName.c_str(), method, CYNARA_API_METHOD_NOT_SUPPORTED)); + }, "tccgd04"); +} + +RUNNER_MULTIPROCESS_TEST(tccgd04_gdbus_credentials_user_uid) +{ + testGdbusUserUid(); } -RUNNER_TEST_SMACK(tccgd04_gdbus_credentials_pid) { +RUNNER_MULTIPROCESS_TEST(tccgd05_gdbus_credentials_user_gid) +{ + testGdbusUserGid(); +} + +RUNNER_MULTIPROCESS_TEST(tccgd06_gdbus_credentials_user_default) { + auto method = getUserDefaultMethod(); + switch(method) { + case USER_METHOD_UID: + testGdbusUserUid(USER_METHOD_DEFAULT); + break; + case USER_METHOD_GID: + testGdbusUserGid(USER_METHOD_DEFAULT); + break; + default: + RUNNER_FAIL_MSG("cynara_creds_get_default_user_method returned unexpected value " + << method); + } +} + +RUNNER_MULTIPROCESS_TEST(tccgd06_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"); + }, "tccgd06"); } RUNNER_TEST_GROUP_INIT(cynara_creds_self) -- 2.7.4