Merge branch 'wl/new-command-doc'
[git.git] / t / t0301-credential-cache.sh
blob698b7159f030905fb63ce4f6856d7ecf49f50b02
1 #!/bin/sh
3 test_description='credential-cache tests'
4 . ./test-lib.sh
5 . "$TEST_DIRECTORY"/lib-credential.sh
7 test -z "$NO_UNIX_SOCKETS" || {
8 skip_all='skipping credential-cache tests, unix sockets not available'
9 test_done
12 uname_s=$(uname -s)
13 case $uname_s in
14 *MINGW*)
15 test_path_is_socket () {
16 # `test -S` cannot detect Win10's Unix sockets
17 test_path_exists "$1"
21 test_path_is_socket () {
22 test -S "$1"
25 esac
27 # don't leave a stale daemon running
28 test_atexit 'git credential-cache exit'
30 # test that the daemon works with no special setup
31 helper_test cache
33 test_expect_success 'socket defaults to ~/.cache/git/credential/socket' '
34 test_when_finished "
35 git credential-cache exit &&
36 rmdir -p .cache/git/credential/
37 " &&
38 test_path_is_missing "$HOME/.git-credential-cache" &&
39 test_path_is_socket "$HOME/.cache/git/credential/socket"
42 XDG_CACHE_HOME="$HOME/xdg"
43 export XDG_CACHE_HOME
44 # test behavior when XDG_CACHE_HOME is set
45 helper_test cache
47 test_expect_success "use custom XDG_CACHE_HOME if set and default sockets are not created" '
48 test_when_finished "git credential-cache exit" &&
49 test_path_is_socket "$XDG_CACHE_HOME/git/credential/socket" &&
50 test_path_is_missing "$HOME/.git-credential-cache/socket" &&
51 test_path_is_missing "$HOME/.cache/git/credential/socket"
53 unset XDG_CACHE_HOME
55 test_expect_success 'credential-cache --socket option overrides default location' '
56 test_when_finished "
57 git credential-cache exit --socket \"\$HOME/dir/socket\" &&
58 rmdir \"\$HOME/dir\"
59 " &&
60 check approve "cache --socket \"\$HOME/dir/socket\"" <<-\EOF &&
61 protocol=https
62 host=example.com
63 username=store-user
64 password=store-pass
65 EOF
66 test_path_is_socket "$HOME/dir/socket"
69 test_expect_success "use custom XDG_CACHE_HOME even if xdg socket exists" '
70 test_when_finished "
71 git credential-cache exit &&
72 sane_unset XDG_CACHE_HOME
73 " &&
74 check approve cache <<-\EOF &&
75 protocol=https
76 host=example.com
77 username=store-user
78 password=store-pass
79 EOF
80 test_path_is_socket "$HOME/.cache/git/credential/socket" &&
81 XDG_CACHE_HOME="$HOME/xdg" &&
82 export XDG_CACHE_HOME &&
83 check approve cache <<-\EOF &&
84 protocol=https
85 host=example.com
86 username=store-user
87 password=store-pass
88 EOF
89 test_path_is_socket "$XDG_CACHE_HOME/git/credential/socket"
92 test_expect_success 'use user socket if user directory exists' '
93 test_when_finished "
94 git credential-cache exit &&
95 rmdir \"\$HOME/.git-credential-cache/\"
96 " &&
97 mkdir -p "$HOME/.git-credential-cache/" &&
98 chmod 700 "$HOME/.git-credential-cache/" &&
99 check approve cache <<-\EOF &&
100 protocol=https
101 host=example.com
102 username=store-user
103 password=store-pass
105 test_path_is_socket "$HOME/.git-credential-cache/socket"
108 test_expect_success SYMLINKS 'use user socket if user directory is a symlink to a directory' '
109 test_when_finished "
110 git credential-cache exit &&
111 rmdir \"\$HOME/dir/\" &&
112 rm \"\$HOME/.git-credential-cache\"
113 " &&
114 mkdir -p -m 700 "$HOME/dir/" &&
115 ln -s "$HOME/dir" "$HOME/.git-credential-cache" &&
116 check approve cache <<-\EOF &&
117 protocol=https
118 host=example.com
119 username=store-user
120 password=store-pass
122 test_path_is_socket "$HOME/.git-credential-cache/socket"
125 helper_test_timeout cache --timeout=1
127 test_done