[libgdata/offline-testing] tests: BROKEN add proxy resolver support
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgdata/offline-testing] tests: BROKEN add proxy resolver support
- Date: Tue, 30 Jul 2013 08:26:01 +0000 (UTC)
commit e408a03d749a524be345f51ef9de75aa2bac29ab
Author: Philip Withnall <philip tecnocode co uk>
Date: Sat Jul 6 18:18:18 2013 +0100
tests: BROKEN add proxy resolver support
Test attempt to route all traffic through a local mock proxy, which
would allow us to use a port above 1024 and hence not run as root.
No such luck. I don't understand GIOExtensions enough and can't get
them to behave. Plus there are mysterious crashes inside GObject.
gdata/tests/Makefile.am | 2 +
gdata/tests/common.c | 13 +++++
gdata/tests/mock-proxy.c | 129 +++++++++++++++++++++++++++++++++++++++++++++
gdata/tests/mock-proxy.h | 50 +++++++++++++++++
gdata/tests/mock-server.c | 5 ++
5 files changed, 199 insertions(+), 0 deletions(-)
---
diff --git a/gdata/tests/Makefile.am b/gdata/tests/Makefile.am
index 986c3a2..f431014 100644
--- a/gdata/tests/Makefile.am
+++ b/gdata/tests/Makefile.am
@@ -23,6 +23,8 @@ noinst_PROGRAMS = $(TEST_PROGS)
TEST_SRCS = \
common.c \
common.h \
+ mock-proxy.c \
+ mock-proxy.h \
mock-resolver.c \
mock-resolver.h \
mock-server.c \
diff --git a/gdata/tests/common.c b/gdata/tests/common.c
index 72306d1..fe8f297 100644
--- a/gdata/tests/common.c
+++ b/gdata/tests/common.c
@@ -25,6 +25,7 @@
#include <libxml/xmlsave.h>
#include "common.h"
+#include "mock-proxy.h"
#include "mock-server.h"
/* %TRUE if there's no Internet connection, so we should only run local tests */
@@ -55,11 +56,23 @@ void
gdata_test_init (int argc, char **argv)
{
gint i;
+ GList *extensions, *l;
+ GIOExtensionPoint *extension_point;
#if !GLIB_CHECK_VERSION (2, 35, 0)
g_type_init ();
#endif
+ _gdata_mock_proxy_resolver_get_type (); /* TODO */
+
+ g_setenv ("GIO_USE_PROXY_RESOLVER", "gdata-mock", TRUE);
+ extension_point = g_io_extension_point_lookup (G_PROXY_RESOLVER_EXTENSION_POINT_NAME);
+ g_assert (extension_point != NULL);
+ extensions = g_io_extension_point_get_extensions (extension_point);
+ for (l = extensions; l != NULL; l = l->next) {
+ g_message ("Extension: %s, %i", g_io_extension_get_name (l->data),
g_io_extension_get_priority (l->data));
+ }
+
/* Parse the custom options */
for (i = 1; i < argc; i++) {
if (strcmp ("--no-internet", argv[i]) == 0 || strcmp ("-n", argv[i]) == 0) {
diff --git a/gdata/tests/mock-proxy.c b/gdata/tests/mock-proxy.c
new file mode 100644
index 0000000..8217f11
--- /dev/null
+++ b/gdata/tests/mock-proxy.c
@@ -0,0 +1,129 @@
+/* GIO - GLib Input, Output and Streaming Library
+ *
+ * Copyright (C) 2010 Collabora, Ltd.
+ *
+ * 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, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Nicolas Dufresne <nicolas dufresne collabora co uk>
+ */
+
+#include "config.h"
+
+#include "mock-proxy.h"
+
+#include <glib.h>
+#include <gio/gio.h>
+
+struct _GDataMockProxyResolver {
+ GObject parent_instance;
+};
+
+static void gdata_mock_proxy_resolver_iface_init (GProxyResolverInterface *iface);
+
+#define gdata_mock_proxy_resolver_get_type _gdata_mock_proxy_resolver_get_type
+G_DEFINE_TYPE_WITH_CODE (GDataMockProxyResolver, gdata_mock_proxy_resolver, G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (G_TYPE_PROXY_RESOLVER,
+ gdata_mock_proxy_resolver_iface_init)
+ { GIOExtensionPoint *ep = g_io_extension_point_register
(G_PROXY_RESOLVER_EXTENSION_POINT_NAME);
+ g_io_extension_point_set_required_type (ep, G_TYPE_PROXY_RESOLVER); /* HACK to ensure the extension
point's registered */ }
+ g_io_extension_point_implement (G_PROXY_RESOLVER_EXTENSION_POINT_NAME,
+ g_define_type_id,
+ "gdata-mock",
+ 1000))
+
+static void
+gdata_mock_proxy_resolver_finalize (GObject *object)
+{
+ /* must chain up */
+ G_OBJECT_CLASS (gdata_mock_proxy_resolver_parent_class)->finalize (object);
+}
+
+static void
+gdata_mock_proxy_resolver_init (GDataMockProxyResolver *resolver)
+{
+}
+
+static gboolean
+gdata_mock_proxy_resolver_is_supported (GProxyResolver *resolver)
+{
+ return TRUE;
+}
+
+static gchar **
+gdata_mock_proxy_resolver_lookup (GProxyResolver *resolver,
+ const gchar *uri,
+ GCancellable *cancellable,
+ GError **error)
+{
+ gchar **proxies;
+
+ if (g_cancellable_set_error_if_cancelled (cancellable, error))
+ return NULL;
+
+ proxies = g_new0 (gchar *, 2);
+ proxies[0] = g_strdup ("https://127.0.0.1:443");
+
+ return proxies;
+}
+
+static void
+gdata_mock_proxy_resolver_lookup_async (GProxyResolver *resolver,
+ const gchar *uri,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GError *error = NULL;
+ GTask *task;
+ gchar **proxies;
+
+ task = g_task_new (resolver, cancellable, callback, user_data);
+
+ proxies = gdata_mock_proxy_resolver_lookup (resolver, uri, cancellable, &error);
+ if (proxies)
+ g_task_return_pointer (task, proxies, (GDestroyNotify) g_strfreev);
+ else
+ g_task_return_error (task, error);
+ g_object_unref (task);
+}
+
+static gchar **
+gdata_mock_proxy_resolver_lookup_finish (GProxyResolver *resolver,
+ GAsyncResult *result,
+ GError **error)
+{
+ g_return_val_if_fail (g_task_is_valid (result, resolver), NULL);
+
+ return g_task_propagate_pointer (G_TASK (result), error);
+}
+
+static void
+gdata_mock_proxy_resolver_class_init (GDataMockProxyResolverClass *resolver_class)
+{
+ GObjectClass *object_class;
+
+ object_class = G_OBJECT_CLASS (resolver_class);
+ object_class->finalize = gdata_mock_proxy_resolver_finalize;
+}
+
+static void
+gdata_mock_proxy_resolver_iface_init (GProxyResolverInterface *iface)
+{
+ iface->is_supported = gdata_mock_proxy_resolver_is_supported;
+ iface->lookup = gdata_mock_proxy_resolver_lookup;
+ iface->lookup_async = gdata_mock_proxy_resolver_lookup_async;
+ iface->lookup_finish = gdata_mock_proxy_resolver_lookup_finish;
+}
diff --git a/gdata/tests/mock-proxy.h b/gdata/tests/mock-proxy.h
new file mode 100644
index 0000000..b688c7f
--- /dev/null
+++ b/gdata/tests/mock-proxy.h
@@ -0,0 +1,50 @@
+/* GIO - GLib Input, Output and Streaming Library
+ *
+ * Copyright (C) 2010 Collabora, Ltd.
+ *
+ * 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, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Nicolas Dufresne <nicolas dufresne collabora co uk>
+ */
+
+#ifndef __GDATA_MOCK_PROXY_RESOLVER_H__
+#define __GDATA_MOCK_PROXY_RESOLVER_H__
+
+#include <gio/gio.h>
+
+G_BEGIN_DECLS
+
+#define G_TYPE_DUMMY_PROXY_RESOLVER (_gdata_mock_proxy_resolver_get_type ())
+#define GDATA_MOCK_PROXY_RESOLVER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o),
G_TYPE_DUMMY_PROXY_RESOLVER, GDataMockProxyResolver))
+#define GDATA_MOCK_PROXY_RESOLVER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), G_TYPE_DUMMY_PROXY_RESOLVER,
GDataMockProxyResolverClass))
+#define G_IS_DUMMY_PROXY_RESOLVER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_TYPE_DUMMY_PROXY_RESOLVER))
+#define G_IS_DUMMY_PROXY_RESOLVER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), G_TYPE_DUMMY_PROXY_RESOLVER))
+#define GDATA_MOCK_PROXY_RESOLVER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), G_TYPE_DUMMY_PROXY_RESOLVER,
GDataMockProxyResolverClass))
+
+typedef struct _GDataMockProxyResolver GDataMockProxyResolver;
+typedef struct _GDataMockProxyResolverClass GDataMockProxyResolverClass;
+
+
+struct _GDataMockProxyResolverClass {
+ GObjectClass parent_class;
+};
+
+GType _gdata_mock_proxy_resolver_get_type (void);
+
+
+G_END_DECLS
+
+#endif /* __GDATA_MOCK_PROXY_RESOLVER_H__ */
diff --git a/gdata/tests/mock-server.c b/gdata/tests/mock-server.c
index e702f4b..ed34b67 100644
--- a/gdata/tests/mock-server.c
+++ b/gdata/tests/mock-server.c
@@ -845,6 +845,7 @@ gdata_mock_server_run (GDataMockServer *self)
struct sockaddr_in sock;
SoupAddress *addr;
GMainContext *thread_context;
+ GProxyResolver *proxy;
g_return_if_fail (GDATA_IS_MOCK_SERVER (self));
g_return_if_fail (priv->resolver == NULL);
@@ -859,6 +860,10 @@ gdata_mock_server_run (GDataMockServer *self)
addr = soup_address_new_from_sockaddr ((struct sockaddr *) &sock, sizeof (sock));
g_assert (addr != NULL);
+proxy = g_proxy_resolver_get_default ();
+g_message ("Resolver %p: %s", proxy, (proxy != NULL) ? G_OBJECT_TYPE_NAME (proxy) : "null");
+
+
/* Set up the resolver, adding TODO */
priv->resolver = gdata_mock_resolver_new ();
gdata_mock_resolver_add_A (priv->resolver, "www.google.com", "127.0.0.1"); /* TODO: get IP from soup
*/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]