[libsoup] Add API to clear cached credentials from SoupAuthManager
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup] Add API to clear cached credentials from SoupAuthManager
- Date: Tue, 15 Nov 2016 11:41:43 +0000 (UTC)
commit c661c44a3689fbc2aa562cc81b9a884f29735694
Author: Carlos Garcia Campos <cgarcia igalia com>
Date: Mon Nov 7 08:44:36 2016 +0100
Add API to clear cached credentials from SoupAuthManager
In WebKit, we need to clear the cached credentials. It's mainly used by
tests to ensure that auth tests are independent to each other.
https://bugzilla.gnome.org/show_bug.cgi?id=774031
docs/reference/libsoup-2.4-sections.txt | 1 +
libsoup/soup-auth-manager.c | 21 +++++++++++++++++++++
libsoup/soup-auth-manager.h | 3 +++
tests/auth-test.c | 24 ++++++++++++++++++++++++
4 files changed, 49 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/libsoup-2.4-sections.txt b/docs/reference/libsoup-2.4-sections.txt
index 285c30e..b3e15c9 100644
--- a/docs/reference/libsoup-2.4-sections.txt
+++ b/docs/reference/libsoup-2.4-sections.txt
@@ -629,6 +629,7 @@ soup_auth_save_password
SoupAuthManager
SOUP_TYPE_AUTH_MANAGER
soup_auth_manager_use_auth
+soup_auth_manager_clear_cached_credentials
<SUBSECTION Standard>
SoupAuthManagerPrivate
SoupAuthManagerClass
diff --git a/libsoup/soup-auth-manager.c b/libsoup/soup-auth-manager.c
index 703d188..4e1645c 100644
--- a/libsoup/soup-auth-manager.c
+++ b/libsoup/soup-auth-manager.c
@@ -740,6 +740,27 @@ soup_auth_manager_use_auth (SoupAuthManager *manager,
g_mutex_unlock (&priv->lock);
}
+/**
+ * soup_auth_manager_clear_cached_credentials:
+ * @manager: a #SoupAuthManager
+ *
+ * Clear all credentials cached by @manager
+ *
+ * Since: 2.58
+ */
+void
+soup_auth_manager_clear_cached_credentials (SoupAuthManager *manager)
+{
+ SoupAuthManagerPrivate *priv;
+
+ g_return_if_fail (SOUP_IS_AUTH_MANAGER (manager));
+
+ priv = manager->priv;
+ g_mutex_lock (&priv->lock);
+ g_hash_table_remove_all (priv->auth_hosts);
+ g_mutex_unlock (&priv->lock);
+}
+
static void
soup_auth_manager_session_feature_init (SoupSessionFeatureInterface *feature_interface,
gpointer interface_data)
diff --git a/libsoup/soup-auth-manager.h b/libsoup/soup-auth-manager.h
index 74d70dd..c935d99 100644
--- a/libsoup/soup-auth-manager.h
+++ b/libsoup/soup-auth-manager.h
@@ -41,6 +41,9 @@ void soup_auth_manager_use_auth (SoupAuthManager *manager,
SoupURI *uri,
SoupAuth *auth);
+SOUP_AVAILABLE_IN_2_58
+void soup_auth_manager_clear_cached_credentials (SoupAuthManager *manager);
+
G_END_DECLS
#endif /* SOUP_AUTH_MANAGER_H */
diff --git a/tests/auth-test.c b/tests/auth-test.c
index 775c7f8..cf1f246 100644
--- a/tests/auth-test.c
+++ b/tests/auth-test.c
@@ -1264,6 +1264,29 @@ do_batch_tests (gconstpointer data)
soup_test_session_abort_unref (session);
}
+static void
+do_clear_credentials_test (void)
+{
+ SoupSession *session;
+ SoupAuthManager *manager;
+ char *uri;
+
+ SOUP_TEST_SKIP_IF_NO_APACHE;
+
+ session = soup_test_session_new (SOUP_TYPE_SESSION, NULL);
+
+ uri = g_strconcat (base_uri, "Digest/realm1/", NULL);
+ do_digest_nonce_test (session, "First", uri, TRUE, TRUE);
+
+ manager = SOUP_AUTH_MANAGER (soup_session_get_feature (session, SOUP_TYPE_AUTH_MANAGER));
+ soup_auth_manager_clear_cached_credentials (manager);
+
+ do_digest_nonce_test (session, "Second", uri, TRUE, TRUE);
+ g_free (uri);
+
+ soup_test_session_abort_unref (session);
+}
+
int
main (int argc, char **argv)
{
@@ -1286,6 +1309,7 @@ main (int argc, char **argv)
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);
+ g_test_add_func ("/auth/clear-credentials", do_clear_credentials_test);
ret = g_test_run ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]