[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

[PATCH] add svn_config_clear_auth_data

From: Kouhei Sutou <kou_at_cozmixng.org>
Date: 2005-07-21 17:19:33 CEST

Hi,

I want to clear auth data cache for cleaning up test
environment. Can I add a new API to clear auth data cache?

[[[
Add auth data cache cleaning up API.

* subversion/include/svn_config.h
 (svn_config_clear_auth_data),
  subversion/libsvn_subr/config_auth.c
 (svn_config_clear_auth_data): New function.

* subversion/tests/libsvn_subr/config-test.c (test3): New
  function. This is a test for the following functions:
  - svn_config_read_auth_data
  - svn_config_write_auth_data
  - svn_config_clear_auth_data
]]]

Thanks,

--
kou

Index: subversion/include/svn_config.h
===================================================================
--- subversion/include/svn_config.h (revision 15373)
+++ subversion/include/svn_config.h (working copy)
@@ -355,6 +355,20 @@
                                           const char *config_dir,
                                           apr_pool_t *pool);
 
+/** Use @a cred_kind and @a realmstring to locate a file within the
+ * ~/.subversion/auth/ area. If the file exists, remove the
+ * file.
+ *
+ * If @a config_dir is not NULL it specifies a directory from which to
+ * read the config overriding all other sources.
+ *
+ * @since New in 1.3.
+ */
+svn_error_t * svn_config_clear_auth_data (const char *cred_kind,
+ const char *realmstring,
+ const char *config_dir,
+ apr_pool_t *pool);
+
 /** @} */
 
 #ifdef __cplusplus
Index: subversion/libsvn_subr/config_auth.c
===================================================================
--- subversion/libsvn_subr/config_auth.c (revision 15373)
+++ subversion/libsvn_subr/config_auth.c (working copy)
@@ -145,3 +145,24 @@
 
   return SVN_NO_ERROR;
 }
+
+svn_error_t *
+svn_config_clear_auth_data (const char *cred_kind,
+ const char *realmstring,
+ const char *config_dir,
+ apr_pool_t *pool)
+{
+ svn_node_kind_t kind;
+ const char *auth_path;
+
+ SVN_ERR (auth_file_path (&auth_path, cred_kind, realmstring, config_dir,
+ pool));
+ if (! auth_path)
+ return SVN_NO_ERROR;
+
+ SVN_ERR (svn_io_check_path (auth_path, &kind, pool));
+ if (kind == svn_node_file)
+ SVN_ERR (svn_io_remove_file (auth_path, pool));
+
+ return SVN_NO_ERROR;
+}
Index: subversion/tests/libsvn_subr/config-test.c
===================================================================
--- subversion/tests/libsvn_subr/config-test.c (revision 15373)
+++ subversion/tests/libsvn_subr/config-test.c (working copy)
@@ -27,9 +27,12 @@
 
 #include <apr_getopt.h>
 #include <apr_pools.h>
+#include <apr_hash.h>
 
 #include "svn_error.h"
 #include "svn_config.h"
+#include "svn_auth.h"
+#include "svn_io.h"
 
 #include "../svn_test.h"
 
@@ -203,6 +206,68 @@
 }
 
 
+static svn_error_t *
+test3 (const char **msg,
+ svn_boolean_t msg_only,
+ svn_test_opts_t *opts,
+ apr_pool_t *pool)
+{
+ svn_node_kind_t kind;
+ char *config_dir;
+ const char *key = "key";
+ svn_string_t *value = svn_string_create("value", pool);
+ svn_string_t *result;
+ const char *cred_kind = SVN_AUTH_CRED_SIMPLE;
+ const char *realm_string = "sample realm";
+ apr_hash_t *params, *read_params;
+
+ *msg = "test svn_config auth";
+
+ if (msg_only)
+ return SVN_NO_ERROR;
+
+ if (!srcdir)
+ SVN_ERR(init_params(pool));
+
+ apr_filepath_merge(&config_dir, srcdir, "config-dir",
+ APR_FILEPATH_NATIVE, pool);
+ SVN_ERR(svn_io_check_path(config_dir, &kind, pool));
+ if (kind != svn_node_none)
+ SVN_ERR(svn_io_remove_dir(config_dir, pool));
+ SVN_ERR(svn_config_ensure(config_dir, pool));
+
+ SVN_ERR(svn_config_read_auth_data(&read_params, cred_kind, realm_string,
+ config_dir, pool));
+ if (read_params)
+ return fail(pool, "Must be not able to read auth data");
+
+
+ params = apr_hash_make(pool);
+ apr_hash_set(params, key, APR_HASH_KEY_STRING, value);
+ SVN_ERR(svn_config_write_auth_data(params, cred_kind, realm_string,
+ config_dir, pool));
+ SVN_ERR(svn_config_read_auth_data(&read_params, cred_kind, realm_string,
+ config_dir, pool));
+ if (!read_params)
+ return fail(pool, "Must be able to read auth data");
+ result = apr_hash_get(read_params, key, APR_HASH_KEY_STRING);
+ if (!result)
+ return fail(pool, "Value of read_params is NULL");
+ if (!svn_string_compare(value, result))
+ return fail(pool, "Value of read_params '%s' is "
+ "different from wrote value '%s'", result->data, value->data);
+
+
+ svn_config_clear_auth_data(cred_kind, realm_string, config_dir, pool);
+ SVN_ERR(svn_config_read_auth_data(&read_params, cred_kind, realm_string,
+ config_dir, pool));
+ if (read_params)
+ return fail(pool, "Must be not able to read auth data");
+
+ return SVN_NO_ERROR;
+}
+
+
 /*
    ====================================================================
    If you add a new test to this file, update this array.
@@ -216,5 +281,6 @@
     SVN_TEST_NULL,
     SVN_TEST_PASS (test1),
     SVN_TEST_PASS (test2),
+ SVN_TEST_PASS (test3),
     SVN_TEST_NULL
   };

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Thu Jul 21 17:20:22 2005

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.