Git fork
1#!/bin/sh
2
3test_description='credential-cache tests'
4
5. ./test-lib.sh
6. "$TEST_DIRECTORY"/lib-credential.sh
7
8test -z "$NO_UNIX_SOCKETS" || {
9 skip_all='skipping credential-cache tests, unix sockets not available'
10 test_done
11}
12if test_have_prereq MINGW
13then
14 service_running=$(sc query afunix | grep "4 RUNNING")
15 test -z "$service_running" || {
16 skip_all='skipping credential-cache tests, unix sockets not available'
17 test_done
18 }
19fi
20
21uname_s=$(uname -s)
22case $uname_s in
23*MINGW*)
24 test_path_is_socket () {
25 # `test -S` cannot detect Win10's Unix sockets
26 test_path_exists "$1"
27 }
28 ;;
29*)
30 test_path_is_socket () {
31 test -S "$1"
32 }
33 ;;
34esac
35
36# don't leave a stale daemon running
37test_atexit 'git credential-cache exit'
38
39# test that the daemon works with no special setup
40helper_test cache
41helper_test_password_expiry_utc cache
42helper_test_oauth_refresh_token cache
43helper_test_authtype cache
44
45test_expect_success 'socket defaults to ~/.cache/git/credential/socket' '
46 test_when_finished "
47 git credential-cache exit &&
48 rmdir -p .cache/git/credential/
49 " &&
50 test_path_is_missing "$HOME/.git-credential-cache" &&
51 test_path_is_socket "$HOME/.cache/git/credential/socket"
52'
53
54XDG_CACHE_HOME="$HOME/xdg"
55export XDG_CACHE_HOME
56# test behavior when XDG_CACHE_HOME is set
57helper_test cache
58
59test_expect_success "use custom XDG_CACHE_HOME if set and default sockets are not created" '
60 test_when_finished "git credential-cache exit" &&
61 test_path_is_socket "$XDG_CACHE_HOME/git/credential/socket" &&
62 test_path_is_missing "$HOME/.git-credential-cache/socket" &&
63 test_path_is_missing "$HOME/.cache/git/credential/socket"
64'
65unset XDG_CACHE_HOME
66
67test_expect_success 'credential-cache --socket option overrides default location' '
68 test_when_finished "
69 git credential-cache exit --socket \"\$HOME/dir/socket\" &&
70 rmdir \"\$HOME/dir\"
71 " &&
72 check approve "cache --socket \"\$HOME/dir/socket\"" <<-\EOF &&
73 protocol=https
74 host=example.com
75 username=store-user
76 password=store-pass
77 EOF
78 test_path_is_socket "$HOME/dir/socket"
79'
80
81test_expect_success "use custom XDG_CACHE_HOME even if xdg socket exists" '
82 test_when_finished "
83 git credential-cache exit &&
84 sane_unset XDG_CACHE_HOME
85 " &&
86 check approve cache <<-\EOF &&
87 protocol=https
88 host=example.com
89 username=store-user
90 password=store-pass
91 EOF
92 test_path_is_socket "$HOME/.cache/git/credential/socket" &&
93 XDG_CACHE_HOME="$HOME/xdg" &&
94 export XDG_CACHE_HOME &&
95 check approve cache <<-\EOF &&
96 protocol=https
97 host=example.com
98 username=store-user
99 password=store-pass
100 EOF
101 test_path_is_socket "$XDG_CACHE_HOME/git/credential/socket"
102'
103
104test_expect_success 'use user socket if user directory exists' '
105 test_when_finished "
106 git credential-cache exit &&
107 rmdir \"\$HOME/.git-credential-cache/\"
108 " &&
109 mkdir -p "$HOME/.git-credential-cache/" &&
110 chmod 700 "$HOME/.git-credential-cache/" &&
111 check approve cache <<-\EOF &&
112 protocol=https
113 host=example.com
114 username=store-user
115 password=store-pass
116 EOF
117 test_path_is_socket "$HOME/.git-credential-cache/socket"
118'
119
120test_expect_success SYMLINKS 'use user socket if user directory is a symlink to a directory' '
121 test_when_finished "
122 git credential-cache exit &&
123 rmdir \"\$HOME/dir/\" &&
124 rm \"\$HOME/.git-credential-cache\"
125 " &&
126 mkdir -p -m 700 "$HOME/dir/" &&
127 ln -s "$HOME/dir" "$HOME/.git-credential-cache" &&
128 check approve cache <<-\EOF &&
129 protocol=https
130 host=example.com
131 username=store-user
132 password=store-pass
133 EOF
134 test_path_is_socket "$HOME/.git-credential-cache/socket"
135'
136
137helper_test_timeout cache --timeout=1
138
139test_done