|
rpm-build |
4f3c61 |
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
|
|
rpm-build |
4f3c61 |
/*
|
|
rpm-build |
4f3c61 |
* Copyright (C) 2007 Red Hat, Inc.
|
|
rpm-build |
4f3c61 |
* Copyright (C) 2011 Igalia, S.L.
|
|
rpm-build |
4f3c61 |
*/
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
#include "test-utils.h"
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
SoupServer *server;
|
|
rpm-build |
4f3c61 |
SoupURI *base_uri;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
server_callback (SoupServer *server, SoupMessage *msg,
|
|
rpm-build |
4f3c61 |
const char *path, GHashTable *query,
|
|
rpm-build |
4f3c61 |
SoupClientContext *context, gpointer data)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
const char *accept_encoding, *options;
|
|
rpm-build |
4f3c61 |
GSList *codings;
|
|
rpm-build |
4f3c61 |
SoupBuffer *response = NULL;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
options = soup_message_headers_get_one (msg->request_headers,
|
|
rpm-build |
4f3c61 |
"X-Test-Options");
|
|
rpm-build |
4f3c61 |
if (!options)
|
|
rpm-build |
4f3c61 |
options = "";
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
accept_encoding = soup_message_headers_get_list (msg->request_headers,
|
|
rpm-build |
4f3c61 |
"Accept-Encoding");
|
|
rpm-build |
4f3c61 |
if (accept_encoding && !soup_header_contains (options, "force-encode"))
|
|
rpm-build |
4f3c61 |
codings = soup_header_parse_quality_list (accept_encoding, NULL);
|
|
rpm-build |
4f3c61 |
else
|
|
rpm-build |
4f3c61 |
codings = NULL;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
if (codings) {
|
|
rpm-build |
4f3c61 |
gboolean claim_deflate, claim_gzip;
|
|
rpm-build |
4f3c61 |
const char *extension = NULL, *encoding = NULL;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
claim_deflate = g_slist_find_custom (codings, "deflate", (GCompareFunc)g_ascii_strcasecmp) != NULL;
|
|
rpm-build |
4f3c61 |
claim_gzip = g_slist_find_custom (codings, "gzip", (GCompareFunc)g_ascii_strcasecmp) != NULL;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
if (claim_gzip && (!claim_deflate ||
|
|
rpm-build |
4f3c61 |
(!soup_header_contains (options, "prefer-deflate-zlib") &&
|
|
rpm-build |
4f3c61 |
!soup_header_contains (options, "prefer-deflate-raw")))) {
|
|
rpm-build |
4f3c61 |
extension = "gz";
|
|
rpm-build |
4f3c61 |
encoding = "gzip";
|
|
rpm-build |
4f3c61 |
} else if (claim_deflate) {
|
|
rpm-build |
4f3c61 |
if (soup_header_contains (options, "prefer-deflate-raw")) {
|
|
rpm-build |
4f3c61 |
extension = "raw";
|
|
rpm-build |
4f3c61 |
encoding = "deflate";
|
|
rpm-build |
4f3c61 |
} else {
|
|
rpm-build |
4f3c61 |
extension = "zlib";
|
|
rpm-build |
4f3c61 |
encoding = "deflate";
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
if (extension && encoding) {
|
|
rpm-build |
4f3c61 |
char *resource;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
resource = g_strdup_printf ("%s.%s", path, extension);
|
|
rpm-build |
4f3c61 |
response = soup_test_load_resource (resource, NULL);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
if (response) {
|
|
rpm-build |
4f3c61 |
soup_message_headers_append (msg->response_headers,
|
|
rpm-build |
4f3c61 |
"Content-Encoding",
|
|
rpm-build |
4f3c61 |
encoding);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
g_free (resource);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
soup_header_free_list (codings);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
if (!response)
|
|
rpm-build |
4f3c61 |
response = soup_test_load_resource (path, NULL);
|
|
rpm-build |
4f3c61 |
if (!response) {
|
|
rpm-build |
4f3c61 |
/* If path.gz exists but can't be read, we'll send back
|
|
rpm-build |
4f3c61 |
* the error with "Content-Encoding: gzip" but there's
|
|
rpm-build |
4f3c61 |
* no body, so, eh.
|
|
rpm-build |
4f3c61 |
*/
|
|
rpm-build |
4f3c61 |
soup_message_set_status (msg, SOUP_STATUS_NOT_FOUND);
|
|
rpm-build |
4f3c61 |
return;
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
if (soup_header_contains (options, "force-encode")) {
|
|
rpm-build |
4f3c61 |
const gchar *encoding = "gzip";
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
if (soup_header_contains (options, "prefer-deflate-zlib") ||
|
|
rpm-build |
4f3c61 |
soup_header_contains (options, "prefer-deflate-raw"))
|
|
rpm-build |
4f3c61 |
encoding = "deflate";
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
soup_message_headers_replace (msg->response_headers,
|
|
rpm-build |
4f3c61 |
"Content-Encoding",
|
|
rpm-build |
4f3c61 |
encoding);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
/* Content-Type matches the "real" format, not the sent format */
|
|
rpm-build |
4f3c61 |
if (g_str_has_suffix (path, ".gz")) {
|
|
rpm-build |
4f3c61 |
soup_message_headers_append (msg->response_headers,
|
|
rpm-build |
4f3c61 |
"Content-Type",
|
|
rpm-build |
4f3c61 |
"application/gzip");
|
|
rpm-build |
4f3c61 |
} else {
|
|
rpm-build |
4f3c61 |
soup_message_headers_append (msg->response_headers,
|
|
rpm-build |
4f3c61 |
"Content-Type",
|
|
rpm-build |
4f3c61 |
"text/plain");
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
soup_message_set_status (msg, SOUP_STATUS_OK);
|
|
rpm-build |
4f3c61 |
soup_message_headers_set_encoding (msg->response_headers, SOUP_ENCODING_CHUNKED);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
if (!soup_header_contains (options, "empty"))
|
|
rpm-build |
4f3c61 |
soup_message_body_append_buffer (msg->response_body, response);
|
|
rpm-build |
4f3c61 |
soup_buffer_free (response);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
if (soup_header_contains (options, "trailing-junk")) {
|
|
rpm-build |
4f3c61 |
soup_message_body_append (msg->response_body, SOUP_MEMORY_COPY,
|
|
rpm-build |
4f3c61 |
options, strlen (options));
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
soup_message_body_complete (msg->response_body);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
typedef struct {
|
|
rpm-build |
4f3c61 |
SoupSession *session;
|
|
rpm-build |
4f3c61 |
SoupMessage *msg;
|
|
rpm-build |
4f3c61 |
SoupRequest *req;
|
|
rpm-build |
4f3c61 |
SoupBuffer *response;
|
|
rpm-build |
4f3c61 |
} CodingTestData;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
typedef enum {
|
|
rpm-build |
4f3c61 |
CODING_TEST_DEFAULT = 0,
|
|
rpm-build |
4f3c61 |
CODING_TEST_NO_DECODER = (1 << 0),
|
|
rpm-build |
4f3c61 |
CODING_TEST_REQUEST_API = (1 << 1),
|
|
rpm-build |
4f3c61 |
CODING_TEST_EMPTY = (1 << 2)
|
|
rpm-build |
4f3c61 |
} CodingTestType;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
typedef enum {
|
|
rpm-build |
4f3c61 |
NO_CHECK,
|
|
rpm-build |
4f3c61 |
EXPECT_DECODED,
|
|
rpm-build |
4f3c61 |
EXPECT_NOT_DECODED
|
|
rpm-build |
4f3c61 |
} MessageContentStatus;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
check_response (CodingTestData *data,
|
|
rpm-build |
4f3c61 |
const char *expected_encoding,
|
|
rpm-build |
4f3c61 |
const char *expected_content_type,
|
|
rpm-build |
4f3c61 |
MessageContentStatus status,
|
|
rpm-build |
4f3c61 |
GByteArray *body)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
const char *coding, *type;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
soup_test_assert_message_status (data->msg, SOUP_STATUS_OK);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
coding = soup_message_headers_get_one (data->msg->response_headers, "Content-Encoding");
|
|
rpm-build |
4f3c61 |
g_assert_cmpstr (coding, ==, expected_encoding);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
if (status != NO_CHECK) {
|
|
rpm-build |
4f3c61 |
if (status == EXPECT_DECODED)
|
|
rpm-build |
4f3c61 |
g_assert_true (soup_message_get_flags (data->msg) & SOUP_MESSAGE_CONTENT_DECODED);
|
|
rpm-build |
4f3c61 |
else
|
|
rpm-build |
4f3c61 |
g_assert_false (soup_message_get_flags (data->msg) & SOUP_MESSAGE_CONTENT_DECODED);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
type = soup_message_headers_get_one (data->msg->response_headers, "Content-Type");
|
|
rpm-build |
4f3c61 |
g_assert_cmpstr (type, ==, expected_content_type);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
if (body) {
|
|
rpm-build |
4f3c61 |
soup_assert_cmpmem (body->data,
|
|
rpm-build |
4f3c61 |
body->len,
|
|
rpm-build |
4f3c61 |
data->response->data,
|
|
rpm-build |
4f3c61 |
data->response->length);
|
|
rpm-build |
4f3c61 |
} else {
|
|
rpm-build |
4f3c61 |
soup_assert_cmpmem (data->msg->response_body->data,
|
|
rpm-build |
4f3c61 |
data->msg->response_body->length,
|
|
rpm-build |
4f3c61 |
data->response->data,
|
|
rpm-build |
4f3c61 |
data->response->length);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
setup_coding_test (CodingTestData *data, gconstpointer test_data)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
CodingTestType test_type = GPOINTER_TO_INT (test_data);
|
|
rpm-build |
4f3c61 |
SoupMessage *msg;
|
|
rpm-build |
4f3c61 |
SoupURI *uri;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
data->session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC,
|
|
rpm-build |
4f3c61 |
SOUP_SESSION_USE_THREAD_CONTEXT, TRUE,
|
|
rpm-build |
4f3c61 |
NULL);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
uri = soup_uri_new_with_base (base_uri, "/mbox");
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
if (test_type & CODING_TEST_EMPTY)
|
|
rpm-build |
4f3c61 |
data->response = soup_buffer_new (SOUP_MEMORY_STATIC, "", 0);
|
|
rpm-build |
4f3c61 |
else {
|
|
rpm-build |
4f3c61 |
msg = soup_message_new_from_uri ("GET", uri);
|
|
rpm-build |
4f3c61 |
soup_session_send_message (data->session, msg);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
data->response = soup_message_body_flatten (msg->response_body);
|
|
rpm-build |
4f3c61 |
g_object_unref (msg);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
if (test_type & CODING_TEST_REQUEST_API) {
|
|
rpm-build |
4f3c61 |
SoupRequestHTTP *reqh;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
reqh = soup_session_request_http_uri (data->session, "GET", uri, NULL);
|
|
rpm-build |
4f3c61 |
data->req = SOUP_REQUEST (reqh);
|
|
rpm-build |
4f3c61 |
data->msg = soup_request_http_get_message (reqh);
|
|
rpm-build |
4f3c61 |
} else
|
|
rpm-build |
4f3c61 |
data->msg = soup_message_new_from_uri ("GET", uri);
|
|
rpm-build |
4f3c61 |
soup_uri_free (uri);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
if (! (test_type & CODING_TEST_NO_DECODER))
|
|
rpm-build |
4f3c61 |
soup_session_add_feature_by_type (data->session, SOUP_TYPE_CONTENT_DECODER);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
teardown_coding_test (CodingTestData *data, gconstpointer test_data)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
soup_buffer_free (data->response);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
g_clear_object (&data->req);
|
|
rpm-build |
4f3c61 |
g_object_unref (data->msg);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
soup_test_session_abort_unref (data->session);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
do_coding_test_plain (CodingTestData *data, gconstpointer test_data)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
soup_session_send_message (data->session, data->msg);
|
|
rpm-build |
4f3c61 |
check_response (data, NULL, "text/plain", EXPECT_NOT_DECODED, NULL);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
do_coding_test_gzip (CodingTestData *data, gconstpointer test_data)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
soup_session_send_message (data->session, data->msg);
|
|
rpm-build |
4f3c61 |
check_response (data, "gzip", "text/plain", EXPECT_DECODED, NULL);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
do_coding_test_gzip_with_junk (CodingTestData *data, gconstpointer test_data)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
g_test_bug ("606352");
|
|
rpm-build |
4f3c61 |
g_test_bug ("676477");
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
soup_message_headers_append (data->msg->request_headers,
|
|
rpm-build |
4f3c61 |
"X-Test-Options", "trailing-junk");
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
soup_session_send_message (data->session, data->msg);
|
|
rpm-build |
4f3c61 |
check_response (data, "gzip", "text/plain", EXPECT_DECODED, NULL);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
do_coding_test_gzip_bad_server (CodingTestData *data, gconstpointer test_data)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
g_test_bug ("613361");
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
soup_message_headers_append (data->msg->request_headers,
|
|
rpm-build |
4f3c61 |
"X-Test-Options", "force-encode");
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
soup_session_send_message (data->session, data->msg);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
/* Failed content-decoding should have left the body untouched
|
|
rpm-build |
4f3c61 |
* from what the server sent... which happens to be the
|
|
rpm-build |
4f3c61 |
* uncompressed data.
|
|
rpm-build |
4f3c61 |
*/
|
|
rpm-build |
4f3c61 |
check_response (data, "gzip", "text/plain", EXPECT_NOT_DECODED, NULL);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
do_coding_test_deflate (CodingTestData *data, gconstpointer test_data)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
soup_message_headers_append (data->msg->request_headers,
|
|
rpm-build |
4f3c61 |
"X-Test-Options", "prefer-deflate-zlib");
|
|
rpm-build |
4f3c61 |
soup_session_send_message (data->session, data->msg);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
check_response (data, "deflate", "text/plain", EXPECT_DECODED, NULL);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
do_coding_test_deflate_with_junk (CodingTestData *data, gconstpointer test_data)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
g_test_bug ("606352");
|
|
rpm-build |
4f3c61 |
g_test_bug ("676477");
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
soup_message_headers_append (data->msg->request_headers,
|
|
rpm-build |
4f3c61 |
"X-Test-Options", "prefer-deflate-zlib, trailing-junk");
|
|
rpm-build |
4f3c61 |
soup_session_send_message (data->session, data->msg);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
check_response (data, "deflate", "text/plain", EXPECT_DECODED, NULL);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
do_coding_test_deflate_bad_server (CodingTestData *data, gconstpointer test_data)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
g_test_bug ("613361");
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
soup_message_headers_append (data->msg->request_headers,
|
|
rpm-build |
4f3c61 |
"X-Test-Options", "force-encode, prefer-deflate-zlib");
|
|
rpm-build |
4f3c61 |
soup_session_send_message (data->session, data->msg);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
check_response (data, "deflate", "text/plain", EXPECT_NOT_DECODED, NULL);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
do_coding_test_deflate_raw (CodingTestData *data, gconstpointer test_data)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
soup_message_headers_append (data->msg->request_headers,
|
|
rpm-build |
4f3c61 |
"X-Test-Options", "prefer-deflate-raw");
|
|
rpm-build |
4f3c61 |
soup_session_send_message (data->session, data->msg);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
check_response (data, "deflate", "text/plain", EXPECT_DECODED, NULL);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
do_coding_test_deflate_raw_bad_server (CodingTestData *data, gconstpointer test_data)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
g_test_bug ("613361");
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
soup_message_headers_append (data->msg->request_headers,
|
|
rpm-build |
4f3c61 |
"X-Test-Options", "force-encode, prefer-deflate-raw");
|
|
rpm-build |
4f3c61 |
soup_session_send_message (data->session, data->msg);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
check_response (data, "deflate", "text/plain", EXPECT_NOT_DECODED, NULL);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
read_finished (GObject *stream, GAsyncResult *result, gpointer user_data)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
gssize *nread = user_data;
|
|
rpm-build |
4f3c61 |
GError *error = NULL;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
*nread = g_input_stream_read_finish (G_INPUT_STREAM (stream),
|
|
rpm-build |
4f3c61 |
result, &error);
|
|
rpm-build |
4f3c61 |
g_assert_no_error (error);
|
|
rpm-build |
4f3c61 |
g_clear_error (&error);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
do_single_coding_req_test (CodingTestData *data,
|
|
rpm-build |
4f3c61 |
const char *expected_encoding,
|
|
rpm-build |
4f3c61 |
const char *expected_content_type,
|
|
rpm-build |
4f3c61 |
MessageContentStatus status)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
GInputStream *stream;
|
|
rpm-build |
4f3c61 |
GByteArray *body;
|
|
rpm-build |
4f3c61 |
guchar buf[1024];
|
|
rpm-build |
4f3c61 |
gssize nread;
|
|
rpm-build |
4f3c61 |
GError *error = NULL;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
body = g_byte_array_new ();
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
stream = soup_test_request_send (data->req, NULL, 0, &error);
|
|
rpm-build |
4f3c61 |
if (!stream) {
|
|
rpm-build |
4f3c61 |
g_assert_no_error (error);
|
|
rpm-build |
4f3c61 |
g_error_free (error);
|
|
rpm-build |
4f3c61 |
return;
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
do {
|
|
rpm-build |
4f3c61 |
nread = -2;
|
|
rpm-build |
4f3c61 |
g_input_stream_read_async (stream, buf, sizeof (buf),
|
|
rpm-build |
4f3c61 |
G_PRIORITY_DEFAULT,
|
|
rpm-build |
4f3c61 |
NULL, read_finished, &nread);
|
|
rpm-build |
4f3c61 |
while (nread == -2)
|
|
rpm-build |
4f3c61 |
g_main_context_iteration (NULL, TRUE);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
if (nread > 0)
|
|
rpm-build |
4f3c61 |
g_byte_array_append (body, buf, nread);
|
|
rpm-build |
4f3c61 |
} while (nread > 0);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
soup_test_request_close_stream (data->req, stream, NULL, &error);
|
|
rpm-build |
4f3c61 |
g_assert_no_error (error);
|
|
rpm-build |
4f3c61 |
g_clear_error (&error);
|
|
rpm-build |
4f3c61 |
g_object_unref (stream);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
check_response (data, expected_encoding, expected_content_type, status, body);
|
|
rpm-build |
4f3c61 |
g_byte_array_free (body, TRUE);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
do_coding_req_test_plain (CodingTestData *data, gconstpointer test_data)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
do_single_coding_req_test (data, NULL, "text/plain", EXPECT_NOT_DECODED);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
do_coding_req_test_gzip (CodingTestData *data, gconstpointer test_data)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
do_single_coding_req_test (data, "gzip", "text/plain", EXPECT_DECODED);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
do_coding_req_test_gzip_with_junk (CodingTestData *data, gconstpointer test_data)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
g_test_bug ("606352");
|
|
rpm-build |
4f3c61 |
g_test_bug ("676477");
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
soup_message_headers_append (data->msg->request_headers,
|
|
rpm-build |
4f3c61 |
"X-Test-Options", "trailing-junk");
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
do_single_coding_req_test (data, "gzip", "text/plain", EXPECT_DECODED);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
do_coding_req_test_gzip_bad_server (CodingTestData *data, gconstpointer test_data)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
g_test_bug ("613361");
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
soup_message_headers_append (data->msg->request_headers,
|
|
rpm-build |
4f3c61 |
"X-Test-Options", "force-encode");
|
|
rpm-build |
4f3c61 |
do_single_coding_req_test (data, "gzip", "text/plain", EXPECT_NOT_DECODED);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
do_coding_req_test_deflate (CodingTestData *data, gconstpointer test_data)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
soup_message_headers_append (data->msg->request_headers,
|
|
rpm-build |
4f3c61 |
"X-Test-Options", "prefer-deflate-zlib");
|
|
rpm-build |
4f3c61 |
do_single_coding_req_test (data, "deflate", "text/plain", EXPECT_DECODED);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
do_coding_req_test_deflate_with_junk (CodingTestData *data, gconstpointer test_data)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
g_test_bug ("606352");
|
|
rpm-build |
4f3c61 |
g_test_bug ("676477");
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
soup_message_headers_append (data->msg->request_headers,
|
|
rpm-build |
4f3c61 |
"X-Test-Options", "prefer-deflate-zlib, trailing-junk");
|
|
rpm-build |
4f3c61 |
do_single_coding_req_test (data, "deflate", "text/plain", EXPECT_DECODED);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
do_coding_req_test_deflate_bad_server (CodingTestData *data, gconstpointer test_data)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
g_test_bug ("613361");
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
soup_message_headers_append (data->msg->request_headers,
|
|
rpm-build |
4f3c61 |
"X-Test-Options", "force-encode, prefer-deflate-zlib");
|
|
rpm-build |
4f3c61 |
do_single_coding_req_test (data, "deflate", "text/plain", EXPECT_NOT_DECODED);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
do_coding_req_test_deflate_raw (CodingTestData *data, gconstpointer test_data)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
soup_message_headers_append (data->msg->request_headers,
|
|
rpm-build |
4f3c61 |
"X-Test-Options", "prefer-deflate-raw");
|
|
rpm-build |
4f3c61 |
do_single_coding_req_test (data, "deflate", "text/plain", EXPECT_DECODED);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
do_coding_req_test_deflate_raw_bad_server (CodingTestData *data, gconstpointer test_data)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
g_test_bug ("613361");
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
soup_message_headers_append (data->msg->request_headers,
|
|
rpm-build |
4f3c61 |
"X-Test-Options", "force-encode, prefer-deflate-raw");
|
|
rpm-build |
4f3c61 |
do_single_coding_req_test (data, "deflate", "text/plain", EXPECT_NOT_DECODED);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
do_coding_msg_empty_test (CodingTestData *data, gconstpointer test_data)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
g_test_bug ("697527");
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
soup_message_headers_append (data->msg->request_headers,
|
|
rpm-build |
4f3c61 |
"X-Test-Options", "empty");
|
|
rpm-build |
4f3c61 |
soup_session_send_message (data->session, data->msg);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
check_response (data, "gzip", "text/plain", EXPECT_NOT_DECODED, NULL);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
do_coding_req_empty_test (CodingTestData *data, gconstpointer test_data)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
g_test_bug ("697527");
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
soup_message_headers_append (data->msg->request_headers,
|
|
rpm-build |
4f3c61 |
"X-Test-Options", "empty");
|
|
rpm-build |
4f3c61 |
do_single_coding_req_test (data, "gzip", "text/plain", EXPECT_NOT_DECODED);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
int
|
|
rpm-build |
4f3c61 |
main (int argc, char **argv)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
int ret;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
test_init (argc, argv, NULL);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
server = soup_test_server_new (SOUP_TEST_SERVER_IN_THREAD);
|
|
rpm-build |
4f3c61 |
soup_server_add_handler (server, NULL, server_callback, NULL, NULL);
|
|
rpm-build |
4f3c61 |
base_uri = soup_test_server_get_uri (server, "http", NULL);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
g_test_add ("/coding/message/plain", CodingTestData,
|
|
rpm-build |
4f3c61 |
GINT_TO_POINTER (CODING_TEST_NO_DECODER),
|
|
rpm-build |
4f3c61 |
setup_coding_test, do_coding_test_plain, teardown_coding_test);
|
|
rpm-build |
4f3c61 |
g_test_add ("/coding/message/gzip", CodingTestData,
|
|
rpm-build |
4f3c61 |
GINT_TO_POINTER (CODING_TEST_DEFAULT),
|
|
rpm-build |
4f3c61 |
setup_coding_test, do_coding_test_gzip, teardown_coding_test);
|
|
rpm-build |
4f3c61 |
g_test_add ("/coding/message/gzip/with-junk", CodingTestData,
|
|
rpm-build |
4f3c61 |
GINT_TO_POINTER (CODING_TEST_DEFAULT),
|
|
rpm-build |
4f3c61 |
setup_coding_test, do_coding_test_gzip_with_junk, teardown_coding_test);
|
|
rpm-build |
4f3c61 |
g_test_add ("/coding/message/gzip/bad-server", CodingTestData,
|
|
rpm-build |
4f3c61 |
GINT_TO_POINTER (CODING_TEST_DEFAULT),
|
|
rpm-build |
4f3c61 |
setup_coding_test, do_coding_test_gzip_bad_server, teardown_coding_test);
|
|
rpm-build |
4f3c61 |
g_test_add ("/coding/message/deflate", CodingTestData,
|
|
rpm-build |
4f3c61 |
GINT_TO_POINTER (CODING_TEST_DEFAULT),
|
|
rpm-build |
4f3c61 |
setup_coding_test, do_coding_test_deflate, teardown_coding_test);
|
|
rpm-build |
4f3c61 |
g_test_add ("/coding/message/deflate/with-junk", CodingTestData,
|
|
rpm-build |
4f3c61 |
GINT_TO_POINTER (CODING_TEST_DEFAULT),
|
|
rpm-build |
4f3c61 |
setup_coding_test, do_coding_test_deflate_with_junk, teardown_coding_test);
|
|
rpm-build |
4f3c61 |
g_test_add ("/coding/message/deflate/bad-server", CodingTestData,
|
|
rpm-build |
4f3c61 |
GINT_TO_POINTER (CODING_TEST_DEFAULT),
|
|
rpm-build |
4f3c61 |
setup_coding_test, do_coding_test_deflate_bad_server, teardown_coding_test);
|
|
rpm-build |
4f3c61 |
g_test_add ("/coding/message/deflate-raw", CodingTestData,
|
|
rpm-build |
4f3c61 |
GINT_TO_POINTER (CODING_TEST_DEFAULT),
|
|
rpm-build |
4f3c61 |
setup_coding_test, do_coding_test_deflate_raw, teardown_coding_test);
|
|
rpm-build |
4f3c61 |
g_test_add ("/coding/message/deflate-raw/bad-server", CodingTestData,
|
|
rpm-build |
4f3c61 |
GINT_TO_POINTER (CODING_TEST_DEFAULT),
|
|
rpm-build |
4f3c61 |
setup_coding_test, do_coding_test_deflate_raw_bad_server, teardown_coding_test);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
g_test_add ("/coding/request/plain", CodingTestData,
|
|
rpm-build |
4f3c61 |
GINT_TO_POINTER (CODING_TEST_NO_DECODER | CODING_TEST_REQUEST_API),
|
|
rpm-build |
4f3c61 |
setup_coding_test, do_coding_req_test_plain, teardown_coding_test);
|
|
rpm-build |
4f3c61 |
g_test_add ("/coding/request/gzip", CodingTestData,
|
|
rpm-build |
4f3c61 |
GINT_TO_POINTER (CODING_TEST_REQUEST_API),
|
|
rpm-build |
4f3c61 |
setup_coding_test, do_coding_req_test_gzip, teardown_coding_test);
|
|
rpm-build |
4f3c61 |
g_test_add ("/coding/request/gzip/with-junk", CodingTestData,
|
|
rpm-build |
4f3c61 |
GINT_TO_POINTER (CODING_TEST_REQUEST_API),
|
|
rpm-build |
4f3c61 |
setup_coding_test, do_coding_req_test_gzip_with_junk, teardown_coding_test);
|
|
rpm-build |
4f3c61 |
g_test_add ("/coding/request/gzip/bad-server", CodingTestData,
|
|
rpm-build |
4f3c61 |
GINT_TO_POINTER (CODING_TEST_REQUEST_API),
|
|
rpm-build |
4f3c61 |
setup_coding_test, do_coding_req_test_gzip_bad_server, teardown_coding_test);
|
|
rpm-build |
4f3c61 |
g_test_add ("/coding/request/deflate", CodingTestData,
|
|
rpm-build |
4f3c61 |
GINT_TO_POINTER (CODING_TEST_REQUEST_API),
|
|
rpm-build |
4f3c61 |
setup_coding_test, do_coding_req_test_deflate, teardown_coding_test);
|
|
rpm-build |
4f3c61 |
g_test_add ("/coding/request/deflate/with-junk", CodingTestData,
|
|
rpm-build |
4f3c61 |
GINT_TO_POINTER (CODING_TEST_REQUEST_API),
|
|
rpm-build |
4f3c61 |
setup_coding_test, do_coding_req_test_deflate_with_junk, teardown_coding_test);
|
|
rpm-build |
4f3c61 |
g_test_add ("/coding/request/deflate/bad-server", CodingTestData,
|
|
rpm-build |
4f3c61 |
GINT_TO_POINTER (CODING_TEST_REQUEST_API),
|
|
rpm-build |
4f3c61 |
setup_coding_test, do_coding_req_test_deflate_bad_server, teardown_coding_test);
|
|
rpm-build |
4f3c61 |
g_test_add ("/coding/request/deflate-raw", CodingTestData,
|
|
rpm-build |
4f3c61 |
GINT_TO_POINTER (CODING_TEST_REQUEST_API),
|
|
rpm-build |
4f3c61 |
setup_coding_test, do_coding_req_test_deflate_raw, teardown_coding_test);
|
|
rpm-build |
4f3c61 |
g_test_add ("/coding/request/deflate-raw/bad-server", CodingTestData,
|
|
rpm-build |
4f3c61 |
GINT_TO_POINTER (CODING_TEST_REQUEST_API),
|
|
rpm-build |
4f3c61 |
setup_coding_test, do_coding_req_test_deflate_raw_bad_server, teardown_coding_test);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
g_test_add ("/coding/message/empty", CodingTestData,
|
|
rpm-build |
4f3c61 |
GINT_TO_POINTER (CODING_TEST_EMPTY),
|
|
rpm-build |
4f3c61 |
setup_coding_test, do_coding_msg_empty_test, teardown_coding_test);
|
|
rpm-build |
4f3c61 |
g_test_add ("/coding/request/empty", CodingTestData,
|
|
rpm-build |
4f3c61 |
GINT_TO_POINTER (CODING_TEST_REQUEST_API | CODING_TEST_EMPTY),
|
|
rpm-build |
4f3c61 |
setup_coding_test, do_coding_req_empty_test, teardown_coding_test);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
ret = g_test_run ();
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
soup_uri_free (base_uri);
|
|
rpm-build |
4f3c61 |
soup_test_server_quit_unref (server);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
test_cleanup ();
|
|
rpm-build |
4f3c61 |
return ret;
|
|
rpm-build |
4f3c61 |
}
|