From 8ace9ccd9a0d2a60276f166362e4646fdf88319b Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 12 Mar 2012 13:13:55 +0000 Subject: [PATCH 3/3] 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 --- test/loopback.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 67 insertions(+), 1 deletions(-) diff --git a/test/loopback.c b/test/loopback.c index d0d69c8..39cf03a 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 - * 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 #include +#include + 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 (); } -- 1.7.9.1