|
|
594167 |
From 24e6f79352a94e6c0d13aefe355c5c316274103d Mon Sep 17 00:00:00 2001
|
|
|
594167 |
From: David Tardon <dtardon@redhat.com>
|
|
|
594167 |
Date: Mon, 27 Jun 2022 08:37:22 +0200
|
|
|
594167 |
Subject: [PATCH] test: add test for org.freedesktop.login1.Session SetType
|
|
|
594167 |
|
|
|
594167 |
(cherry picked from commit 9ac0855b614b068e699092be7ec8cb39559ff88f)
|
|
|
594167 |
|
|
|
594167 |
Related: #2100464
|
|
|
594167 |
---
|
|
|
594167 |
src/login/meson.build | 3 ++
|
|
|
594167 |
src/login/test-session-properties.c | 71 +++++++++++++++++++++++++++++
|
|
|
594167 |
test/units/testsuite-35.sh | 16 +++++++
|
|
|
594167 |
3 files changed, 90 insertions(+)
|
|
|
594167 |
create mode 100644 src/login/test-session-properties.c
|
|
|
594167 |
|
|
|
594167 |
diff --git a/src/login/meson.build b/src/login/meson.build
|
|
|
594167 |
index 92f491665c..8ee364144c 100644
|
|
|
594167 |
--- a/src/login/meson.build
|
|
|
594167 |
+++ b/src/login/meson.build
|
|
|
594167 |
@@ -110,4 +110,7 @@ tests += [
|
|
|
594167 |
[liblogind_core,
|
|
|
594167 |
libshared],
|
|
|
594167 |
[threads]],
|
|
|
594167 |
+
|
|
|
594167 |
+ [files('test-session-properties.c'),
|
|
|
594167 |
+ [], [], [], '', 'manual'],
|
|
|
594167 |
]
|
|
|
594167 |
diff --git a/src/login/test-session-properties.c b/src/login/test-session-properties.c
|
|
|
594167 |
new file mode 100644
|
|
|
594167 |
index 0000000000..8406147a2c
|
|
|
594167 |
--- /dev/null
|
|
|
594167 |
+++ b/src/login/test-session-properties.c
|
|
|
594167 |
@@ -0,0 +1,71 @@
|
|
|
594167 |
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
|
|
594167 |
+
|
|
|
594167 |
+/* Usage:
|
|
|
594167 |
+ * ./test-session-properties <SESSION-OBJECT-PATH>
|
|
|
594167 |
+ * e.g.,
|
|
|
594167 |
+ * ./test-session-properties /org/freedesktop/login1/session/_32
|
|
|
594167 |
+ */
|
|
|
594167 |
+
|
|
|
594167 |
+#include "alloc-util.h"
|
|
|
594167 |
+#include "bus-common-errors.h"
|
|
|
594167 |
+#include "bus-locator.h"
|
|
|
594167 |
+#include "string-util.h"
|
|
|
594167 |
+#include "tests.h"
|
|
|
594167 |
+
|
|
|
594167 |
+static BusLocator session;
|
|
|
594167 |
+
|
|
|
594167 |
+/* Tests org.freedesktop.logind.Session SetType */
|
|
|
594167 |
+TEST(set_type) {
|
|
|
594167 |
+ _cleanup_(sd_bus_flush_close_unrefp) sd_bus* bus = NULL;
|
|
|
594167 |
+ _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
|
|
|
594167 |
+ const char* types[] = {"tty", "x11", "wayland", "mir", "web"};
|
|
|
594167 |
+ _cleanup_free_ char *type = NULL, *type2 = NULL;
|
|
|
594167 |
+
|
|
|
594167 |
+ assert_se(sd_bus_open_system(&bus) >= 0);
|
|
|
594167 |
+
|
|
|
594167 |
+ /* Default type is set */
|
|
|
594167 |
+ assert_se(bus_get_property_string(bus, &session, "Type", NULL, &type) >= 0);
|
|
|
594167 |
+ assert_se(streq(type, "tty"));
|
|
|
594167 |
+
|
|
|
594167 |
+ /* Type can only be set by the session controller (which we're not ATM) */
|
|
|
594167 |
+ assert_se(bus_call_method(bus, &session, "SetType", &error, NULL, "s", "x11") < 0);
|
|
|
594167 |
+ assert_se(sd_bus_error_has_name(&error, BUS_ERROR_NOT_IN_CONTROL));
|
|
|
594167 |
+
|
|
|
594167 |
+ assert_se(bus_call_method(bus, &session, "TakeControl", NULL, NULL, "b", true) >= 0);
|
|
|
594167 |
+
|
|
|
594167 |
+ /* All defined session types can be set */
|
|
|
594167 |
+ for (size_t i = 0; i < ELEMENTSOF(types); i++) {
|
|
|
594167 |
+ type = mfree(type);
|
|
|
594167 |
+ assert_se(bus_call_method(bus, &session, "SetType", NULL, NULL, "s", types[i]) >= 0);
|
|
|
594167 |
+ assert_se(bus_get_property_string(bus, &session, "Type", NULL, &type) >= 0);
|
|
|
594167 |
+ assert_se(streq(type, types[i]));
|
|
|
594167 |
+ }
|
|
|
594167 |
+
|
|
|
594167 |
+ /* An unknown type is rejected */
|
|
|
594167 |
+ sd_bus_error_free(&error);
|
|
|
594167 |
+ assert_se(bus_call_method(bus, &session, "SetType", &error, NULL, "s", "hello") < 0);
|
|
|
594167 |
+ assert_se(sd_bus_error_has_name(&error, SD_BUS_ERROR_INVALID_ARGS));
|
|
|
594167 |
+ assert_se(bus_get_property_string(bus, &session, "Type", NULL, &type2) >= 0);
|
|
|
594167 |
+
|
|
|
594167 |
+ /* Type is reset to the original value when we release control of the session */
|
|
|
594167 |
+ assert_se(!streq(type, "tty"));
|
|
|
594167 |
+ assert_se(bus_call_method(bus, &session, "ReleaseControl", NULL, NULL, "") >= 0);
|
|
|
594167 |
+ type = mfree(type);
|
|
|
594167 |
+ assert_se(bus_get_property_string(bus, &session, "Type", NULL, &type) >= 0);
|
|
|
594167 |
+ assert_se(streq(type, "tty"));
|
|
|
594167 |
+}
|
|
|
594167 |
+
|
|
|
594167 |
+static int intro(void) {
|
|
|
594167 |
+ if (saved_argc <= 1)
|
|
|
594167 |
+ return EXIT_FAILURE;
|
|
|
594167 |
+
|
|
|
594167 |
+ session = (BusLocator) {
|
|
|
594167 |
+ .destination = "org.freedesktop.login1",
|
|
|
594167 |
+ .path = saved_argv[1],
|
|
|
594167 |
+ .interface = "org.freedesktop.login1.Session",
|
|
|
594167 |
+ };
|
|
|
594167 |
+
|
|
|
594167 |
+ return EXIT_SUCCESS;
|
|
|
594167 |
+}
|
|
|
594167 |
+
|
|
|
594167 |
+DEFINE_TEST_MAIN_WITH_INTRO(LOG_DEBUG, intro);
|
|
|
594167 |
diff --git a/test/units/testsuite-35.sh b/test/units/testsuite-35.sh
|
|
|
594167 |
index ad14d8a73c..4fb2944e2d 100755
|
|
|
594167 |
--- a/test/units/testsuite-35.sh
|
|
|
594167 |
+++ b/test/units/testsuite-35.sh
|
|
|
594167 |
@@ -373,6 +373,21 @@ EOF
|
|
|
594167 |
assert_in "user:logind-test-user:rw-" "$(getfacl -p "$dev")"
|
|
|
594167 |
}
|
|
|
594167 |
|
|
|
594167 |
+test_session_properties() {
|
|
|
594167 |
+ local s
|
|
|
594167 |
+
|
|
|
594167 |
+ if [[ ! -c /dev/tty2 ]]; then
|
|
|
594167 |
+ echo "/dev/tty2 does not exist, skipping test ${FUNCNAME[0]}."
|
|
|
594167 |
+ return
|
|
|
594167 |
+ fi
|
|
|
594167 |
+
|
|
|
594167 |
+ trap cleanup_session RETURN
|
|
|
594167 |
+ create_session
|
|
|
594167 |
+
|
|
|
594167 |
+ s=$(loginctl list-sessions --no-legend | awk '$3 == "logind-test-user" { print $1 }')
|
|
|
594167 |
+ /usr/lib/systemd/tests/manual/test-session-properties "/org/freedesktop/login1/session/_3${s?}"
|
|
|
594167 |
+}
|
|
|
594167 |
+
|
|
|
594167 |
: >/failed
|
|
|
594167 |
|
|
|
594167 |
setup_test_user
|
|
|
594167 |
@@ -382,6 +397,7 @@ test_started
|
|
|
594167 |
test_suspend_on_lid
|
|
|
594167 |
test_shutdown
|
|
|
594167 |
test_session
|
|
|
594167 |
+test_session_properties
|
|
|
594167 |
|
|
|
594167 |
touch /testok
|
|
|
594167 |
rm /failed
|