summaryrefslogtreecommitdiff
path: root/tests/auth-test.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auth-test.c')
-rw-r--r--tests/auth-test.c474
1 files changed, 280 insertions, 194 deletions
diff --git a/tests/auth-test.c b/tests/auth-test.c
index 85c4d414..8ed5cead 100644
--- a/tests/auth-test.c
+++ b/tests/auth-test.c
@@ -2,6 +2,7 @@
#include "test-utils.h"
+static const char *base_uri;
static GMainLoop *loop;
typedef struct {
@@ -35,10 +36,6 @@ typedef struct {
guint final_status;
} SoupAuthTest;
-/* Will either point to main_tests or relogin_tests
- */
-static SoupAuthTest *current_tests;
-
static SoupAuthTest main_tests[] = {
{ "No auth available, should fail",
"Basic/realm1/", "", FALSE, "0", SOUP_STATUS_UNAUTHORIZED },
@@ -146,7 +143,12 @@ static SoupAuthTest main_tests[] = {
"Digest/realm1/not/", "1", FALSE, /* should not be used */ "1", SOUP_STATUS_UNAUTHORIZED },
{ "Make sure we've forgotten it",
- "Digest/realm1/", "", FALSE, "0", SOUP_STATUS_UNAUTHORIZED }
+ "Digest/realm1/", "", FALSE, "0", SOUP_STATUS_UNAUTHORIZED },
+
+ { "Fail with URI-embedded password, then use right password in the authenticate signal",
+ "Basic/realm3/", "43", TRUE, "43", SOUP_STATUS_OK },
+
+ { NULL }
};
static const char *auths[] = {
@@ -202,14 +204,12 @@ handler (SoupMessage *msg, gpointer data)
if (*expected) {
exp = *expected - '0';
- if (auth != exp) {
- debug_printf (1, " expected %s!\n", auths[exp]);
- errors++;
- }
+ soup_test_assert (auth == exp,
+ "expected %s", auths[exp]);
memmove (expected, expected + 1, strlen (expected));
} else {
- debug_printf (1, " expected to be finished\n");
- errors++;
+ soup_test_assert (*expected,
+ "expected to be finished");
}
}
@@ -217,18 +217,18 @@ static void
authenticate (SoupSession *session, SoupMessage *msg,
SoupAuth *auth, gboolean retrying, gpointer data)
{
- int *i = data;
+ SoupAuthTest *test = data;
char *username, *password;
char num;
- if (!current_tests[*i].provided[0])
+ if (!test->provided[0])
return;
if (retrying) {
- if (!current_tests[*i].provided[1])
+ if (!test->provided[1])
return;
- num = current_tests[*i].provided[1];
+ num = test->provided[1];
} else
- num = current_tests[*i].provided[0];
+ num = test->provided[0];
username = g_strdup_printf ("user%c", num);
password = g_strdup_printf ("realm%c", num);
@@ -244,13 +244,10 @@ bug271540_sent (SoupMessage *msg, gpointer data)
gboolean *authenticated = data;
int auth = identify_auth (msg);
- if (!*authenticated && auth) {
- debug_printf (1, " using auth on message %d before authenticating!!??\n", n);
- errors++;
- } else if (*authenticated && !auth) {
- debug_printf (1, " sent unauthenticated message %d after authenticating!\n", n);
- errors++;
- }
+ soup_test_assert (*authenticated || !auth,
+ "using auth on message %d before authenticating", n);
+ soup_test_assert (!*authenticated || auth,
+ "sent unauthenticated message %d after authenticating", n);
}
static void
@@ -269,8 +266,8 @@ bug271540_authenticate (SoupSession *session, SoupMessage *msg,
soup_auth_authenticate (auth, "user1", "realm1");
*authenticated = TRUE;
} else {
- debug_printf (1, " asked to authenticate message %d after authenticating!\n", n);
- errors++;
+ soup_test_assert (!*authenticated,
+ "asked to authenticate message %d after authenticating", n);
}
}
@@ -278,13 +275,8 @@ static void
bug271540_finished (SoupSession *session, SoupMessage *msg, gpointer data)
{
int *left = data;
- int n = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (msg), "#"));
- if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
- debug_printf (1, " got status '%d %s' on message %d!\n",
- msg->status_code, msg->reason_phrase, n);
- errors++;
- }
+ soup_test_assert_message_status (msg, SOUP_STATUS_OK);
(*left)--;
if (!*left)
@@ -292,7 +284,7 @@ bug271540_finished (SoupSession *session, SoupMessage *msg, gpointer data)
}
static void
-do_pipelined_auth_test (const char *base_uri)
+do_pipelined_auth_test (void)
{
SoupSession *session;
SoupMessage *msg;
@@ -300,7 +292,10 @@ do_pipelined_auth_test (const char *base_uri)
char *uri;
int i;
- debug_printf (1, "Testing pipelined auth (bug 271540):\n");
+ g_test_bug ("271540");
+
+ SOUP_TEST_SKIP_IF_NO_APACHE;
+
session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
authenticated = FALSE;
@@ -437,28 +432,21 @@ do_digest_nonce_test (SoupSession *session,
&got_401);
got_401 = FALSE;
soup_session_send_message (session, msg);
- if (got_401 != expect_401) {
- debug_printf (1, " %s request %s a 401 Unauthorized!\n", nth,
- got_401 ? "got" : "did not get");
- errors++;
- }
- if (msg->status_code != SOUP_STATUS_OK) {
- debug_printf (1, " %s request got status %d %s!\n", nth,
- msg->status_code, msg->reason_phrase);
- errors++;
- }
- if (errors == 0)
- debug_printf (1, " %s request succeeded\n", nth);
+ soup_test_assert (got_401 == expect_401,
+ "%s request %s a 401 Unauthorized!\n", nth,
+ got_401 ? "got" : "did not get");
+ soup_test_assert_message_status (msg, SOUP_STATUS_OK);
+
g_object_unref (msg);
}
static void
-do_digest_expiration_test (const char *base_uri)
+do_digest_expiration_test (void)
{
SoupSession *session;
char *uri;
- debug_printf (1, "\nTesting digest nonce expiration:\n");
+ SOUP_TEST_SKIP_IF_NO_APACHE;
session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
@@ -530,10 +518,8 @@ async_authenticate_assert_once (SoupSession *session, SoupMessage *msg,
debug_printf (2, " async_authenticate_assert_once\n");
- if (*been_here) {
- debug_printf (1, " ERROR: async_authenticate_assert_once called twice\n");
- errors++;
- }
+ soup_test_assert (!*been_here,
+ "async_authenticate_assert_once called twice");
*been_here = TRUE;
}
@@ -545,10 +531,8 @@ async_authenticate_assert_once_and_stop (SoupSession *session, SoupMessage *msg,
debug_printf (2, " async_authenticate_assert_once_and_stop\n");
- if (*been_here) {
- debug_printf (1, " ERROR: async_authenticate_assert_once called twice\n");
- errors++;
- }
+ soup_test_assert (!*been_here,
+ "async_authenticate_assert_once called twice");
*been_here = TRUE;
soup_session_pause_message (session, msg);
@@ -556,7 +540,7 @@ async_authenticate_assert_once_and_stop (SoupSession *session, SoupMessage *msg,
}
static void
-do_async_auth_test (const char *base_uri)
+do_async_auth_good_password_test (void)
{
SoupSession *session;
SoupMessage *msg1, *msg2, *msg3, msg2_bak;
@@ -564,15 +548,13 @@ do_async_auth_test (const char *base_uri)
char *uri;
SoupAuth *auth = NULL;
int remaining;
- gboolean been_there;
- debug_printf (1, "\nTesting async auth:\n");
+ SOUP_TEST_SKIP_IF_NO_APACHE;
loop = g_main_loop_new (NULL, TRUE);
session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
- remaining = 0;
-
uri = g_strconcat (base_uri, "Basic/realm1/", NULL);
+ remaining = 0;
msg1 = soup_message_new ("GET", uri);
g_object_set_data (G_OBJECT (msg1), "id", GINT_TO_POINTER (1));
@@ -590,13 +572,7 @@ do_async_auth_test (const char *base_uri)
g_object_set_data (G_OBJECT (msg2), "id", GINT_TO_POINTER (2));
soup_session_send_message (session, msg2);
- if (msg2->status_code == SOUP_STATUS_UNAUTHORIZED)
- debug_printf (1, " msg2 failed as expected\n");
- else {
- debug_printf (1, " msg2 got wrong status! (%u)\n",
- msg2->status_code);
- errors++;
- }
+ soup_test_assert_message_status (msg2, SOUP_STATUS_UNAUTHORIZED);
/* msg2 should be done at this point; assuming everything is
* working correctly, the session won't look at it again; we
@@ -627,25 +603,11 @@ do_async_auth_test (const char *base_uri)
g_main_loop_run (loop);
/* async_finished will quit the loop */
- } else {
- debug_printf (1, " msg1 didn't get authenticate signal!\n");
- errors++;
- }
+ } else
+ soup_test_assert (auth, "msg1 didn't get authenticate signal");
- if (msg1->status_code == SOUP_STATUS_OK)
- debug_printf (1, " msg1 succeeded\n");
- else {
- debug_printf (1, " msg1 FAILED! (%u %s)\n",
- msg1->status_code, msg1->reason_phrase);
- errors++;
- }
- if (msg3->status_code == SOUP_STATUS_OK)
- debug_printf (1, " msg3 succeeded\n");
- else {
- debug_printf (1, " msg3 FAILED! (%u %s)\n",
- msg3->status_code, msg3->reason_phrase);
- errors++;
- }
+ soup_test_assert_message_status (msg1, SOUP_STATUS_OK);
+ soup_test_assert_message_status (msg3, SOUP_STATUS_OK);
soup_test_session_abort_unref (session);
@@ -654,27 +616,46 @@ do_async_auth_test (const char *base_uri)
memcpy (msg2, &msg2_bak, sizeof (SoupMessage));
g_object_unref (msg2);
+ g_free (uri);
+ g_main_loop_unref (loop);
+}
+
+static void
+do_async_auth_bad_password_test (void)
+{
+ SoupSession *session;
+ SoupMessage *msg;
+ guint auth_id;
+ char *uri;
+ SoupAuth *auth = NULL;
+ int remaining;
+ gboolean been_there;
+
/* Test that giving the wrong password doesn't cause multiple
* authenticate signals the second time.
*/
- debug_printf (1, "\nTesting async auth with wrong password (#522601):\n");
+ g_test_bug ("522601");
+
+ SOUP_TEST_SKIP_IF_NO_APACHE;
+ loop = g_main_loop_new (NULL, TRUE);
session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
+ uri = g_strconcat (base_uri, "Basic/realm1/", NULL);
remaining = 0;
auth = NULL;
- msg1 = soup_message_new ("GET", uri);
- g_object_set_data (G_OBJECT (msg1), "id", GINT_TO_POINTER (1));
+ msg = soup_message_new ("GET", uri);
+ g_object_set_data (G_OBJECT (msg), "id", GINT_TO_POINTER (1));
auth_id = g_signal_connect (session, "authenticate",
G_CALLBACK (async_authenticate), &auth);
- g_object_ref (msg1);
+ g_object_ref (msg);
remaining++;
- soup_session_queue_message (session, msg1, async_finished, &remaining);
+ soup_session_queue_message (session, msg, async_finished, &remaining);
g_main_loop_run (loop);
g_signal_handler_disconnect (session, auth_id);
soup_auth_authenticate (auth, "user1", "wrong");
g_object_unref (auth);
- soup_session_unpause_message (session, msg1);
+ soup_session_unpause_message (session, msg);
been_there = FALSE;
auth_id = g_signal_connect (session, "authenticate",
@@ -683,55 +664,71 @@ do_async_auth_test (const char *base_uri)
g_main_loop_run (loop);
g_signal_handler_disconnect (session, auth_id);
- if (!been_there) {
- debug_printf (1, " authenticate not emitted?\n");
- errors++;
- }
+ soup_test_assert (been_there,
+ "authenticate not emitted");
soup_test_session_abort_unref (session);
- g_object_unref (msg1);
+ g_object_unref (msg);
+
+ g_free (uri);
+ g_main_loop_unref (loop);
+}
+
+static void
+do_async_auth_no_password_test (void)
+{
+ SoupSession *session;
+ SoupMessage *msg;
+ guint auth_id;
+ char *uri;
+ int remaining;
+ gboolean been_there;
/* Test that giving no password doesn't cause multiple
* authenticate signals the second time.
*/
- debug_printf (1, "\nTesting async auth with no password (#583462):\n");
+ g_test_bug ("583462");
+
+ SOUP_TEST_SKIP_IF_NO_APACHE;
+ loop = g_main_loop_new (NULL, TRUE);
session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
+ uri = g_strconcat (base_uri, "Basic/realm1/", NULL);
remaining = 0;
/* Send a message that doesn't actually authenticate
*/
- msg1 = soup_message_new ("GET", uri);
- g_object_set_data (G_OBJECT (msg1), "id", GINT_TO_POINTER (1));
+ msg = soup_message_new ("GET", uri);
+ g_object_set_data (G_OBJECT (msg), "id", GINT_TO_POINTER (1));
auth_id = g_signal_connect (session, "authenticate",
G_CALLBACK (async_authenticate), NULL);
- g_object_ref (msg1);
+ g_object_ref (msg);
remaining++;
- soup_session_queue_message (session, msg1, async_finished, &remaining);
+ soup_session_queue_message (session, msg, async_finished, &remaining);
g_main_loop_run (loop);
g_signal_handler_disconnect (session, auth_id);
- soup_session_unpause_message (session, msg1);
+ soup_session_unpause_message (session, msg);
g_main_loop_run (loop);
- g_object_unref(msg1);
+ g_object_unref(msg);
/* Now send a second message */
- msg1 = soup_message_new ("GET", uri);
- g_object_set_data (G_OBJECT (msg1), "id", GINT_TO_POINTER (2));
- g_object_ref (msg1);
+ msg = soup_message_new ("GET", uri);
+ g_object_set_data (G_OBJECT (msg), "id", GINT_TO_POINTER (2));
+ g_object_ref (msg);
been_there = FALSE;
auth_id = g_signal_connect (session, "authenticate",
G_CALLBACK (async_authenticate_assert_once_and_stop),
&been_there);
remaining++;
- soup_session_queue_message (session, msg1, async_finished, &remaining);
+ soup_session_queue_message (session, msg, async_finished, &remaining);
g_main_loop_run (loop);
- soup_session_unpause_message (session, msg1);
+ soup_session_unpause_message (session, msg);
g_main_loop_run (loop);
g_signal_handler_disconnect (session, auth_id);
soup_test_session_abort_unref (session);
- g_object_unref (msg1);
+ g_object_unref (msg);
g_free (uri);
g_main_loop_unref (loop);
@@ -795,41 +792,27 @@ select_auth_test_one (SoupURI *uri,
msg = soup_message_new_from_uri ("GET", uri);
soup_session_send_message (session, msg);
- if (strcmp (sad.round[0].headers, first_headers) != 0) {
- debug_printf (1, " Header order wrong: expected %s, got %s\n",
- first_headers, sad.round[0].headers);
- errors++;
- }
- if (strcmp (sad.round[0].response, first_response) != 0) {
- debug_printf (1, " Selected auth type wrong: expected %s, got %s\n",
- first_response, sad.round[0].response);
- errors++;
- }
-
- if (second_headers && !sad.round[1].headers) {
- debug_printf (1, " Expected a second round!\n");
- errors++;
- } else if (!second_headers && sad.round[1].headers) {
- debug_printf (1, " Didn't expect a second round!\n");
- errors++;
- } else if (second_headers) {
- if (strcmp (sad.round[1].headers, second_headers) != 0) {
- debug_printf (1, " Second round header order wrong: expected %s, got %s\n",
- second_headers, sad.round[1].headers);
- errors++;
- }
- if (strcmp (sad.round[1].response, second_response) != 0) {
- debug_printf (1, " Second round selected auth type wrong: expected %s, got %s\n",
- second_response, sad.round[1].response);
- errors++;
- }
+ soup_test_assert (strcmp (sad.round[0].headers, first_headers) == 0,
+ "Header order wrong: expected %s, got %s",
+ first_headers, sad.round[0].headers);
+ soup_test_assert (strcmp (sad.round[0].response, first_response) == 0,
+ "Selected auth type wrong: expected %s, got %s",
+ first_response, sad.round[0].response);
+
+ soup_test_assert (sad.round[1].headers || !second_headers,
+ "Expected a second round");
+ soup_test_assert (!sad.round[1].headers || second_headers,
+ "Didn't expect a second round");
+ if (second_headers && second_response) {
+ soup_test_assert (strcmp (sad.round[1].headers, second_headers) == 0,
+ "Second round header order wrong: expected %s, got %s\n",
+ second_headers, sad.round[1].headers);
+ soup_test_assert (strcmp (sad.round[1].response, second_response) == 0,
+ "Second round selected auth type wrong: expected %s, got %s\n",
+ second_response, sad.round[1].response);
}
- if (msg->status_code != final_status) {
- debug_printf (1, " Final status wrong: expected %u, got %u\n",
- final_status, msg->status_code);
- errors++;
- }
+ soup_test_assert_message_status (msg, final_status);
g_object_unref (msg);
soup_test_session_abort_unref (session);
@@ -873,7 +856,7 @@ do_select_auth_test (void)
SoupAuthDomain *basic_auth_domain, *digest_auth_domain;
SoupURI *uri;
- debug_printf (1, "\nTesting selection among multiple auths:\n");
+ g_test_bug ("562339");
/* It doesn't seem to be possible to configure Apache to serve
* multiple auth types for a single URL. So we have to use
@@ -1029,8 +1012,6 @@ do_auth_close_test (void)
SoupURI *uri;
AuthCloseData acd;
- debug_printf (1, "\nTesting auth when server times out connection:\n");
-
server = soup_test_server_new (FALSE);
soup_server_add_handler (server, NULL,
server_callback, NULL, NULL);
@@ -1057,18 +1038,130 @@ do_auth_close_test (void)
soup_uri_free (uri);
soup_session_send_message (acd.session, acd.msg);
- if (acd.msg->status_code != SOUP_STATUS_OK) {
- debug_printf (1, " Final status wrong: expected %u, got %u %s\n",
- SOUP_STATUS_OK, acd.msg->status_code,
- acd.msg->reason_phrase);
- errors++;
- }
+ soup_test_assert_message_status (acd.msg, SOUP_STATUS_OK);
g_object_unref (acd.msg);
soup_test_session_abort_unref (acd.session);
soup_test_server_quit_unref (server);
}
+static gboolean
+infinite_cancel (gpointer session)
+{
+ soup_session_abort (session);
+ return FALSE;
+}
+
+static void
+infinite_authenticate (SoupSession *session, SoupMessage *msg,
+ SoupAuth *auth, gboolean retrying, gpointer data)
+{
+ soup_auth_authenticate (auth, "user", "bad");
+}
+
+static void
+do_infinite_auth_test (void)
+{
+ SoupSession *session;
+ SoupMessage *msg;
+ char *uri;
+ int timeout;
+
+ SOUP_TEST_SKIP_IF_NO_APACHE;
+
+ session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
+ g_signal_connect (session, "authenticate",
+ G_CALLBACK (infinite_authenticate), NULL);
+
+ uri = g_strconcat (base_uri, "Basic/realm1/", NULL);
+ msg = soup_message_new ("GET", uri);
+ g_free (uri);
+
+ timeout = g_timeout_add (500, infinite_cancel, session);
+ g_test_expect_message ("libsoup", G_LOG_LEVEL_WARNING,
+ "*stuck in infinite loop*");
+ soup_session_send_message (session, msg);
+ g_test_assert_expected_messages ();
+
+ soup_test_assert (msg->status_code != SOUP_STATUS_CANCELLED,
+ "Got stuck in loop");
+ soup_test_assert_message_status (msg, SOUP_STATUS_UNAUTHORIZED);
+
+ g_source_remove (timeout);
+ soup_test_session_abort_unref (session);
+ g_object_unref (msg);
+}
+
+static void
+disappear_request_read (SoupServer *server, SoupMessage *msg,
+ SoupClientContext *context, gpointer user_data)
+{
+ /* Remove the WWW-Authenticate header if this was a failed attempt */
+ if (soup_message_headers_get_one (msg->request_headers, "Authorization") &&
+ msg->status_code == SOUP_STATUS_UNAUTHORIZED)
+ soup_message_headers_remove (msg->response_headers, "WWW-Authenticate");
+}
+
+static void
+disappear_authenticate (SoupSession *session, SoupMessage *msg,
+ SoupAuth *auth, gboolean retrying, gpointer data)
+{
+ int *counter = data;
+
+ (*counter)++;
+ if (!retrying)
+ soup_auth_authenticate (auth, "user", "bad");
+}
+
+static void
+do_disappearing_auth_test (void)
+{
+ SoupServer *server;
+ SoupAuthDomain *auth_domain;
+ SoupURI *uri;
+ SoupMessage *msg;
+ SoupSession *session;
+ int counter;
+
+ g_test_bug ("https://bugzilla.redhat.com/show_bug.cgi?id=916224");
+
+ server = soup_test_server_new (FALSE);
+ soup_server_add_handler (server, NULL,
+ server_callback, NULL, NULL);
+
+ uri = soup_uri_new ("http://127.0.0.1/");
+ soup_uri_set_port (uri, soup_server_get_port (server));
+
+ auth_domain = soup_auth_domain_basic_new (
+ SOUP_AUTH_DOMAIN_REALM, "auth-test",
+ SOUP_AUTH_DOMAIN_ADD_PATH, "/",
+ SOUP_AUTH_DOMAIN_BASIC_AUTH_CALLBACK, server_basic_auth_callback,
+ NULL);
+ soup_server_add_auth_domain (server, auth_domain);
+ g_signal_connect (server, "request-read",
+ G_CALLBACK (disappear_request_read), NULL);
+
+ session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
+
+ counter = 0;
+ g_signal_connect (session, "authenticate",
+ G_CALLBACK (disappear_authenticate), &counter);
+
+ msg = soup_message_new_from_uri ("GET", uri);
+ soup_session_send_message (session, msg);
+
+ soup_test_assert (counter <= 2,
+ "Got stuck in loop");
+ soup_test_assert_message_status (msg, SOUP_STATUS_UNAUTHORIZED);
+
+ g_object_unref (msg);
+ soup_test_session_abort_unref (session);
+
+ g_object_unref (auth_domain);
+ soup_uri_free (uri);
+ soup_test_server_quit_unref (server);
+}
+
static SoupAuthTest relogin_tests[] = {
{ "Auth provided via URL, should succeed",
"Basic/realm12/", "1", TRUE, "01", SOUP_STATUS_OK },
@@ -1090,25 +1183,28 @@ static SoupAuthTest relogin_tests[] = {
{ "Should fail with no auth, fail again with bad password, and give up",
"Basic/realm12/", "3", FALSE, "03", SOUP_STATUS_UNAUTHORIZED },
+
+ { NULL }
};
static void
-do_batch_tests (const gchar *base_uri_str, gint ntests)
+do_batch_tests (gconstpointer data)
{
+ const SoupAuthTest *current_tests = data;
SoupSession *session;
SoupMessage *msg;
char *expected, *uristr;
- SoupURI *base_uri;
+ SoupURI *base;
+ guint signal;
int i;
- session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
- g_signal_connect (session, "authenticate",
- G_CALLBACK (authenticate), &i);
+ SOUP_TEST_SKIP_IF_NO_APACHE;
- base_uri = soup_uri_new (base_uri_str);
+ session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
+ base = soup_uri_new (base_uri);
- for (i = 0; i < ntests; i++) {
- SoupURI *soup_uri = soup_uri_new_with_base (base_uri, current_tests[i].url);
+ for (i = 0; current_tests[i].url; i++) {
+ SoupURI *soup_uri = soup_uri_new_with_base (base, current_tests[i].url);
debug_printf (1, "Test %d: %s\n", i + 1, current_tests[i].explanation);
@@ -1139,30 +1235,24 @@ do_batch_tests (const gchar *base_uri_str, gint ntests)
soup_message_add_status_code_handler (
msg, "got_headers", SOUP_STATUS_OK,
G_CALLBACK (handler), expected);
+
+ signal = g_signal_connect (session, "authenticate",
+ G_CALLBACK (authenticate),
+ (gpointer)&current_tests[i]);
soup_session_send_message (session, msg);
- if (msg->status_code != SOUP_STATUS_UNAUTHORIZED &&
- msg->status_code != SOUP_STATUS_OK) {
- debug_printf (1, " %d %s !\n", msg->status_code,
- msg->reason_phrase);
- errors++;
- }
- if (*expected) {
- debug_printf (1, " expected %d more round(s)\n",
- (int)strlen (expected));
- errors++;
- }
- g_free (expected);
+ g_signal_handler_disconnect (session, signal);
- if (msg->status_code != current_tests[i].final_status) {
- debug_printf (1, " expected %d\n",
- current_tests[i].final_status);
- }
+ soup_test_assert_message_status (msg, current_tests[i].final_status);
+ soup_test_assert (!*expected,
+ "expected %d more round(s)\n",
+ (int)strlen (expected));
+ g_free (expected);
debug_printf (1, "\n");
g_object_unref (msg);
}
- soup_uri_free (base_uri);
+ soup_uri_free (base);
soup_test_session_abort_unref (session);
}
@@ -1170,31 +1260,27 @@ do_batch_tests (const gchar *base_uri_str, gint ntests)
int
main (int argc, char **argv)
{
- const char *base_uri;
- int ntests;
+ int ret;
test_init (argc, argv, NULL);
apache_init ();
base_uri = "http://127.0.0.1:47524/";
- /* Main tests */
- current_tests = main_tests;
- ntests = G_N_ELEMENTS (main_tests);
- do_batch_tests (base_uri, ntests);
-
- /* Re-login tests */
- current_tests = relogin_tests;
- ntests = G_N_ELEMENTS (relogin_tests);
- do_batch_tests (base_uri, ntests);
+ g_test_add_data_func ("/auth/main-tests", main_tests, do_batch_tests);
+ g_test_add_data_func ("/auth/relogin-tests", relogin_tests, do_batch_tests);
+ g_test_add_func ("/auth/pipelined-auth", do_pipelined_auth_test);
+ g_test_add_func ("/auth/digest-expiration", do_digest_expiration_test);
+ g_test_add_func ("/auth/async-auth/good-password", do_async_auth_good_password_test);
+ g_test_add_func ("/auth/async-auth/bad-password", do_async_auth_bad_password_test);
+ g_test_add_func ("/auth/async-auth/no-password", do_async_auth_no_password_test);
+ g_test_add_func ("/auth/select-auth", do_select_auth_test);
+ g_test_add_func ("/auth/auth-close", do_auth_close_test);
+ g_test_add_func ("/auth/infinite-auth", do_infinite_auth_test);
+ g_test_add_func ("/auth/disappearing-auth", do_disappearing_auth_test);
- /* Other regression tests */
- do_pipelined_auth_test (base_uri);
- do_digest_expiration_test (base_uri);
- do_async_auth_test (base_uri);
- do_select_auth_test ();
- do_auth_close_test ();
+ ret = g_test_run ();
test_cleanup ();
- return errors != 0;
+ return ret;
}