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
42 helper_test_authtype cache
44 test_expect_success
'socket defaults to ~/.cache/git/credential/socket' '
46 git credential-cache exit &&
47 rmdir -p .cache/git/credential/
49 test_path_is_missing "$HOME/.git-credential-cache" &&
50 test_path_is_socket "$HOME/.cache/git/credential/socket"
53 XDG_CACHE_HOME
="$HOME/xdg"
55 # test behavior when XDG_CACHE_HOME is set
58 test_expect_success
"use custom XDG_CACHE_HOME if set and default sockets are not created" '
59 test_when_finished "git credential-cache exit" &&
60 test_path_is_socket "$XDG_CACHE_HOME/git/credential/socket" &&
61 test_path_is_missing "$HOME/.git-credential-cache/socket" &&
62 test_path_is_missing "$HOME/.cache/git/credential/socket"
66 test_expect_success
'credential-cache --socket option overrides default location' '
68 git credential-cache exit --socket \"\$HOME/dir/socket\" &&
71 check approve "cache --socket \"\$HOME/dir/socket\"" <<-\EOF &&
77 test_path_is_socket "$HOME/dir/socket"
80 test_expect_success
"use custom XDG_CACHE_HOME even if xdg socket exists" '
82 git credential-cache exit &&
83 sane_unset XDG_CACHE_HOME
85 check approve cache <<-\EOF &&
91 test_path_is_socket "$HOME/.cache/git/credential/socket" &&
92 XDG_CACHE_HOME="$HOME/xdg" &&
93 export XDG_CACHE_HOME &&
94 check approve cache <<-\EOF &&
100 test_path_is_socket "$XDG_CACHE_HOME/git/credential/socket"
103 test_expect_success
'use user socket if user directory exists' '
105 git credential-cache exit &&
106 rmdir \"\$HOME/.git-credential-cache/\"
108 mkdir -p "$HOME/.git-credential-cache/" &&
109 chmod 700 "$HOME/.git-credential-cache/" &&
110 check approve cache <<-\EOF &&
116 test_path_is_socket "$HOME/.git-credential-cache/socket"
119 test_expect_success SYMLINKS
'use user socket if user directory is a symlink to a directory' '
121 git credential-cache exit &&
122 rmdir \"\$HOME/dir/\" &&
123 rm \"\$HOME/.git-credential-cache\"
125 mkdir -p -m 700 "$HOME/dir/" &&
126 ln -s "$HOME/dir" "$HOME/.git-credential-cache" &&
127 check approve cache <<-\EOF &&
133 test_path_is_socket "$HOME/.git-credential-cache/socket"
136 helper_test_timeout cache
--timeout=1