diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2015-03-18 13:33:26 +0000 |
---|---|---|
committer | <> | 2015-07-08 14:41:01 +0000 |
commit | bb0ef45f7c46b0ae221b26265ef98a768c33f820 (patch) | |
tree | 98bae10dde41c746c51ae97ec4f879e330415aa7 /subversion/tests/libsvn_subr/auth-test.c | |
parent | 239dfafe71711b2f4c43d7b90a1228d7bdc5195e (diff) | |
download | subversion-tarball-subversion-1.8.13.tar.gz |
Imported from /home/lorry/working-area/delta_subversion-tarball/subversion-1.8.13.tar.gz.subversion-1.8.13
Diffstat (limited to 'subversion/tests/libsvn_subr/auth-test.c')
-rw-r--r-- | subversion/tests/libsvn_subr/auth-test.c | 128 |
1 files changed, 122 insertions, 6 deletions
diff --git a/subversion/tests/libsvn_subr/auth-test.c b/subversion/tests/libsvn_subr/auth-test.c index 6c3862d..9d7d866 100644 --- a/subversion/tests/libsvn_subr/auth-test.c +++ b/subversion/tests/libsvn_subr/auth-test.c @@ -22,9 +22,11 @@ */ #include "svn_auth.h" +#include "svn_dirent_uri.h" #include "svn_private_config.h" #include "../svn_test.h" +#include "private/svn_auth_private.h" static svn_error_t * test_platform_specific_auth_providers(apr_pool_t *pool) @@ -54,6 +56,9 @@ test_platform_specific_auth_providers(apr_pool_t *pool) #ifdef SVN_HAVE_KWALLET number_of_providers += 2; #endif +#ifdef SVN_HAVE_GPG_AGENT + number_of_providers += 1; +#endif #ifdef SVN_HAVE_KEYCHAIN_SERVICES number_of_providers += 2; #endif @@ -140,8 +145,8 @@ test_platform_specific_auth_providers(apr_pool_t *pool) /* Test GNOME Keyring auth providers */ #ifdef SVN_HAVE_GNOME_KEYRING - svn_auth_get_platform_specific_provider(&provider, "gnome_keyring", - "simple", pool); + SVN_ERR(svn_auth_get_platform_specific_provider(&provider, "gnome_keyring", + "simple", pool)); if (!provider) return svn_error_createf @@ -149,8 +154,8 @@ test_platform_specific_auth_providers(apr_pool_t *pool) "svn_auth_get_platform_specific_provider('gnome_keyring', 'simple') " "should not return NULL"); - svn_auth_get_platform_specific_provider(&provider, "gnome_keyring", - "ssl_client_cert_pw", pool); + SVN_ERR(svn_auth_get_platform_specific_provider(&provider, "gnome_keyring", + "ssl_client_cert_pw", pool)); if (!provider) return svn_error_createf @@ -159,8 +164,8 @@ test_platform_specific_auth_providers(apr_pool_t *pool) "'ssl_client_cert_pw') should not return NULL"); /* Make sure you do not get a Windows auth provider */ - svn_auth_get_platform_specific_provider(&provider, "windows", - "simple", pool); + SVN_ERR(svn_auth_get_platform_specific_provider(&provider, "windows", + "simple", pool)); if (provider) return svn_error_createf @@ -203,6 +208,109 @@ test_platform_specific_auth_providers(apr_pool_t *pool) return SVN_NO_ERROR; } +/* Helper for test_auth_clear(). Implements svn_config_auth_walk_func_t */ +static svn_error_t * +cleanup_callback(svn_boolean_t *delete_cred, + void *walk_baton, + const char *cred_kind, + const char *realmstring, + apr_hash_t *cred_hash, + apr_pool_t *scratch_pool) +{ + svn_auth_baton_t *b = walk_baton; + + SVN_TEST_ASSERT(strcmp(cred_kind, SVN_AUTH_CRED_SIMPLE) == 0); + SVN_TEST_ASSERT(strcmp(realmstring, "<http://my.host> My realm") == 0); + + SVN_ERR(svn_auth_forget_credentials(b, cred_kind, realmstring, scratch_pool)); + + *delete_cred = TRUE; + + return SVN_NO_ERROR; +} + +static svn_error_t * +test_auth_clear(apr_pool_t *pool) +{ + const char *auth_dir; + svn_auth_provider_object_t *provider; + svn_auth_baton_t *baton; + apr_array_header_t *providers; + void *credentials; + svn_auth_cred_simple_t *creds; + svn_auth_iterstate_t *state; + + SVN_ERR(svn_dirent_get_absolute(&auth_dir, "", pool)); + auth_dir = svn_dirent_join(auth_dir, "auth-clear", pool); + + svn_test_add_dir_cleanup(auth_dir); + + SVN_ERR(svn_io_remove_dir2(auth_dir, TRUE, NULL, NULL, pool)); + SVN_ERR(svn_io_dir_make(auth_dir, APR_OS_DEFAULT, pool)); + + svn_auth_get_simple_provider2(&provider, NULL, NULL, pool); + + providers = apr_array_make(pool, 1, sizeof(svn_auth_provider_object_t *)); + APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider; + + svn_auth_open(&baton, providers, pool); + + svn_auth_set_parameter(baton, SVN_AUTH_PARAM_DEFAULT_USERNAME, "jrandom"); + svn_auth_set_parameter(baton, SVN_AUTH_PARAM_DEFAULT_PASSWORD, "rayjandom"); + svn_auth_set_parameter(baton, SVN_AUTH_PARAM_CONFIG_DIR, auth_dir); + + /* Create the auth subdirs. Without these we can't store passwords */ + SVN_ERR(svn_config_ensure(auth_dir, pool)); + + /* Obtain the default credentials just passed */ + SVN_ERR(svn_auth_first_credentials(&credentials, + &state, + SVN_AUTH_CRED_SIMPLE, + "<http://my.host> My realm", + baton, + pool)); + + creds = credentials; + SVN_TEST_ASSERT(strcmp(creds->username, "jrandom") == 0); + SVN_TEST_ASSERT(creds->may_save); + + /* And tell that they are ok and can be saved */ + SVN_ERR(svn_auth_save_credentials(state, pool)); + + /* Ok, and now we try to remove the credentials */ + svn_auth_set_parameter(baton, SVN_AUTH_PARAM_DEFAULT_USERNAME, NULL); + svn_auth_set_parameter(baton, SVN_AUTH_PARAM_DEFAULT_PASSWORD, NULL); + + /* Are they still in the baton? */ + SVN_ERR(svn_auth_first_credentials(&credentials, + &state, + SVN_AUTH_CRED_SIMPLE, + "<http://my.host> My realm", + baton, + pool)); + + SVN_TEST_ASSERT(credentials); + creds = credentials; + SVN_TEST_ASSERT(strcmp(creds->username, "jrandom") == 0); + SVN_TEST_ASSERT(creds->may_save); + + /* Use our walker function to delete credentials (and forget them + from the auth baton). */ + SVN_ERR(svn_config_walk_auth_data(auth_dir, cleanup_callback, baton, pool)); + + /* Finally, they should be gone! */ + SVN_ERR(svn_auth_first_credentials(&credentials, + &state, + SVN_AUTH_CRED_SIMPLE, + "<http://my.host> My realm", + baton, + pool)); + + SVN_TEST_ASSERT(! credentials); + + return SVN_NO_ERROR; +} + /* The test table. */ @@ -211,5 +319,13 @@ struct svn_test_descriptor_t test_funcs[] = SVN_TEST_NULL, SVN_TEST_PASS2(test_platform_specific_auth_providers, "test retrieving platform-specific auth providers"), +#ifndef SVN_DISABLE_PLAINTEXT_PASSWORD_STORAGE + SVN_TEST_PASS2(test_auth_clear, + "test svn_auth_clear()"), +#else + SVN_TEST_WIMP(test_auth_clear, + "test svn_auth_clear()", + "Needs testing with SVN_DISABLE_PLAINTEXT_PASSWORD_STORAGE"), +#endif SVN_TEST_NULL }; |