[libsoup] Fix runtime critical warning when loading an authenticated proxy resource from the disk cache
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup] Fix runtime critical warning when loading an authenticated proxy resource from the disk cache
- Date: Thu, 8 Oct 2015 06:57:35 +0000 (UTC)
commit dceacf693e898bb2409f1b3ab69bcb63fdb3adb3
Author: Carlos Garcia Campos <cgarcia igalia com>
Date: Mon Oct 5 13:09:57 2015 +0200
Fix runtime critical warning when loading an authenticated proxy resource from the disk cache
It happens when we load a resource that goes through an authenticated
proxy, and is cached in the disk. If the same resource is loaded again
the response is sent from the cache, and the auth manager tries to get
the proxy uri from the item connection. But there's no connection when
loading cached resources.
https://bugzilla.gnome.org/show_bug.cgi?id=756076
libsoup/soup-auth-manager.c | 10 +++---
tests/proxy-test.c | 79 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 84 insertions(+), 5 deletions(-)
---
diff --git a/libsoup/soup-auth-manager.c b/libsoup/soup-auth-manager.c
index 21e2065..6aa4dad 100644
--- a/libsoup/soup-auth-manager.c
+++ b/libsoup/soup-auth-manager.c
@@ -474,12 +474,12 @@ authenticate_auth (SoupAuthManager *manager, SoupAuth *auth,
queue = soup_session_get_queue (priv->session);
item = soup_message_queue_lookup (queue, msg);
- if (item) {
- uri = soup_connection_get_proxy_uri (item->conn);
- soup_message_queue_item_unref (item);
- } else
- uri = NULL;
+ if (!item)
+ return;
+ /* When loaded from the disk cache, the connection is NULL. */
+ uri = item->conn ? soup_connection_get_proxy_uri (item->conn) : NULL;
+ soup_message_queue_item_unref (item);
if (!uri)
return;
} else
diff --git a/tests/proxy-test.c b/tests/proxy-test.c
index 2632551..1d68aa0 100644
--- a/tests/proxy-test.c
+++ b/tests/proxy-test.c
@@ -322,6 +322,84 @@ do_proxy_redirect_test (void)
soup_test_session_abort_unref (session);
}
+static void
+do_proxy_auth_request (const char *url, SoupSession *session, gboolean do_read)
+{
+ SoupRequest *request;
+ SoupMessage *msg;
+ GInputStream *stream;
+ GError *error = NULL;
+
+ request = soup_session_request (session, url, NULL);
+ msg = soup_request_http_get_message (SOUP_REQUEST_HTTP (request));
+
+ stream = soup_test_request_send (request, NULL, 0, &error);
+ g_assert_no_error (error);
+ g_clear_error (&error);
+
+ if (do_read) {
+ char buffer[256];
+ gsize nread;
+
+ do {
+ g_input_stream_read_all (stream, buffer, sizeof (buffer), &nread,
+ NULL, &error);
+ g_assert_no_error (error);
+ g_clear_error (&error);
+ } while (nread > 0);
+ }
+
+ soup_test_request_close_stream (request, stream, NULL, &error);
+ g_assert_no_error (error);
+ g_clear_error (&error);
+ g_object_unref (stream);
+
+ debug_printf (1, " %d %s\n", msg->status_code, msg->reason_phrase);
+ soup_test_assert_message_status (msg, SOUP_STATUS_OK);
+
+ g_object_unref (msg);
+ g_object_unref (request);
+}
+
+static void
+do_proxy_auth_cache_test (void)
+{
+ SoupSession *session;
+ char *cache_dir;
+ SoupCache *cache;
+ char *url;
+
+ g_test_bug ("756076");
+
+ SOUP_TEST_SKIP_IF_NO_APACHE;
+
+ cache_dir = g_dir_make_tmp ("cache-test-XXXXXX", NULL);
+ debug_printf (2, " Caching to %s\n", cache_dir);
+ cache = soup_cache_new (cache_dir, SOUP_CACHE_SINGLE_USER);
+ g_free (cache_dir);
+
+ session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC,
+ SOUP_SESSION_PROXY_RESOLVER, proxy_resolvers[AUTH_PROXY],
+ SOUP_SESSION_USE_THREAD_CONTEXT, TRUE,
+ SOUP_SESSION_ADD_FEATURE, cache,
+ NULL);
+ g_signal_connect (session, "authenticate",
+ G_CALLBACK (authenticate), NULL);
+
+ url = g_strconcat (HTTP_SERVER, "/Basic/realm1/", NULL);
+
+ debug_printf (1, " GET %s via %s (from network)\n", url, proxy_names[AUTH_PROXY]);
+ do_proxy_auth_request (url, session, TRUE);
+ soup_cache_flush (cache);
+
+ debug_printf (1, " GET %s via %s (from cache)\n", url, proxy_names[AUTH_PROXY]);
+ do_proxy_auth_request (url, session, FALSE);
+
+ g_free (url);
+ soup_test_session_abort_unref (session);
+ g_object_unref (cache);
+}
+
int
main (int argc, char **argv)
{
@@ -355,6 +433,7 @@ main (int argc, char **argv)
g_test_add_data_func ("/proxy/fragment", base_uri, do_proxy_fragment_test);
g_test_add_func ("/proxy/redirect", do_proxy_redirect_test);
+ g_test_add_func ("/proxy/auth-cache", do_proxy_auth_cache_test);
ret = g_test_run ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]