SoupMessage *msg, SoupSocket *socket);
static void request_unqueued (SoupSessionFeature *feature,
SoupSession *session, SoupMessage *msg);
+static gboolean add_feature (SoupSessionFeature *feature, GType type);
+static gboolean remove_feature (SoupSessionFeature *feature, GType type);
+static gboolean has_feature (SoupSessionFeature *feature, GType type);
enum {
AUTHENTICATE,
feature_interface->request_queued = request_queued;
feature_interface->request_started = request_started;
feature_interface->request_unqueued = request_unqueued;
+ feature_interface->add_feature = add_feature;
+ feature_interface->remove_feature = remove_feature;
+ feature_interface->has_feature = has_feature;
}
static int
return (*auth1)->strength - (*auth2)->strength;
}
-void
-soup_auth_manager_add_type (SoupAuthManager *manager, GType type)
+static gboolean
+add_feature (SoupSessionFeature *feature, GType type)
{
- SoupAuthManagerPrivate *priv = SOUP_AUTH_MANAGER_GET_PRIVATE (manager);
+ SoupAuthManagerPrivate *priv = SOUP_AUTH_MANAGER_GET_PRIVATE (feature);
SoupAuthClass *auth_class;
- g_return_if_fail (g_type_is_a (type, SOUP_TYPE_AUTH));
+ if (!g_type_is_a (type, SOUP_TYPE_AUTH))
+ return FALSE;
auth_class = g_type_class_ref (type);
g_ptr_array_add (priv->auth_types, auth_class);
g_ptr_array_sort (priv->auth_types, auth_type_compare_func);
+ return TRUE;
}
-void
-soup_auth_manager_remove_type (SoupAuthManager *manager, GType type)
+static gboolean
+remove_feature (SoupSessionFeature *feature, GType type)
{
- SoupAuthManagerPrivate *priv = SOUP_AUTH_MANAGER_GET_PRIVATE (manager);
+ SoupAuthManagerPrivate *priv = SOUP_AUTH_MANAGER_GET_PRIVATE (feature);
SoupAuthClass *auth_class;
int i;
- g_return_if_fail (g_type_is_a (type, SOUP_TYPE_AUTH));
+ if (!g_type_is_a (type, SOUP_TYPE_AUTH))
+ return FALSE;
auth_class = g_type_class_peek (type);
for (i = 0; i < priv->auth_types->len; i++) {
if (priv->auth_types->pdata[i] == (gpointer)auth_class) {
g_ptr_array_remove_index (priv->auth_types, i);
g_type_class_unref (auth_class);
- return;
+ return TRUE;
}
}
+
+ return FALSE;
+}
+
+static gboolean
+has_feature (SoupSessionFeature *feature, GType type)
+{
+ SoupAuthManagerPrivate *priv = SOUP_AUTH_MANAGER_GET_PRIVATE (feature);
+ SoupAuthClass *auth_class;
+ int i;
+
+ if (!g_type_is_a (type, SOUP_TYPE_AUTH))
+ return FALSE;
+
+ auth_class = g_type_class_peek (type);
+ for (i = 0; i < priv->auth_types->len; i++) {
+ if (priv->auth_types->pdata[i] == (gpointer)auth_class)
+ return TRUE;
+ }
+ return FALSE;
}
void
}
static void
-select_auth_test_one (SoupURI *uri, const char *password,
+select_auth_test_one (SoupURI *uri,
+ gboolean disable_digest, const char *password,
const char *first_headers, const char *first_response,
const char *second_headers, const char *second_response,
guint final_status)
SoupSession *session;
session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
+ if (disable_digest)
+ soup_session_remove_feature_by_type (session, SOUP_TYPE_AUTH_DIGEST);
+
g_signal_connect (session, "authenticate",
G_CALLBACK (select_auth_authenticate), &sad);
memset (&sad, 0, sizeof (sad));
server_basic_auth_callback (SoupAuthDomain *auth_domain, SoupMessage *msg,
const char *username, const char *password, gpointer data)
{
- return FALSE;
+ if (strcmp (username, "user") != 0)
+ return FALSE;
+ return strcmp (password, "good-basic") == 0;
}
static char *
NULL);
soup_server_add_auth_domain (server, digest_auth_domain);
- /* FIXME: when we support disabling auth types in the session,
- * test that too.
- */
-
debug_printf (1, " Testing with no auth\n");
- select_auth_test_one (uri, NULL,
+ select_auth_test_one (uri, FALSE, NULL,
"Basic, Digest", "Digest",
NULL, NULL,
SOUP_STATUS_UNAUTHORIZED);
debug_printf (1, " Testing with bad password\n");
- select_auth_test_one (uri, "bad",
+ select_auth_test_one (uri, FALSE, "bad",
"Basic, Digest", "Digest",
"Basic, Digest", "Digest",
SOUP_STATUS_UNAUTHORIZED);
debug_printf (1, " Testing with good password\n");
- select_auth_test_one (uri, "good",
+ select_auth_test_one (uri, FALSE, "good",
"Basic, Digest", "Digest",
NULL, NULL,
SOUP_STATUS_OK);
+ /* Test with Digest disabled in the client. */
+ debug_printf (1, " Testing without Digest with no auth\n");
+ select_auth_test_one (uri, TRUE, NULL,
+ "Basic, Digest", "Basic",
+ NULL, NULL,
+ SOUP_STATUS_UNAUTHORIZED);
+
+ debug_printf (1, " Testing without Digest with bad password\n");
+ select_auth_test_one (uri, TRUE, "bad",
+ "Basic, Digest", "Basic",
+ "Basic, Digest", "Basic",
+ SOUP_STATUS_UNAUTHORIZED);
+
+ debug_printf (1, " Testing without Digest with good password\n");
+ select_auth_test_one (uri, TRUE, "good-basic",
+ "Basic, Digest", "Basic",
+ NULL, NULL,
+ SOUP_STATUS_OK);
+
/* Now flip the order of the domains, verify that this flips
* the order of the headers, and make sure that digest auth
* *still* gets used.
soup_server_add_auth_domain (server, basic_auth_domain);
debug_printf (1, " Testing flipped with no auth\n");
- select_auth_test_one (uri, NULL,
+ select_auth_test_one (uri, FALSE, NULL,
"Digest, Basic", "Digest",
NULL, NULL,
SOUP_STATUS_UNAUTHORIZED);
debug_printf (1, " Testing flipped with bad password\n");
- select_auth_test_one (uri, "bad",
+ select_auth_test_one (uri, FALSE, "bad",
"Digest, Basic", "Digest",
"Digest, Basic", "Digest",
SOUP_STATUS_UNAUTHORIZED);
debug_printf (1, " Testing flipped with good password\n");
- select_auth_test_one (uri, "good",
+ select_auth_test_one (uri, FALSE, "good",
"Digest, Basic", "Digest",
NULL, NULL,
SOUP_STATUS_OK);