diff options
Diffstat (limited to 'tests/sniffing-test.c')
-rw-r--r-- | tests/sniffing-test.c | 541 |
1 files changed, 297 insertions, 244 deletions
diff --git a/tests/sniffing-test.c b/tests/sniffing-test.c index dd4eb4aa..32fad9fc 100644 --- a/tests/sniffing-test.c +++ b/tests/sniffing-test.c @@ -16,8 +16,8 @@ server_callback (SoupServer *server, SoupMessage *msg, { GError *error = NULL; char *query_key; - char *contents; - gsize length = 0, offset; + SoupBuffer *response = NULL; + gsize offset; gboolean empty_response = FALSE; if (msg->method != SOUP_METHOD_GET) { @@ -40,41 +40,35 @@ server_callback (SoupServer *server, SoupMessage *msg, } if (!strcmp (path, "/mbox")) { - if (empty_response) { - contents = g_strdup (""); - length = 0; - } else { - g_file_get_contents (SRCDIR "/resources/mbox", - &contents, &length, - &error); - } - - if (error) { - g_error ("%s", error->message); - g_error_free (error); - exit (1); + if (!empty_response) { + response = soup_test_load_resource ("mbox", &error); + g_assert_no_error (error); } soup_message_headers_append (msg->response_headers, "Content-Type", "text/plain"); } - if (g_str_has_prefix (path, "/text_or_binary/")) { + if (g_str_has_prefix (path, "/nosniff/")) { char *base_name = g_path_get_basename (path); - char *file_name = g_strdup_printf (SRCDIR "/resources/%s", base_name); - - g_file_get_contents (file_name, - &contents, &length, - &error); + response = soup_test_load_resource (base_name, &error); + g_assert_no_error (error); g_free (base_name); - g_free (file_name); - if (error) { - g_error ("%s", error->message); - g_error_free (error); - exit (1); - } + soup_message_headers_append (msg->response_headers, + "X-Content-Type-Options", "nosniff"); + + soup_message_headers_append (msg->response_headers, + "Content-Type", "no/sniffing-allowed"); + } + + if (g_str_has_prefix (path, "/text_or_binary/") || g_str_has_prefix (path, "/apache_bug/")) { + char *base_name = g_path_get_basename (path); + + response = soup_test_load_resource (base_name, &error); + g_assert_no_error (error); + g_free (base_name); soup_message_headers_append (msg->response_headers, "Content-Type", "text/plain"); @@ -82,20 +76,10 @@ server_callback (SoupServer *server, SoupMessage *msg, if (g_str_has_prefix (path, "/unknown/")) { char *base_name = g_path_get_basename (path); - char *file_name = g_strdup_printf (SRCDIR "/resources/%s", base_name); - - g_file_get_contents (file_name, - &contents, &length, - &error); + response = soup_test_load_resource (base_name, &error); + g_assert_no_error (error); g_free (base_name); - g_free (file_name); - - if (error) { - g_error ("%s", error->message); - g_error_free (error); - exit (1); - } soup_message_headers_append (msg->response_headers, "Content-Type", "UNKNOWN/unknown"); @@ -106,20 +90,10 @@ server_callback (SoupServer *server, SoupMessage *msg, char *ptr; char *base_name = g_path_get_basename (path); - char *file_name = g_strdup_printf (SRCDIR "/resources/%s", base_name); - - g_file_get_contents (file_name, - &contents, &length, - &error); + response = soup_test_load_resource (base_name, &error); + g_assert_no_error (error); g_free (base_name); - g_free (file_name); - - if (error) { - g_error ("%s", error->message); - g_error_free (error); - exit (1); - } /* Hack to allow passing type in the URI */ ptr = g_strrstr (components[2], "_"); @@ -132,20 +106,10 @@ server_callback (SoupServer *server, SoupMessage *msg, if (g_str_has_prefix (path, "/multiple_headers/")) { char *base_name = g_path_get_basename (path); - char *file_name = g_strdup_printf (SRCDIR "/resources/%s", base_name); - - g_file_get_contents (file_name, - &contents, &length, - &error); + response = soup_test_load_resource (base_name, &error); + g_assert_no_error (error); g_free (base_name); - g_free (file_name); - - if (error) { - g_error ("%s", error->message); - g_error_free (error); - exit (1); - } soup_message_headers_append (msg->response_headers, "Content-Type", "text/xml"); @@ -153,15 +117,18 @@ server_callback (SoupServer *server, SoupMessage *msg, "Content-Type", "text/plain"); } - for (offset = 0; offset < length; offset += 500) { - soup_message_body_append (msg->response_body, - SOUP_MEMORY_COPY, - contents + offset, - MIN(500, length - offset)); + if (response) { + for (offset = 0; offset < response->length; offset += 500) { + soup_message_body_append (msg->response_body, + SOUP_MEMORY_COPY, + response->data + offset, + MIN (500, response->length - offset)); + } + + soup_buffer_free (response); } - soup_message_body_complete (msg->response_body); - g_free (contents); + soup_message_body_complete (msg->response_body); } static gboolean @@ -181,10 +148,8 @@ content_sniffed (SoupMessage *msg, char *content_type, GHashTable *params, gpoin debug_printf (2, " content-sniffed -> %s\n", content_type); - if (g_object_get_data (G_OBJECT (msg), "got-chunk")) { - debug_printf (1, " got-chunk got emitted before content-sniffed\n"); - errors++; - } + soup_test_assert (g_object_get_data (G_OBJECT (msg), "got-chunk") == NULL, + "got-chunk got emitted before content-sniffed"); g_object_set_data (G_OBJECT (msg), "content-sniffed", GINT_TO_POINTER (TRUE)); @@ -202,10 +167,8 @@ got_headers (SoupMessage *msg, gpointer data) debug_printf (2, " got-headers\n"); - if (g_object_get_data (G_OBJECT (msg), "content-sniffed")) { - debug_printf (1, " content-sniffed got emitted before got-headers\n"); - errors++; - } + soup_test_assert (g_object_get_data (G_OBJECT (msg), "content-sniffed") == NULL, + "content-sniffed got emitted before got-headers"); g_object_set_data (G_OBJECT (msg), "got-headers", GINT_TO_POINTER (TRUE)); @@ -233,13 +196,6 @@ got_chunk (SoupMessage *msg, SoupBuffer *chunk, gpointer data) } static void -finished (SoupSession *session, SoupMessage *msg, gpointer data) -{ - GMainLoop *loop = (GMainLoop*)data; - g_main_loop_quit (loop); -} - -static void do_signals_test (gboolean should_content_sniff, gboolean should_pause, gboolean should_accumulate, @@ -248,9 +204,7 @@ do_signals_test (gboolean should_content_sniff, { SoupURI *uri = soup_uri_new_with_base (base_uri, "/mbox"); SoupMessage *msg = soup_message_new_from_uri ("GET", uri); - GMainLoop *loop = g_main_loop_new (NULL, TRUE); - char *contents; - gsize length; + SoupBuffer *expected; GError *error = NULL; SoupBuffer *body = NULL; @@ -283,34 +237,21 @@ do_signals_test (gboolean should_content_sniff, "signal::content_sniffed", content_sniffed, GINT_TO_POINTER (should_pause), NULL); - g_object_ref (msg); - soup_session_queue_message (session, msg, finished, loop); - - g_main_loop_run (loop); - - if (!should_content_sniff && - g_object_get_data (G_OBJECT (msg), "content-sniffed")) { - debug_printf (1, " content-sniffed got emitted without a sniffer\n"); - errors++; - } else if (should_content_sniff && - !g_object_get_data (G_OBJECT (msg), "content-sniffed")) { - debug_printf (1, " content-sniffed did not get emitted\n"); - errors++; - } + soup_session_send_message (session, msg); - if (empty_response) { - contents = g_strdup (""); - length = 0; + if (should_content_sniff) { + soup_test_assert (g_object_get_data (G_OBJECT (msg), "content-sniffed") != NULL, + "content-sniffed did not get emitted"); } else { - g_file_get_contents (SRCDIR "/resources/mbox", - &contents, &length, - &error); + soup_test_assert (g_object_get_data (G_OBJECT (msg), "content-sniffed") == NULL, + "content-sniffed got emitted without a sniffer"); } - if (error) { - g_error ("%s", error->message); - g_error_free (error); - exit (1); + if (empty_response) + expected = soup_buffer_new (SOUP_MEMORY_STATIC, "", 0); + else { + expected = soup_test_load_resource ("mbox", &error); + g_assert_no_error (error); } if (!should_accumulate && chunk_data) @@ -318,17 +259,12 @@ do_signals_test (gboolean should_content_sniff, else if (msg->response_body) body = soup_message_body_flatten (msg->response_body); - if (body && body->length != length) { - debug_printf (1, " lengths do not match\n"); - errors++; + if (body) { + soup_assert_cmpmem (body->data, body->length, + expected->data, expected->length); } - if (body && memcmp (body->data, contents, length)) { - debug_printf (1, " downloaded data does not match\n"); - errors++; - } - - g_free (contents); + soup_buffer_free (expected); if (body) soup_buffer_free (body); if (chunk_data) { @@ -338,7 +274,42 @@ do_signals_test (gboolean should_content_sniff, soup_uri_free (uri); g_object_unref (msg); - g_main_loop_unref (loop); +} + +static void +do_signals_tests (gconstpointer data) +{ + gboolean should_content_sniff = GPOINTER_TO_INT (data); + + if (!should_content_sniff) + soup_session_remove_feature_by_type (session, SOUP_TYPE_CONTENT_SNIFFER); + + do_signals_test (should_content_sniff, + FALSE, FALSE, FALSE, FALSE); + do_signals_test (should_content_sniff, + FALSE, FALSE, TRUE, FALSE); + do_signals_test (should_content_sniff, + FALSE, TRUE, FALSE, FALSE); + do_signals_test (should_content_sniff, + FALSE, TRUE, TRUE, FALSE); + + do_signals_test (should_content_sniff, + TRUE, TRUE, FALSE, FALSE); + do_signals_test (should_content_sniff, + TRUE, TRUE, TRUE, FALSE); + do_signals_test (should_content_sniff, + TRUE, FALSE, FALSE, FALSE); + do_signals_test (should_content_sniff, + TRUE, FALSE, TRUE, FALSE); + + /* FIXME g_test_bug ("587907") */ + do_signals_test (should_content_sniff, + TRUE, TRUE, FALSE, TRUE); + do_signals_test (should_content_sniff, + TRUE, TRUE, TRUE, TRUE); + + if (!should_content_sniff) + soup_session_add_feature_by_type (session, SOUP_TYPE_CONTENT_SNIFFER); } static void @@ -347,102 +318,125 @@ sniffing_content_sniffed (SoupMessage *msg, const char *content_type, { char **sniffed_type = (char **)data; GString *full_header; - GList *keys; - GList *iter; - - if (params == NULL) { - *sniffed_type = g_strdup (content_type); - return; - } + GHashTableIter iter; + gpointer key, value; full_header = g_string_new (content_type); - g_string_append (full_header, "; "); - - keys = g_hash_table_get_keys (params); - for (iter = keys; iter != NULL; iter = iter->next) { - const gchar *value = (const gchar*) g_hash_table_lookup (params, iter->data); + g_hash_table_iter_init (&iter, params); + while (g_hash_table_iter_next (&iter, &key, &value)) { + if (full_header->len) + g_string_append (full_header, "; "); soup_header_g_string_append_param (full_header, - (const gchar*) iter->data, - value); + (const char *) key, + (const char *) value); } - *sniffed_type = full_header->str; - - g_string_free (full_header, FALSE); - g_list_free (keys); + *sniffed_type = g_string_free (full_header, FALSE); } static void test_sniffing (const char *path, const char *expected_type) { - SoupURI *uri = soup_uri_new_with_base (base_uri, path); - SoupMessage *msg = soup_message_new_from_uri ("GET", uri); - GMainLoop *loop = g_main_loop_new (NULL, TRUE); + SoupURI *uri; + SoupMessage *msg; + SoupRequest *req; + GInputStream *stream; char *sniffed_type = NULL; + const char *req_sniffed_type; + GError *error = NULL; - debug_printf (1, "test_sniffing(\"%s\", \"%s\")\n", path, expected_type); + uri = soup_uri_new_with_base (base_uri, path); + msg = soup_message_new_from_uri ("GET", uri); g_signal_connect (msg, "content-sniffed", G_CALLBACK (sniffing_content_sniffed), &sniffed_type); - g_object_ref (msg); - - soup_session_queue_message (session, msg, finished, loop); - - g_main_loop_run (loop); + soup_session_send_message (session, msg); + g_assert_cmpstr (sniffed_type, ==, expected_type); + g_free (sniffed_type); + g_object_unref (msg); - if (!sniffed_type) { - debug_printf (1, " message was not sniffed!\n"); - errors++; - } else if (strcmp (sniffed_type, expected_type) != 0) { - debug_printf (1, " sniffing failed! expected %s, got %s\n", - expected_type, sniffed_type); - errors++; + req = soup_session_request_uri (session, uri, NULL); + stream = soup_test_request_send (req, NULL, 0, &error); + if (stream) { + soup_test_request_close_stream (req, stream, NULL, &error); + g_object_unref (stream); } - g_free (sniffed_type); + g_assert_no_error (error); + g_clear_error (&error); + + req_sniffed_type = soup_request_get_content_type (req); + g_assert_cmpstr (req_sniffed_type, ==, expected_type); + g_object_unref (req); soup_uri_free (uri); - g_object_unref (msg); - g_main_loop_unref (loop); } static void -test_disabled (const char *path) +do_sniffing_test (gconstpointer data) { - SoupURI *uri = soup_uri_new_with_base (base_uri, path); - SoupMessage *msg = soup_message_new_from_uri ("GET", uri); - GMainLoop *loop = g_main_loop_new (NULL, TRUE); + const char *path_and_result = data; + char **parts; + + parts = g_strsplit (path_and_result, " => ", -1); + g_assert (parts && parts[0] && parts[1] && !parts[2]); + + test_sniffing (parts[0], parts[1]); + g_strfreev (parts); +} + +static void +test_disabled (gconstpointer data) +{ + const char *path = data; + SoupURI *uri; + SoupMessage *msg; + SoupRequest *req; + GInputStream *stream; char *sniffed_type = NULL; + const char *sniffed_content_type; + GError *error = NULL; - soup_message_disable_feature (msg, SOUP_TYPE_CONTENT_SNIFFER); + g_test_bug ("574773"); - debug_printf (1, "test_disabled(\"%s\")\n", path); + uri = soup_uri_new_with_base (base_uri, path); + + msg = soup_message_new_from_uri ("GET", uri); + soup_message_disable_feature (msg, SOUP_TYPE_CONTENT_SNIFFER); g_signal_connect (msg, "content-sniffed", G_CALLBACK (sniffing_content_sniffed), &sniffed_type); - g_object_ref (msg); - - soup_session_queue_message (session, msg, finished, loop); + soup_session_send_message (session, msg); - g_main_loop_run (loop); + g_assert_null (sniffed_type); + g_object_unref (msg); - if (sniffed_type) { - debug_printf (1, " message was sniffed!\n"); - errors++; - g_free (sniffed_type); + req = soup_session_request_uri (session, uri, NULL); + msg = soup_request_http_get_message (SOUP_REQUEST_HTTP (req)); + soup_message_disable_feature (msg, SOUP_TYPE_CONTENT_SNIFFER); + g_object_unref (msg); + stream = soup_test_request_send (req, NULL, 0, &error); + if (stream) { + soup_test_request_close_stream (req, stream, NULL, &error); + g_object_unref (stream); } + g_assert_no_error (error); + + sniffed_content_type = soup_request_get_content_type (req); + g_assert_cmpstr (sniffed_content_type, ==, NULL); + + g_object_unref (req); soup_uri_free (uri); - g_object_unref (msg); - g_main_loop_unref (loop); } int main (int argc, char **argv) { SoupServer *server; + int ret; test_init (argc, argv, NULL); @@ -451,112 +445,171 @@ main (int argc, char **argv) base_uri = soup_uri_new ("http://127.0.0.1/"); soup_uri_set_port (base_uri, soup_server_get_port (server)); - session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL); - - /* No sniffer, no content_sniffed should be emitted */ - do_signals_test (FALSE, FALSE, FALSE, FALSE, FALSE); - do_signals_test (FALSE, FALSE, FALSE, TRUE, FALSE); - do_signals_test (FALSE, FALSE, TRUE, FALSE, FALSE); - do_signals_test (FALSE, FALSE, TRUE, TRUE, FALSE); - - do_signals_test (FALSE, TRUE, TRUE, FALSE, FALSE); - do_signals_test (FALSE, TRUE, TRUE, TRUE, FALSE); - do_signals_test (FALSE, TRUE, FALSE, FALSE, FALSE); - do_signals_test (FALSE, TRUE, FALSE, TRUE, FALSE); - - /* Tests that the signals are correctly emitted for empty - * responses; see - * http://bugzilla.gnome.org/show_bug.cgi?id=587907 */ - - do_signals_test (FALSE, TRUE, TRUE, FALSE, TRUE); - do_signals_test (FALSE, TRUE, TRUE, TRUE, TRUE); - + session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, + SOUP_SESSION_USE_THREAD_CONTEXT, TRUE, + NULL); soup_session_add_feature_by_type (session, SOUP_TYPE_CONTENT_SNIFFER); - /* Now, with a sniffer, content_sniffed must be emitted after - * got-headers, and before got-chunk. - */ - do_signals_test (TRUE, FALSE, FALSE, FALSE, FALSE); - do_signals_test (TRUE, FALSE, FALSE, TRUE, FALSE); - do_signals_test (TRUE, FALSE, TRUE, FALSE, FALSE); - do_signals_test (TRUE, FALSE, TRUE, TRUE, FALSE); - - do_signals_test (TRUE, TRUE, TRUE, FALSE, FALSE); - do_signals_test (TRUE, TRUE, TRUE, TRUE, FALSE); - do_signals_test (TRUE, TRUE, FALSE, FALSE, FALSE); - do_signals_test (TRUE, TRUE, FALSE, TRUE, FALSE); - - /* Empty response tests */ - do_signals_test (TRUE, TRUE, TRUE, FALSE, TRUE); - do_signals_test (TRUE, TRUE, TRUE, TRUE, TRUE); - - /* Test the text_or_binary sniffing path */ + g_test_add_data_func ("/sniffing/signals/no-sniffer", + GINT_TO_POINTER (FALSE), + do_signals_tests); + g_test_add_data_func ("/sniffing/signals/with-sniffer", + GINT_TO_POINTER (TRUE), + do_signals_tests); + + /* Test the apache bug sniffing path */ + g_test_add_data_func ("/sniffing/apache-bug/binary", + "/apache_bug/text_binary.txt => application/octet-stream", + do_sniffing_test); + g_test_add_data_func ("/sniffing/apache-bug/text", + "/apache_bug/text.txt => text/plain", + do_sniffing_test); + + /* X-Content-Type-Options: nosniff */ + g_test_add_data_func ("/sniffing/nosniff", + "nosniff/home.gif => no/sniffing-allowed", + do_sniffing_test); /* GIF is a 'safe' type */ - test_sniffing ("/text_or_binary/home.gif", "image/gif"); + g_test_add_data_func ("/sniffing/type/gif", + "text_or_binary/home.gif => image/gif", + do_sniffing_test); /* With our current code, no sniffing is done using GIO, so * the mbox will be identified as text/plain; should we change * this? */ - test_sniffing ("/text_or_binary/mbox", "text/plain"); + g_test_add_data_func ("/sniffing/type/mbox", + "text_or_binary/mbox => text/plain", + do_sniffing_test); /* HTML is considered unsafe for this algorithm, since it is * scriptable, so going from text/plain to text/html is * considered 'privilege escalation' */ - test_sniffing ("/text_or_binary/test.html", "text/plain"); + g_test_add_data_func ("/sniffing/type/html-in-text-context", + "text_or_binary/test.html => text/plain", + do_sniffing_test); /* text/plain with binary content and unknown pattern should be - * application/octet-stream */ - test_sniffing ("/text_or_binary/text_binary.txt", "application/octet-stream"); + * application/octet-stream + */ + g_test_add_data_func ("/sniffing/type/text-binary", + "text_or_binary/text_binary.txt => application/octet-stream", + do_sniffing_test); - /* text/plain with binary content and scriptable pattern should be - * application/octet-stream to avoid 'privilege escalation' */ - test_sniffing ("/text_or_binary/html_binary.html", "application/octet-stream"); + /* text/html with binary content and scriptable pattern should be + * application/octet-stream to avoid 'privilege escalation' + */ + g_test_add_data_func ("/sniffing/type/html-binary", + "text_or_binary/html_binary.html => application/octet-stream", + do_sniffing_test); /* text/plain with binary content and non scriptable known pattern should - * be the given type */ - test_sniffing ("/text_or_binary/ps_binary.ps", "application/postscript"); + * be the given type + */ + g_test_add_data_func ("/sniffing/type/ps", + "text_or_binary/ps_binary.ps => application/postscript", + do_sniffing_test); /* Test the unknown sniffing path */ - - test_sniffing ("/unknown/test.html", "text/html"); - test_sniffing ("/unknown/home.gif", "image/gif"); - test_sniffing ("/unknown/mbox", "text/plain"); - test_sniffing ("/unknown/text_binary.txt", "application/octet-stream"); + g_test_add_data_func ("/sniffing/type/unknown-html", + "unknown/test.html => text/html", + do_sniffing_test); + g_test_add_data_func ("/sniffing/type/unknown-gif", + "unknown/home.gif => image/gif", + do_sniffing_test); + g_test_add_data_func ("/sniffing/type/unknown-mbox", + "unknown/mbox => text/plain", + do_sniffing_test); + g_test_add_data_func ("/sniffing/type/unknown-binary", + "unknown/text_binary.txt => application/octet-stream", + do_sniffing_test); + /* FIXME g_test_bug ("715126") */ + g_test_add_data_func ("/sniffing/type/unknown-leading-space", + "unknown/leading_space.html => text/html", + do_sniffing_test); /* Test the XML sniffing path */ - - test_sniffing ("/type/text_xml/home.gif", "text/xml"); - test_sniffing ("/type/anice_type+xml/home.gif", "anice/type+xml"); - test_sniffing ("/type/application_xml/home.gif", "application/xml"); - - /* Test the image sniffing path */ - - test_sniffing ("/type/image_png/home.gif", "image/gif"); + g_test_add_data_func ("/sniffing/type/xml", + "type/text_xml/home.gif => text/xml", + do_sniffing_test); + g_test_add_data_func ("/sniffing/type/xml+xml", + "type/anice_type+xml/home.gif => anice/type+xml", + do_sniffing_test); + g_test_add_data_func ("/sniffing/type/application-xml", + "type/application_xml/home.gif => application/xml", + do_sniffing_test); /* Test the feed or html path */ + g_test_add_data_func ("/sniffing/type/html/html", + "type/text_html/test.html => text/html", + do_sniffing_test); + g_test_add_data_func ("/sniffing/type/html/rss", + "type/text_html/rss20.xml => application/rss+xml", + do_sniffing_test); + g_test_add_data_func ("/sniffing/type/html/atom", + "type/text_html/atom.xml => application/atom+xml", + do_sniffing_test); + g_test_add_data_func ("/sniffing/type/html/rdf", + "type/text_html/feed.rdf => application/rss+xml", + do_sniffing_test); - test_sniffing ("/type/text_html/test.html", "text/html"); - test_sniffing ("/type/text_html/rss20.xml", "application/rss+xml"); - test_sniffing ("/type/text_html/atom.xml", "application/atom+xml"); + /* Test the image sniffing path */ + g_test_add_data_func ("/sniffing/type/image/gif", + "type/image_png/home.gif => image/gif", + do_sniffing_test); + g_test_add_data_func ("/sniffing/type/image/png", + "type/image_gif/home.png => image/png", + do_sniffing_test); + g_test_add_data_func ("/sniffing/type/image/jpeg", + "type/image_png/home.jpg => image/jpeg", + do_sniffing_test); + g_test_add_data_func ("/sniffing/type/image/webp", + "type/image_png/tux.webp => image/webp", + do_sniffing_test); + + /* Test audio and video sniffing path */ + g_test_add_data_func ("/sniffing/type/audio/wav", + "type/audio_mpeg/test.wav => audio/wave", + do_sniffing_test); + g_test_add_data_func ("/sniffing/type/audio/aiff", + "type/audio_mpeg/test.aiff => audio/aiff", + do_sniffing_test); + g_test_add_data_func ("/sniffing/type/audio/ogg", + "type/audio_mpeg/test.ogg => application/ogg", + do_sniffing_test); + g_test_add_data_func ("/sniffing/type/video/webm", + "type/video_theora/test.webm => video/webm", + do_sniffing_test); + + /* Test the MP4 sniffing path */ + g_test_add_data_func ("/sniffing/type/video/mp4", + "unknown/test.mp4 => video/mp4", + do_sniffing_test); /* The spec tells us to only use the last Content-Type header */ - - test_sniffing ("/multiple_headers/home.gif", "image/gif"); + g_test_add_data_func ("/sniffing/multiple-headers", + "multiple_headers/home.gif => image/gif", + do_sniffing_test); /* Test that we keep the parameters when sniffing */ - test_sniffing ("/type/text_html; charset=UTF-8/test.html", "text/html; charset=UTF-8"); + g_test_add_data_func ("/sniffing/parameters", + "type/text_html; charset=UTF-8/test.html => text/html; charset=UTF-8", + do_sniffing_test); /* Test that disabling the sniffer works correctly */ + g_test_add_data_func ("/sniffing/disabled", + "/text_or_binary/home.gif", + test_disabled); - test_disabled ("/text_or_binary/home.gif"); + ret = g_test_run (); soup_uri_free (base_uri); soup_test_session_abort_unref (session); soup_test_server_quit_unref (server); + test_cleanup (); - return errors != 0; + return ret; } |