test: cover Manager1 edge semantics against the legacy API

Regression tests for the recent handler fixes: bogus SetRunlevel is
InvalidArgs, Signal on a stopped service is Failed, and the reboot
family declares the timeout argument.  Reboot cannot be invoked
without taking down the sandbox, so the latter is asserted via
introspection.  New call-u and call-su modes in dbus-auth-client.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2026-08-16 22:03:39 +02:00
parent 62b55d5b43
commit 3efa9d6f41
2 changed files with 82 additions and 0 deletions
+46
View File
@@ -137,3 +137,49 @@ case "$rl" in
*)
fail "Unexpected initctl runlevel output: $rl" ;;
esac
# ---------- legacy-parity edge semantics ----------
say "Manager1.SetRunlevel with bogus level returns InvalidArgs"
set +e
texec "$CLIENT" call-u "$BUS" /org/finit/manager \
org.finit.Manager1 SetRunlevel 42 >/tmp/dbus-rl.out 2>&1
rl_rc=$?
set -e
assert "Bogus runlevel rejected (rc=$rl_rc)" "$rl_rc" -eq 1
case "$(cat /tmp/dbus-rl.out)" in
*InvalidArgs*) assert "Error is InvalidArgs" 0 -eq 0 ;;
*) fail "Unexpected reply: $(cat /tmp/dbus-rl.out)" ;;
esac
say "Manager1.Signal on a stopped service returns Failed"
cat >> "$SYSROOT$FINIT_CONF" <<CONF
service stopped-serv {
manual = true
command = "serv -np"
}
CONF
run "initctl reload"
set +e
texec "$CLIENT" call-su "$BUS" /org/finit/manager \
org.finit.Manager1 Signal stopped-serv 1 >/tmp/dbus-sig.out 2>&1
sig_rc=$?
set -e
assert "Signal to stopped service rejected (rc=$sig_rc)" "$sig_rc" -eq 1
case "$(cat /tmp/dbus-sig.out)" in
*Failed*) assert "Error is Failed" 0 -eq 0 ;;
*) fail "Unexpected reply: $(cat /tmp/dbus-sig.out)" ;;
esac
# Reboot cannot be invoked without shutting down the sandbox, so
# verify the timeout argument via introspection instead.
say "Reboot family declares the timeout argument in introspection"
flat=$(printf '%s' "$xml" | tr -d '\n')
for m in Reboot Poweroff Halt; do
case "$flat" in
*"<method name=\"$m\"> <arg type=\"u\" direction=\"in\"/>"*)
assert "$m takes (u)" 0 -eq 0 ;;
*)
fail "$m does not declare the timeout argument" ;;
esac
done
+36
View File
@@ -322,6 +322,40 @@ static int mode_call_s(int argc, char *argv[])
return do_call(argv[2], argv[3], argv[4], argv[5], argv[6]);
}
/* "u" and "su" variants for methods taking a uint32 argument */
static int do_call_u(const char *sock, const char *obj, const char *iface,
const char *method, const char *arg, uint32_t val)
{
link_client_t *c;
int rc;
c = link_client_open(sock);
if (!c) return 2;
rc = arg
? link_client_call_v(c, obj, iface, method, "su", arg, val)
: link_client_call_v(c, obj, iface, method, "u", val);
rc = report_rc(c, rc);
if (rc == 0)
printf("OK\n");
link_client_close(c);
return rc;
}
static int mode_call_u(int argc, char *argv[])
{
if (argc != 7) return 2;
return do_call_u(argv[2], argv[3], argv[4], argv[5], NULL,
(uint32_t)strtoul(argv[6], NULL, 0));
}
static int mode_call_su(int argc, char *argv[])
{
if (argc != 8) return 2;
return do_call_u(argv[2], argv[3], argv[4], argv[5], argv[6],
(uint32_t)strtoul(argv[7], NULL, 0));
}
static int mode_call_void(int argc, char *argv[])
{
if (argc != 6) return 2;
@@ -513,6 +547,8 @@ int main(int argc, char *argv[])
if (!strcmp(argv[1], "introspect")) return mode_introspect (argc, argv);
if (!strcmp(argv[1], "liststrings")) return mode_liststrings (argc, argv);
if (!strcmp(argv[1], "call-s")) return mode_call_s (argc, argv);
if (!strcmp(argv[1], "call-u")) return mode_call_u (argc, argv);
if (!strcmp(argv[1], "call-su")) return mode_call_su (argc, argv);
if (!strcmp(argv[1], "call-void")) return mode_call_void (argc, argv);
if (!strcmp(argv[1], "call-s-as-uid")) return mode_call_s_as_uid (argc, argv);
if (!strcmp(argv[1], "call-void-as-uid")) return mode_call_void_as_uid(argc, argv);