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