RUNNER_TEST_GROUP_INIT(cynara_creds_dbus)
-RUNNER_TEST_SMACK(tccd01_dbus_credentials_client_pid) {
- dbusTestTemplate([] (DBusConnectionPtr conn, pid_t pid, const std::string &requestedName,
+void testDbusClientPid(cynara_client_creds method = CLIENT_METHOD_PID) {
+ dbusTestTemplate([method] (DBusConnectionPtr conn, pid_t pid, const std::string &requestedName,
const ProcessCredentials &) {
CStringPtr clientPidStr(CynaraHelperCredentials::dbusGetClient(std::move(conn),
- requestedName.c_str(), CLIENT_METHOD_PID, CYNARA_API_SUCCESS));
+ requestedName.c_str(), method, CYNARA_API_SUCCESS));
pid_t clientPid = std::stoi(clientPidStr.get());
RUNNER_ASSERT_MSG(pid == clientPid, "PIDs don't match ret = " << clientPid
<< "; expected = " << pid);
}, "tccd01");
}
-RUNNER_TEST_SMACK(tccd02_dbus_credentials_client_smack) {
- dbusTestTemplate([] (DBusConnectionPtr conn, pid_t, const std::string &requestedName,
+void testDbusClientSmack(cynara_client_creds method = CLIENT_METHOD_SMACK) {
+ dbusTestTemplate([method] (DBusConnectionPtr conn, pid_t, const std::string &requestedName,
const ProcessCredentials &peerCredentials) {
CStringPtr label(CynaraHelperCredentials::dbusGetClient(std::move(conn),
- requestedName.c_str(), CLIENT_METHOD_SMACK, CYNARA_API_SUCCESS));
+ requestedName.c_str(), method, CYNARA_API_SUCCESS));
RUNNER_ASSERT_MSG(peerCredentials.label() == label.get(),
"Labels don't match ret = " << label.get()
<< "; expected = " << peerCredentials.label());
}, "tccd02");
}
-RUNNER_TEST_SMACK(tccd03_dbus_credentials_user_uid) {
- dbusTestTemplate([] (DBusConnectionPtr conn, pid_t, const std::string &requestedName,
+RUNNER_MULTIPROCESS_TEST(tccd01_dbus_credentials_client_pid)
+{
+ testDbusClientPid();
+}
+
+RUNNER_MULTIPROCESS_TEST_SMACK(tccd02_dbus_credentials_client_smack)
+{
+ testDbusClientSmack();
+}
+
+RUNNER_MULTIPROCESS_TEST_SMACK(tccd03_dbus_credentials_client_default)
+{
+ auto method = getClientDefaultMethod();
+ switch(method) {
+ case CLIENT_METHOD_SMACK:
+ testDbusClientSmack(CLIENT_METHOD_DEFAULT);
+ break;
+ case CLIENT_METHOD_PID:
+ testDbusClientPid(CLIENT_METHOD_DEFAULT);
+ break;
+ default:
+ RUNNER_FAIL_MSG("cynara_creds_get_default_client_method returned unexpected value "
+ << method);
+ }
+}
+
+void testDbusUserUid(cynara_user_creds method = USER_METHOD_UID) {
+ dbusTestTemplate([method] (DBusConnectionPtr conn, pid_t, const std::string &requestedName,
const ProcessCredentials &peerCredentials) {
CStringPtr uidStr(CynaraHelperCredentials::dbusGetUser(std::move(conn),
- requestedName.c_str(), USER_METHOD_UID, CYNARA_API_SUCCESS));
+ requestedName.c_str(), method, CYNARA_API_SUCCESS));
uid_t uid = std::stoul(uidStr.get());
RUNNER_ASSERT_MSG(peerCredentials.uid() == uid, "UIDs don't match ret = " << uid
<< "; expected = "<< peerCredentials.uid());
- }, "tccd03");
+ }, "tccd04");
}
-RUNNER_TEST_SMACK(tccd04_dbus_credentials_pid) {
+void testDbusUserGid(cynara_user_creds method = USER_METHOD_GID) {
+ // Acquiring gid from dbus connection is not yet implemented for cynara helpers
+ dbusTestTemplate([method] (DBusConnectionPtr conn, pid_t, const std::string &requestedName,
+ const ProcessCredentials &) {
+ CStringPtr gidStr(CynaraHelperCredentials::dbusGetUser(std::move(conn),
+ requestedName.c_str(), method, CYNARA_API_METHOD_NOT_SUPPORTED));
+ }, "tccd04");
+}
+
+RUNNER_MULTIPROCESS_TEST(tccd04_dbus_credentials_user_uid)
+{
+ testDbusUserUid();
+}
+
+RUNNER_MULTIPROCESS_TEST(tccd05_dbus_credentials_user_gid)
+{
+ testDbusUserGid();
+}
+
+RUNNER_MULTIPROCESS_TEST(tccd06_dbus_credentials_user_default) {
+ auto method = getUserDefaultMethod();
+ switch(method) {
+ case USER_METHOD_UID:
+ testDbusUserUid(USER_METHOD_DEFAULT);
+ break;
+ case USER_METHOD_GID:
+ testDbusUserGid(USER_METHOD_DEFAULT);
+ break;
+ default:
+ RUNNER_FAIL_MSG("cynara_creds_get_default_user_method returned unexpected value "
+ << method);
+ }
+}
+
+RUNNER_TEST_SMACK(tccd06_dbus_credentials_pid) {
dbusTestTemplate([] (DBusConnectionPtr conn, pid_t expectedPid,
const std::string &requestedName, const ProcessCredentials &) {
auto helperPid = CynaraHelperCredentials::dbusGetPid(std::move(conn),
requestedName.c_str(), CYNARA_API_SUCCESS);
RUNNER_ASSERT_MSG(helperPid == expectedPid, "PIDs don't match ret = " << helperPid
<< "; expected = " << expectedPid);
- }, "tccd04");
+ }, "tccd06");
}
GDBusConnectionPtr createGDBusConnection() {