From 88366621eee608013fedd661884e769bbce87321 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 27 Oct 2016 17:59:49 +0200 Subject: [PATCH] GSimpleProxyResolver: Add test case for broken hostname https://bugzilla.gnome.org/show_bug.cgi?id=772989 --- gio/tests/simple-proxy.c | 54 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/gio/tests/simple-proxy.c b/gio/tests/simple-proxy.c index 0f1f63d81..00bdb2ea4 100644 --- a/gio/tests/simple-proxy.c +++ b/gio/tests/simple-proxy.c @@ -19,6 +19,15 @@ #include +static void +async_result_cb (GObject *obj, + GAsyncResult *result, + gpointer user_data) +{ + GAsyncResult **result_out = user_data; + *result_out = g_object_ref (result); +} + static void test_uris (void) { @@ -26,6 +35,51 @@ test_uris (void) gchar *ignore_hosts[2] = { "127.0.0.1", NULL }; gchar **proxies; GError *error = NULL; + const gchar *uri; + gchar *str = NULL; + GAsyncResult *result = NULL; + + /* Valid URI. */ + uri = "http://%E0%B4%A8%E0%B4%B2:80/"; + resolver = g_simple_proxy_resolver_new (NULL, ignore_hosts); + + proxies = g_proxy_resolver_lookup (resolver, uri, NULL, &error); + g_assert_no_error (error); + g_strfreev (proxies); + + g_proxy_resolver_lookup_async (resolver, uri, NULL, async_result_cb, &result); + while (result == NULL) + g_main_context_iteration (NULL, TRUE); + proxies = g_proxy_resolver_lookup_finish (resolver, result, &error); + g_assert_no_error (error); + g_strfreev (proxies); + g_clear_object (&result); + + g_object_unref (resolver); + + /* Invalid URI. */ + uri = "%E0%B4%A8%E0%B4%B2"; + str = g_strdup_printf ("Invalid URI ā€˜%s’", uri); + resolver = g_simple_proxy_resolver_new (NULL, ignore_hosts); + + proxies = g_proxy_resolver_lookup (resolver, uri, NULL, &error); + g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT); + g_assert_cmpstr (error->message, ==, str); + g_clear_error (&error); + g_assert_null (proxies); + g_clear_object (&result); + + g_proxy_resolver_lookup_async (resolver, uri, NULL, async_result_cb, &result); + while (result == NULL) + g_main_context_iteration (NULL, TRUE); + proxies = g_proxy_resolver_lookup_finish (resolver, result, &error); + g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT); + g_assert_cmpstr (error->message, ==, str); + g_clear_error (&error); + g_assert_null (proxies); + + g_object_unref (resolver); + g_free (str); resolver = g_simple_proxy_resolver_new ("default://", ignore_hosts); g_simple_proxy_resolver_set_uri_proxy (G_SIMPLE_PROXY_RESOLVER (resolver),