[glib] proxy-test: work even when the upstream DNS lies
- From: Dan Winship <danw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] proxy-test: work even when the upstream DNS lies
- Date: Fri, 18 May 2012 16:19:31 +0000 (UTC)
commit 8df2b96a6910aa557a6db2b1b5e618f3ace70f11
Author: Dan Winship <danw gnome org>
Date: Fri May 18 12:18:23 2012 -0400
proxy-test: work even when the upstream DNS lies
Rather than depending on the host's DNS configuration to properly
return an error for a non-existent hostname, just substitute in
a dummy GResolver implementation that does it for us.
gio/tests/proxy-test.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 60 insertions(+), 0 deletions(-)
---
diff --git a/gio/tests/proxy-test.c b/gio/tests/proxy-test.c
index 079b9ad..0527608 100644
--- a/gio/tests/proxy-test.c
+++ b/gio/tests/proxy-test.c
@@ -674,6 +674,62 @@ create_server (ServerData *data, GCancellable *cancellable)
}
+/******************************************************************/
+/* Now a GResolver implementation, so the can't-resolve test will */
+/* pass even if you have an evil DNS-faking ISP. */
+/******************************************************************/
+
+typedef GResolver GFakeResolver;
+typedef GResolverClass GFakeResolverClass;
+
+G_DEFINE_TYPE (GFakeResolver, g_fake_resolver, G_TYPE_RESOLVER)
+
+static void
+g_fake_resolver_init (GFakeResolver *gtr)
+{
+}
+
+static GList *
+g_fake_resolver_lookup_by_name (GResolver *resolver,
+ const gchar *hostname,
+ GCancellable *cancellable,
+ GError **error)
+{
+ /* This is only ever called with lookups that are expected to
+ * fail.
+ */
+ g_set_error (error,
+ G_RESOLVER_ERROR,
+ G_RESOLVER_ERROR_NOT_FOUND,
+ "Not found");
+ return NULL;
+}
+
+static void
+g_fake_resolver_lookup_by_name_async (GResolver *resolver,
+ const gchar *hostname,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ g_simple_async_report_error_in_idle (G_OBJECT (resolver),
+ callback, user_data,
+ G_RESOLVER_ERROR,
+ G_RESOLVER_ERROR_NOT_FOUND,
+ "Not found");
+}
+
+static void
+g_fake_resolver_class_init (GFakeResolverClass *fake_class)
+{
+ GResolverClass *resolver_class = G_RESOLVER_CLASS (fake_class);
+
+ resolver_class->lookup_by_name = g_fake_resolver_lookup_by_name;
+ resolver_class->lookup_by_name_async = g_fake_resolver_lookup_by_name_async;
+}
+
+
+
/****************************************/
/* We made it! Now for the actual test! */
/****************************************/
@@ -1030,6 +1086,7 @@ int
main (int argc,
char *argv[])
{
+ GResolver *fake_resolver;
GCancellable *cancellable;
gint result;
@@ -1047,6 +1104,9 @@ main (int argc,
g_proxy_b_get_type ();
g_setenv ("GIO_USE_PROXY_RESOLVER", "test", TRUE);
+ fake_resolver = g_object_new (g_fake_resolver_get_type (), NULL);
+ g_resolver_set_default (fake_resolver);
+
cancellable = g_cancellable_new ();
create_server (&server, cancellable);
create_proxy (&proxy_a, 'a', "alpha", cancellable);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]