Raw
1 #!/bin/sh
2
3 test_description='credential-cache tests'
4
5 . ./test-lib.sh
6 . "$TEST_DIRECTORY"/lib-credential.sh
7
8 test -z "$NO_UNIX_SOCKETS" || {
9 skip_all='skipping credential-cache tests, unix sockets not available'
10 test_done
11 }
12 if test_have_prereq MINGW
13 then
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 }
19 fi
20
21 uname_s=$(uname -s)
22 case $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 ;;
34 esac
35
36 # don't leave a stale daemon running
37 test_atexit 'git credential-cache exit'
38
39 # test that the daemon works with no special setup
40 helper_test cache
41 helper_test_password_expiry_utc cache
42 helper_test_oauth_refresh_token cache
43 helper_test_authtype cache
44
45 test_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
54 XDG_CACHE_HOME="$HOME/xdg"
55 export XDG_CACHE_HOME
56 # test behavior when XDG_CACHE_HOME is set
57 helper_test cache
58
59 test_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 '
65 unset XDG_CACHE_HOME
66
67 test_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
81 test_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
104 test_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
120 test_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 "$HOME/dir/" &&
127 chmod 700 "$HOME/dir/" &&
128 ln -s "$HOME/dir" "$HOME/.git-credential-cache" &&
129 check approve cache <<-\EOF &&
130 protocol=https
131 host=example.com
132 username=store-user
133 password=store-pass
134 EOF
135 test_path_is_socket "$HOME/.git-credential-cache/socket"
136 '
137
138 helper_test_timeout cache --timeout=1
139
140 test_done