2011-02-22 13:04:18 +00:00
|
|
|
/* Simple sanity-check for loopback through TCP and Unix sockets.
|
|
|
|
|
*
|
|
|
|
|
* Author: Simon McVittie <simon.mcvittie@collabora.co.uk>
|
2012-03-12 13:13:55 +00:00
|
|
|
* Copyright © 2010-2012 Nokia Corporation
|
2015-01-29 13:41:29 +00:00
|
|
|
* Copyright © 2015 Collabora Ltd.
|
2011-02-22 13:04:18 +00:00
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person
|
|
|
|
|
* obtaining a copy of this software and associated documentation files
|
|
|
|
|
* (the "Software"), to deal in the Software without restriction,
|
|
|
|
|
* including without limitation the rights to use, copy, modify, merge,
|
|
|
|
|
* publish, distribute, sublicense, and/or sell copies of the Software,
|
|
|
|
|
* and to permit persons to whom the Software is furnished to do so,
|
|
|
|
|
* subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
|
* SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include <glib.h>
|
2015-01-29 13:41:29 +00:00
|
|
|
#include <glib/gstdio.h>
|
2011-02-22 13:04:18 +00:00
|
|
|
|
|
|
|
|
#include <dbus/dbus.h>
|
2018-01-16 13:32:49 +00:00
|
|
|
#include "dbus/dbus-connection-internal.h"
|
2011-02-22 13:04:18 +00:00
|
|
|
|
2015-01-29 13:41:29 +00:00
|
|
|
#include <errno.h>
|
2012-03-12 13:13:55 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
2015-02-03 14:45:35 +00:00
|
|
|
#include "test-utils-glib.h"
|
Tests: allow dbus-glib to be replaced with use of libdbus-internal
We only use dbus-glib for its main loop; within dbus, DBusLoop is
available as an alternative, although it isn't thread-safe and
isn't public API.
For tests that otherwise only use libdbus public API, it's desirable to
be able to avoid DBusLoop, so we can run them against an installed
libdbus as an integration test. However, if we don't have dbus-glib,
we're going to have to use an in-tree main loop, which might as well
be DBusLoop.
The major disadvantage of using dbus-glib is that it isn't safe to
link both dbus-1 and dbus-internal at the same time. This is awkward
for a future test case that wants to use _dbus_getsid() in dbus-daemon.c,
but only on Windows (fd.o #54445). If we use the same API wrapper around
both dbus-glib and DBusLoop, we can compile that test against dbus-glib
or against DBusLoop, depending on the platform.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68852
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2013-09-02 16:32:31 +01:00
|
|
|
|
2011-02-22 13:04:18 +00:00
|
|
|
typedef struct {
|
Tests: allow dbus-glib to be replaced with use of libdbus-internal
We only use dbus-glib for its main loop; within dbus, DBusLoop is
available as an alternative, although it isn't thread-safe and
isn't public API.
For tests that otherwise only use libdbus public API, it's desirable to
be able to avoid DBusLoop, so we can run them against an installed
libdbus as an integration test. However, if we don't have dbus-glib,
we're going to have to use an in-tree main loop, which might as well
be DBusLoop.
The major disadvantage of using dbus-glib is that it isn't safe to
link both dbus-1 and dbus-internal at the same time. This is awkward
for a future test case that wants to use _dbus_getsid() in dbus-daemon.c,
but only on Windows (fd.o #54445). If we use the same API wrapper around
both dbus-glib and DBusLoop, we can compile that test against dbus-glib
or against DBusLoop, depending on the platform.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68852
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2013-09-02 16:32:31 +01:00
|
|
|
TestMainContext *ctx;
|
2011-02-22 13:04:18 +00:00
|
|
|
DBusError e;
|
test: Skip TCP tests if getaddrinfo doesn't work
For example, this can be the case in bubblewrap or Debian pbuilder after
unsharing the network namespace:
bwrap \
--bind / / \
--dev-bind /dev /dev \
--bind /dev/shm /dev/shm \
--bind /dev/pts /dev/pts \
--unshare-net \
${builddir}/test/test-loopback --tap
...
ok 1 /connect/tcp # SKIP Name resolution does not work here:
getaddrinfo("127.0.0.1", "0", {flags=ADDRCONFIG, family=INET,
socktype=STREAM, protocol=TCP}): Name or service not known
On some systems this can be circumvented by using nss_wrapper from
<https://cwrap.org/nss_wrapper.html>:
cat > hosts <<EOF
127.0.0.1 localhost
EOF
bwrap \
... \
env \
LD_PRELOAD=libnss_wrapper.so \
NSS_WRAPPER_HOSTS=$(pwd)/hosts \
${builddir}/test/test-loopback --tap
...
# listening at tcp:host=127.0.0.1,port=39219,family=ipv4,guid=...
but for systems where that does't work, we should be prepared to skip
the affected tests.
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=106812
2018-06-04 16:27:50 +01:00
|
|
|
gboolean skip;
|
2011-02-22 13:04:18 +00:00
|
|
|
|
|
|
|
|
DBusServer *server;
|
|
|
|
|
DBusConnection *server_conn;
|
|
|
|
|
/* queue of DBusMessage */
|
|
|
|
|
GQueue server_messages;
|
|
|
|
|
|
|
|
|
|
DBusConnection *client_conn;
|
2015-01-29 13:41:29 +00:00
|
|
|
|
|
|
|
|
gchar *tmp_runtime_dir;
|
|
|
|
|
gchar *saved_runtime_dir;
|
2011-02-22 13:04:18 +00:00
|
|
|
} Fixture;
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
assert_no_error (const DBusError *e)
|
|
|
|
|
{
|
|
|
|
|
if (G_UNLIKELY (dbus_error_is_set (e)))
|
|
|
|
|
g_error ("expected success but got error: %s: %s", e->name, e->message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static DBusHandlerResult
|
|
|
|
|
server_message_cb (DBusConnection *server_conn,
|
|
|
|
|
DBusMessage *message,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
|
|
|
|
Fixture *f = data;
|
|
|
|
|
|
|
|
|
|
g_assert (server_conn == f->server_conn);
|
|
|
|
|
g_queue_push_tail (&f->server_messages, dbus_message_ref (message));
|
|
|
|
|
|
|
|
|
|
return DBUS_HANDLER_RESULT_HANDLED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
new_conn_cb (DBusServer *server,
|
|
|
|
|
DBusConnection *server_conn,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
|
|
|
|
Fixture *f = data;
|
|
|
|
|
dbus_bool_t have_mem;
|
|
|
|
|
|
|
|
|
|
g_assert (f->server_conn == NULL);
|
|
|
|
|
f->server_conn = dbus_connection_ref (server_conn);
|
Tests: allow dbus-glib to be replaced with use of libdbus-internal
We only use dbus-glib for its main loop; within dbus, DBusLoop is
available as an alternative, although it isn't thread-safe and
isn't public API.
For tests that otherwise only use libdbus public API, it's desirable to
be able to avoid DBusLoop, so we can run them against an installed
libdbus as an integration test. However, if we don't have dbus-glib,
we're going to have to use an in-tree main loop, which might as well
be DBusLoop.
The major disadvantage of using dbus-glib is that it isn't safe to
link both dbus-1 and dbus-internal at the same time. This is awkward
for a future test case that wants to use _dbus_getsid() in dbus-daemon.c,
but only on Windows (fd.o #54445). If we use the same API wrapper around
both dbus-glib and DBusLoop, we can compile that test against dbus-glib
or against DBusLoop, depending on the platform.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68852
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2013-09-02 16:32:31 +01:00
|
|
|
test_connection_setup (f->ctx, server_conn);
|
2011-02-22 13:04:18 +00:00
|
|
|
|
|
|
|
|
have_mem = dbus_connection_add_filter (server_conn,
|
|
|
|
|
server_message_cb, f, NULL);
|
|
|
|
|
g_assert (have_mem);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
setup (Fixture *f,
|
|
|
|
|
gconstpointer addr)
|
|
|
|
|
{
|
Tests: allow dbus-glib to be replaced with use of libdbus-internal
We only use dbus-glib for its main loop; within dbus, DBusLoop is
available as an alternative, although it isn't thread-safe and
isn't public API.
For tests that otherwise only use libdbus public API, it's desirable to
be able to avoid DBusLoop, so we can run them against an installed
libdbus as an integration test. However, if we don't have dbus-glib,
we're going to have to use an in-tree main loop, which might as well
be DBusLoop.
The major disadvantage of using dbus-glib is that it isn't safe to
link both dbus-1 and dbus-internal at the same time. This is awkward
for a future test case that wants to use _dbus_getsid() in dbus-daemon.c,
but only on Windows (fd.o #54445). If we use the same API wrapper around
both dbus-glib and DBusLoop, we can compile that test against dbus-glib
or against DBusLoop, depending on the platform.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68852
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2013-09-02 16:32:31 +01:00
|
|
|
f->ctx = test_main_context_get ();
|
2011-02-22 13:04:18 +00:00
|
|
|
dbus_error_init (&f->e);
|
|
|
|
|
g_queue_init (&f->server_messages);
|
|
|
|
|
|
2022-02-09 11:34:35 +04:00
|
|
|
if ((g_str_has_prefix (addr, "unix:") && !test_check_af_unix_works ()) ||
|
|
|
|
|
((g_str_has_prefix (addr, "tcp:") ||
|
|
|
|
|
g_str_has_prefix (addr, "nonce-tcp:")) &&
|
|
|
|
|
!test_check_tcp_works ()))
|
test: Skip TCP tests if getaddrinfo doesn't work
For example, this can be the case in bubblewrap or Debian pbuilder after
unsharing the network namespace:
bwrap \
--bind / / \
--dev-bind /dev /dev \
--bind /dev/shm /dev/shm \
--bind /dev/pts /dev/pts \
--unshare-net \
${builddir}/test/test-loopback --tap
...
ok 1 /connect/tcp # SKIP Name resolution does not work here:
getaddrinfo("127.0.0.1", "0", {flags=ADDRCONFIG, family=INET,
socktype=STREAM, protocol=TCP}): Name or service not known
On some systems this can be circumvented by using nss_wrapper from
<https://cwrap.org/nss_wrapper.html>:
cat > hosts <<EOF
127.0.0.1 localhost
EOF
bwrap \
... \
env \
LD_PRELOAD=libnss_wrapper.so \
NSS_WRAPPER_HOSTS=$(pwd)/hosts \
${builddir}/test/test-loopback --tap
...
# listening at tcp:host=127.0.0.1,port=39219,family=ipv4,guid=...
but for systems where that does't work, we should be prepared to skip
the affected tests.
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=106812
2018-06-04 16:27:50 +01:00
|
|
|
{
|
|
|
|
|
f->skip = TRUE;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-22 13:04:18 +00:00
|
|
|
f->server = dbus_server_listen (addr, &f->e);
|
|
|
|
|
assert_no_error (&f->e);
|
|
|
|
|
g_assert (f->server != NULL);
|
|
|
|
|
|
|
|
|
|
dbus_server_set_new_connection_function (f->server,
|
|
|
|
|
new_conn_cb, f, NULL);
|
Tests: allow dbus-glib to be replaced with use of libdbus-internal
We only use dbus-glib for its main loop; within dbus, DBusLoop is
available as an alternative, although it isn't thread-safe and
isn't public API.
For tests that otherwise only use libdbus public API, it's desirable to
be able to avoid DBusLoop, so we can run them against an installed
libdbus as an integration test. However, if we don't have dbus-glib,
we're going to have to use an in-tree main loop, which might as well
be DBusLoop.
The major disadvantage of using dbus-glib is that it isn't safe to
link both dbus-1 and dbus-internal at the same time. This is awkward
for a future test case that wants to use _dbus_getsid() in dbus-daemon.c,
but only on Windows (fd.o #54445). If we use the same API wrapper around
both dbus-glib and DBusLoop, we can compile that test against dbus-glib
or against DBusLoop, depending on the platform.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68852
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2013-09-02 16:32:31 +01:00
|
|
|
test_server_setup (f->ctx, f->server);
|
2011-02-22 13:04:18 +00:00
|
|
|
}
|
|
|
|
|
|
2015-01-29 13:41:29 +00:00
|
|
|
static void
|
|
|
|
|
setup_runtime (Fixture *f,
|
|
|
|
|
gconstpointer addr)
|
|
|
|
|
{
|
|
|
|
|
char *listening_at;
|
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
|
|
/* this is chosen to be something needing escaping */
|
|
|
|
|
f->tmp_runtime_dir = g_dir_make_tmp ("dbus=daemon=test.XXXXXX", &error);
|
|
|
|
|
g_assert_no_error (error);
|
|
|
|
|
|
|
|
|
|
/* we're relying on being single-threaded for this to be safe */
|
|
|
|
|
f->saved_runtime_dir = g_strdup (g_getenv ("XDG_RUNTIME_DIR"));
|
|
|
|
|
g_setenv ("XDG_RUNTIME_DIR", f->tmp_runtime_dir, TRUE);
|
2022-03-24 16:59:16 +04:00
|
|
|
g_test_message ("XDG_RUNTIME_DIR %s", f->tmp_runtime_dir);
|
2015-01-29 13:41:29 +00:00
|
|
|
|
|
|
|
|
setup (f, addr);
|
|
|
|
|
|
test: Skip TCP tests if getaddrinfo doesn't work
For example, this can be the case in bubblewrap or Debian pbuilder after
unsharing the network namespace:
bwrap \
--bind / / \
--dev-bind /dev /dev \
--bind /dev/shm /dev/shm \
--bind /dev/pts /dev/pts \
--unshare-net \
${builddir}/test/test-loopback --tap
...
ok 1 /connect/tcp # SKIP Name resolution does not work here:
getaddrinfo("127.0.0.1", "0", {flags=ADDRCONFIG, family=INET,
socktype=STREAM, protocol=TCP}): Name or service not known
On some systems this can be circumvented by using nss_wrapper from
<https://cwrap.org/nss_wrapper.html>:
cat > hosts <<EOF
127.0.0.1 localhost
EOF
bwrap \
... \
env \
LD_PRELOAD=libnss_wrapper.so \
NSS_WRAPPER_HOSTS=$(pwd)/hosts \
${builddir}/test/test-loopback --tap
...
# listening at tcp:host=127.0.0.1,port=39219,family=ipv4,guid=...
but for systems where that does't work, we should be prepared to skip
the affected tests.
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=106812
2018-06-04 16:27:50 +01:00
|
|
|
if (f->skip)
|
|
|
|
|
return;
|
|
|
|
|
|
2015-01-29 13:41:29 +00:00
|
|
|
listening_at = dbus_server_get_address (f->server);
|
2015-02-26 17:12:22 +00:00
|
|
|
g_test_message ("listening at %s", listening_at);
|
2015-01-29 13:41:29 +00:00
|
|
|
g_assert (g_str_has_prefix (listening_at, "unix:path="));
|
2022-03-24 16:59:16 +04:00
|
|
|
#ifndef DBUS_WIN
|
|
|
|
|
/* FIXME: on gitlab CI win32, it doesn't use runtime dir, why..? */
|
2015-01-29 13:41:29 +00:00
|
|
|
g_assert (strstr (listening_at, "dbus%3ddaemon%3dtest.") != NULL);
|
2022-02-09 11:56:19 +04:00
|
|
|
g_assert (strstr (listening_at, DBUS_DIR_SEPARATOR_S "bus,") != NULL ||
|
|
|
|
|
g_str_has_suffix (listening_at, DBUS_DIR_SEPARATOR_S "bus"));
|
2022-03-24 16:59:16 +04:00
|
|
|
#endif
|
2015-01-29 13:41:29 +00:00
|
|
|
|
|
|
|
|
dbus_free (listening_at);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
setup_no_runtime (Fixture *f,
|
|
|
|
|
gconstpointer addr)
|
|
|
|
|
{
|
|
|
|
|
char *listening_at;
|
|
|
|
|
|
|
|
|
|
/* we're relying on being single-threaded for this to be safe */
|
|
|
|
|
f->saved_runtime_dir = g_strdup (g_getenv ("XDG_RUNTIME_DIR"));
|
|
|
|
|
g_unsetenv ("XDG_RUNTIME_DIR");
|
|
|
|
|
|
|
|
|
|
setup (f, addr);
|
|
|
|
|
|
test: Skip TCP tests if getaddrinfo doesn't work
For example, this can be the case in bubblewrap or Debian pbuilder after
unsharing the network namespace:
bwrap \
--bind / / \
--dev-bind /dev /dev \
--bind /dev/shm /dev/shm \
--bind /dev/pts /dev/pts \
--unshare-net \
${builddir}/test/test-loopback --tap
...
ok 1 /connect/tcp # SKIP Name resolution does not work here:
getaddrinfo("127.0.0.1", "0", {flags=ADDRCONFIG, family=INET,
socktype=STREAM, protocol=TCP}): Name or service not known
On some systems this can be circumvented by using nss_wrapper from
<https://cwrap.org/nss_wrapper.html>:
cat > hosts <<EOF
127.0.0.1 localhost
EOF
bwrap \
... \
env \
LD_PRELOAD=libnss_wrapper.so \
NSS_WRAPPER_HOSTS=$(pwd)/hosts \
${builddir}/test/test-loopback --tap
...
# listening at tcp:host=127.0.0.1,port=39219,family=ipv4,guid=...
but for systems where that does't work, we should be prepared to skip
the affected tests.
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=106812
2018-06-04 16:27:50 +01:00
|
|
|
if (f->skip)
|
|
|
|
|
return;
|
|
|
|
|
|
2015-01-29 13:41:29 +00:00
|
|
|
listening_at = dbus_server_get_address (f->server);
|
2015-02-26 17:12:22 +00:00
|
|
|
g_test_message ("listening at %s", listening_at);
|
2015-01-29 13:41:29 +00:00
|
|
|
/* we have fallen back to something in /tmp, either abstract or not */
|
|
|
|
|
g_assert (g_str_has_prefix (listening_at, "unix:"));
|
2022-03-17 17:12:41 +04:00
|
|
|
#ifdef DBUS_UNIX
|
2022-02-09 11:56:19 +04:00
|
|
|
g_assert (strstr (listening_at, "=/tmp" DBUS_DIR_SEPARATOR_S) != NULL);
|
2022-03-17 17:12:41 +04:00
|
|
|
#endif
|
2015-01-29 13:41:29 +00:00
|
|
|
|
|
|
|
|
dbus_free (listening_at);
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-22 13:04:18 +00:00
|
|
|
static void
|
|
|
|
|
test_connect (Fixture *f,
|
2017-06-28 18:52:12 +01:00
|
|
|
gconstpointer addr)
|
2011-02-22 13:04:18 +00:00
|
|
|
{
|
2017-06-28 18:52:12 +01:00
|
|
|
const char *listening_address = addr;
|
2017-06-28 18:49:18 +01:00
|
|
|
char *address;
|
2017-06-28 18:52:12 +01:00
|
|
|
DBusAddressEntry **entries;
|
2018-01-16 13:32:49 +00:00
|
|
|
DBusCredentials *creds;
|
|
|
|
|
DBusString cred_string;
|
2017-06-28 18:52:12 +01:00
|
|
|
int n_entries;
|
|
|
|
|
dbus_bool_t ok;
|
|
|
|
|
|
test: Skip TCP tests if getaddrinfo doesn't work
For example, this can be the case in bubblewrap or Debian pbuilder after
unsharing the network namespace:
bwrap \
--bind / / \
--dev-bind /dev /dev \
--bind /dev/shm /dev/shm \
--bind /dev/pts /dev/pts \
--unshare-net \
${builddir}/test/test-loopback --tap
...
ok 1 /connect/tcp # SKIP Name resolution does not work here:
getaddrinfo("127.0.0.1", "0", {flags=ADDRCONFIG, family=INET,
socktype=STREAM, protocol=TCP}): Name or service not known
On some systems this can be circumvented by using nss_wrapper from
<https://cwrap.org/nss_wrapper.html>:
cat > hosts <<EOF
127.0.0.1 localhost
EOF
bwrap \
... \
env \
LD_PRELOAD=libnss_wrapper.so \
NSS_WRAPPER_HOSTS=$(pwd)/hosts \
${builddir}/test/test-loopback --tap
...
# listening at tcp:host=127.0.0.1,port=39219,family=ipv4,guid=...
but for systems where that does't work, we should be prepared to skip
the affected tests.
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=106812
2018-06-04 16:27:50 +01:00
|
|
|
if (f->skip)
|
|
|
|
|
return;
|
|
|
|
|
|
2011-02-22 13:04:18 +00:00
|
|
|
g_assert (f->server_conn == NULL);
|
|
|
|
|
|
2017-06-28 18:49:18 +01:00
|
|
|
address = dbus_server_get_address (f->server);
|
|
|
|
|
g_test_message ("listening at %s", address);
|
2017-06-28 18:52:12 +01:00
|
|
|
|
|
|
|
|
ok = dbus_parse_address (address, &entries, &n_entries, &f->e);
|
|
|
|
|
assert_no_error (&f->e);
|
|
|
|
|
g_assert_true (ok);
|
|
|
|
|
g_assert_cmpint (n_entries, ==, 1);
|
|
|
|
|
|
|
|
|
|
g_assert_cmpstr (dbus_address_entry_get_value (entries[0], "guid"), !=,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
if (g_strcmp0 (listening_address, "tcp:host=127.0.0.1") == 0)
|
|
|
|
|
{
|
|
|
|
|
g_assert_cmpstr (dbus_address_entry_get_method (entries[0]), ==, "tcp");
|
|
|
|
|
g_assert_cmpstr (dbus_address_entry_get_value (entries[0], "host"), ==,
|
|
|
|
|
"127.0.0.1");
|
|
|
|
|
g_assert_cmpstr (dbus_address_entry_get_value (entries[0], "port"), !=,
|
|
|
|
|
NULL);
|
|
|
|
|
g_assert_cmpstr (dbus_address_entry_get_value (entries[0], "noncefile"),
|
|
|
|
|
==, NULL);
|
|
|
|
|
}
|
|
|
|
|
else if (g_strcmp0 (listening_address, "nonce-tcp:host=127.0.0.1") == 0)
|
|
|
|
|
{
|
|
|
|
|
g_assert_cmpstr (dbus_address_entry_get_method (entries[0]), ==,
|
|
|
|
|
"nonce-tcp");
|
|
|
|
|
g_assert_cmpstr (dbus_address_entry_get_value (entries[0], "host"), ==,
|
|
|
|
|
"127.0.0.1");
|
|
|
|
|
g_assert_cmpstr (dbus_address_entry_get_value (entries[0], "port"), !=,
|
|
|
|
|
NULL);
|
|
|
|
|
g_assert_cmpstr (dbus_address_entry_get_value (entries[0], "noncefile"),
|
|
|
|
|
!=, NULL);
|
|
|
|
|
}
|
2022-03-17 17:12:41 +04:00
|
|
|
else if (g_str_has_prefix (listening_address, "unix:tmpdir="))
|
2017-06-28 18:52:12 +01:00
|
|
|
{
|
|
|
|
|
g_assert_cmpstr (dbus_address_entry_get_method (entries[0]), ==, "unix");
|
|
|
|
|
|
|
|
|
|
if (dbus_address_entry_get_value (entries[0], "abstract") != NULL)
|
|
|
|
|
{
|
|
|
|
|
const char *abstract = dbus_address_entry_get_value (entries[0],
|
|
|
|
|
"abstract");
|
|
|
|
|
|
2022-02-09 11:56:19 +04:00
|
|
|
g_assert_true (g_str_has_prefix (abstract, "/tmp" DBUS_DIR_SEPARATOR_S "dbus-"));
|
2017-06-28 18:52:12 +01:00
|
|
|
g_assert_cmpstr (dbus_address_entry_get_value (entries[0], "path"),
|
|
|
|
|
==, NULL);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
const char *path = dbus_address_entry_get_value (entries[0],
|
|
|
|
|
"path");
|
|
|
|
|
|
|
|
|
|
g_assert_nonnull (path);
|
2022-03-17 17:12:41 +04:00
|
|
|
#ifdef DBUS_UNIX
|
2022-02-09 11:56:19 +04:00
|
|
|
g_assert_true (g_str_has_prefix (path, "/tmp" DBUS_DIR_SEPARATOR_S "dbus-"));
|
2022-03-17 17:12:41 +04:00
|
|
|
#endif
|
2017-06-28 18:52:12 +01:00
|
|
|
}
|
|
|
|
|
}
|
2022-03-17 17:12:41 +04:00
|
|
|
else if (g_str_has_prefix (listening_address, "unix:dir="))
|
2017-06-28 18:52:29 +01:00
|
|
|
{
|
|
|
|
|
const char *path = dbus_address_entry_get_value (entries[0],
|
|
|
|
|
"path");
|
|
|
|
|
|
|
|
|
|
g_assert_cmpstr (dbus_address_entry_get_method (entries[0]), ==, "unix");
|
|
|
|
|
g_assert_nonnull (path);
|
2022-03-17 17:12:41 +04:00
|
|
|
#ifdef DBUS_UNIX
|
2022-02-09 11:56:19 +04:00
|
|
|
g_assert_true (g_str_has_prefix (path, "/tmp" DBUS_DIR_SEPARATOR_S "dbus-"));
|
2022-03-17 17:12:41 +04:00
|
|
|
#endif
|
2017-06-28 18:52:29 +01:00
|
|
|
}
|
2022-03-17 17:12:41 +04:00
|
|
|
else if (g_str_has_prefix (listening_address,
|
|
|
|
|
"unix:runtime=yes;unix:tmpdir="))
|
2017-06-28 18:52:12 +01:00
|
|
|
{
|
|
|
|
|
g_assert_cmpstr (dbus_address_entry_get_method (entries[0]), ==, "unix");
|
|
|
|
|
/* No particular statement about the path here: for that see
|
|
|
|
|
* setup_runtime() and setup_no_runtime() */
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_address_entries_free (entries);
|
|
|
|
|
|
2017-06-28 18:49:18 +01:00
|
|
|
f->client_conn = dbus_connection_open_private (address, &f->e);
|
2011-02-22 13:04:18 +00:00
|
|
|
assert_no_error (&f->e);
|
|
|
|
|
g_assert (f->client_conn != NULL);
|
Tests: allow dbus-glib to be replaced with use of libdbus-internal
We only use dbus-glib for its main loop; within dbus, DBusLoop is
available as an alternative, although it isn't thread-safe and
isn't public API.
For tests that otherwise only use libdbus public API, it's desirable to
be able to avoid DBusLoop, so we can run them against an installed
libdbus as an integration test. However, if we don't have dbus-glib,
we're going to have to use an in-tree main loop, which might as well
be DBusLoop.
The major disadvantage of using dbus-glib is that it isn't safe to
link both dbus-1 and dbus-internal at the same time. This is awkward
for a future test case that wants to use _dbus_getsid() in dbus-daemon.c,
but only on Windows (fd.o #54445). If we use the same API wrapper around
both dbus-glib and DBusLoop, we can compile that test against dbus-glib
or against DBusLoop, depending on the platform.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68852
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2013-09-02 16:32:31 +01:00
|
|
|
test_connection_setup (f->ctx, f->client_conn);
|
2011-02-22 13:04:18 +00:00
|
|
|
|
|
|
|
|
while (f->server_conn == NULL)
|
|
|
|
|
{
|
2015-02-26 17:12:22 +00:00
|
|
|
test_progress ('.');
|
Tests: allow dbus-glib to be replaced with use of libdbus-internal
We only use dbus-glib for its main loop; within dbus, DBusLoop is
available as an alternative, although it isn't thread-safe and
isn't public API.
For tests that otherwise only use libdbus public API, it's desirable to
be able to avoid DBusLoop, so we can run them against an installed
libdbus as an integration test. However, if we don't have dbus-glib,
we're going to have to use an in-tree main loop, which might as well
be DBusLoop.
The major disadvantage of using dbus-glib is that it isn't safe to
link both dbus-1 and dbus-internal at the same time. This is awkward
for a future test case that wants to use _dbus_getsid() in dbus-daemon.c,
but only on Windows (fd.o #54445). If we use the same API wrapper around
both dbus-glib and DBusLoop, we can compile that test against dbus-glib
or against DBusLoop, depending on the platform.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68852
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2013-09-02 16:32:31 +01:00
|
|
|
test_main_context_iterate (f->ctx, TRUE);
|
2011-02-22 13:04:18 +00:00
|
|
|
}
|
2017-06-28 18:49:18 +01:00
|
|
|
|
2018-01-16 13:32:49 +00:00
|
|
|
/* Wait for the server to have credentials, check that their string
|
|
|
|
|
* form is non-NULL and log them. We don't make any further assertions,
|
|
|
|
|
* because we don't really know what to expect. */
|
|
|
|
|
|
|
|
|
|
creds = _dbus_connection_get_credentials (f->server_conn);
|
|
|
|
|
|
|
|
|
|
while (creds == NULL)
|
|
|
|
|
{
|
|
|
|
|
test_progress ('.');
|
|
|
|
|
test_main_context_iterate (f->ctx, TRUE);
|
|
|
|
|
creds = _dbus_connection_get_credentials (f->server_conn);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_assert_nonnull (creds);
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_init (&cred_string) ||
|
|
|
|
|
!_dbus_credentials_to_string_append (creds, &cred_string))
|
|
|
|
|
g_error ("OOM");
|
|
|
|
|
|
|
|
|
|
g_test_message ("Credentials: %s",
|
|
|
|
|
_dbus_string_get_const_data (&cred_string));
|
|
|
|
|
g_assert_cmpstr (_dbus_string_get_const_data (&cred_string), !=, NULL);
|
|
|
|
|
_dbus_string_free (&cred_string);
|
|
|
|
|
|
2017-06-28 18:49:18 +01:00
|
|
|
dbus_free (address);
|
2011-02-22 13:04:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-03-12 13:13:55 +00:00
|
|
|
static void
|
|
|
|
|
test_bad_guid (Fixture *f,
|
|
|
|
|
gconstpointer addr G_GNUC_UNUSED)
|
|
|
|
|
{
|
|
|
|
|
DBusMessage *incoming;
|
test: Skip TCP tests if getaddrinfo doesn't work
For example, this can be the case in bubblewrap or Debian pbuilder after
unsharing the network namespace:
bwrap \
--bind / / \
--dev-bind /dev /dev \
--bind /dev/shm /dev/shm \
--bind /dev/pts /dev/pts \
--unshare-net \
${builddir}/test/test-loopback --tap
...
ok 1 /connect/tcp # SKIP Name resolution does not work here:
getaddrinfo("127.0.0.1", "0", {flags=ADDRCONFIG, family=INET,
socktype=STREAM, protocol=TCP}): Name or service not known
On some systems this can be circumvented by using nss_wrapper from
<https://cwrap.org/nss_wrapper.html>:
cat > hosts <<EOF
127.0.0.1 localhost
EOF
bwrap \
... \
env \
LD_PRELOAD=libnss_wrapper.so \
NSS_WRAPPER_HOSTS=$(pwd)/hosts \
${builddir}/test/test-loopback --tap
...
# listening at tcp:host=127.0.0.1,port=39219,family=ipv4,guid=...
but for systems where that does't work, we should be prepared to skip
the affected tests.
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=106812
2018-06-04 16:27:50 +01:00
|
|
|
char *address;
|
2012-03-12 13:13:55 +00:00
|
|
|
gchar *guid;
|
|
|
|
|
|
test: Skip TCP tests if getaddrinfo doesn't work
For example, this can be the case in bubblewrap or Debian pbuilder after
unsharing the network namespace:
bwrap \
--bind / / \
--dev-bind /dev /dev \
--bind /dev/shm /dev/shm \
--bind /dev/pts /dev/pts \
--unshare-net \
${builddir}/test/test-loopback --tap
...
ok 1 /connect/tcp # SKIP Name resolution does not work here:
getaddrinfo("127.0.0.1", "0", {flags=ADDRCONFIG, family=INET,
socktype=STREAM, protocol=TCP}): Name or service not known
On some systems this can be circumvented by using nss_wrapper from
<https://cwrap.org/nss_wrapper.html>:
cat > hosts <<EOF
127.0.0.1 localhost
EOF
bwrap \
... \
env \
LD_PRELOAD=libnss_wrapper.so \
NSS_WRAPPER_HOSTS=$(pwd)/hosts \
${builddir}/test/test-loopback --tap
...
# listening at tcp:host=127.0.0.1,port=39219,family=ipv4,guid=...
but for systems where that does't work, we should be prepared to skip
the affected tests.
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=106812
2018-06-04 16:27:50 +01:00
|
|
|
if (f->skip)
|
|
|
|
|
return;
|
|
|
|
|
|
2012-03-12 13:13:55 +00:00
|
|
|
g_test_bug ("39720");
|
|
|
|
|
|
|
|
|
|
g_assert (f->server_conn == NULL);
|
|
|
|
|
|
test: Skip TCP tests if getaddrinfo doesn't work
For example, this can be the case in bubblewrap or Debian pbuilder after
unsharing the network namespace:
bwrap \
--bind / / \
--dev-bind /dev /dev \
--bind /dev/shm /dev/shm \
--bind /dev/pts /dev/pts \
--unshare-net \
${builddir}/test/test-loopback --tap
...
ok 1 /connect/tcp # SKIP Name resolution does not work here:
getaddrinfo("127.0.0.1", "0", {flags=ADDRCONFIG, family=INET,
socktype=STREAM, protocol=TCP}): Name or service not known
On some systems this can be circumvented by using nss_wrapper from
<https://cwrap.org/nss_wrapper.html>:
cat > hosts <<EOF
127.0.0.1 localhost
EOF
bwrap \
... \
env \
LD_PRELOAD=libnss_wrapper.so \
NSS_WRAPPER_HOSTS=$(pwd)/hosts \
${builddir}/test/test-loopback --tap
...
# listening at tcp:host=127.0.0.1,port=39219,family=ipv4,guid=...
but for systems where that does't work, we should be prepared to skip
the affected tests.
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=106812
2018-06-04 16:27:50 +01:00
|
|
|
address = dbus_server_get_address (f->server);
|
2012-03-12 13:13:55 +00:00
|
|
|
g_assert (strstr (address, "guid=") != NULL);
|
|
|
|
|
guid = strstr (address, "guid=");
|
|
|
|
|
g_assert_cmpuint (strlen (guid), >=, 5 + 32);
|
|
|
|
|
|
|
|
|
|
/* Change the first char of the guid to something different */
|
|
|
|
|
if (guid[5] == '0')
|
|
|
|
|
guid[5] = 'f';
|
|
|
|
|
else
|
|
|
|
|
guid[5] = '0';
|
|
|
|
|
|
|
|
|
|
f->client_conn = dbus_connection_open_private (address, &f->e);
|
|
|
|
|
assert_no_error (&f->e);
|
|
|
|
|
g_assert (f->client_conn != NULL);
|
Tests: allow dbus-glib to be replaced with use of libdbus-internal
We only use dbus-glib for its main loop; within dbus, DBusLoop is
available as an alternative, although it isn't thread-safe and
isn't public API.
For tests that otherwise only use libdbus public API, it's desirable to
be able to avoid DBusLoop, so we can run them against an installed
libdbus as an integration test. However, if we don't have dbus-glib,
we're going to have to use an in-tree main loop, which might as well
be DBusLoop.
The major disadvantage of using dbus-glib is that it isn't safe to
link both dbus-1 and dbus-internal at the same time. This is awkward
for a future test case that wants to use _dbus_getsid() in dbus-daemon.c,
but only on Windows (fd.o #54445). If we use the same API wrapper around
both dbus-glib and DBusLoop, we can compile that test against dbus-glib
or against DBusLoop, depending on the platform.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68852
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2013-09-02 16:32:31 +01:00
|
|
|
test_connection_setup (f->ctx, f->client_conn);
|
2012-03-12 13:13:55 +00:00
|
|
|
|
|
|
|
|
while (f->server_conn == NULL)
|
|
|
|
|
{
|
2015-02-26 17:12:22 +00:00
|
|
|
test_progress ('.');
|
Tests: allow dbus-glib to be replaced with use of libdbus-internal
We only use dbus-glib for its main loop; within dbus, DBusLoop is
available as an alternative, although it isn't thread-safe and
isn't public API.
For tests that otherwise only use libdbus public API, it's desirable to
be able to avoid DBusLoop, so we can run them against an installed
libdbus as an integration test. However, if we don't have dbus-glib,
we're going to have to use an in-tree main loop, which might as well
be DBusLoop.
The major disadvantage of using dbus-glib is that it isn't safe to
link both dbus-1 and dbus-internal at the same time. This is awkward
for a future test case that wants to use _dbus_getsid() in dbus-daemon.c,
but only on Windows (fd.o #54445). If we use the same API wrapper around
both dbus-glib and DBusLoop, we can compile that test against dbus-glib
or against DBusLoop, depending on the platform.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68852
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2013-09-02 16:32:31 +01:00
|
|
|
test_main_context_iterate (f->ctx, TRUE);
|
2012-03-12 13:13:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* We get disconnected */
|
|
|
|
|
|
|
|
|
|
while (g_queue_is_empty (&f->server_messages))
|
|
|
|
|
{
|
2015-02-26 17:12:22 +00:00
|
|
|
test_progress ('.');
|
Tests: allow dbus-glib to be replaced with use of libdbus-internal
We only use dbus-glib for its main loop; within dbus, DBusLoop is
available as an alternative, although it isn't thread-safe and
isn't public API.
For tests that otherwise only use libdbus public API, it's desirable to
be able to avoid DBusLoop, so we can run them against an installed
libdbus as an integration test. However, if we don't have dbus-glib,
we're going to have to use an in-tree main loop, which might as well
be DBusLoop.
The major disadvantage of using dbus-glib is that it isn't safe to
link both dbus-1 and dbus-internal at the same time. This is awkward
for a future test case that wants to use _dbus_getsid() in dbus-daemon.c,
but only on Windows (fd.o #54445). If we use the same API wrapper around
both dbus-glib and DBusLoop, we can compile that test against dbus-glib
or against DBusLoop, depending on the platform.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68852
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2013-09-02 16:32:31 +01:00
|
|
|
test_main_context_iterate (f->ctx, TRUE);
|
2012-03-12 13:13:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_assert_cmpuint (g_queue_get_length (&f->server_messages), ==, 1);
|
|
|
|
|
|
|
|
|
|
incoming = g_queue_pop_head (&f->server_messages);
|
|
|
|
|
|
|
|
|
|
g_assert (!dbus_message_contains_unix_fds (incoming));
|
|
|
|
|
g_assert_cmpstr (dbus_message_get_destination (incoming), ==, NULL);
|
|
|
|
|
g_assert_cmpstr (dbus_message_get_error_name (incoming), ==, NULL);
|
|
|
|
|
g_assert_cmpstr (dbus_message_get_interface (incoming), ==,
|
|
|
|
|
DBUS_INTERFACE_LOCAL);
|
|
|
|
|
g_assert_cmpstr (dbus_message_get_member (incoming), ==, "Disconnected");
|
|
|
|
|
g_assert_cmpstr (dbus_message_get_sender (incoming), ==, NULL);
|
|
|
|
|
g_assert_cmpstr (dbus_message_get_signature (incoming), ==, "");
|
|
|
|
|
g_assert_cmpstr (dbus_message_get_path (incoming), ==, DBUS_PATH_LOCAL);
|
|
|
|
|
|
2017-07-21 19:15:05 +01:00
|
|
|
dbus_clear_message (&incoming);
|
2017-06-28 18:49:18 +01:00
|
|
|
dbus_free (address);
|
2012-03-12 13:13:55 +00:00
|
|
|
}
|
|
|
|
|
|
2011-02-22 13:04:18 +00:00
|
|
|
static void
|
|
|
|
|
test_message (Fixture *f,
|
|
|
|
|
gconstpointer addr)
|
|
|
|
|
{
|
|
|
|
|
dbus_bool_t have_mem;
|
|
|
|
|
dbus_uint32_t serial;
|
|
|
|
|
DBusMessage *outgoing, *incoming;
|
|
|
|
|
|
test: Skip TCP tests if getaddrinfo doesn't work
For example, this can be the case in bubblewrap or Debian pbuilder after
unsharing the network namespace:
bwrap \
--bind / / \
--dev-bind /dev /dev \
--bind /dev/shm /dev/shm \
--bind /dev/pts /dev/pts \
--unshare-net \
${builddir}/test/test-loopback --tap
...
ok 1 /connect/tcp # SKIP Name resolution does not work here:
getaddrinfo("127.0.0.1", "0", {flags=ADDRCONFIG, family=INET,
socktype=STREAM, protocol=TCP}): Name or service not known
On some systems this can be circumvented by using nss_wrapper from
<https://cwrap.org/nss_wrapper.html>:
cat > hosts <<EOF
127.0.0.1 localhost
EOF
bwrap \
... \
env \
LD_PRELOAD=libnss_wrapper.so \
NSS_WRAPPER_HOSTS=$(pwd)/hosts \
${builddir}/test/test-loopback --tap
...
# listening at tcp:host=127.0.0.1,port=39219,family=ipv4,guid=...
but for systems where that does't work, we should be prepared to skip
the affected tests.
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=106812
2018-06-04 16:27:50 +01:00
|
|
|
if (f->skip)
|
|
|
|
|
return;
|
|
|
|
|
|
2011-02-22 13:04:18 +00:00
|
|
|
test_connect (f, addr);
|
|
|
|
|
|
|
|
|
|
outgoing = dbus_message_new_signal ("/com/example/Hello",
|
|
|
|
|
"com.example.Hello", "Greeting");
|
|
|
|
|
g_assert (outgoing != NULL);
|
|
|
|
|
|
|
|
|
|
have_mem = dbus_connection_send (f->client_conn, outgoing, &serial);
|
|
|
|
|
g_assert (have_mem);
|
|
|
|
|
g_assert (serial != 0);
|
|
|
|
|
|
|
|
|
|
while (g_queue_is_empty (&f->server_messages))
|
|
|
|
|
{
|
2015-02-26 17:12:22 +00:00
|
|
|
test_progress ('.');
|
Tests: allow dbus-glib to be replaced with use of libdbus-internal
We only use dbus-glib for its main loop; within dbus, DBusLoop is
available as an alternative, although it isn't thread-safe and
isn't public API.
For tests that otherwise only use libdbus public API, it's desirable to
be able to avoid DBusLoop, so we can run them against an installed
libdbus as an integration test. However, if we don't have dbus-glib,
we're going to have to use an in-tree main loop, which might as well
be DBusLoop.
The major disadvantage of using dbus-glib is that it isn't safe to
link both dbus-1 and dbus-internal at the same time. This is awkward
for a future test case that wants to use _dbus_getsid() in dbus-daemon.c,
but only on Windows (fd.o #54445). If we use the same API wrapper around
both dbus-glib and DBusLoop, we can compile that test against dbus-glib
or against DBusLoop, depending on the platform.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68852
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2013-09-02 16:32:31 +01:00
|
|
|
test_main_context_iterate (f->ctx, TRUE);
|
2011-02-22 13:04:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_assert_cmpuint (g_queue_get_length (&f->server_messages), ==, 1);
|
|
|
|
|
|
|
|
|
|
incoming = g_queue_pop_head (&f->server_messages);
|
|
|
|
|
|
|
|
|
|
g_assert (!dbus_message_contains_unix_fds (incoming));
|
|
|
|
|
g_assert_cmpstr (dbus_message_get_destination (incoming), ==, NULL);
|
|
|
|
|
g_assert_cmpstr (dbus_message_get_error_name (incoming), ==, NULL);
|
|
|
|
|
g_assert_cmpstr (dbus_message_get_interface (incoming), ==,
|
|
|
|
|
"com.example.Hello");
|
|
|
|
|
g_assert_cmpstr (dbus_message_get_member (incoming), ==, "Greeting");
|
|
|
|
|
g_assert_cmpstr (dbus_message_get_sender (incoming), ==, NULL);
|
|
|
|
|
g_assert_cmpstr (dbus_message_get_signature (incoming), ==, "");
|
|
|
|
|
g_assert_cmpstr (dbus_message_get_path (incoming), ==, "/com/example/Hello");
|
|
|
|
|
g_assert_cmpuint (dbus_message_get_serial (incoming), ==, serial);
|
2011-02-22 16:31:02 +00:00
|
|
|
|
2017-07-21 19:15:05 +01:00
|
|
|
dbus_clear_message (&incoming);
|
|
|
|
|
dbus_clear_message (&outgoing);
|
2011-02-22 13:04:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
teardown (Fixture *f,
|
|
|
|
|
gconstpointer addr G_GNUC_UNUSED)
|
|
|
|
|
{
|
|
|
|
|
if (f->client_conn != NULL)
|
2018-07-12 12:51:38 +01:00
|
|
|
{
|
|
|
|
|
test_connection_shutdown (f->ctx, f->client_conn);
|
|
|
|
|
dbus_connection_close (f->client_conn);
|
|
|
|
|
}
|
2011-02-22 13:04:18 +00:00
|
|
|
|
|
|
|
|
if (f->server_conn != NULL)
|
2018-07-12 12:51:38 +01:00
|
|
|
{
|
|
|
|
|
test_connection_shutdown (f->ctx, f->server_conn);
|
|
|
|
|
dbus_connection_close (f->server_conn);
|
|
|
|
|
}
|
2017-07-21 19:15:05 +01:00
|
|
|
|
|
|
|
|
dbus_clear_connection (&f->client_conn);
|
|
|
|
|
dbus_clear_connection (&f->server_conn);
|
2011-02-22 13:04:18 +00:00
|
|
|
|
|
|
|
|
if (f->server != NULL)
|
2018-07-11 16:22:49 +01:00
|
|
|
test_server_shutdown (f->ctx, f->server);
|
Tests: allow dbus-glib to be replaced with use of libdbus-internal
We only use dbus-glib for its main loop; within dbus, DBusLoop is
available as an alternative, although it isn't thread-safe and
isn't public API.
For tests that otherwise only use libdbus public API, it's desirable to
be able to avoid DBusLoop, so we can run them against an installed
libdbus as an integration test. However, if we don't have dbus-glib,
we're going to have to use an in-tree main loop, which might as well
be DBusLoop.
The major disadvantage of using dbus-glib is that it isn't safe to
link both dbus-1 and dbus-internal at the same time. This is awkward
for a future test case that wants to use _dbus_getsid() in dbus-daemon.c,
but only on Windows (fd.o #54445). If we use the same API wrapper around
both dbus-glib and DBusLoop, we can compile that test against dbus-glib
or against DBusLoop, depending on the platform.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68852
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2013-09-02 16:32:31 +01:00
|
|
|
|
2017-07-21 19:15:05 +01:00
|
|
|
dbus_clear_server (&f->server);
|
Tests: allow dbus-glib to be replaced with use of libdbus-internal
We only use dbus-glib for its main loop; within dbus, DBusLoop is
available as an alternative, although it isn't thread-safe and
isn't public API.
For tests that otherwise only use libdbus public API, it's desirable to
be able to avoid DBusLoop, so we can run them against an installed
libdbus as an integration test. However, if we don't have dbus-glib,
we're going to have to use an in-tree main loop, which might as well
be DBusLoop.
The major disadvantage of using dbus-glib is that it isn't safe to
link both dbus-1 and dbus-internal at the same time. This is awkward
for a future test case that wants to use _dbus_getsid() in dbus-daemon.c,
but only on Windows (fd.o #54445). If we use the same API wrapper around
both dbus-glib and DBusLoop, we can compile that test against dbus-glib
or against DBusLoop, depending on the platform.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68852
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2013-09-02 16:32:31 +01:00
|
|
|
test_main_context_unref (f->ctx);
|
2011-02-22 13:04:18 +00:00
|
|
|
}
|
|
|
|
|
|
2015-01-29 13:41:29 +00:00
|
|
|
static void
|
|
|
|
|
teardown_no_runtime (Fixture *f,
|
|
|
|
|
gconstpointer addr)
|
|
|
|
|
{
|
|
|
|
|
teardown (f, addr);
|
|
|
|
|
|
|
|
|
|
/* we're relying on being single-threaded for this to be safe */
|
|
|
|
|
if (f->saved_runtime_dir != NULL)
|
|
|
|
|
g_setenv ("XDG_RUNTIME_DIR", f->saved_runtime_dir, TRUE);
|
|
|
|
|
else
|
|
|
|
|
g_unsetenv ("XDG_RUNTIME_DIR");
|
|
|
|
|
g_free (f->saved_runtime_dir);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
teardown_runtime (Fixture *f,
|
|
|
|
|
gconstpointer addr)
|
|
|
|
|
{
|
|
|
|
|
gchar *path;
|
|
|
|
|
|
|
|
|
|
teardown (f, addr);
|
|
|
|
|
|
|
|
|
|
/* the socket may exist */
|
|
|
|
|
path = g_strdup_printf ("%s/bus", f->tmp_runtime_dir);
|
2017-02-14 19:49:46 +00:00
|
|
|
test_remove_if_exists (path);
|
2015-01-29 13:41:29 +00:00
|
|
|
g_free (path);
|
|
|
|
|
/* there shouldn't be anything else in there */
|
2017-02-14 19:49:46 +00:00
|
|
|
test_rmdir_must_exist (f->tmp_runtime_dir);
|
2015-01-29 13:41:29 +00:00
|
|
|
|
|
|
|
|
/* we're relying on being single-threaded for this to be safe */
|
|
|
|
|
if (f->saved_runtime_dir != NULL)
|
|
|
|
|
g_setenv ("XDG_RUNTIME_DIR", f->saved_runtime_dir, TRUE);
|
|
|
|
|
else
|
|
|
|
|
g_unsetenv ("XDG_RUNTIME_DIR");
|
|
|
|
|
g_free (f->saved_runtime_dir);
|
|
|
|
|
g_free (f->tmp_runtime_dir);
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-22 13:04:18 +00:00
|
|
|
int
|
|
|
|
|
main (int argc,
|
|
|
|
|
char **argv)
|
|
|
|
|
{
|
2018-07-11 16:40:12 +01:00
|
|
|
int ret;
|
2022-03-17 17:12:41 +04:00
|
|
|
#ifdef DBUS_UNIX
|
|
|
|
|
char *tmp = _dbus_strdup ("/tmp");
|
|
|
|
|
#else
|
|
|
|
|
char *tmp = dbus_address_escape_value (g_get_tmp_dir ());
|
|
|
|
|
#endif
|
|
|
|
|
gchar *unix_tmpdir = g_strdup_printf ("unix:tmpdir=%s", tmp);
|
|
|
|
|
gchar *unix_dir = g_strdup_printf ("unix:dir=%s", tmp);
|
|
|
|
|
gchar *unix_runtime_or_fallback = g_strdup_printf ("unix:runtime=yes;%s", unix_tmpdir);
|
2018-07-11 16:40:12 +01:00
|
|
|
|
2015-02-03 14:45:35 +00:00
|
|
|
test_init (&argc, &argv);
|
2011-02-22 13:04:18 +00:00
|
|
|
|
|
|
|
|
g_test_add ("/connect/tcp", Fixture, "tcp:host=127.0.0.1", setup,
|
|
|
|
|
test_connect, teardown);
|
|
|
|
|
g_test_add ("/message/tcp", Fixture, "tcp:host=127.0.0.1", setup,
|
|
|
|
|
test_message, teardown);
|
|
|
|
|
|
2011-02-22 13:43:18 +00:00
|
|
|
g_test_add ("/connect/nonce-tcp", Fixture, "nonce-tcp:host=127.0.0.1", setup,
|
|
|
|
|
test_connect, teardown);
|
|
|
|
|
g_test_add ("/message/nonce-tcp", Fixture, "nonce-tcp:host=127.0.0.1", setup,
|
|
|
|
|
test_message, teardown);
|
|
|
|
|
|
2018-06-04 16:27:49 +01:00
|
|
|
g_test_add ("/message/bad-guid/tcp", Fixture, "tcp:host=127.0.0.1", setup,
|
|
|
|
|
test_bad_guid, teardown);
|
|
|
|
|
|
2022-03-17 17:12:41 +04:00
|
|
|
g_test_add ("/connect/unix/tmpdir", Fixture, unix_tmpdir, setup,
|
2017-06-28 18:52:29 +01:00
|
|
|
test_connect, teardown);
|
2022-03-17 17:12:41 +04:00
|
|
|
g_test_add ("/message/unix/tmpdir", Fixture, unix_tmpdir, setup,
|
2017-06-28 18:52:29 +01:00
|
|
|
test_message, teardown);
|
2022-03-17 17:12:41 +04:00
|
|
|
g_test_add ("/connect/unix/dir", Fixture, unix_dir, setup,
|
2011-02-22 13:04:18 +00:00
|
|
|
test_connect, teardown);
|
2022-03-17 17:12:41 +04:00
|
|
|
g_test_add ("/message/unix/dir", Fixture, unix_dir, setup,
|
2011-02-22 13:04:18 +00:00
|
|
|
test_message, teardown);
|
2015-01-29 13:41:29 +00:00
|
|
|
|
|
|
|
|
g_test_add ("/connect/unix/runtime", Fixture,
|
2022-03-17 17:12:41 +04:00
|
|
|
unix_runtime_or_fallback, setup_runtime, test_connect,
|
2015-01-29 13:41:29 +00:00
|
|
|
teardown_runtime);
|
|
|
|
|
g_test_add ("/connect/unix/no-runtime", Fixture,
|
2022-03-17 17:12:41 +04:00
|
|
|
unix_runtime_or_fallback, setup_no_runtime, test_connect,
|
2015-01-29 13:41:29 +00:00
|
|
|
teardown_no_runtime);
|
2011-02-22 13:04:18 +00:00
|
|
|
|
2022-03-17 17:12:41 +04:00
|
|
|
g_test_add ("/message/bad-guid/unix", Fixture, unix_tmpdir, setup,
|
2012-03-12 13:13:55 +00:00
|
|
|
test_bad_guid, teardown);
|
|
|
|
|
|
2018-07-11 16:40:12 +01:00
|
|
|
ret = g_test_run ();
|
|
|
|
|
dbus_shutdown ();
|
2022-03-17 17:12:41 +04:00
|
|
|
|
|
|
|
|
g_free (unix_tmpdir);
|
|
|
|
|
g_free (unix_dir);
|
|
|
|
|
g_free (unix_runtime_or_fallback);
|
|
|
|
|
dbus_free (tmp);
|
2018-07-11 16:40:12 +01:00
|
|
|
return ret;
|
2011-02-22 13:04:18 +00:00
|
|
|
}
|