Commit graph

19 commits

Author SHA1 Message Date
Simon McVittie
8177bbcf52 tests: Detach most connections from main loop before closing
We don't need to do this for connections that were never set up
with the main loop.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=107194
2018-08-02 17:16:43 +01:00
Simon McVittie
e95dc1d58f tests: Call dbus_shutdown()
Not all of these tests will be fully valgrind-clean yet (or perhaps
ever), but it's easier to add this to all of them than to think
about it.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=107194
2018-08-02 17:14:39 +01:00
Simon McVittie
963ce92f68 test: Avoid g_queue_foreach
In gcc 8, -Wall -Wextra includes -Wcast-function-type, which warns
about passing an extra (unwanted) parameter to callbacks. Instead
of using g_list_foreach(), open-code the equivalent.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=107349
Reviewed-by: Thiago Macieira <thiago@kde.org>
2018-08-02 15:26:47 +01:00
Simon McVittie
e36873d981 tests: Use test_main_context_call_and_wait
Also use test_oom() where the relevant lines are changing anyway.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=103600
2017-11-24 12:19:16 +00:00
Simon McVittie
9baff7044e tests: Don't use the same variable for call and reply
It seemed like a nice idea at the time, but I now think it's more
confusing than it's worth.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=103600
2017-11-24 12:19:12 +00:00
Simon McVittie
7fbc4adcba Add a regression test for applying bus policy to broadcasts/unicasts
This test-case is actually in the test for monitoring the bus,
because it's easier to see what's going on there - the error reply
to a rejected broadcast is not visible unless you are monitoring.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Reviewed-by: Thiago Macieira <thiago@kde.org>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=92853
2017-07-28 11:24:20 +01:00
Simon McVittie
093ec67b8f bus/driver: Make non-core interfaces unavailable on most object paths
The o.fd.DBus interface needs to remain available on arbitrary object
paths for backwards compatibility, and the Introspectable interface
is genuinely useful, but everything else can be skipped.

This is arguably an incompatible change for the undocumented Verbose
interface, and for the GetAllMatchRules method on the undocumented
Stats interface: previously those were available at all object paths.

Reviewed-by: Philip Withnall <withnall@endlessm.com>
[smcv: Adjust comments, enum order, variable naming as per Philip's review]
Signed-off-by: Simon McVittie <smcv@collabora.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101256
2017-06-02 10:43:29 +01:00
Simon McVittie
36893e76c4 test/monitor: Assert that BecomeMonitor() on wrong object path fails
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101256
2017-06-02 10:38:30 +01:00
Simon McVittie
06904a8d96 tests: Consistently don't try to kill pid 0
daemon_pid will still be 0 if any tests were skipped. In particular
this happens during `make installcheck`.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=99825
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2017-02-21 11:56:56 +00:00
Simon McVittie
eef176eb72 test_get_dbus_daemon: Take a custom XDG_RUNTIME_DIR as an argument
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=99825
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2017-02-20 12:52:38 +00:00
Simon McVittie
6d8a198de9 various tests: produce better diagnostics on error
Same root cause as <https://bugs.freedesktop.org/show_bug.cgi?id=96653>:
we didn't check whether the message was in fact an error reply.

Signed-off-by: Simon McVittie <smcv@debian.org>
2016-08-12 10:25:06 +01:00
Simon McVittie
f3be583b40 monitor: use the addressed_recipient to select matches
This means we respect the destination keyword in arguments to
BecomeMonitor.

In bus_dispatch(), this means that we need to defer capturing until
we have decided whether there is an addressed recipient; so instead
of capturing once, we capture at each leaf of the decision tree.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=92074
Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
Reviewed-by: Lars Uebernickel <lars@uebernic.de>
2015-11-17 20:53:08 +00:00
Simon McVittie
dc8bb27099 Add a regression test for invalid BecomeMonitor calls
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=92298
2015-10-26 12:46:55 +00:00
Simon McVittie
382cb17d37 Disable activation tests on Windows builds
These rely on the --systemd-activation code path, which is not
compiled for Windows.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=92538
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2015-10-22 17:35:59 +01:00
Simon McVittie
27a6538d5b Add test-case for the same situation as fd.o #90952
This does not directly test the code in the previous commit, but it does
confirm that calling dbus_connection_set_route_peer_messages() is enough
to fix the observed bug.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=90952
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
[smcv: re-worded commit message in response to review]
2015-07-21 16:52:23 +01:00
Simon McVittie
b7e56c18a9 tests: avoid noise on stdout when not --verbose
This makes life easier for frameworks like LAVA that screen-scrape
test results.

g_test_message() is not displayed by default, but each test can be run
with either --tap or --verbose to get these messages displayed.

Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89846
2015-04-16 13:05:37 +01:00
Simon McVittie
6439ab73b3 monitor test: don't block in main context if we already have messages
Functions like become_monitor() sometimes iterate the main context,
which could leave us with unprocessed messages in f->monitored.
We need to drain that queue of unprocessed messages (setting flags
accordingly, which might meet the loop's exit condition or cause
a break) before we are willing to block in the main context again.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89222
Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
2015-02-24 17:00:26 +00:00
Simon McVittie
94610d7de6 Add a common test_init() for GLib tests which prevents hanging forever
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=46787
Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
2015-02-04 17:15:36 +00:00
Simon McVittie
a650bd055f Add a regression test for being a new-style monitor
This includes most of the situations I could think of:

* method call on dbus-daemon and response
* NameOwnerChanged
* NameAcquired, NameLost (although I'm not 100% sure these should
  get captured, since they're redundant with NameOwnerChanged)
* unicast message is allowed through
* unicast message is rejected by no-sending or no-receiving policy
* broadcast is allowed through
* broadcast is rejected by no-sending policy (the error reply
  is also captured)
* broadcast is rejected by no-receiving policy (there is no error
  reply)
* message causing service activation, and the message telling systemd
  to do the actual activation
* systemd reporting that activation failed

It does not cover:

* sending a message to dbus-daemon, then provoking a reply, then
  dbus-daemon does not allow itself to send the reply due to its
  own security policy

This is such an obscure corner case that I'm not even convinced it's
testable without dropping down into lower-level socket manipulation:
dbus-daemon's replies are always assumed to be requested replies,
and replies contain so little other metadata that I think we can
only forbid them by forbidding all method replies. If we do that,
the reply to Hello() won't arrive and the client-side connection will
not become active.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=46787
Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
2015-02-04 17:15:24 +00:00