bus/driver: Make non-core interfaces unavailable on most object paths
[platform/upstream/dbus.git] / test / monitor.c
1 /* Integration tests for monitor-mode D-Bus connections
2  *
3  * Copyright © 2010-2011 Nokia Corporation
4  * Copyright © 2015 Collabora Ltd.
5  *
6  * Permission is hereby granted, free of charge, to any person
7  * obtaining a copy of this software and associated documentation files
8  * (the "Software"), to deal in the Software without restriction,
9  * including without limitation the rights to use, copy, modify, merge,
10  * publish, distribute, sublicense, and/or sell copies of the Software,
11  * and to permit persons to whom the Software is furnished to do so,
12  * subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be
15  * included in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24  * SOFTWARE.
25  */
26
27 #include <config.h>
28
29 #include <string.h>
30
31 #include "test-utils-glib.h"
32
33 typedef struct {
34     const char *config_file;
35     const char * const *match_rules;
36     gboolean care_about_our_names;
37 } Config;
38
39 typedef struct {
40     const Config *config;
41     TestMainContext *ctx;
42     DBusError e;
43     GError *ge;
44
45     gchar *address;
46     GPid daemon_pid;
47
48     DBusConnection *monitor;
49     DBusConnection *sender;
50     DBusConnection *recipient;
51
52     GQueue monitored;
53
54     const char *monitor_name;
55     const char *sender_name;
56     const char *recipient_name;
57
58     DBusConnection *systemd;
59     const char *systemd_name;
60     DBusMessage *systemd_message;
61     DBusConnection *activated;
62     const char *activated_name;
63     DBusMessage *activated_message;
64 } Fixture;
65
66 static const char * const no_match_rules[] = {
67     NULL
68 };
69
70 static const char * const wildcard_match_rules[] = {
71     "",
72     NULL,
73     FALSE
74 };
75
76 static const char * const eavesdrop_match_rules[] = {
77     "eavesdrop=true",
78     NULL,
79     FALSE
80 };
81
82 static const char * const no_eavesdrop_match_rules[] = {
83     "eavesdrop=false",
84     NULL,
85     FALSE
86 };
87
88 static const char * const selective_match_rules[] = {
89     "interface='com.example.Interesting'",
90     "interface='com.example.Fun'",
91     NULL,
92     FALSE
93 };
94
95 static const char * const well_known_destination_match_rules[] = {
96     "destination='com.example.Recipient'",
97     NULL
98 };
99
100 static Config forbidding_config = {
101     "valid-config-files/forbidding.conf",
102     NULL,
103     FALSE
104 };
105
106 static Config wildcard_config = {
107     NULL,
108     wildcard_match_rules,
109     FALSE
110 };
111
112 static Config selective_config = {
113     NULL,
114     selective_match_rules,
115     FALSE
116 };
117
118 static Config well_known_destination_config = {
119     NULL,
120     well_known_destination_match_rules,
121     FALSE
122 };
123
124 static Config no_rules_config = {
125     NULL,
126     no_match_rules,
127     FALSE
128 };
129
130 static Config eavesdrop_config = {
131     NULL,
132     eavesdrop_match_rules,
133     FALSE
134 };
135
136 static Config no_eavesdrop_config = {
137     NULL,
138     no_eavesdrop_match_rules,
139     FALSE
140 };
141
142 #ifdef DBUS_UNIX
143 static Config fake_systemd_config = {
144     "valid-config-files/systemd-activation.conf",
145     NULL,
146     FALSE
147 };
148 #endif
149
150 static Config side_effects_config = {
151     NULL,
152     NULL,
153     TRUE
154 };
155
156 static inline const char *
157 not_null2 (const char *x,
158     const char *fallback)
159 {
160   if (x == NULL)
161     return fallback;
162
163   return x;
164 }
165
166 static inline const char *
167 not_null (const char *x)
168 {
169   return not_null2 (x, "(null)");
170 }
171
172 #define log_message(m) _log_message (m, __FILE__, __LINE__)
173
174 G_GNUC_UNUSED
175 static void
176 _log_message (DBusMessage *m,
177     const char *file,
178     int line)
179 {
180   g_test_message ("%s:%d: message type %d (%s)", file, line,
181       dbus_message_get_type (m),
182       dbus_message_type_to_string (dbus_message_get_type (m)));
183   g_test_message ("\tfrom: %s",
184       not_null2 (dbus_message_get_sender (m), "(dbus-daemon)"));
185   g_test_message ("\tto: %s",
186       not_null2 (dbus_message_get_destination (m), "(broadcast)"));
187   g_test_message ("\tpath: %s",
188       not_null (dbus_message_get_path (m)));
189   g_test_message ("\tinterface: %s",
190       not_null (dbus_message_get_interface (m)));
191   g_test_message ("\tmember: %s",
192       not_null (dbus_message_get_member (m)));
193   g_test_message ("\tsignature: %s",
194       not_null (dbus_message_get_signature (m)));
195   g_test_message ("\terror name: %s",
196       not_null (dbus_message_get_error_name (m)));
197
198   if (strcmp ("s", dbus_message_get_signature (m)) == 0)
199     {
200       DBusError e = DBUS_ERROR_INIT;
201       const char *s;
202
203       dbus_message_get_args (m, &e,
204             DBUS_TYPE_STRING, &s,
205             DBUS_TYPE_INVALID);
206       test_assert_no_error (&e);
207       g_test_message ("\tstring payload: %s", s);
208     }
209 }
210
211 /* these are macros so they get the right line number */
212
213 #define assert_hello(m) \
214 do { \
215   g_assert_cmpstr (dbus_message_type_to_string (dbus_message_get_type (m)), \
216       ==, dbus_message_type_to_string (DBUS_MESSAGE_TYPE_METHOD_CALL)); \
217   g_assert_cmpstr (dbus_message_get_destination (m), ==, DBUS_SERVICE_DBUS); \
218   g_assert_cmpstr (dbus_message_get_path (m), ==, DBUS_PATH_DBUS); \
219   g_assert_cmpstr (dbus_message_get_interface (m), ==, DBUS_INTERFACE_DBUS); \
220   g_assert_cmpstr (dbus_message_get_member (m), ==, "Hello"); \
221   g_assert_cmpstr (dbus_message_get_signature (m), ==, ""); \
222   g_assert_cmpint (dbus_message_get_serial (m), !=, 0); \
223   g_assert_cmpint (dbus_message_get_reply_serial (m), ==, 0); \
224 } while (0)
225
226 #define assert_hello_reply(m) \
227 do { \
228   DBusError _e = DBUS_ERROR_INIT; \
229   const char *_s; \
230     \
231   g_assert_cmpstr (dbus_message_type_to_string (dbus_message_get_type (m)), \
232       ==, dbus_message_type_to_string (DBUS_MESSAGE_TYPE_METHOD_RETURN)); \
233   g_assert_cmpstr (dbus_message_get_sender (m), ==, DBUS_SERVICE_DBUS); \
234   g_assert_cmpstr (dbus_message_get_path (m), ==, NULL); \
235   g_assert_cmpstr (dbus_message_get_interface (m), ==, NULL); \
236   g_assert_cmpstr (dbus_message_get_member (m), ==, NULL); \
237   g_assert_cmpstr (dbus_message_get_signature (m), ==, "s"); \
238   g_assert_cmpint (dbus_message_get_serial (m), !=, 0); \
239   g_assert_cmpint (dbus_message_get_reply_serial (m), !=, 0); \
240     \
241   dbus_message_get_args (m, &_e, \
242         DBUS_TYPE_STRING, &_s, \
243         DBUS_TYPE_INVALID); \
244   test_assert_no_error (&_e); \
245   g_assert_cmpstr (dbus_message_get_destination (m), ==, _s); \
246 } while (0)
247
248 #define assert_name_acquired(m) \
249 do { \
250   DBusError _e = DBUS_ERROR_INIT; \
251   const char *_s; \
252     \
253   g_assert_cmpstr (dbus_message_type_to_string (dbus_message_get_type (m)), \
254       ==, dbus_message_type_to_string (DBUS_MESSAGE_TYPE_SIGNAL)); \
255   g_assert_cmpstr (dbus_message_get_sender (m), ==, DBUS_SERVICE_DBUS); \
256   g_assert_cmpstr (dbus_message_get_path (m), ==, DBUS_PATH_DBUS); \
257   g_assert_cmpstr (dbus_message_get_interface (m), ==, DBUS_INTERFACE_DBUS); \
258   g_assert_cmpstr (dbus_message_get_member (m), ==, "NameAcquired"); \
259   g_assert_cmpstr (dbus_message_get_signature (m), ==, "s"); \
260   g_assert_cmpint (dbus_message_get_serial (m), !=, 0); \
261   g_assert_cmpint (dbus_message_get_reply_serial (m), ==, 0); \
262     \
263   dbus_message_get_args (m, &_e, \
264         DBUS_TYPE_STRING, &_s, \
265         DBUS_TYPE_INVALID); \
266   test_assert_no_error (&_e); \
267   g_assert_cmpstr (dbus_message_get_destination (m), ==, _s); \
268 } while (0)
269
270 #define assert_method_call(m, sender, \
271     destination, path, iface, method, signature) \
272 do { \
273   g_assert_cmpstr (dbus_message_type_to_string (dbus_message_get_type (m)), \
274       ==, dbus_message_type_to_string (DBUS_MESSAGE_TYPE_METHOD_CALL)); \
275   g_assert_cmpstr (dbus_message_get_sender (m), ==, sender); \
276   g_assert_cmpstr (dbus_message_get_destination (m), ==, destination); \
277   g_assert_cmpstr (dbus_message_get_path (m), ==, path); \
278   g_assert_cmpstr (dbus_message_get_interface (m), ==, iface); \
279   g_assert_cmpstr (dbus_message_get_member (m), ==, method); \
280   g_assert_cmpstr (dbus_message_get_signature (m), ==, signature); \
281   g_assert_cmpint (dbus_message_get_serial (m), !=, 0); \
282   g_assert_cmpint (dbus_message_get_reply_serial (m), ==, 0); \
283 } while (0)
284
285 #define assert_signal(m, \
286     sender, path, iface, member, signature, \
287     destination) \
288 do { \
289   g_assert_cmpstr (dbus_message_type_to_string (dbus_message_get_type (m)), \
290       ==, dbus_message_type_to_string (DBUS_MESSAGE_TYPE_SIGNAL)); \
291   g_assert_cmpstr (dbus_message_get_sender (m), ==, sender); \
292   g_assert_cmpstr (dbus_message_get_destination (m), ==, destination); \
293   g_assert_cmpstr (dbus_message_get_path (m), ==, path); \
294   g_assert_cmpstr (dbus_message_get_interface (m), ==, iface); \
295   g_assert_cmpstr (dbus_message_get_member (m), ==, member); \
296   g_assert_cmpstr (dbus_message_get_signature (m), ==, signature); \
297   g_assert_cmpint (dbus_message_get_serial (m), !=, 0); \
298   g_assert_cmpint (dbus_message_get_reply_serial (m), ==, 0); \
299 } while (0)
300
301 #define assert_method_reply(m, sender, destination, signature) \
302 do { \
303   g_assert_cmpstr (dbus_message_type_to_string (dbus_message_get_type (m)), \
304       ==, dbus_message_type_to_string (DBUS_MESSAGE_TYPE_METHOD_RETURN)); \
305   g_assert_cmpstr (dbus_message_get_sender (m), ==, sender); \
306   g_assert_cmpstr (dbus_message_get_destination (m), ==, destination); \
307   g_assert_cmpstr (dbus_message_get_path (m), ==, NULL); \
308   g_assert_cmpstr (dbus_message_get_interface (m), ==, NULL); \
309   g_assert_cmpstr (dbus_message_get_member (m), ==, NULL); \
310   g_assert_cmpstr (dbus_message_get_signature (m), ==, signature); \
311   g_assert_cmpint (dbus_message_get_serial (m), !=, 0); \
312   g_assert_cmpint (dbus_message_get_reply_serial (m), !=, 0); \
313 } while (0)
314
315 #define assert_error_reply(m, sender, destination, error_name) \
316 do { \
317   g_assert_cmpstr (dbus_message_type_to_string (dbus_message_get_type (m)), \
318       ==, dbus_message_type_to_string (DBUS_MESSAGE_TYPE_ERROR)); \
319   g_assert_cmpstr (dbus_message_get_sender (m), ==, sender); \
320   g_assert_cmpstr (dbus_message_get_destination (m), ==, destination); \
321   g_assert_cmpstr (dbus_message_get_error_name (m), ==, error_name); \
322   g_assert_cmpstr (dbus_message_get_path (m), ==, NULL); \
323   g_assert_cmpstr (dbus_message_get_interface (m), ==, NULL); \
324   g_assert_cmpstr (dbus_message_get_member (m), ==, NULL); \
325   g_assert_cmpstr (dbus_message_get_signature (m), ==, "s"); \
326   g_assert_cmpint (dbus_message_get_serial (m), !=, 0); \
327   g_assert_cmpint (dbus_message_get_reply_serial (m), !=, 0); \
328 } while (0)
329
330 /* This is called after processing pending replies to our own method
331  * calls, but before anything else.
332  */
333 static DBusHandlerResult
334 monitor_filter (DBusConnection *connection,
335     DBusMessage *message,
336     void *user_data)
337 {
338   Fixture *f = user_data;
339
340   g_assert_cmpstr (dbus_message_get_interface (message), !=,
341       "com.example.Tedious");
342
343   /* we are not interested in the monitor getting NameAcquired or NameLost
344    * for most tests */
345   if (f->config == NULL || !f->config->care_about_our_names)
346     {
347       if (dbus_message_is_signal (message, DBUS_INTERFACE_DBUS,
348             "NameAcquired") ||
349           dbus_message_is_signal (message, DBUS_INTERFACE_DBUS,
350             "NameLost"))
351         {
352           DBusError e = DBUS_ERROR_INIT;
353           const char *s;
354
355           dbus_message_get_args (message, &e,
356                 DBUS_TYPE_STRING, &s,
357                 DBUS_TYPE_INVALID);
358           test_assert_no_error (&e);
359
360           if (strcmp (s, f->monitor_name) == 0)
361             {
362               /* ignore */
363               return DBUS_HANDLER_RESULT_HANDLED;
364             }
365         }
366     }
367
368   g_queue_push_tail (&f->monitored, dbus_message_ref (message));
369
370   return DBUS_HANDLER_RESULT_HANDLED;
371 }
372
373 static DBusHandlerResult
374 recipient_filter (DBusConnection *connection,
375     DBusMessage *message,
376     void *user_data)
377 {
378   g_assert_cmpstr (dbus_message_get_interface (message), !=,
379       "com.example.CannotSend");
380   g_assert_cmpstr (dbus_message_get_interface (message), !=,
381       "com.example.CannotReceive");
382
383   return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
384 }
385
386 static DBusHandlerResult
387 systemd_filter (DBusConnection *connection,
388     DBusMessage *message,
389     void *user_data)
390 {
391   Fixture *f = user_data;
392
393   if (dbus_message_is_signal (message, DBUS_INTERFACE_DBUS,
394         "NameAcquired") ||
395       dbus_message_is_signal (message, DBUS_INTERFACE_DBUS,
396         "NameLost"))
397     {
398       return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
399     }
400
401   g_assert (f->systemd_message == NULL);
402   f->systemd_message = dbus_message_ref (message);
403
404   return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
405 }
406
407 static DBusHandlerResult
408 activated_filter (DBusConnection *connection,
409     DBusMessage *message,
410     void *user_data)
411 {
412   Fixture *f = user_data;
413
414   if (dbus_message_is_signal (message, DBUS_INTERFACE_DBUS,
415         "NameAcquired") ||
416       dbus_message_is_signal (message, DBUS_INTERFACE_DBUS,
417         "NameLost"))
418     {
419       return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
420     }
421
422   g_assert (f->activated_message == NULL);
423   f->activated_message = dbus_message_ref (message);
424
425   return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
426 }
427
428 static void
429 take_well_known_name (Fixture *f,
430     DBusConnection *connection,
431     const char *name)
432 {
433   int ret;
434
435   ret = dbus_bus_request_name (connection, name,
436       DBUS_NAME_FLAG_DO_NOT_QUEUE, &f->e);
437   test_assert_no_error (&f->e);
438   g_assert_cmpint (ret, ==, DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER);
439 }
440
441 static void
442 setup (Fixture *f,
443     gconstpointer context)
444 {
445   f->config = context;
446
447   f->ctx = test_main_context_get ();
448
449   f->ge = NULL;
450   dbus_error_init (&f->e);
451
452   f->address = test_get_dbus_daemon (f->config ? f->config->config_file : NULL,
453       TEST_USER_ME, NULL, &f->daemon_pid);
454
455   if (f->address == NULL)
456     return;
457
458   f->monitor = test_connect_to_bus (f->ctx, f->address);
459   f->monitor_name = dbus_bus_get_unique_name (f->monitor);
460   f->sender = test_connect_to_bus (f->ctx, f->address);
461   f->sender_name = dbus_bus_get_unique_name (f->sender);
462   f->recipient = test_connect_to_bus (f->ctx, f->address);
463   f->recipient_name = dbus_bus_get_unique_name (f->recipient);
464
465   if (!dbus_connection_add_filter (f->monitor, monitor_filter, f, NULL))
466     g_error ("OOM");
467
468   if (!dbus_connection_add_filter (f->recipient, recipient_filter, f, NULL))
469     g_error ("OOM");
470 }
471
472 static void
473 become_monitor (Fixture *f,
474     const Config *config)
475 {
476   DBusMessage *m;
477   DBusPendingCall *pc;
478   dbus_bool_t ok;
479   DBusMessageIter appender, array_appender;
480   const char * const *match_rules;
481   int i;
482   dbus_uint32_t zero = 0;
483
484   dbus_connection_set_route_peer_messages (f->monitor, TRUE);
485
486   if (config == NULL)
487     config = f->config;
488
489   if (config != NULL && config->match_rules != NULL)
490     match_rules = config->match_rules;
491   else
492     match_rules = wildcard_match_rules;
493
494   m = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
495       DBUS_PATH_DBUS, DBUS_INTERFACE_MONITORING, "BecomeMonitor");
496
497   if (m == NULL)
498     g_error ("OOM");
499
500   dbus_message_iter_init_append (m, &appender);
501
502   if (!dbus_message_iter_open_container (&appender, DBUS_TYPE_ARRAY, "s",
503         &array_appender))
504     g_error ("OOM");
505
506   for (i = 0; match_rules[i] != NULL; i++)
507     {
508       if (!dbus_message_iter_append_basic (&array_appender, DBUS_TYPE_STRING,
509             &match_rules[i]))
510         g_error ("OOM");
511     }
512
513   if (!dbus_message_iter_close_container (&appender, &array_appender) ||
514       !dbus_message_iter_append_basic (&appender, DBUS_TYPE_UINT32, &zero))
515     g_error ("OOM");
516
517   if (!dbus_connection_send_with_reply (f->monitor, m, &pc,
518         DBUS_TIMEOUT_USE_DEFAULT) ||
519       pc == NULL)
520     g_error ("OOM");
521
522   dbus_message_unref (m);
523   m = NULL;
524
525   if (dbus_pending_call_get_completed (pc))
526     test_pending_call_store_reply (pc, &m);
527   else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
528         &m, NULL))
529     g_error ("OOM");
530
531   while (m == NULL)
532     test_main_context_iterate (f->ctx, TRUE);
533
534   ok = dbus_message_get_args (m, &f->e,
535       DBUS_TYPE_INVALID);
536   test_assert_no_error (&f->e);
537   g_assert (ok);
538
539   dbus_pending_call_unref (pc);
540   dbus_message_unref (m);
541   m = NULL;
542 }
543
544 /*
545  * Test what happens if the method call arguments are invalid.
546  */
547 static void
548 test_invalid (Fixture *f,
549     gconstpointer context)
550 {
551   DBusMessage *m;
552   DBusPendingCall *pc;
553   dbus_bool_t ok;
554   DBusMessageIter appender, array_appender;
555   dbus_uint32_t zero = 0;
556   dbus_uint32_t invalid_flags = G_MAXUINT32;
557   const char *s;
558
559   if (f->address == NULL)
560     return;
561
562   dbus_connection_set_route_peer_messages (f->monitor, TRUE);
563
564   /* Try to become a monitor but specify nonzero flags - not allowed */
565
566   m = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
567       DBUS_PATH_DBUS, DBUS_INTERFACE_MONITORING, "BecomeMonitor");
568
569   if (m == NULL)
570     g_error ("OOM");
571
572   dbus_message_iter_init_append (m, &appender);
573
574   if (!dbus_message_iter_open_container (&appender, DBUS_TYPE_ARRAY, "s",
575         &array_appender))
576     g_error ("OOM");
577
578   if (!dbus_message_iter_close_container (&appender, &array_appender) ||
579       !dbus_message_iter_append_basic (&appender, DBUS_TYPE_UINT32,
580         &invalid_flags))
581     g_error ("OOM");
582
583   if (!dbus_connection_send_with_reply (f->monitor, m, &pc,
584         DBUS_TIMEOUT_USE_DEFAULT) ||
585       pc == NULL)
586     g_error ("OOM");
587
588   dbus_message_unref (m);
589   m = NULL;
590
591   if (dbus_pending_call_get_completed (pc))
592     test_pending_call_store_reply (pc, &m);
593   else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
594         &m, NULL))
595     g_error ("OOM");
596
597   while (m == NULL)
598     test_main_context_iterate (f->ctx, TRUE);
599
600   g_assert_cmpint (dbus_message_get_type (m), ==, DBUS_MESSAGE_TYPE_ERROR);
601   g_assert_cmpstr (dbus_message_get_error_name (m), ==,
602       DBUS_ERROR_INVALID_ARGS);
603
604   /* Try to become a monitor but use the wrong object path - not allowed
605    * (security hardening against inappropriate XML policy rules) */
606
607   dbus_pending_call_unref (pc);
608   dbus_message_unref (m);
609
610   m = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
611       "/", DBUS_INTERFACE_MONITORING, "BecomeMonitor");
612
613   if (m == NULL)
614     g_error ("OOM");
615
616   dbus_message_iter_init_append (m, &appender);
617
618   if (!dbus_message_iter_open_container (&appender, DBUS_TYPE_ARRAY, "s",
619         &array_appender))
620     g_error ("OOM");
621
622   if (!dbus_message_iter_close_container (&appender, &array_appender) ||
623       !dbus_message_iter_append_basic (&appender, DBUS_TYPE_UINT32, &zero))
624     g_error ("OOM");
625
626   if (!dbus_connection_send_with_reply (f->monitor, m, &pc,
627         DBUS_TIMEOUT_USE_DEFAULT) ||
628       pc == NULL)
629     g_error ("OOM");
630
631   dbus_message_unref (m);
632   m = NULL;
633
634   if (dbus_pending_call_get_completed (pc))
635     test_pending_call_store_reply (pc, &m);
636   else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
637         &m, NULL))
638     g_error ("OOM");
639
640   while (m == NULL)
641     test_main_context_iterate (f->ctx, TRUE);
642
643   g_assert_cmpint (dbus_message_get_type (m), ==, DBUS_MESSAGE_TYPE_ERROR);
644   g_assert_cmpstr (dbus_message_get_error_name (m), ==,
645       DBUS_ERROR_UNKNOWN_INTERFACE);
646
647   /* Try to become a monitor but specify a bad match rule -
648    * also not allowed */
649
650   dbus_pending_call_unref (pc);
651   dbus_message_unref (m);
652
653   m = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
654       DBUS_PATH_DBUS, DBUS_INTERFACE_MONITORING, "BecomeMonitor");
655
656   if (m == NULL)
657     g_error ("OOM");
658
659   dbus_message_iter_init_append (m, &appender);
660
661   if (!dbus_message_iter_open_container (&appender, DBUS_TYPE_ARRAY, "s",
662         &array_appender))
663     g_error ("OOM");
664
665   /* Syntactically incorrect match rule taken from #92298 - was probably
666    * intended to be path='/modules/...'
667    */
668   s = "interface='org.kde.walletd',member='/modules/kwalletd/org.kde.KWallet/walletOpened'";
669
670   if (!dbus_message_iter_append_basic (&array_appender, DBUS_TYPE_STRING,
671         &s) ||
672       !dbus_message_iter_close_container (&appender, &array_appender) ||
673       !dbus_message_iter_append_basic (&appender, DBUS_TYPE_UINT32, &zero) ||
674       !dbus_connection_send_with_reply (f->monitor, m, &pc,
675         DBUS_TIMEOUT_USE_DEFAULT) ||
676       pc == NULL)
677     g_error ("OOM");
678
679   dbus_message_unref (m);
680   m = NULL;
681
682   if (dbus_pending_call_get_completed (pc))
683     test_pending_call_store_reply (pc, &m);
684   else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
685         &m, NULL))
686     g_error ("OOM");
687
688   while (m == NULL)
689     test_main_context_iterate (f->ctx, TRUE);
690
691   g_assert_cmpint (dbus_message_get_type (m), ==, DBUS_MESSAGE_TYPE_ERROR);
692   g_assert_cmpstr (dbus_message_get_error_name (m), ==,
693       DBUS_ERROR_MATCH_RULE_INVALID);
694
695   dbus_pending_call_unref (pc);
696   dbus_message_unref (m);
697
698   /* We did not become a monitor, so we can still call methods. */
699
700   pc = NULL;
701   m = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
702       DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, "GetId");
703
704   if (m == NULL)
705     g_error ("OOM");
706
707   if (!dbus_connection_send_with_reply (f->monitor, m, &pc,
708         DBUS_TIMEOUT_USE_DEFAULT) ||
709       pc == NULL)
710     g_error ("OOM");
711
712   dbus_message_unref (m);
713   m = NULL;
714
715   if (dbus_pending_call_get_completed (pc))
716     test_pending_call_store_reply (pc, &m);
717   else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
718         &m, NULL))
719     g_error ("OOM");
720
721   while (m == NULL)
722     test_main_context_iterate (f->ctx, TRUE);
723
724   if (dbus_set_error_from_message (&f->e, m))
725     g_error ("%s: %s", f->e.name, f->e.message);
726
727   ok = dbus_message_get_args (m, &f->e,
728       DBUS_TYPE_STRING, &s,
729       DBUS_TYPE_INVALID);
730   test_assert_no_error (&f->e);
731   g_assert (ok);
732   g_assert_cmpstr (s, !=, NULL);
733   g_assert_cmpstr (s, !=, "");
734
735   dbus_pending_call_unref (pc);
736   dbus_message_unref (m);
737 }
738
739 /*
740  * Test the side-effects of becoming a monitor.
741  */
742 static void
743 test_become_monitor (Fixture *f,
744     gconstpointer context)
745 {
746   DBusMessage *m;
747   int ret;
748   dbus_bool_t got_unique = FALSE, got_a = FALSE, got_b = FALSE, got_c = FALSE;
749   dbus_bool_t lost_unique = FALSE, lost_a = FALSE, lost_b = FALSE, lost_c = FALSE;
750
751   if (f->address == NULL)
752     return;
753
754   ret = dbus_bus_request_name (f->monitor, "com.example.A",
755       DBUS_NAME_FLAG_DO_NOT_QUEUE, &f->e);
756   test_assert_no_error (&f->e);
757   g_assert_cmpint (ret, ==, DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER);
758
759   ret = dbus_bus_request_name (f->monitor, "com.example.B",
760       DBUS_NAME_FLAG_DO_NOT_QUEUE, &f->e);
761   test_assert_no_error (&f->e);
762   g_assert_cmpint (ret, ==, DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER);
763
764   ret = dbus_bus_request_name (f->monitor, "com.example.C",
765       DBUS_NAME_FLAG_DO_NOT_QUEUE, &f->e);
766   test_assert_no_error (&f->e);
767   g_assert_cmpint (ret, ==, DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER);
768
769   while (!got_unique || !got_a || !got_b || !got_c)
770     {
771       if (g_queue_is_empty (&f->monitored))
772         test_main_context_iterate (f->ctx, TRUE);
773
774       while ((m = g_queue_pop_head (&f->monitored)) != NULL)
775         {
776           if (dbus_message_is_signal (m, DBUS_INTERFACE_DBUS,
777                 "NameAcquired"))
778             {
779               const char *name;
780               dbus_bool_t ok = dbus_message_get_args (m, &f->e,
781                   DBUS_TYPE_STRING, &name,
782                   DBUS_TYPE_INVALID);
783
784               g_assert_cmpstr (dbus_message_get_path (m), ==,
785                   DBUS_PATH_DBUS);
786
787               test_assert_no_error (&f->e);
788               g_assert (ok);
789
790               if (g_str_equal (name, f->monitor_name))
791                 {
792                   g_assert (!got_unique);
793                   got_unique = TRUE;
794                 }
795               else if (g_str_equal (name, "com.example.A"))
796                 {
797                   g_assert (!got_a);
798                   got_a = TRUE;
799                 }
800               else if (g_str_equal (name, "com.example.B"))
801                 {
802                   g_assert (!got_b);
803                   got_b = TRUE;
804                 }
805               else
806                 {
807                   g_assert_cmpstr (name, ==, "com.example.C");
808                   g_assert (!got_c);
809                   got_c = TRUE;
810                 }
811             }
812           else
813             {
814               g_error ("unexpected message %s.%s",
815                   dbus_message_get_interface (m),
816                   dbus_message_get_member (m));
817             }
818
819           dbus_message_unref (m);
820         }
821     }
822
823   become_monitor (f, NULL);
824
825   while (!lost_unique || !lost_a || !lost_b || !lost_c)
826     {
827       if (g_queue_is_empty (&f->monitored))
828         test_main_context_iterate (f->ctx, TRUE);
829
830       while ((m = g_queue_pop_head (&f->monitored)) != NULL)
831         {
832           if (dbus_message_is_signal (m, DBUS_INTERFACE_DBUS,
833                 "NameLost"))
834             {
835               const char *name;
836               dbus_bool_t ok = dbus_message_get_args (m, &f->e,
837                   DBUS_TYPE_STRING, &name,
838                   DBUS_TYPE_INVALID);
839
840               test_assert_no_error (&f->e);
841               g_assert (ok);
842
843               if (g_str_equal (name, f->monitor_name))
844                 {
845                   g_assert (!lost_unique);
846                   lost_unique = TRUE;
847                 }
848               else if (g_str_equal (name, "com.example.A"))
849                 {
850                   g_assert (!lost_a);
851                   lost_a = TRUE;
852                 }
853               else if (g_str_equal (name, "com.example.B"))
854                 {
855                   g_assert (!lost_b);
856                   lost_b = TRUE;
857                 }
858               else
859                 {
860                   g_assert_cmpstr (name, ==, "com.example.C");
861                   g_assert (!lost_c);
862                   lost_c = TRUE;
863                 }
864             }
865           else
866             {
867               g_error ("unexpected message %s.%s",
868                   dbus_message_get_interface (m),
869                   dbus_message_get_member (m));
870             }
871
872           dbus_message_unref (m);
873         }
874     }
875
876   /* Calling methods is forbidden; we get disconnected. */
877   dbus_bus_add_match (f->monitor, "", &f->e);
878   g_assert_cmpstr (f->e.name, ==, DBUS_ERROR_NO_REPLY);
879   g_assert (!dbus_connection_get_is_connected (f->monitor));
880
881   while (TRUE)
882     {
883       if (g_queue_is_empty (&f->monitored))
884         test_main_context_iterate (f->ctx, TRUE);
885
886       /* When we iterate all the connection's messages, we see ourselves
887        * losing all our names, then we're disconnected. */
888       while ((m = g_queue_pop_head (&f->monitored)) != NULL)
889         {
890           if (dbus_message_is_signal (m, DBUS_INTERFACE_LOCAL, "Disconnected"))
891             {
892               dbus_message_unref (m);
893               goto disconnected;
894             }
895           else
896             {
897               g_error ("unexpected message %s.%s",
898                   dbus_message_get_interface (m),
899                   dbus_message_get_member (m));
900             }
901
902           dbus_message_unref (m);
903         }
904     }
905
906 disconnected:
907
908   g_assert (lost_a);
909   g_assert (lost_b);
910   g_assert (lost_c);
911 }
912
913 static void
914 test_broadcast (Fixture *f,
915     gconstpointer context)
916 {
917   DBusMessage *m;
918
919   if (f->address == NULL)
920     return;
921
922   dbus_bus_add_match (f->recipient, "type='signal'", &f->e);
923   test_assert_no_error (&f->e);
924
925   become_monitor (f, NULL);
926
927   m = dbus_message_new_signal ("/foo", "com.example.bar", "BroadcastSignal1");
928   dbus_connection_send (f->sender, m, NULL);
929   dbus_message_unref (m);
930
931   m = dbus_message_new_signal ("/foo", "com.example.bar", "BroadcastSignal2");
932   dbus_connection_send (f->sender, m, NULL);
933   dbus_message_unref (m);
934
935   m = dbus_message_new_signal ("/foo", "com.example.bar", "BroadcastSignal3");
936   dbus_connection_send (f->sender, m, NULL);
937   dbus_message_unref (m);
938
939   while (g_queue_get_length (&f->monitored) < 3)
940     test_main_context_iterate (f->ctx, TRUE);
941
942   m = g_queue_pop_head (&f->monitored);
943   assert_signal (m, f->sender_name, "/foo", "com.example.bar",
944       "BroadcastSignal1", "", NULL);
945   dbus_message_unref (m);
946
947   m = g_queue_pop_head (&f->monitored);
948   assert_signal (m, f->sender_name, "/foo", "com.example.bar",
949       "BroadcastSignal2", "", NULL);
950   dbus_message_unref (m);
951
952   m = g_queue_pop_head (&f->monitored);
953   assert_signal (m, f->sender_name, "/foo", "com.example.bar",
954       "BroadcastSignal3", "", NULL);
955   dbus_message_unref (m);
956
957   m = g_queue_pop_head (&f->monitored);
958   g_assert (m == NULL);
959 }
960
961 static void
962 test_forbidden_broadcast (Fixture *f,
963     gconstpointer context)
964 {
965   DBusMessage *m;
966
967   if (f->address == NULL)
968     return;
969
970   dbus_bus_add_match (f->recipient, "type='signal'", &f->e);
971   test_assert_no_error (&f->e);
972
973   become_monitor (f, NULL);
974
975   m = dbus_message_new_signal ("/foo", "com.example.CannotSend",
976       "BroadcastSignal1");
977   dbus_connection_send (f->sender, m, NULL);
978   dbus_message_unref (m);
979
980   m = dbus_message_new_signal ("/foo", "com.example.CannotReceive",
981       "BroadcastSignal2");
982   dbus_connection_send (f->sender, m, NULL);
983   dbus_message_unref (m);
984
985   m = dbus_message_new_signal ("/foo", "com.example.CannotSend",
986       "BroadcastSignal3");
987   dbus_connection_send (f->sender, m, NULL);
988   dbus_message_unref (m);
989
990   while (g_queue_get_length (&f->monitored) < 6)
991     test_main_context_iterate (f->ctx, TRUE);
992
993   m = g_queue_pop_head (&f->monitored);
994   assert_signal (m, f->sender_name, "/foo", "com.example.CannotSend",
995       "BroadcastSignal1", "", NULL);
996   dbus_message_unref (m);
997
998   m = g_queue_pop_head (&f->monitored);
999   assert_error_reply (m, DBUS_SERVICE_DBUS, f->sender_name,
1000       DBUS_ERROR_ACCESS_DENIED);
1001   dbus_message_unref (m);
1002
1003   m = g_queue_pop_head (&f->monitored);
1004   assert_signal (m, f->sender_name, "/foo", "com.example.CannotReceive",
1005       "BroadcastSignal2", "", NULL);
1006   dbus_message_unref (m);
1007
1008   m = g_queue_pop_head (&f->monitored);
1009   assert_error_reply (m, DBUS_SERVICE_DBUS, f->sender_name,
1010       DBUS_ERROR_ACCESS_DENIED);
1011   dbus_message_unref (m);
1012
1013   m = g_queue_pop_head (&f->monitored);
1014   assert_signal (m, f->sender_name, "/foo", "com.example.CannotSend",
1015       "BroadcastSignal3", "", NULL);
1016   dbus_message_unref (m);
1017
1018   m = g_queue_pop_head (&f->monitored);
1019   assert_error_reply (m, DBUS_SERVICE_DBUS, f->sender_name,
1020       DBUS_ERROR_ACCESS_DENIED);
1021   dbus_message_unref (m);
1022
1023   m = g_queue_pop_head (&f->monitored);
1024   g_assert (m == NULL);
1025 }
1026
1027 static void
1028 test_unicast_signal (Fixture *f,
1029     gconstpointer context)
1030 {
1031   DBusMessage *m;
1032
1033   if (f->address == NULL)
1034     return;
1035
1036   become_monitor (f, NULL);
1037
1038   m = dbus_message_new_signal ("/foo", "com.example.bar", "UnicastSignal1");
1039   if (!dbus_message_set_destination (m, f->recipient_name))
1040     g_error ("OOM");
1041   dbus_connection_send (f->sender, m, NULL);
1042   dbus_message_unref (m);
1043
1044   m = dbus_message_new_signal ("/foo", "com.example.bar", "UnicastSignal2");
1045   if (!dbus_message_set_destination (m, f->recipient_name))
1046     g_error ("OOM");
1047   dbus_connection_send (f->sender, m, NULL);
1048   dbus_message_unref (m);
1049
1050   m = dbus_message_new_signal ("/foo", "com.example.bar", "UnicastSignal3");
1051   if (!dbus_message_set_destination (m, f->recipient_name))
1052     g_error ("OOM");
1053   dbus_connection_send (f->sender, m, NULL);
1054   dbus_message_unref (m);
1055
1056   while (g_queue_get_length (&f->monitored) < 3)
1057     test_main_context_iterate (f->ctx, TRUE);
1058
1059   m = g_queue_pop_head (&f->monitored);
1060   assert_signal (m, f->sender_name, "/foo",
1061       "com.example.bar", "UnicastSignal1", "", f->recipient_name);
1062   dbus_message_unref (m);
1063
1064   m = g_queue_pop_head (&f->monitored);
1065   assert_signal (m, f->sender_name, "/foo",
1066       "com.example.bar", "UnicastSignal2", "", f->recipient_name);
1067   dbus_message_unref (m);
1068
1069   m = g_queue_pop_head (&f->monitored);
1070   assert_signal (m, f->sender_name, "/foo",
1071       "com.example.bar", "UnicastSignal3", "", f->recipient_name);
1072   dbus_message_unref (m);
1073
1074   m = g_queue_pop_head (&f->monitored);
1075   g_assert (m == NULL);
1076 }
1077
1078 static void
1079 test_forbidden (Fixture *f,
1080     gconstpointer context)
1081 {
1082   DBusMessage *m;
1083
1084   if (f->address == NULL)
1085     return;
1086
1087   become_monitor (f, NULL);
1088
1089   m = dbus_message_new_signal ("/foo", "com.example.CannotSend",
1090       "UnicastSignal1");
1091   if (!dbus_message_set_destination (m, f->recipient_name))
1092     g_error ("OOM");
1093   dbus_connection_send (f->sender, m, NULL);
1094   dbus_message_unref (m);
1095
1096   m = dbus_message_new_signal ("/foo", "com.example.CannotReceive",
1097       "UnicastSignal2");
1098   if (!dbus_message_set_destination (m, f->recipient_name))
1099     g_error ("OOM");
1100   dbus_connection_send (f->sender, m, NULL);
1101   dbus_message_unref (m);
1102
1103   m = dbus_message_new_signal ("/foo", "com.example.CannotSend",
1104       "UnicastSignal3");
1105   if (!dbus_message_set_destination (m, f->recipient_name))
1106     g_error ("OOM");
1107   dbus_connection_send (f->sender, m, NULL);
1108   dbus_message_unref (m);
1109
1110   while (g_queue_get_length (&f->monitored) < 6)
1111     test_main_context_iterate (f->ctx, TRUE);
1112
1113   m = g_queue_pop_head (&f->monitored);
1114   assert_signal (m, f->sender_name, "/foo",
1115       "com.example.CannotSend", "UnicastSignal1", "", f->recipient_name);
1116   dbus_message_unref (m);
1117
1118   m = g_queue_pop_head (&f->monitored);
1119   assert_error_reply (m, DBUS_SERVICE_DBUS, f->sender_name,
1120       DBUS_ERROR_ACCESS_DENIED);
1121   dbus_message_unref (m);
1122
1123   m = g_queue_pop_head (&f->monitored);
1124   assert_signal (m, f->sender_name, "/foo",
1125       "com.example.CannotReceive", "UnicastSignal2", "", f->recipient_name);
1126   dbus_message_unref (m);
1127
1128   m = g_queue_pop_head (&f->monitored);
1129   assert_error_reply (m, DBUS_SERVICE_DBUS, f->sender_name,
1130       DBUS_ERROR_ACCESS_DENIED);
1131   dbus_message_unref (m);
1132
1133   m = g_queue_pop_head (&f->monitored);
1134   assert_signal (m, f->sender_name, "/foo",
1135       "com.example.CannotSend", "UnicastSignal3", "", f->recipient_name);
1136   dbus_message_unref (m);
1137
1138   m = g_queue_pop_head (&f->monitored);
1139   assert_error_reply (m, DBUS_SERVICE_DBUS, f->sender_name,
1140       DBUS_ERROR_ACCESS_DENIED);
1141   dbus_message_unref (m);
1142
1143   m = g_queue_pop_head (&f->monitored);
1144   g_assert (m == NULL);
1145 }
1146
1147 static void
1148 test_method_call (Fixture *f,
1149     gconstpointer context)
1150 {
1151   DBusMessage *m;
1152
1153   if (f->address == NULL)
1154     return;
1155
1156   become_monitor (f, NULL);
1157
1158   /* regression test for
1159    * https://bugs.freedesktop.org/show_bug.cgi?id=90952 */
1160   m = dbus_message_new_method_call (f->recipient_name, "/foo",
1161       DBUS_INTERFACE_PEER, "Ping");
1162   dbus_connection_send (f->sender, m, NULL);
1163   dbus_message_unref (m);
1164
1165   while (g_queue_get_length (&f->monitored) < 2)
1166     test_main_context_iterate (f->ctx, TRUE);
1167
1168   m = g_queue_pop_head (&f->monitored);
1169   assert_method_call (m, f->sender_name, f->recipient_name, "/foo",
1170       DBUS_INTERFACE_PEER, "Ping", "");
1171   dbus_message_unref (m);
1172
1173   m = g_queue_pop_head (&f->monitored);
1174   assert_method_reply (m, f->recipient_name, f->sender_name, "");
1175   dbus_message_unref (m);
1176
1177   m = g_queue_pop_head (&f->monitored);
1178   g_assert (m == NULL);
1179
1180   m = dbus_message_new_method_call (f->recipient_name, "/foo", "com.example.bar",
1181       "Call1");
1182   dbus_connection_send (f->sender, m, NULL);
1183   dbus_message_unref (m);
1184
1185   while (g_queue_get_length (&f->monitored) < 2)
1186     test_main_context_iterate (f->ctx, TRUE);
1187
1188   m = g_queue_pop_head (&f->monitored);
1189   assert_method_call (m, f->sender_name, f->recipient_name, "/foo",
1190       "com.example.bar", "Call1", "");
1191   dbus_message_unref (m);
1192
1193   m = g_queue_pop_head (&f->monitored);
1194   assert_error_reply (m, f->recipient_name, f->sender_name,
1195       DBUS_ERROR_UNKNOWN_METHOD);
1196   dbus_message_unref (m);
1197
1198   m = g_queue_pop_head (&f->monitored);
1199   g_assert (m == NULL);
1200 }
1201
1202 static void
1203 test_forbidden_method_call (Fixture *f,
1204     gconstpointer context)
1205 {
1206   DBusMessage *m;
1207
1208   if (f->address == NULL)
1209     return;
1210
1211   become_monitor (f, NULL);
1212
1213   m = dbus_message_new_method_call (f->recipient_name, "/foo",
1214       "com.example.CannotSend", "Call1");
1215   dbus_connection_send (f->sender, m, NULL);
1216   dbus_message_unref (m);
1217
1218   while (g_queue_get_length (&f->monitored) < 2)
1219     test_main_context_iterate (f->ctx, TRUE);
1220
1221   m = g_queue_pop_head (&f->monitored);
1222   assert_method_call (m, f->sender_name, f->recipient_name, "/foo",
1223       "com.example.CannotSend", "Call1", "");
1224   dbus_message_unref (m);
1225
1226   m = g_queue_pop_head (&f->monitored);
1227   assert_error_reply (m, DBUS_SERVICE_DBUS, f->sender_name,
1228       DBUS_ERROR_ACCESS_DENIED);
1229   dbus_message_unref (m);
1230
1231   m = g_queue_pop_head (&f->monitored);
1232   g_assert (m == NULL);
1233
1234   m = dbus_message_new_method_call (f->recipient_name, "/foo",
1235       "com.example.CannotReceive", "Call2");
1236   dbus_connection_send (f->sender, m, NULL);
1237   dbus_message_unref (m);
1238
1239   while (g_queue_get_length (&f->monitored) < 2)
1240     test_main_context_iterate (f->ctx, TRUE);
1241
1242   m = g_queue_pop_head (&f->monitored);
1243   assert_method_call (m, f->sender_name, f->recipient_name, "/foo",
1244       "com.example.CannotReceive", "Call2", "");
1245   dbus_message_unref (m);
1246
1247   m = g_queue_pop_head (&f->monitored);
1248   assert_error_reply (m, DBUS_SERVICE_DBUS, f->sender_name,
1249       DBUS_ERROR_ACCESS_DENIED);
1250   dbus_message_unref (m);
1251
1252   m = g_queue_pop_head (&f->monitored);
1253   g_assert (m == NULL);
1254 }
1255
1256 static void
1257 test_dbus_daemon (Fixture *f,
1258     gconstpointer context)
1259 {
1260   DBusMessage *m;
1261   int res;
1262
1263   if (f->address == NULL)
1264     return;
1265
1266   become_monitor (f, NULL);
1267
1268   res = dbus_bus_request_name (f->sender, "com.example.Sender",
1269       DBUS_NAME_FLAG_DO_NOT_QUEUE, &f->e);
1270   test_assert_no_error (&f->e);
1271   g_assert_cmpint (res, ==, DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER);
1272
1273   res = dbus_bus_release_name (f->sender, "com.example.Sender", &f->e);
1274   test_assert_no_error (&f->e);
1275   g_assert_cmpint (res, ==, DBUS_RELEASE_NAME_REPLY_RELEASED);
1276
1277   while (g_queue_get_length (&f->monitored) < 8)
1278     test_main_context_iterate (f->ctx, TRUE);
1279
1280   m = g_queue_pop_head (&f->monitored);
1281   assert_method_call (m, f->sender_name, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
1282       DBUS_INTERFACE_DBUS, "RequestName", "su");
1283   dbus_message_unref (m);
1284
1285   m = g_queue_pop_head (&f->monitored);
1286   assert_signal (m, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS,
1287       "NameOwnerChanged", "sss", NULL);
1288   dbus_message_unref (m);
1289
1290   /* FIXME: should we get this? */
1291   m = g_queue_pop_head (&f->monitored);
1292   assert_signal (m, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS,
1293       "NameAcquired", "s", f->sender_name);
1294   dbus_message_unref (m);
1295
1296   m = g_queue_pop_head (&f->monitored);
1297   assert_method_reply (m, DBUS_SERVICE_DBUS, f->sender_name, "u");
1298   dbus_message_unref (m);
1299
1300   m = g_queue_pop_head (&f->monitored);
1301   assert_method_call (m, f->sender_name, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
1302       DBUS_INTERFACE_DBUS, "ReleaseName", "s");
1303   dbus_message_unref (m);
1304
1305   /* FIXME: should we get this? */
1306   m = g_queue_pop_head (&f->monitored);
1307   assert_signal (m, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS,
1308       "NameLost", "s", f->sender_name);
1309   dbus_message_unref (m);
1310
1311   m = g_queue_pop_head (&f->monitored);
1312   assert_signal (m, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS,
1313       "NameOwnerChanged", "sss", NULL);
1314   dbus_message_unref (m);
1315
1316   m = g_queue_pop_head (&f->monitored);
1317   assert_method_reply (m, DBUS_SERVICE_DBUS, f->sender_name, "u");
1318   dbus_message_unref (m);
1319
1320   m = g_queue_pop_head (&f->monitored);
1321   g_assert (m == NULL);
1322 }
1323
1324 static void
1325 test_selective (Fixture *f,
1326     gconstpointer context)
1327 {
1328   DBusMessage *m;
1329
1330   if (f->address == NULL)
1331     return;
1332
1333   /* Match rules added before becoming a monitor should be cleared:
1334    * if they weren't, this test would get Interesting twice, then Tedious,
1335    * and only see Fun after that. */
1336   dbus_bus_add_match (f->monitor,
1337       "eavesdrop='true',interface='com.example.Interesting'", &f->e);
1338   test_assert_no_error (&f->e);
1339   dbus_bus_add_match (f->monitor,
1340       "eavesdrop='true',interface='com.example.Tedious'", &f->e);
1341   test_assert_no_error (&f->e);
1342
1343   become_monitor (f, NULL);
1344
1345   m = dbus_message_new_signal ("/foo", "com.example.Interesting",
1346       "UnicastSignal1");
1347   if (!dbus_message_set_destination (m, f->recipient_name))
1348     g_error ("OOM");
1349   dbus_connection_send (f->sender, m, NULL);
1350   dbus_message_unref (m);
1351
1352   m = dbus_message_new_signal ("/foo", "com.example.Tedious",
1353       "UnicastSignal2");
1354   if (!dbus_message_set_destination (m, f->recipient_name))
1355     g_error ("OOM");
1356   dbus_connection_send (f->sender, m, NULL);
1357   dbus_message_unref (m);
1358
1359   m = dbus_message_new_signal ("/foo", "com.example.Fun",
1360       "UnicastSignal3");
1361   if (!dbus_message_set_destination (m, f->recipient_name))
1362     g_error ("OOM");
1363   dbus_connection_send (f->sender, m, NULL);
1364   dbus_message_unref (m);
1365
1366   while (g_queue_get_length (&f->monitored) < 2)
1367     test_main_context_iterate (f->ctx, TRUE);
1368
1369   /* We get the interesting signal and the fun signal, but not the tedious
1370    * signal. */
1371
1372   m = g_queue_pop_head (&f->monitored);
1373   assert_signal (m, f->sender_name, "/foo",
1374       "com.example.Interesting", "UnicastSignal1", "", f->recipient_name);
1375   dbus_message_unref (m);
1376
1377   m = g_queue_pop_head (&f->monitored);
1378   assert_signal (m, f->sender_name, "/foo",
1379       "com.example.Fun", "UnicastSignal3", "", f->recipient_name);
1380   dbus_message_unref (m);
1381
1382   m = g_queue_pop_head (&f->monitored);
1383   g_assert (m == NULL);
1384 }
1385
1386 static void
1387 test_well_known_destination (Fixture *f,
1388     gconstpointer context)
1389 {
1390   DBusMessage *m;
1391
1392   if (f->address == NULL)
1393     return;
1394
1395   take_well_known_name (f, f->recipient, "com.example.Recipient");
1396   /* we don't expect_take_well_known_name here because the
1397    * monitor isn't up yet */
1398
1399   become_monitor (f, NULL);
1400
1401   /* The sender sends a message to itself. It will not be observed. */
1402   m = dbus_message_new_signal ("/foo", "com.example.bar", "Unobserved");
1403   if (!dbus_message_set_destination (m, f->sender_name))
1404     g_error ("OOM");
1405   dbus_connection_send (f->sender, m, NULL);
1406   dbus_message_unref (m);
1407
1408   /* The sender sends a message to the recipient by well-known name.
1409    * It will be observed. */
1410   m = dbus_message_new_signal ("/foo", "com.example.bar", "Observed1");
1411   if (!dbus_message_set_destination (m, "com.example.Recipient"))
1412     g_error ("OOM");
1413   dbus_connection_send (f->sender, m, NULL);
1414   dbus_message_unref (m);
1415
1416   /* The sender sends a message to the recipient by unique name.
1417    * It will still be observed. */
1418   m = dbus_message_new_signal ("/foo", "com.example.bar", "Observed2");
1419   if (!dbus_message_set_destination (m, f->recipient_name))
1420     g_error ("OOM");
1421   dbus_connection_send (f->sender, m, NULL);
1422   dbus_message_unref (m);
1423
1424   while (g_queue_get_length (&f->monitored) < 2)
1425     test_main_context_iterate (f->ctx, TRUE);
1426
1427   m = g_queue_pop_head (&f->monitored);
1428   assert_signal (m, f->sender_name, "/foo", "com.example.bar",
1429       "Observed1", "", "com.example.Recipient");
1430   dbus_message_unref (m);
1431
1432   m = g_queue_pop_head (&f->monitored);
1433   assert_signal (m, f->sender_name, "/foo", "com.example.bar",
1434       "Observed2", "", f->recipient_name);
1435   dbus_message_unref (m);
1436
1437   m = g_queue_pop_head (&f->monitored);
1438   g_assert (m == NULL);
1439 }
1440
1441 static void
1442 test_unique_destination (Fixture *f,
1443     gconstpointer context)
1444 {
1445   DBusMessage *m;
1446   Config config = {
1447     NULL,
1448     NULL, /* match rules */
1449     FALSE
1450   };
1451   const gchar *match_rules[2] = { NULL, NULL };
1452   gchar *rule;
1453
1454   if (f->address == NULL)
1455     return;
1456
1457   take_well_known_name (f, f->recipient, "com.example.Recipient");
1458   /* we don't expect_take_well_known_name here because the
1459    * monitor isn't up yet */
1460
1461   rule = g_strdup_printf ("destination='%s'", f->recipient_name);
1462   /* free it later */
1463   g_test_queue_free (rule);
1464   match_rules[0] = rule;
1465   config.match_rules = match_rules;
1466
1467   become_monitor (f, &config);
1468
1469   /* The sender sends a message to itself. It will not be observed. */
1470   m = dbus_message_new_signal ("/foo", "com.example.bar", "Unobserved");
1471   if (!dbus_message_set_destination (m, f->sender_name))
1472     g_error ("OOM");
1473   dbus_connection_send (f->sender, m, NULL);
1474   dbus_message_unref (m);
1475
1476   /* The sender sends a message to the recipient by well-known name.
1477    * It will be observed. */
1478   m = dbus_message_new_signal ("/foo", "com.example.bar", "Observed1");
1479   if (!dbus_message_set_destination (m, "com.example.Recipient"))
1480     g_error ("OOM");
1481   dbus_connection_send (f->sender, m, NULL);
1482   dbus_message_unref (m);
1483
1484   /* The sender sends a message to the recipient by unique name.
1485    * It will still be observed. */
1486   m = dbus_message_new_signal ("/foo", "com.example.bar", "Observed2");
1487   if (!dbus_message_set_destination (m, f->recipient_name))
1488     g_error ("OOM");
1489   dbus_connection_send (f->sender, m, NULL);
1490   dbus_message_unref (m);
1491
1492   while (g_queue_get_length (&f->monitored) < 2)
1493     test_main_context_iterate (f->ctx, TRUE);
1494
1495   m = g_queue_pop_head (&f->monitored);
1496   assert_signal (m, f->sender_name, "/foo", "com.example.bar",
1497       "Observed1", "", "com.example.Recipient");
1498   dbus_message_unref (m);
1499
1500   m = g_queue_pop_head (&f->monitored);
1501   assert_signal (m, f->sender_name, "/foo", "com.example.bar",
1502       "Observed2", "", f->recipient_name);
1503   dbus_message_unref (m);
1504
1505   m = g_queue_pop_head (&f->monitored);
1506   g_assert (m == NULL);
1507 }
1508
1509 #ifdef DBUS_UNIX
1510 /* currently only used for the systemd activation test */
1511 static void
1512 expect_new_connection (Fixture *f)
1513 {
1514   DBusMessage *m;
1515
1516   while (g_queue_get_length (&f->monitored) < 4)
1517     test_main_context_iterate (f->ctx, TRUE);
1518
1519   m = g_queue_pop_head (&f->monitored);
1520   assert_hello (m);
1521   dbus_message_unref (m);
1522
1523   m = g_queue_pop_head (&f->monitored);
1524   assert_hello_reply (m);
1525   dbus_message_unref (m);
1526
1527   m = g_queue_pop_head (&f->monitored);
1528   assert_signal (m, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS,
1529       "NameOwnerChanged", "sss", NULL);
1530   dbus_message_unref (m);
1531
1532   m = g_queue_pop_head (&f->monitored);
1533   assert_name_acquired (m);
1534   dbus_message_unref (m);
1535 }
1536
1537 /* currently only used for the systemd activation test */
1538 static void
1539 expect_take_well_known_name (Fixture *f,
1540     DBusConnection *connection,
1541     const char *name)
1542 {
1543   DBusMessage *m;
1544   const char *connection_name = dbus_bus_get_unique_name (connection);
1545
1546   while (g_queue_get_length (&f->monitored) < 4)
1547     test_main_context_iterate (f->ctx, TRUE);
1548
1549   m = g_queue_pop_head (&f->monitored);
1550   assert_method_call (m, connection_name, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
1551       DBUS_INTERFACE_DBUS, "RequestName", "su");
1552   dbus_message_unref (m);
1553
1554   m = g_queue_pop_head (&f->monitored);
1555   assert_signal (m, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS,
1556       "NameOwnerChanged", "sss", NULL);
1557   dbus_message_unref (m);
1558
1559   m = g_queue_pop_head (&f->monitored);
1560   assert_signal (m, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS,
1561       "NameAcquired", "s", connection_name);
1562   dbus_message_unref (m);
1563
1564   m = g_queue_pop_head (&f->monitored);
1565   assert_method_reply (m, DBUS_SERVICE_DBUS, connection_name, "u");
1566   dbus_message_unref (m);
1567 }
1568
1569 static void
1570 test_activation (Fixture *f,
1571     gconstpointer context)
1572 {
1573   DBusMessage *m;
1574
1575   if (f->address == NULL)
1576     return;
1577
1578   become_monitor (f, NULL);
1579
1580   /* The sender sends a message to an activatable service. */
1581   m = dbus_message_new_signal ("/foo", "com.example.bar", "UnicastSignal1");
1582   if (!dbus_message_set_destination (m, "com.example.SystemdActivatable1"))
1583     g_error ("OOM");
1584   dbus_connection_send (f->sender, m, NULL);
1585   dbus_message_unref (m);
1586
1587   /* We observe the activation request, and the message that caused it,
1588    * before systemd has even joined the bus. */
1589   while (g_queue_get_length (&f->monitored) < 2)
1590     test_main_context_iterate (f->ctx, TRUE);
1591
1592   m = g_queue_pop_head (&f->monitored);
1593   assert_signal (m, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
1594       "org.freedesktop.systemd1.Activator", "ActivationRequest", "s",
1595       "org.freedesktop.systemd1");
1596   dbus_message_unref (m);
1597   m = g_queue_pop_head (&f->monitored);
1598   assert_signal (m, f->sender_name, "/foo",
1599       "com.example.bar", "UnicastSignal1", "",
1600       "com.example.SystemdActivatable1");
1601   dbus_message_unref (m);
1602
1603   /* The fake systemd connects to the bus. */
1604   f->systemd = test_connect_to_bus (f->ctx, f->address);
1605   if (!dbus_connection_add_filter (f->systemd, systemd_filter, f, NULL))
1606     g_error ("OOM");
1607   f->systemd_name = dbus_bus_get_unique_name (f->systemd);
1608
1609   expect_new_connection (f);
1610   take_well_known_name (f, f->systemd, "org.freedesktop.systemd1");
1611   expect_take_well_known_name (f, f->systemd, "org.freedesktop.systemd1");
1612
1613   /* It gets its activation request. */
1614   while (f->systemd_message == NULL)
1615     test_main_context_iterate (f->ctx, TRUE);
1616
1617   m = f->systemd_message;
1618   f->systemd_message = NULL;
1619   assert_signal (m, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
1620       "org.freedesktop.systemd1.Activator", "ActivationRequest", "s",
1621       "org.freedesktop.systemd1");
1622   dbus_message_unref (m);
1623
1624   /* systemd starts the activatable service. */
1625   f->activated = test_connect_to_bus (f->ctx, f->address);
1626   if (!dbus_connection_add_filter (f->activated, activated_filter,
1627         f, NULL))
1628     g_error ("OOM");
1629   f->activated_name = dbus_bus_get_unique_name (f->activated);
1630
1631   expect_new_connection (f);
1632   take_well_known_name (f, f->activated, "com.example.SystemdActivatable1");
1633   expect_take_well_known_name (f, f->activated,
1634       "com.example.SystemdActivatable1");
1635
1636   /* The message is delivered to the activatable service. */
1637   while (f->activated_message == NULL)
1638     test_main_context_iterate (f->ctx, TRUE);
1639
1640   m = f->activated_message;
1641   f->activated_message = NULL;
1642   assert_signal (m, f->sender_name, "/foo",
1643       "com.example.bar", "UnicastSignal1", "",
1644       "com.example.SystemdActivatable1");
1645   dbus_message_unref (m);
1646
1647   /* The sender sends a message to a different activatable service. */
1648   m = dbus_message_new_signal ("/foo", "com.example.bar", "UnicastSignal2");
1649   if (!dbus_message_set_destination (m, "com.example.SystemdActivatable2"))
1650     g_error ("OOM");
1651   dbus_connection_send (f->sender, m, NULL);
1652   dbus_message_unref (m);
1653
1654   /* This time systemd is already ready for it. */
1655   while (g_queue_get_length (&f->monitored) < 2 ||
1656       f->systemd_message == NULL)
1657     test_main_context_iterate (f->ctx, TRUE);
1658
1659   m = f->systemd_message;
1660   f->systemd_message = NULL;
1661   assert_signal (m, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
1662       "org.freedesktop.systemd1.Activator", "ActivationRequest", "s",
1663       "org.freedesktop.systemd1");
1664   dbus_message_unref (m);
1665
1666   /* The monitor sees the activation request and the signal that
1667    * prompted it.*/
1668   m = g_queue_pop_head (&f->monitored);
1669   assert_signal (m, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
1670       "org.freedesktop.systemd1.Activator", "ActivationRequest", "s",
1671       "org.freedesktop.systemd1");
1672   dbus_message_unref (m);
1673   m = g_queue_pop_head (&f->monitored);
1674   assert_signal (m, f->sender_name, "/foo",
1675       "com.example.bar", "UnicastSignal2", "",
1676       "com.example.SystemdActivatable2");
1677   dbus_message_unref (m);
1678
1679   /* The activatable service takes its name. Here I'm faking it by using
1680    * an existing connection. */
1681   take_well_known_name (f, f->activated, "com.example.SystemdActivatable2");
1682
1683   /* The message is delivered to the activatable service.
1684    * Implementation detail: the monitor sees this happen before it even
1685    * sees that the name request happened, which is pretty odd. */
1686   while (f->activated_message == NULL)
1687     test_main_context_iterate (f->ctx, TRUE);
1688
1689   m = f->activated_message;
1690   f->activated_message = NULL;
1691   assert_signal (m, f->sender_name, "/foo",
1692       "com.example.bar", "UnicastSignal2", "",
1693       "com.example.SystemdActivatable2");
1694   dbus_message_unref (m);
1695
1696   expect_take_well_known_name (f, f->activated,
1697       "com.example.SystemdActivatable2");
1698
1699   /* A third activation. */
1700   m = dbus_message_new_signal ("/foo", "com.example.bar", "UnicastSignal3");
1701   if (!dbus_message_set_destination (m, "com.example.SystemdActivatable3"))
1702     g_error ("OOM");
1703   dbus_connection_send (f->sender, m, NULL);
1704   dbus_message_unref (m);
1705
1706   /* Once again, we see the activation request and the reason. */
1707   while (g_queue_get_length (&f->monitored) < 2)
1708     test_main_context_iterate (f->ctx, TRUE);
1709
1710   m = g_queue_pop_head (&f->monitored);
1711   assert_signal (m, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
1712       "org.freedesktop.systemd1.Activator", "ActivationRequest", "s",
1713       "org.freedesktop.systemd1");
1714   dbus_message_unref (m);
1715   m = g_queue_pop_head (&f->monitored);
1716   assert_signal (m, f->sender_name, "/foo",
1717       "com.example.bar", "UnicastSignal3", "",
1718       "com.example.SystemdActivatable3");
1719   dbus_message_unref (m);
1720
1721   /* systemd gets the request too. */
1722   while (f->systemd_message == NULL)
1723     test_main_context_iterate (f->ctx, TRUE);
1724
1725   m = f->systemd_message;
1726   f->systemd_message = NULL;
1727   assert_signal (m, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
1728       "org.freedesktop.systemd1.Activator", "ActivationRequest", "s",
1729       "org.freedesktop.systemd1");
1730   dbus_message_unref (m);
1731
1732   /* This time activation fails */
1733   m = dbus_message_new_signal ("/org/freedesktop/systemd1",
1734       "org.freedesktop.systemd1.Activator", "ActivationFailure");
1735
1736   do
1737     {
1738       const char *unit = "dbus-com.example.SystemdActivatable3.service";
1739       const char *error_name = "com.example.Nope";
1740       const char *error_message = "Computer says no";
1741
1742       if (!dbus_message_append_args (m,
1743             DBUS_TYPE_STRING, &unit,
1744             DBUS_TYPE_STRING, &error_name,
1745             DBUS_TYPE_STRING, &error_message,
1746             DBUS_TYPE_INVALID))
1747         g_error ("OOM");
1748     }
1749   while (0);
1750
1751   if (!dbus_message_set_destination (m, "org.freedesktop.DBus"))
1752     g_error ("OOM");
1753   dbus_connection_send (f->systemd, m, NULL);
1754   dbus_message_unref (m);
1755
1756   /* The monitor sees activation fail */
1757
1758   /* Once again, we see the activation request and the reason. */
1759   while (g_queue_get_length (&f->monitored) < 1)
1760     test_main_context_iterate (f->ctx, TRUE);
1761
1762   m = g_queue_pop_head (&f->monitored);
1763   assert_error_reply (m, DBUS_SERVICE_DBUS, f->sender_name,
1764       "com.example.Nope");
1765   dbus_message_unref (m);
1766 }
1767 #endif /* DBUS_UNIX */
1768
1769 static void
1770 teardown (Fixture *f,
1771     gconstpointer context G_GNUC_UNUSED)
1772 {
1773   dbus_error_free (&f->e);
1774   g_clear_error (&f->ge);
1775
1776   if (f->monitor != NULL)
1777     {
1778       dbus_connection_remove_filter (f->monitor, monitor_filter, f);
1779       dbus_connection_close (f->monitor);
1780       dbus_connection_unref (f->monitor);
1781       f->monitor = NULL;
1782     }
1783
1784   if (f->sender != NULL)
1785     {
1786       dbus_connection_close (f->sender);
1787       dbus_connection_unref (f->sender);
1788       f->sender = NULL;
1789     }
1790
1791   if (f->recipient != NULL)
1792     {
1793       dbus_connection_remove_filter (f->recipient, recipient_filter, f);
1794       dbus_connection_close (f->recipient);
1795       dbus_connection_unref (f->recipient);
1796       f->recipient = NULL;
1797     }
1798
1799   if (f->systemd != NULL)
1800     {
1801       dbus_connection_remove_filter (f->systemd, systemd_filter, f);
1802       dbus_connection_close (f->systemd);
1803       dbus_connection_unref (f->systemd);
1804       f->systemd = NULL;
1805     }
1806
1807   if (f->activated != NULL)
1808     {
1809       dbus_connection_remove_filter (f->activated, activated_filter, f);
1810       dbus_connection_close (f->activated);
1811       dbus_connection_unref (f->activated);
1812       f->activated = NULL;
1813     }
1814
1815   if (f->daemon_pid != 0)
1816     {
1817       test_kill_pid (f->daemon_pid);
1818       g_spawn_close_pid (f->daemon_pid);
1819       f->daemon_pid = 0;
1820     }
1821
1822   test_main_context_unref (f->ctx);
1823
1824   g_queue_foreach (&f->monitored, (GFunc) dbus_message_unref, NULL);
1825   g_queue_clear (&f->monitored);
1826
1827   g_free (f->address);
1828 }
1829
1830 int
1831 main (int argc,
1832     char **argv)
1833 {
1834   test_init (&argc, &argv);
1835
1836   g_test_add ("/monitor/invalid", Fixture, NULL,
1837       setup, test_invalid, teardown);
1838   g_test_add ("/monitor/become", Fixture, &side_effects_config,
1839       setup, test_become_monitor, teardown);
1840   g_test_add ("/monitor/broadcast", Fixture, NULL,
1841       setup, test_broadcast, teardown);
1842   g_test_add ("/monitor/forbidden-broadcast", Fixture, &forbidding_config,
1843       setup, test_forbidden_broadcast, teardown);
1844   g_test_add ("/monitor/unicast-signal", Fixture, NULL,
1845       setup, test_unicast_signal, teardown);
1846   g_test_add ("/monitor/forbidden", Fixture, &forbidding_config,
1847       setup, test_forbidden, teardown);
1848   g_test_add ("/monitor/method-call", Fixture, NULL,
1849       setup, test_method_call, teardown);
1850   g_test_add ("/monitor/forbidden-method", Fixture, &forbidding_config,
1851       setup, test_forbidden_method_call, teardown);
1852   g_test_add ("/monitor/dbus-daemon", Fixture, NULL,
1853       setup, test_dbus_daemon, teardown);
1854   g_test_add ("/monitor/selective", Fixture, &selective_config,
1855       setup, test_selective, teardown);
1856   g_test_add ("/monitor/well-known-destination",
1857       Fixture, &well_known_destination_config,
1858       setup, test_well_known_destination, teardown);
1859   g_test_add ("/monitor/unique-destination",
1860       Fixture, NULL,
1861       setup, test_unique_destination, teardown);
1862   g_test_add ("/monitor/wildcard", Fixture, &wildcard_config,
1863       setup, test_unicast_signal, teardown);
1864   g_test_add ("/monitor/no-rule", Fixture, &no_rules_config,
1865       setup, test_unicast_signal, teardown);
1866   g_test_add ("/monitor/eavesdrop", Fixture, &eavesdrop_config,
1867       setup, test_unicast_signal, teardown);
1868   g_test_add ("/monitor/no-eavesdrop", Fixture, &no_eavesdrop_config,
1869       setup, test_unicast_signal, teardown);
1870
1871 #ifdef DBUS_UNIX
1872   /* this relies on the systemd activation code path */
1873   g_test_add ("/monitor/activation", Fixture, &fake_systemd_config,
1874       setup, test_activation, teardown);
1875 #endif
1876
1877   return g_test_run ();
1878 }