[glib-networking/glib-2-36] libproxy: fix handling of SOCKS in async API, add tests
- From: Dan Winship <danw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib-networking/glib-2-36] libproxy: fix handling of SOCKS in async API, add tests
- Date: Mon, 13 May 2013 21:09:19 +0000 (UTC)
commit c44321c50fdf13e1da0ea7b7be731c38d6c37f6c
Author: Dan Winship <danw gnome org>
Date: Wed May 1 08:43:12 2013 -0400
libproxy: fix handling of SOCKS in async API, add tests
Fix the handling of SOCKS proxies with g_proxy_resolver_lookup_async()
and the libproxy resolver. (Also, make the sync proxy resolver
properly cancellable.)
Add some tests of the libproxy resolver, based on the existing gnome
proxy resolver tests. Unfortunately, libproxy doesn't implement ignore
hosts in exactly the same way GProxyResolverGnome does, so we need to
keep track of which URIs they give different results for...
https://bugzilla.gnome.org/show_bug.cgi?id=699359
.gitignore | 1 +
proxy/libproxy/glibproxyresolver.c | 86 ++++++----------
proxy/tests/Makefile.am | 6 +
proxy/tests/common.c | 192 ++++++++++++++++++++++++++++++++++++
proxy/tests/gnome.c | 155 +----------------------------
proxy/tests/libproxy.c | 91 +++++++++++++++++
6 files changed, 327 insertions(+), 204 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 3d3f55c..0e70b23 100644
--- a/.gitignore
+++ b/.gitignore
@@ -34,6 +34,7 @@ m4
proxy/libproxy/glib-pacrunner
proxy/libproxy/org.gtk.GLib.PACRunner.service
proxy/tests/gnome
+proxy/tests/libproxy
/tls/tests/certificate
/tls/tests/file-database
diff --git a/proxy/libproxy/glibproxyresolver.c b/proxy/libproxy/glibproxyresolver.c
index 96a3fbe..5daee5d 100644
--- a/proxy/libproxy/glibproxyresolver.c
+++ b/proxy/libproxy/glibproxyresolver.c
@@ -128,29 +128,35 @@ free_libproxy_proxies (gchar **proxies)
free (proxies);
}
-static gchar **
-get_libproxy_proxies (GLibProxyResolver *resolver,
- const gchar *uri,
- GCancellable *cancellable,
- GError **error)
+static void
+get_libproxy_proxies (GTask *task,
+ gpointer source_object,
+ gpointer task_data,
+ GCancellable *cancellable)
{
+ GLibProxyResolver *resolver = source_object;
+ const gchar *uri = task_data;
+ GError *error = NULL;
gchar **proxies;
- /* FIXME: this is not really cancellable; to do it right we'd
- * need to run this function in a thread pool like GThreadedResolver.
- */
-
- if (g_cancellable_set_error_if_cancelled (cancellable, error))
- return NULL;
+ if (g_task_return_error_if_cancelled (task))
+ return;
proxies = px_proxy_factory_get_proxies (resolver->factory, uri);
- if (!proxies)
+ if (proxies)
+ {
+ /* We always copy to be able to translate "socks" entry into
+ * three entries ("socks5", "socks4a", "socks4").
+ */
+ g_task_return_pointer (task, copy_proxies (proxies), (GDestroyNotify) g_strfreev);
+ free_libproxy_proxies (proxies);
+ }
+ else
{
- g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_FAILED,
_("Proxy resolver internal error."));
+ g_task_return_error (task, error);
}
-
- return proxies;
}
static gchar **
@@ -159,51 +165,22 @@ g_libproxy_resolver_lookup (GProxyResolver *iresolver,
GCancellable *cancellable,
GError **error)
{
- GLibProxyResolver *resolver;
+ GLibProxyResolver *resolver = G_LIBPROXY_RESOLVER (iresolver);
+ GTask *task;
gchar **proxies;
- g_return_val_if_fail (G_IS_LIBPROXY_RESOLVER (iresolver), NULL);
- g_return_val_if_fail (uri != NULL, NULL);
-
- resolver = G_LIBPROXY_RESOLVER (iresolver);
-
- proxies = get_libproxy_proxies (resolver, uri, cancellable, error);
+ task = g_task_new (resolver, cancellable, NULL, NULL);
+ g_task_set_task_data (task, g_strdup (uri), g_free);
+ g_task_set_return_on_cancel (task, TRUE);
- /* We always copy to be able to translate "socks" entry into
- * three entries ("socks5", "socks4a", "socks4").
- */
- if (proxies)
- {
- gchar **copy;
-
- copy = copy_proxies (proxies);
- free_libproxy_proxies (proxies);
- proxies = copy;
- }
+ g_task_run_in_thread_sync (task, get_libproxy_proxies);
+ proxies = g_task_propagate_pointer (task, error);
+ g_object_unref (task);
return proxies;
}
static void
-_lookup_async (GTask *task,
- gpointer object,
- gpointer task_data,
- GCancellable *cancellable)
-{
- GLibProxyResolver *resolver = object;
- gchar *uri = task_data;
- GError *error = NULL;
- gchar **proxies = NULL;
-
- proxies = get_libproxy_proxies (resolver, uri, cancellable, &error);
-
- if (error)
- g_task_return_error (task, error);
- else
- g_task_return_pointer (task, proxies, (GDestroyNotify)free_libproxy_proxies);
-}
-
-static void
g_libproxy_resolver_lookup_async (GProxyResolver *resolver,
const gchar *uri,
GCancellable *cancellable,
@@ -213,8 +190,9 @@ g_libproxy_resolver_lookup_async (GProxyResolver *resolver,
GTask *task;
task = g_task_new (resolver, cancellable, callback, user_data);
- g_task_set_task_data (task, g_strdup (uri), (GDestroyNotify) g_free);
- g_task_run_in_thread (task, _lookup_async);
+ g_task_set_task_data (task, g_strdup (uri), g_free);
+ g_task_set_return_on_cancel (task, TRUE);
+ g_task_run_in_thread (task, get_libproxy_proxies);
g_object_unref (task);
}
diff --git a/proxy/tests/Makefile.am b/proxy/tests/Makefile.am
index ec4732c..ad5dd3c 100644
--- a/proxy/tests/Makefile.am
+++ b/proxy/tests/Makefile.am
@@ -14,3 +14,9 @@ LDADD = \
if HAVE_GNOME_PROXY
TEST_PROGS += gnome
endif
+
+if HAVE_LIBPROXY
+TEST_PROGS += libproxy
+endif
+
+EXTRA_DIST = common.c
diff --git a/proxy/tests/common.c b/proxy/tests/common.c
new file mode 100644
index 0000000..23ebb20
--- /dev/null
+++ b/proxy/tests/common.c
@@ -0,0 +1,192 @@
+/* GProxyResolver tests
+ *
+ * Copyright 2011-2013 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+#include <gio/gio.h>
+
+static void
+test_proxy_uri_common (void)
+{
+ GProxyResolver *resolver;
+ gchar **proxies;
+ GError *error = NULL;
+
+ resolver = g_proxy_resolver_get_default ();
+
+ proxies = g_proxy_resolver_lookup (resolver, "http://one.example.com/",
+ NULL, &error);
+ g_assert_no_error (error);
+ g_assert_cmpint (g_strv_length (proxies), ==, 1);
+ g_assert_cmpstr (proxies[0], ==, "http://proxy.example.com:8080");
+ g_strfreev (proxies);
+
+ proxies = g_proxy_resolver_lookup (resolver, "HTTPS://uppercase.example.com/",
+ NULL, &error);
+ g_assert_no_error (error);
+ g_assert_cmpint (g_strv_length (proxies), ==, 1);
+ g_assert_cmpstr (proxies[0], ==, "http://proxy-s.example.com:7070");
+ g_strfreev (proxies);
+
+ /* Unknown protocols will use the http proxy by default in this configuration. */
+ proxies = g_proxy_resolver_lookup (resolver, "htt://missing-letter.example.com/",
+ NULL, &error);
+ g_assert_no_error (error);
+ g_assert_cmpint (g_strv_length (proxies), ==, 1);
+ g_assert_cmpstr (proxies[0], ==, "http://proxy.example.com:8080");
+ g_strfreev (proxies);
+
+ proxies = g_proxy_resolver_lookup (resolver, "ftps://extra-letter.example.com/",
+ NULL, &error);
+ g_assert_no_error (error);
+ g_assert_cmpint (g_strv_length (proxies), ==, 1);
+ g_assert_cmpstr (proxies[0], ==, "http://proxy.example.com:8080");
+ g_strfreev (proxies);
+
+ proxies = g_proxy_resolver_lookup (resolver, "ftp://five.example.com/",
+ NULL, &error);
+ g_assert_no_error (error);
+ g_assert_cmpint (g_strv_length (proxies), ==, 1);
+ g_assert_cmpstr (proxies[0], ==, "ftp://proxy-f.example.com:6060");
+ g_strfreev (proxies);
+}
+
+static void
+test_proxy_socks_common (void)
+{
+ GProxyResolver *resolver;
+ gchar **proxies;
+ GError *error = NULL;
+
+ resolver = g_proxy_resolver_get_default ();
+
+ proxies = g_proxy_resolver_lookup (resolver, "http://one.example.com/",
+ NULL, &error);
+ g_assert_no_error (error);
+ g_assert_cmpint (g_strv_length (proxies), ==, 3);
+ g_assert_cmpstr (proxies[0], ==, "socks5://proxy.example.com:1234");
+ g_assert_cmpstr (proxies[1], ==, "socks4a://proxy.example.com:1234");
+ g_assert_cmpstr (proxies[2], ==, "socks4://proxy.example.com:1234");
+ g_strfreev (proxies);
+
+ proxies = g_proxy_resolver_lookup (resolver, "wednesday://two.example.com/",
+ NULL, &error);
+ g_assert_no_error (error);
+ g_assert_cmpint (g_strv_length (proxies), ==, 3);
+ g_assert_cmpstr (proxies[0], ==, "socks5://proxy.example.com:1234");
+ g_assert_cmpstr (proxies[1], ==, "socks4a://proxy.example.com:1234");
+ g_assert_cmpstr (proxies[2], ==, "socks4://proxy.example.com:1234");
+ g_strfreev (proxies);
+
+ proxies = g_proxy_resolver_lookup (resolver, "http://127.0.0.1/",
+ NULL, &error);
+ g_assert_no_error (error);
+ g_assert_cmpint (g_strv_length (proxies), ==, 1);
+ g_assert_cmpstr (proxies[0], ==, "direct://");
+ g_strfreev (proxies);
+}
+
+static const char *ignore_hosts[] = {
+ ".bbb.xx",
+ "*.ccc.xx",
+ "ddd.xx",
+ "*.eee.xx:8000",
+ "127.0.0.0/24",
+ "10.0.0.1:8000",
+ "::1",
+ "fe80::/10",
+ NULL
+};
+static const int n_ignore_hosts = G_N_ELEMENTS (ignore_hosts) - 1;
+
+static const struct {
+ const char *uri;
+ const char *proxy;
+ gboolean libproxy_fails;
+} ignore_tests[] = {
+ { "http://aaa.xx/", "http://localhost:8080" },
+ { "http://aaa.xx:8000/", "http://localhost:8080" },
+ { "http://www.aaa.xx/", "http://localhost:8080" },
+ { "http://www.aaa.xx:8000/", "http://localhost:8080" },
+ { "https://aaa.xx/", "http://localhost:8080" },
+ { "http://bbb.xx/", "direct://", TRUE },
+ { "http://www.bbb.xx/", "direct://" },
+ { "http://bbb.xx:8000/", "direct://", TRUE },
+ { "http://www.bbb.xx:8000/", "direct://" },
+ { "https://bbb.xx/", "direct://", TRUE },
+ { "http://nobbb.xx/", "http://localhost:8080" },
+ { "http://www.nobbb.xx/", "http://localhost:8080" },
+ { "http://nobbb.xx:8000/", "http://localhost:8080" },
+ { "http://www.nobbb.xx:8000/", "http://localhost:8080" },
+ { "https://nobbb.xx/", "http://localhost:8080" },
+ { "http://ccc.xx/", "direct://", TRUE },
+ { "http://www.ccc.xx/", "direct://" },
+ { "http://ccc.xx:8000/", "direct://", TRUE },
+ { "http://www.ccc.xx:8000/", "direct://" },
+ { "https://ccc.xx/", "direct://", TRUE },
+ { "http://ddd.xx/", "direct://" },
+ { "http://ddd.xx:8000/", "direct://" },
+ { "http://www.ddd.xx/", "direct://", TRUE },
+ { "http://www.ddd.xx:8000/", "direct://", TRUE },
+ { "https://ddd.xx/", "direct://" },
+ { "http://eee.xx/", "http://localhost:8080", TRUE },
+ { "http://eee.xx:8000/", "direct://", TRUE },
+ { "http://www.eee.xx/", "http://localhost:8080" },
+ { "http://www.eee.xx:8000/", "direct://" },
+ { "https://eee.xx/", "http://localhost:8080", TRUE },
+ { "http://1.2.3.4/", "http://localhost:8080" },
+ { "http://127.0.0.1/", "direct://" },
+ { "http://127.0.0.2/", "direct://" },
+ { "http://127.0.0.255/", "direct://" },
+ { "http://127.0.1.0/", "http://localhost:8080" },
+ { "http://10.0.0.1/", "http://localhost:8080" },
+ { "http://10.0.0.1:8000/", "direct://" },
+ { "http://[::1]/", "direct://", TRUE },
+ { "http://[::1]:80/", "direct://", TRUE },
+ { "http://[::1:1]/", "http://localhost:8080" },
+ { "http://[::1:1]:80/", "http://localhost:8080" },
+ { "http://[fe80::1]/", "direct://", TRUE },
+ { "http://[fe80::1]:80/", "direct://", TRUE },
+ { "http://[fec0::1]/", "http://localhost:8080" },
+ { "http://[fec0::1]:80/", "http://localhost:8080" }
+};
+static const int n_ignore_tests = G_N_ELEMENTS (ignore_tests);
+
+static void
+test_proxy_ignore_common (gboolean is_libproxy)
+{
+ GProxyResolver *resolver;
+ GError *error = NULL;
+ char **proxies;
+ int i;
+
+ resolver = g_proxy_resolver_get_default ();
+
+ for (i = 0; i < n_ignore_tests; i++)
+ {
+ proxies = g_proxy_resolver_lookup (resolver, ignore_tests[i].uri,
+ NULL, &error);
+ g_assert_no_error (error);
+
+ if (is_libproxy && ignore_tests[i].libproxy_fails)
+ g_assert_cmpstr (proxies[0], ==, "http://localhost:8080");
+ else
+ g_assert_cmpstr (proxies[0], ==, ignore_tests[i].proxy);
+
+ g_strfreev (proxies);
+ }
+}
diff --git a/proxy/tests/gnome.c b/proxy/tests/gnome.c
index 69f43ac..578ac49 100644
--- a/proxy/tests/gnome.c
+++ b/proxy/tests/gnome.c
@@ -20,6 +20,8 @@
#include <gio/gio.h>
#include <gdesktop-enums.h>
+#include "common.c"
+
#define GNOME_PROXY_SETTINGS_SCHEMA "org.gnome.system.proxy"
#define GNOME_PROXY_MODE_KEY "mode"
#define GNOME_PROXY_AUTOCONFIG_URL_KEY "autoconfig-url"
@@ -83,9 +85,6 @@ test_proxy_uri (gpointer fixture,
gconstpointer user_data)
{
GSettings *settings, *child;
- GProxyResolver *resolver;
- gchar **proxies;
- GError *error = NULL;
settings = g_settings_new (GNOME_PROXY_SETTINGS_SCHEMA);
g_settings_set_enum (settings, GNOME_PROXY_MODE_KEY, G_DESKTOP_PROXY_MODE_MANUAL);
@@ -108,45 +107,7 @@ test_proxy_uri (gpointer fixture,
g_object_unref (settings);
- resolver = g_proxy_resolver_get_default ();
-
- proxies = g_proxy_resolver_lookup (resolver, "http://one.example.com/",
- NULL, &error);
- g_assert_no_error (error);
- g_assert_cmpint (g_strv_length (proxies), ==, 1);
- g_assert_cmpstr (proxies[0], ==, "http://proxy.example.com:8080");
- g_strfreev (proxies);
-
- proxies = g_proxy_resolver_lookup (resolver, "HTTPS://uppercase.example.com/",
- NULL, &error);
- g_assert_no_error (error);
- g_assert_cmpint (g_strv_length (proxies), ==, 1);
- g_assert_cmpstr (proxies[0], ==, "http://proxy-s.example.com:7070");
- g_strfreev (proxies);
-
- /* Because we set use_same_proxy = TRUE, unknown protocols will use
- * the http proxy by default.
- */
- proxies = g_proxy_resolver_lookup (resolver, "htt://missing-letter.example.com/",
- NULL, &error);
- g_assert_no_error (error);
- g_assert_cmpint (g_strv_length (proxies), ==, 1);
- g_assert_cmpstr (proxies[0], ==, "http://proxy.example.com:8080");
- g_strfreev (proxies);
-
- proxies = g_proxy_resolver_lookup (resolver, "ftps://extra-letter.example.com/",
- NULL, &error);
- g_assert_no_error (error);
- g_assert_cmpint (g_strv_length (proxies), ==, 1);
- g_assert_cmpstr (proxies[0], ==, "http://proxy.example.com:8080");
- g_strfreev (proxies);
-
- proxies = g_proxy_resolver_lookup (resolver, "ftp://five.example.com/",
- NULL, &error);
- g_assert_no_error (error);
- g_assert_cmpint (g_strv_length (proxies), ==, 1);
- g_assert_cmpstr (proxies[0], ==, "ftp://proxy-f.example.com:6060");
- g_strfreev (proxies);
+ test_proxy_uri_common ();
}
static void
@@ -154,10 +115,7 @@ test_proxy_socks (gpointer fixture,
gconstpointer user_data)
{
GSettings *settings, *child;
- GProxyResolver *resolver;
const gchar *ignore_hosts[2] = { "127.0.0.1", NULL };
- gchar **proxies;
- GError *error = NULL;
settings = g_settings_new (GNOME_PROXY_SETTINGS_SCHEMA);
g_settings_set_enum (settings, GNOME_PROXY_MODE_KEY, G_DESKTOP_PROXY_MODE_MANUAL);
@@ -170,107 +128,14 @@ test_proxy_socks (gpointer fixture,
g_object_unref (child);
g_object_unref (settings);
- resolver = g_proxy_resolver_get_default ();
-
- proxies = g_proxy_resolver_lookup (resolver, "http://one.example.com/",
- NULL, &error);
- g_assert_no_error (error);
- g_assert_cmpint (g_strv_length (proxies), ==, 3);
- g_assert_cmpstr (proxies[0], ==, "socks5://proxy.example.com:1234");
- g_assert_cmpstr (proxies[1], ==, "socks4a://proxy.example.com:1234");
- g_assert_cmpstr (proxies[2], ==, "socks4://proxy.example.com:1234");
- g_strfreev (proxies);
-
- proxies = g_proxy_resolver_lookup (resolver, "wednesday://two.example.com/",
- NULL, &error);
- g_assert_no_error (error);
- g_assert_cmpint (g_strv_length (proxies), ==, 3);
- g_assert_cmpstr (proxies[0], ==, "socks5://proxy.example.com:1234");
- g_assert_cmpstr (proxies[1], ==, "socks4a://proxy.example.com:1234");
- g_assert_cmpstr (proxies[2], ==, "socks4://proxy.example.com:1234");
- g_strfreev (proxies);
-
- proxies = g_proxy_resolver_lookup (resolver, "http://127.0.0.1/",
- NULL, &error);
- g_assert_no_error (error);
- g_assert_cmpint (g_strv_length (proxies), ==, 1);
- g_assert_cmpstr (proxies[0], ==, "direct://");
- g_strfreev (proxies);
+ test_proxy_socks_common ();
}
-static const char *ignore_hosts[] = {
- ".bbb.xx",
- "*.ccc.xx",
- "ddd.xx",
- "*.eee.xx:8000",
- "127.0.0.0/24",
- "10.0.0.1:8000",
- "::1",
- "fe80::/10"
-};
-static const int n_ignore_hosts = G_N_ELEMENTS (ignore_hosts);
-
-static const struct {
- const char *uri;
- const char *proxy;
-} ignore_tests[] = {
- { "http://aaa.xx/", "http://localhost:8080" },
- { "http://aaa.xx:8000/", "http://localhost:8080" },
- { "http://www.aaa.xx/", "http://localhost:8080" },
- { "http://www.aaa.xx:8000/", "http://localhost:8080" },
- { "https://aaa.xx/", "http://localhost:8080" },
- { "http://bbb.xx/", "direct://" },
- { "http://www.bbb.xx/", "direct://" },
- { "http://bbb.xx:8000/", "direct://" },
- { "http://www.bbb.xx:8000/", "direct://" },
- { "https://bbb.xx/", "direct://" },
- { "http://nobbb.xx/", "http://localhost:8080" },
- { "http://www.nobbb.xx/", "http://localhost:8080" },
- { "http://nobbb.xx:8000/", "http://localhost:8080" },
- { "http://www.nobbb.xx:8000/", "http://localhost:8080" },
- { "https://nobbb.xx/", "http://localhost:8080" },
- { "http://ccc.xx/", "direct://" },
- { "http://www.ccc.xx/", "direct://" },
- { "http://ccc.xx:8000/", "direct://" },
- { "http://www.ccc.xx:8000/", "direct://" },
- { "https://ccc.xx/", "direct://" },
- { "http://ddd.xx/", "direct://" },
- { "http://ddd.xx:8000/", "direct://" },
- { "http://www.ddd.xx/", "direct://" },
- { "http://www.ddd.xx:8000/", "direct://" },
- { "https://ddd.xx/", "direct://" },
- { "http://eee.xx/", "http://localhost:8080" },
- { "http://eee.xx:8000/", "direct://" },
- { "http://www.eee.xx/", "http://localhost:8080" },
- { "http://www.eee.xx:8000/", "direct://" },
- { "https://eee.xx/", "http://localhost:8080" },
- { "http://1.2.3.4/", "http://localhost:8080" },
- { "http://127.0.0.1/", "direct://" },
- { "http://127.0.0.2/", "direct://" },
- { "http://127.0.0.255/", "direct://" },
- { "http://127.0.1.0/", "http://localhost:8080" },
- { "http://10.0.0.1/", "http://localhost:8080" },
- { "http://10.0.0.1:8000/", "direct://" },
- { "http://[::1]/", "direct://" },
- { "http://[::1]:80/", "direct://" },
- { "http://[::1:1]/", "http://localhost:8080" },
- { "http://[::1:1]:80/", "http://localhost:8080" },
- { "http://[fe80::1]/", "direct://" },
- { "http://[fe80::1]:80/", "direct://" },
- { "http://[fec0::1]/", "http://localhost:8080" },
- { "http://[fec0::1]:80/", "http://localhost:8080" }
-};
-static const int n_ignore_tests = G_N_ELEMENTS (ignore_tests);
-
static void
test_proxy_ignore (gpointer fixture,
gconstpointer user_data)
{
GSettings *settings, *http;
- GProxyResolver *resolver;
- GError *error = NULL;
- char **proxies;
- int i;
settings = g_settings_new (GNOME_PROXY_SETTINGS_SCHEMA);
g_settings_set_enum (settings, GNOME_PROXY_MODE_KEY, G_DESKTOP_PROXY_MODE_MANUAL);
@@ -284,17 +149,7 @@ test_proxy_ignore (gpointer fixture,
g_object_unref (http);
g_object_unref (settings);
- resolver = g_proxy_resolver_get_default ();
-
- for (i = 0; i < n_ignore_tests; i++)
- {
- proxies = g_proxy_resolver_lookup (resolver, ignore_tests[i].uri,
- NULL, &error);
- g_assert_no_error (error);
-
- g_assert_cmpstr (proxies[0], ==, ignore_tests[i].proxy);
- g_strfreev (proxies);
- }
+ test_proxy_ignore_common (FALSE);
}
int
diff --git a/proxy/tests/libproxy.c b/proxy/tests/libproxy.c
new file mode 100644
index 0000000..b2f6de8
--- /dev/null
+++ b/proxy/tests/libproxy.c
@@ -0,0 +1,91 @@
+/* GLibProxyResolver tests
+ *
+ * Copyright 2011-2013 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+#include <gio/gio.h>
+
+#include "common.c"
+
+static void
+reset_proxy_settings (gpointer fixture,
+ gconstpointer user_data)
+{
+ g_unsetenv ("http_proxy");
+ g_unsetenv ("HTTP_PROXY");
+ g_unsetenv ("https_proxy");
+ g_unsetenv ("HTTPS_PROXY");
+ g_unsetenv ("ftp_proxy");
+ g_unsetenv ("FTP_PROXY");
+ g_unsetenv ("no_proxy");
+ g_unsetenv ("NO_PROXY");
+}
+
+static void
+test_proxy_uri (gpointer fixture,
+ gconstpointer user_data)
+{
+ g_setenv ("http_proxy", "http://proxy.example.com:8080", TRUE);
+ g_setenv ("https_proxy", "http://proxy-s.example.com:7070", TRUE);
+ g_setenv ("ftp_proxy", "ftp://proxy-f.example.com:6060", TRUE);
+
+ test_proxy_uri_common ();
+}
+
+static void
+test_proxy_socks (gpointer fixture,
+ gconstpointer user_data)
+{
+ g_setenv ("http_proxy", "socks://proxy.example.com:1234", TRUE);
+ g_setenv ("no_proxy", "127.0.0.1", TRUE);
+
+ test_proxy_socks_common ();
+}
+
+static void
+test_proxy_ignore (gpointer fixture,
+ gconstpointer user_data)
+{
+ gchar *no_proxy = g_strjoinv (",", (gchar **) ignore_hosts);
+
+ g_setenv ("http_proxy", "http://localhost:8080", TRUE);
+ g_setenv ("no_proxy", no_proxy, TRUE);
+ g_free (no_proxy);
+
+ test_proxy_ignore_common (TRUE);
+}
+
+int
+main (int argc,
+ char *argv[])
+{
+ g_test_init (&argc, &argv, NULL);
+
+ /* Unset variables that would make libproxy try to use gconf or ksettings */
+ g_unsetenv ("GNOME_DESKTOP_SESSION_ID");
+ g_unsetenv ("DESKTOP_SESSION");
+ g_unsetenv ("KDE_FULL_SESSION");
+
+ g_test_add_vtable ("/proxy/libproxy/uri", 0, NULL,
+ reset_proxy_settings, test_proxy_uri, NULL);
+ g_test_add_vtable ("/proxy/libproxy/socks", 0, NULL,
+ reset_proxy_settings, test_proxy_socks, NULL);
+ g_test_add_vtable ("/proxy/libproxy/ignore", 0, NULL,
+ reset_proxy_settings, test_proxy_ignore, NULL);
+
+ return g_test_run();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]