+ });
+}
+
+void testDbusCredsDefault(int expectedResult, char **pClientBuff,
+ char **pUserBuff, pid_t *pPidCred)
+{
+ // reset variables if set by previous test cases
+ if (pClientBuff != nullptr) *pClientBuff = nullptr;
+ if (pUserBuff != nullptr) *pUserBuff = nullptr;
+ if (pPidCred != nullptr) *pPidCred = -1;
+
+ dbusTestTemplate([&] (DBusConnectionPtr conn, pid_t pid,
+ const std::string &requestedName,
+ const ProcessCredentials &peerCredentials) {
+ cynara_user_creds userMethod = getUserDefaultMethod();
+ cynara_client_creds clientMethod = getClientDefaultMethod();
+
+ // exception override
+ if (expectedResult == CYNARA_API_SUCCESS && userMethod == USER_METHOD_GID) {
+ expectedResult = CYNARA_API_METHOD_NOT_SUPPORTED;
+ }
+
+ int ret = cynara_creds_dbus_get_default(conn.get(), requestedName.c_str(),
+ pClientBuff, pUserBuff, pPidCred);
+
+ RUNNER_ASSERT_MSG(ret == expectedResult,
+ "cynara_creds_dbus_get_default returned unexpected result: " << ret <<
+ "; expected: " << expectedResult);
+
+ if (ret != CYNARA_API_SUCCESS) {
+ return;
+ }
+
+ if (pClientBuff != nullptr) {
+ switch (clientMethod) {
+ case CLIENT_METHOD_SMACK:
+ RUNNER_ASSERT_MSG(*pClientBuff == peerCredentials.label(),
+ "Client labels don't match, ret = "
+ << *pClientBuff << "; expected = "
+ << peerCredentials.label());
+ free(*pClientBuff);
+ break;
+ case CLIENT_METHOD_PID:
+ RUNNER_ASSERT_MSG(*pClientBuff == std::to_string(pid),
+ "PIDs don't match, ret = "
+ << *pClientBuff << "; expected = " << pid);
+ free(*pClientBuff);
+ break;
+ default:
+ break;
+ }
+ }
+
+ if (pUserBuff != nullptr) {
+ switch (userMethod) {
+ case USER_METHOD_UID:
+ RUNNER_ASSERT_MSG(*pUserBuff == std::to_string(peerCredentials.uid()),
+ "UIDs don't match, ret = "
+ << *pUserBuff
+ << "; expected = " << peerCredentials.uid());
+ free(*pUserBuff);
+ break;
+ default:
+ break;
+ }
+ }
+
+ if (pPidCred != nullptr) {
+ RUNNER_ASSERT_MSG(*pPidCred == pid, "PIDs don't match, ret = "
+ << *pPidCred
+ << "; expected = " << pid);
+ }
+ });
+}
+
+RUNNER_MULTIPROCESS_TEST(tccd08_dbus_credentials_default_positive_all)
+{
+ char *clientBuff = nullptr;
+ char *userBuff = nullptr;
+ pid_t pidCred = -1;
+
+ testDbusCredsDefault(CYNARA_API_SUCCESS, &clientBuff, &userBuff, &pidCred);
+}
+
+RUNNER_MULTIPROCESS_TEST(tccd09_dbus_credentials_default_positive_partial_single)
+{
+ char *clientBuff = nullptr;
+ char *userBuff = nullptr;
+ pid_t pidCred = -1;
+
+ testDbusCredsDefault(CYNARA_API_SUCCESS, &clientBuff, nullptr, nullptr);
+ testDbusCredsDefault(CYNARA_API_SUCCESS, nullptr, &userBuff, nullptr);
+ testDbusCredsDefault(CYNARA_API_SUCCESS, nullptr, nullptr, &pidCred);
+}
+
+RUNNER_MULTIPROCESS_TEST(tccd10_dbus_credentials_default_positive_partial_double)
+{
+ char *clientBuff = nullptr;
+ char *userBuff = nullptr;
+ pid_t pidCred = -1;
+
+ testDbusCredsDefault(CYNARA_API_SUCCESS, nullptr, &userBuff, &pidCred);
+ testDbusCredsDefault(CYNARA_API_SUCCESS, &clientBuff, nullptr, &pidCred);
+ testDbusCredsDefault(CYNARA_API_SUCCESS, &clientBuff, &userBuff, nullptr);
+}
+
+RUNNER_MULTIPROCESS_TEST(tccd11_dbus_credentials_default_negative_incomplete)
+{
+ testDbusCredsDefault(CYNARA_API_INVALID_PARAM, nullptr, nullptr, nullptr);
+}
+
+void testDbusCreds(int expectedResult,
+ const cynara_client_creds *pClientMethod, char **pClientBuff,
+ const cynara_user_creds *pUserMethod, char **pUserBuff,
+ pid_t *pPidCred)
+{
+ // reset variables if set by previous test cases
+ if (pClientBuff != nullptr) *pClientBuff = nullptr;
+ if (pUserBuff != nullptr) *pUserBuff = nullptr;
+ if (pPidCred != nullptr) *pPidCred = -1;
+
+ dbusTestTemplate([&] (DBusConnectionPtr conn, pid_t pid,
+ const std::string &requestedName,
+ const ProcessCredentials &peerCredentials) {
+
+ int ret = cynara_creds_dbus_get(conn.get(), requestedName.c_str(),
+ pClientMethod, pClientBuff,
+ pUserMethod, pUserBuff, pPidCred);
+
+ RUNNER_ASSERT_MSG(ret == expectedResult,
+ "cynara_creds_dbus_get returned unexpected result: " << ret <<
+ "; expected: " << expectedResult);
+
+ if (ret != CYNARA_API_SUCCESS) {
+ return;
+ }
+
+ if (pClientBuff != nullptr && pClientMethod != nullptr) {
+ switch (*pClientMethod) {
+ case CLIENT_METHOD_SMACK:
+ RUNNER_ASSERT_MSG(*pClientBuff == peerCredentials.label(),
+ "Client labels don't match, ret = "
+ << *pClientBuff << "; expected = "
+ << peerCredentials.label());
+ free(*pClientBuff);
+ break;
+ case CLIENT_METHOD_PID:
+ RUNNER_ASSERT_MSG(*pClientBuff == std::to_string(pid),
+ "PIDs don't match, ret = "
+ << *pClientBuff << "; expected = " << pid);
+ free(*pClientBuff);
+ break;
+ default:
+ break;
+ }
+ }
+
+ if (pUserBuff != nullptr && pUserMethod != nullptr) {
+ switch (*pUserMethod) {
+ case USER_METHOD_UID:
+ RUNNER_ASSERT_MSG(*pUserBuff == std::to_string(peerCredentials.uid()),
+ "UIDs don't match, ret = "
+ << *pUserBuff
+ << "; expected = " << peerCredentials.uid());
+ free(*pUserBuff);
+ break;
+ default:
+ break;
+ }
+ }
+
+ if (pPidCred != nullptr) {
+ RUNNER_ASSERT_MSG(*pPidCred == pid, "PIDs don't match, ret = "
+ << *pPidCred
+ << "; expected = " << pid);
+ }
+ });
+}
+
+RUNNER_MULTIPROCESS_TEST(tccd12_dbus_credentials_positive_all)
+{
+ char *clientBuff = nullptr;
+ char *userBuff = nullptr;
+ pid_t pidCred = -1;
+
+ testDbusCreds(CYNARA_API_SUCCESS,
+ &G_CLIENT_METHOD_DEFAULT, &clientBuff,
+ &G_USER_METHOD_DEFAULT, &userBuff, &pidCred);
+ testDbusCreds(CYNARA_API_SUCCESS,
+ &G_CLIENT_METHOD_SMACK, &clientBuff,
+ &G_USER_METHOD_UID, &userBuff, &pidCred);
+ testDbusCreds(CYNARA_API_SUCCESS,
+ &G_CLIENT_METHOD_PID, &clientBuff,
+ &G_USER_METHOD_UID, &userBuff, &pidCred);
+
+ testDbusCreds(CYNARA_API_METHOD_NOT_SUPPORTED,
+ &G_CLIENT_METHOD_SMACK, &clientBuff,
+ &G_USER_METHOD_GID, &userBuff, &pidCred);
+ testDbusCreds(CYNARA_API_METHOD_NOT_SUPPORTED,
+ &G_CLIENT_METHOD_PID, &clientBuff,
+ &G_USER_METHOD_GID, &userBuff, &pidCred);
+}
+
+RUNNER_MULTIPROCESS_TEST(tccd13_dbus_credentials_positive_partial_single)
+{
+ char *clientBuff = nullptr;
+ char *userBuff = nullptr;
+ pid_t pidCred = -1;
+
+ testDbusCreds(CYNARA_API_SUCCESS,
+ &G_CLIENT_METHOD_PID, &clientBuff,
+ &G_USER_METHOD_DEFAULT, nullptr,
+ nullptr);
+ testDbusCreds(CYNARA_API_SUCCESS,
+ &G_CLIENT_METHOD_SMACK, &clientBuff,
+ nullptr, nullptr,
+ nullptr);
+
+ testDbusCreds(CYNARA_API_SUCCESS,
+ &G_CLIENT_METHOD_DEFAULT, nullptr,
+ &G_USER_METHOD_DEFAULT, &userBuff,
+ nullptr);
+ testDbusCreds(CYNARA_API_SUCCESS,
+ nullptr, nullptr,
+ &G_USER_METHOD_DEFAULT, &userBuff,
+ nullptr);
+
+ testDbusCreds(CYNARA_API_SUCCESS,
+ nullptr, nullptr,
+ &G_USER_METHOD_DEFAULT, nullptr,
+ &pidCred);
+ testDbusCreds(CYNARA_API_SUCCESS,
+ &G_CLIENT_METHOD_DEFAULT, nullptr,
+ nullptr, nullptr,
+ &pidCred);
+ testDbusCreds(CYNARA_API_SUCCESS,
+ nullptr, nullptr,
+ nullptr, nullptr,
+ &pidCred);
+}
+
+RUNNER_MULTIPROCESS_TEST(tccd14_dbus_credentials_positive_partial_double)
+{
+ char *clientBuff = nullptr;
+ char *userBuff = nullptr;
+ pid_t pidCred = -1;
+
+ testDbusCreds(CYNARA_API_SUCCESS,
+ &G_CLIENT_METHOD_DEFAULT, nullptr,
+ &G_USER_METHOD_UID, &userBuff, &pidCred);
+ testDbusCreds(CYNARA_API_SUCCESS,
+ nullptr, nullptr,
+ &G_USER_METHOD_DEFAULT, &userBuff, &pidCred);
+
+ testDbusCreds(CYNARA_API_SUCCESS,
+ &G_CLIENT_METHOD_PID, &clientBuff,
+ &G_USER_METHOD_DEFAULT, nullptr, &pidCred);
+ testDbusCreds(CYNARA_API_SUCCESS,
+ &G_CLIENT_METHOD_DEFAULT, &clientBuff,
+ nullptr, nullptr, &pidCred);
+
+ testDbusCreds(CYNARA_API_SUCCESS,
+ &G_CLIENT_METHOD_SMACK, &clientBuff,
+ &G_USER_METHOD_UID, &userBuff, nullptr);
+}
+
+RUNNER_MULTIPROCESS_TEST(tccd14_dbus_credentials_negative_incomplete)
+{
+ char *clientBuff = nullptr;
+ char *userBuff = nullptr;
+ pid_t pidCred = -1;
+
+ testDbusCreds(CYNARA_API_INVALID_PARAM,
+ nullptr, &clientBuff,
+ &G_USER_METHOD_UID, &userBuff, &pidCred);
+ testDbusCreds(CYNARA_API_INVALID_PARAM,
+ nullptr, &clientBuff,
+ &G_USER_METHOD_UID, nullptr, &pidCred);
+ testDbusCreds(CYNARA_API_INVALID_PARAM,
+ nullptr, &clientBuff,
+ nullptr, nullptr, &pidCred);
+
+ testDbusCreds(CYNARA_API_INVALID_PARAM,
+ &G_CLIENT_METHOD_DEFAULT, &clientBuff,
+ nullptr, &userBuff, &pidCred);
+ testDbusCreds(CYNARA_API_INVALID_PARAM,
+ &G_CLIENT_METHOD_DEFAULT, nullptr,
+ nullptr, &userBuff, &pidCred);
+ testDbusCreds(CYNARA_API_INVALID_PARAM,
+ nullptr, nullptr,
+ nullptr, &userBuff, &pidCred);
+
+ testDbusCreds(CYNARA_API_INVALID_PARAM,
+ &G_CLIENT_METHOD_DEFAULT, nullptr,
+ &G_USER_METHOD_UID, nullptr, nullptr);
+ testDbusCreds(CYNARA_API_INVALID_PARAM,
+ &G_CLIENT_METHOD_DEFAULT, nullptr,
+ nullptr, nullptr, nullptr);
+ testDbusCreds(CYNARA_API_INVALID_PARAM,
+ nullptr, nullptr,
+ &G_USER_METHOD_DEFAULT, nullptr, nullptr);
+ testDbusCreds(CYNARA_API_INVALID_PARAM,
+ nullptr, nullptr,
+ nullptr, nullptr, nullptr);
+}
+
+RUNNER_MULTIPROCESS_TEST(tccd14_dbus_credentials_negative_incorrect)
+{
+ char *clientBuff = nullptr;
+ char *userBuff = nullptr;
+ pid_t pidCred = -1;
+
+ testDbusCreds(CYNARA_API_METHOD_NOT_SUPPORTED,
+ &G_CLIENT_METHOD_LOW, &clientBuff,
+ &G_USER_METHOD_DEFAULT, &userBuff, &pidCred);
+ testDbusCreds(CYNARA_API_METHOD_NOT_SUPPORTED,
+ &G_CLIENT_METHOD_HIGH, &clientBuff,
+ &G_USER_METHOD_DEFAULT, &userBuff, &pidCred);
+ testDbusCreds(CYNARA_API_METHOD_NOT_SUPPORTED,
+ &G_CLIENT_METHOD_DEFAULT, &clientBuff,
+ &G_USER_METHOD_LOW, &userBuff, &pidCred);
+ testDbusCreds(CYNARA_API_METHOD_NOT_SUPPORTED,
+ &G_CLIENT_METHOD_DEFAULT, &clientBuff,
+ &G_USER_METHOD_HIGH, &userBuff, &pidCred);