summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2012-03-12 13:13:55 +0000
committerRalf Habacker <ralf.habacker@freenet.de>2013-08-23 03:03:30 +0200
commit71cfa9cdd0d73c650f79b49c21b42ccd36ad71cf (patch)
treef799bf9d5ae3293c241dce8eed8b6d771c6079b0
parent65cd1208e0559fffe4ba82ef10c6491744869b09 (diff)
downloaddbus-71cfa9cdd0d73c650f79b49c21b42ccd36ad71cf.tar.gz
Add a test-case for trying to connect with the wrong GUID
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=39720 Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
-rw-r--r--test/loopback.c68
1 files changed, 67 insertions, 1 deletions
diff --git a/test/loopback.c b/test/loopback.c
index d0d69c82..39cf03ab 100644
--- a/test/loopback.c
+++ b/test/loopback.c
@@ -1,7 +1,7 @@
/* Simple sanity-check for loopback through TCP and Unix sockets.
*
* Author: Simon McVittie <simon.mcvittie@collabora.co.uk>
- * Copyright © 2010-2011 Nokia Corporation
+ * Copyright © 2010-2012 Nokia Corporation
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation files
@@ -31,6 +31,8 @@
#include <dbus/dbus.h>
#include <dbus/dbus-glib-lowlevel.h>
+#include <string.h>
+
typedef struct {
DBusError e;
@@ -115,6 +117,66 @@ test_connect (Fixture *f,
}
static void
+test_bad_guid (Fixture *f,
+ gconstpointer addr G_GNUC_UNUSED)
+{
+ DBusMessage *incoming;
+ gchar *address = g_strdup (dbus_server_get_address (f->server));
+ gchar *guid;
+
+ g_test_bug ("39720");
+
+ g_assert (f->server_conn == NULL);
+
+ 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);
+ dbus_connection_setup_with_g_main (f->client_conn, NULL);
+
+ while (f->server_conn == NULL)
+ {
+ g_print (".");
+ g_main_context_iteration (NULL, TRUE);
+ }
+
+ /* We get disconnected */
+
+ while (g_queue_is_empty (&f->server_messages))
+ {
+ g_print (".");
+ g_main_context_iteration (NULL, TRUE);
+ }
+
+ 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);
+
+ dbus_message_unref (incoming);
+
+ g_free (address);
+}
+
+static void
test_message (Fixture *f,
gconstpointer addr)
{
@@ -189,6 +251,7 @@ main (int argc,
char **argv)
{
g_test_init (&argc, &argv, NULL);
+ g_test_bug_base ("https://bugs.freedesktop.org/show_bug.cgi?id=");
g_test_add ("/connect/tcp", Fixture, "tcp:host=127.0.0.1", setup,
test_connect, teardown);
@@ -207,5 +270,8 @@ main (int argc,
test_message, teardown);
#endif
+ g_test_add ("/message/bad-guid", Fixture, "tcp:host=127.0.0.1", setup,
+ test_bad_guid, teardown);
+
return g_test_run ();
}