static void do_digest_nonce_test (SoupSession *session, const char *nth, const char *uri, gboolean use_auth_cache, gboolean expect_401, gboolean expect_signal) { SoupMessage *msg; gboolean got_401; msg = soup_message_new (SOUP_METHOD_GET, uri); if (!use_auth_cache) { SoupMessageFlags flags = soup_message_get_flags (msg); soup_message_set_flags (msg, flags | SOUP_MESSAGE_DO_NOT_USE_AUTH_CACHE); } if (expect_signal) { g_signal_connect (session, "authenticate", G_CALLBACK (digest_nonce_authenticate), NULL); } soup_message_add_status_code_handler (msg, "got_headers", SOUP_STATUS_UNAUTHORIZED, G_CALLBACK (digest_nonce_unauthorized), &got_401); got_401 = FALSE; soup_session_send_message (session, msg); 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_nonce_test (SoupSession *session, const char *nth, const char *uri, gboolean expect_401, gboolean expect_signal) { SoupMessage *msg; gboolean got_401; msg = soup_message_new (SOUP_METHOD_GET, uri); if (expect_signal) { g_signal_connect (session, "authenticate", G_CALLBACK (digest_nonce_authenticate), NULL); } soup_message_add_status_code_handler (msg, "got_headers", SOUP_STATUS_UNAUTHORIZED, G_CALLBACK (digest_nonce_unauthorized), &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); g_object_unref (msg); }
static void soup_auth_manager_request_queued (SoupSessionFeature *manager, SoupSession *session, SoupMessage *msg) { soup_message_add_status_code_handler ( msg, "got_headers", SOUP_STATUS_UNAUTHORIZED, G_CALLBACK (auth_got_headers), manager); soup_message_add_status_code_handler ( msg, "got_body", SOUP_STATUS_UNAUTHORIZED, G_CALLBACK (auth_got_body), manager); soup_message_add_status_code_handler ( msg, "got_headers", SOUP_STATUS_PROXY_UNAUTHORIZED, G_CALLBACK (proxy_auth_got_headers), manager); soup_message_add_status_code_handler ( msg, "got_body", SOUP_STATUS_PROXY_UNAUTHORIZED, G_CALLBACK (proxy_auth_got_body), manager); }
static void do_batch_tests (const gchar *base_uri_str, gint ntests) { SoupSession *session; SoupMessage *msg; char *expected; SoupURI *base_uri; int i; session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL); g_signal_connect (session, "authenticate", G_CALLBACK (authenticate), &i); base_uri = soup_uri_new (base_uri_str); for (i = 0; i < ntests; i++) { SoupURI *soup_uri = soup_uri_new_with_base (base_uri, current_tests[i].url); debug_printf (1, "Test %d: %s\n", i + 1, current_tests[i].explanation); if (current_tests[i].url_auth) { gchar *username = g_strdup_printf ("user%c", current_tests[i].provided[0]); gchar *password = g_strdup_printf ("realm%c", current_tests[i].provided[0]); soup_uri_set_user (soup_uri, username); soup_uri_set_password (soup_uri, password); g_free (username); g_free (password); } msg = soup_message_new_from_uri (SOUP_METHOD_GET, soup_uri); soup_uri_free (soup_uri); if (!msg) { fprintf (stderr, "auth-test: Could not parse URI\n"); exit (1); } debug_printf (1, " GET %s\n", soup_uri_to_string (soup_message_get_uri (msg), FALSE)); expected = g_strdup (current_tests[i].expected); soup_message_add_status_code_handler ( msg, "got_headers", SOUP_STATUS_UNAUTHORIZED, G_CALLBACK (handler), expected); soup_message_add_status_code_handler ( msg, "got_headers", SOUP_STATUS_OK, G_CALLBACK (handler), expected); 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); if (msg->status_code != current_tests[i].final_status) { debug_printf (1, " expected %d\n", current_tests[i].final_status); } debug_printf (1, "\n"); g_object_unref (msg); } soup_uri_free (base_uri); soup_test_session_abort_unref (session); }
static void do_batch_tests (gconstpointer data) { const SoupAuthTest *current_tests = data; SoupSession *session; SoupMessage *msg; char *expected, *uristr; SoupURI *base; guint signal; int i; SOUP_TEST_SKIP_IF_NO_APACHE; session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL); base = soup_uri_new (base_uri); 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); if (current_tests[i].url_auth) { gchar *username = g_strdup_printf ("user%c", current_tests[i].provided[0]); gchar *password = g_strdup_printf ("realm%c", current_tests[i].provided[0]); soup_uri_set_user (soup_uri, username); soup_uri_set_password (soup_uri, password); g_free (username); g_free (password); } msg = soup_message_new_from_uri (SOUP_METHOD_GET, soup_uri); soup_uri_free (soup_uri); if (!msg) { g_printerr ("auth-test: Could not parse URI\n"); exit (1); } uristr = soup_uri_to_string (soup_message_get_uri (msg), FALSE); debug_printf (1, " GET %s\n", uristr); g_free (uristr); expected = g_strdup (current_tests[i].expected); soup_message_add_status_code_handler ( msg, "got_headers", SOUP_STATUS_UNAUTHORIZED, G_CALLBACK (handler), expected); 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)¤t_tests[i]); soup_session_send_message (session, msg); g_signal_handler_disconnect (session, signal); 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); soup_test_session_abort_unref (session); }