Files
finit/test/dbus-bus.sh
T
Joachim Wiberg 5cc41b3ba4 libink: take the match keys clients send without asking
A rule carrying sender, destination, or eavesdrop was refused whole,
and a peer whose AddMatch fails gets no signals at all.  That is a
poor trade for keys clients attach as a matter of course: better a
filter wider than asked for than a subscription that never happened.

They are accepted and ignored rather than honoured.  Widening costs
nothing here since Finit is the only sender on this bus, and what it
emits through the match table is state any peer that got this far may
already read.

argN and argNpath still take the whole rule down.  Honouring them
means parsing message bodies, and nothing asks for them yet.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-08-13 10:15:19 +02:00

83 lines
2.8 KiB
Bash
Executable File

#!/bin/sh
# libink: org.freedesktop.DBus built-in interface.
#
# Covers the stock D-Bus interface every conforming bus implements:
# Hello (peer name allocation), Introspect (XML), and AddMatch's
# error-path rule parser.
set -eu
TEST_DIR=$(dirname "$0")
# shellcheck source=/dev/null
. "$TEST_DIR/lib/setup.sh"
# shellcheck source=/dev/null
. "$TEST_DIR/lib/dbus-setup.sh"
say "Hello() returns a unique name beginning with ':1.'"
name=$(texec "$CLIENT" hello "$BUS")
case "$name" in
:1.*) assert "Hello returned a :1.N name (got $name)" 0 -eq 0 ;;
*) fail "Hello returned unexpected name: $name" ;;
esac
say "Two Hello() calls produce different unique names"
n1=$(texec "$CLIENT" hello "$BUS")
n2=$(texec "$CLIENT" hello "$BUS")
assert "Unique names increment ($n1 vs $n2)" "$n1" != "$n2"
say "Introspect on root path returns valid XML"
xml=$(texec "$CLIENT" introspect "$BUS" /)
case "$xml" in
*'<node'*) assert "XML has <node> root (good)" 0 -eq 0 ;;
*) fail "Root introspect missing <node>: $xml" ;;
esac
say "Introspect on /org/finit/manager exposes Manager1.ListServices"
xml=$(texec "$CLIENT" introspect "$BUS" /org/finit/manager)
case "$xml" in
*'org.finit.Manager1'*'ListServices'*)
assert "Manager1 and ListServices visible in XML" 0 -eq 0 ;;
*)
fail "Manager1 XML missing; got: $xml" ;;
esac
say "AddMatch with a bogus key is rejected"
set +e
texec "$CLIENT" call-s "$BUS" /org/freedesktop/DBus \
org.freedesktop.DBus AddMatch "bogus='whatever'" >/tmp/dbus-match.out 2>&1
am_rc=$?
set -e
assert "Bad rule rejected (rc=$am_rc)" "$am_rc" -eq 1
case "$(cat /tmp/dbus-match.out)" in
*MatchRuleInvalid*) assert "Error is MatchRuleInvalid" 0 -eq 0 ;;
*) fail "Unexpected reply: $(cat /tmp/dbus-match.out)" ;;
esac
# A client that sends these must still get its signals: refusing the
# rule would leave it with none at all. The sender here is deliberately
# wrong, so a delivered signal proves the key was ignored and not
# quietly honoured.
say "AddMatch accepts, and ignores, sender/destination/eavesdrop"
rm -f /tmp/dbus-ignored.out
( texec "$CLIENT" monitor-signal "$BUS" \
"type='signal',sender='org.freedesktop.DBus',destination=':1.99',eavesdrop='false',interface='org.finit.Cond1',member='ConditionChanged'" \
5000 > /tmp/dbus-ignored.out 2>&1 ) &
ign_pid=$!
sleep 0.5
texec "$CLIENT" call-s "$BUS" /org/finit/cond \
org.finit.Cond1 Set "dbus-ignored-keys" >/dev/null \
|| fail "Cond1.Set returned non-zero"
set +e
wait "$ign_pid"
ign_rc=$?
set -e
assert "Signal still delivered through the wider rule (rc=$ign_rc)" "$ign_rc" -eq 0
say "Unknown method on a Finit interface gets an org.freedesktop.DBus.Error.* reply"
set +e
texec "$CLIENT" unknown "$BUS"
unknown_rc=$?
set -e
assert "Unknown method returned an error (rc=$unknown_rc)" "$unknown_rc" -eq 0