3 test_description
='credential-cache tests'
5 .
"$TEST_DIRECTORY"/lib-credential.sh
7 test -z "$NO_UNIX_SOCKETS" ||
{
8 skip_all
='skipping credential-cache tests, unix sockets not available'
15 test_path_is_socket
() {
16 # `test -S` cannot detect Win10's Unix sockets
21 test_path_is_socket
() {
27 # don't leave a stale daemon running
28 test_atexit
'git credential-cache exit'
30 # test that the daemon works with no special setup
33 test_expect_success
'socket defaults to ~/.cache/git/credential/socket' '
35 git credential-cache exit &&
36 rmdir -p .cache/git/credential/
38 test_path_is_missing "$HOME/.git-credential-cache" &&
39 test_path_is_socket "$HOME/.cache/git/credential/socket"
42 XDG_CACHE_HOME
="$HOME/xdg"
44 # test behavior when XDG_CACHE_HOME is set
47 test_expect_success
"use custom XDG_CACHE_HOME if set and default sockets are not created" '
48 test_when_finished "git credential-cache exit" &&
49 test_path_is_socket "$XDG_CACHE_HOME/git/credential/socket" &&
50 test_path_is_missing "$HOME/.git-credential-cache/socket" &&
51 test_path_is_missing "$HOME/.cache/git/credential/socket"
55 test_expect_success
'credential-cache --socket option overrides default location' '
57 git credential-cache exit --socket \"\$HOME/dir/socket\" &&
60 check approve "cache --socket \"\$HOME/dir/socket\"" <<-\EOF &&
66 test_path_is_socket "$HOME/dir/socket"
69 test_expect_success
"use custom XDG_CACHE_HOME even if xdg socket exists" '
71 git credential-cache exit &&
72 sane_unset XDG_CACHE_HOME
74 check approve cache <<-\EOF &&
80 test_path_is_socket "$HOME/.cache/git/credential/socket" &&
81 XDG_CACHE_HOME="$HOME/xdg" &&
82 export XDG_CACHE_HOME &&
83 check approve cache <<-\EOF &&
89 test_path_is_socket "$XDG_CACHE_HOME/git/credential/socket"
92 test_expect_success
'use user socket if user directory exists' '
94 git credential-cache exit &&
95 rmdir \"\$HOME/.git-credential-cache/\"
97 mkdir -p "$HOME/.git-credential-cache/" &&
98 chmod 700 "$HOME/.git-credential-cache/" &&
99 check approve cache <<-\EOF &&
105 test_path_is_socket "$HOME/.git-credential-cache/socket"
108 test_expect_success SYMLINKS
'use user socket if user directory is a symlink to a directory' '
110 git credential-cache exit &&
111 rmdir \"\$HOME/dir/\" &&
112 rm \"\$HOME/.git-credential-cache\"
114 mkdir -p -m 700 "$HOME/dir/" &&
115 ln -s "$HOME/dir" "$HOME/.git-credential-cache" &&
116 check approve cache <<-\EOF &&
122 test_path_is_socket "$HOME/.git-credential-cache/socket"
125 helper_test_timeout cache
--timeout=1