3 test_description
='credential-cache tests'
5 TEST_PASSES_SANITIZE_LEAK
=true
7 .
"$TEST_DIRECTORY"/lib-credential.sh
9 test -z "$NO_UNIX_SOCKETS" ||
{
10 skip_all
='skipping credential-cache tests, unix sockets not available'
13 if test_have_prereq MINGW
15 service_running
=$
(sc query afunix |
grep "4 RUNNING")
16 test -z "$service_running" ||
{
17 skip_all
='skipping credential-cache tests, unix sockets not available'
25 test_path_is_socket
() {
26 # `test -S` cannot detect Win10's Unix sockets
31 test_path_is_socket
() {
37 # don't leave a stale daemon running
38 test_atexit
'git credential-cache exit'
40 # test that the daemon works with no special setup
42 helper_test_password_expiry_utc cache
43 helper_test_oauth_refresh_token cache
44 helper_test_authtype cache
46 test_expect_success
'socket defaults to ~/.cache/git/credential/socket' '
48 git credential-cache exit &&
49 rmdir -p .cache/git/credential/
51 test_path_is_missing "$HOME/.git-credential-cache" &&
52 test_path_is_socket "$HOME/.cache/git/credential/socket"
55 XDG_CACHE_HOME
="$HOME/xdg"
57 # test behavior when XDG_CACHE_HOME is set
60 test_expect_success
"use custom XDG_CACHE_HOME if set and default sockets are not created" '
61 test_when_finished "git credential-cache exit" &&
62 test_path_is_socket "$XDG_CACHE_HOME/git/credential/socket" &&
63 test_path_is_missing "$HOME/.git-credential-cache/socket" &&
64 test_path_is_missing "$HOME/.cache/git/credential/socket"
68 test_expect_success
'credential-cache --socket option overrides default location' '
70 git credential-cache exit --socket \"\$HOME/dir/socket\" &&
73 check approve "cache --socket \"\$HOME/dir/socket\"" <<-\EOF &&
79 test_path_is_socket "$HOME/dir/socket"
82 test_expect_success
"use custom XDG_CACHE_HOME even if xdg socket exists" '
84 git credential-cache exit &&
85 sane_unset XDG_CACHE_HOME
87 check approve cache <<-\EOF &&
93 test_path_is_socket "$HOME/.cache/git/credential/socket" &&
94 XDG_CACHE_HOME="$HOME/xdg" &&
95 export XDG_CACHE_HOME &&
96 check approve cache <<-\EOF &&
102 test_path_is_socket "$XDG_CACHE_HOME/git/credential/socket"
105 test_expect_success
'use user socket if user directory exists' '
107 git credential-cache exit &&
108 rmdir \"\$HOME/.git-credential-cache/\"
110 mkdir -p "$HOME/.git-credential-cache/" &&
111 chmod 700 "$HOME/.git-credential-cache/" &&
112 check approve cache <<-\EOF &&
118 test_path_is_socket "$HOME/.git-credential-cache/socket"
121 test_expect_success SYMLINKS
'use user socket if user directory is a symlink to a directory' '
123 git credential-cache exit &&
124 rmdir \"\$HOME/dir/\" &&
125 rm \"\$HOME/.git-credential-cache\"
127 mkdir -p -m 700 "$HOME/dir/" &&
128 ln -s "$HOME/dir" "$HOME/.git-credential-cache" &&
129 check approve cache <<-\EOF &&
135 test_path_is_socket "$HOME/.git-credential-cache/socket"
138 helper_test_timeout cache
--timeout=1