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'
11 if test_have_prereq MINGW
13 service_running
=$
(sc query afunix |
grep "4 RUNNING")
14 test -z "$service_running" ||
{
15 skip_all
='skipping credential-cache tests, unix sockets not available'
23 test_path_is_socket
() {
24 # `test -S` cannot detect Win10's Unix sockets
29 test_path_is_socket
() {
35 # don't leave a stale daemon running
36 test_atexit
'git credential-cache exit'
38 # test that the daemon works with no special setup
40 helper_test_password_expiry_utc cache
41 helper_test_oauth_refresh_token cache
43 test_expect_success
'socket defaults to ~/.cache/git/credential/socket' '
45 git credential-cache exit &&
46 rmdir -p .cache/git/credential/
48 test_path_is_missing "$HOME/.git-credential-cache" &&
49 test_path_is_socket "$HOME/.cache/git/credential/socket"
52 XDG_CACHE_HOME
="$HOME/xdg"
54 # test behavior when XDG_CACHE_HOME is set
57 test_expect_success
"use custom XDG_CACHE_HOME if set and default sockets are not created" '
58 test_when_finished "git credential-cache exit" &&
59 test_path_is_socket "$XDG_CACHE_HOME/git/credential/socket" &&
60 test_path_is_missing "$HOME/.git-credential-cache/socket" &&
61 test_path_is_missing "$HOME/.cache/git/credential/socket"
65 test_expect_success
'credential-cache --socket option overrides default location' '
67 git credential-cache exit --socket \"\$HOME/dir/socket\" &&
70 check approve "cache --socket \"\$HOME/dir/socket\"" <<-\EOF &&
76 test_path_is_socket "$HOME/dir/socket"
79 test_expect_success
"use custom XDG_CACHE_HOME even if xdg socket exists" '
81 git credential-cache exit &&
82 sane_unset XDG_CACHE_HOME
84 check approve cache <<-\EOF &&
90 test_path_is_socket "$HOME/.cache/git/credential/socket" &&
91 XDG_CACHE_HOME="$HOME/xdg" &&
92 export XDG_CACHE_HOME &&
93 check approve cache <<-\EOF &&
99 test_path_is_socket "$XDG_CACHE_HOME/git/credential/socket"
102 test_expect_success
'use user socket if user directory exists' '
104 git credential-cache exit &&
105 rmdir \"\$HOME/.git-credential-cache/\"
107 mkdir -p "$HOME/.git-credential-cache/" &&
108 chmod 700 "$HOME/.git-credential-cache/" &&
109 check approve cache <<-\EOF &&
115 test_path_is_socket "$HOME/.git-credential-cache/socket"
118 test_expect_success SYMLINKS
'use user socket if user directory is a symlink to a directory' '
120 git credential-cache exit &&
121 rmdir \"\$HOME/dir/\" &&
122 rm \"\$HOME/.git-credential-cache\"
124 mkdir -p -m 700 "$HOME/dir/" &&
125 ln -s "$HOME/dir" "$HOME/.git-credential-cache" &&
126 check approve cache <<-\EOF &&
132 test_path_is_socket "$HOME/.git-credential-cache/socket"
135 helper_test_timeout cache
--timeout=1