commit-reach(paint_down_to_common): plug two memory leaks
[git.git] / t / t0301-credential-cache.sh
blob8300faadea9a76f19e3d2c82f5ff600f38bfe18f
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
32 helper_test_password_expiry_utc cache
33 helper_test_oauth_refresh_token cache
35 test_expect_success 'socket defaults to ~/.cache/git/credential/socket' '
36 test_when_finished "
37 git credential-cache exit &&
38 rmdir -p .cache/git/credential/
39 " &&
40 test_path_is_missing "$HOME/.git-credential-cache" &&
41 test_path_is_socket "$HOME/.cache/git/credential/socket"
44 XDG_CACHE_HOME="$HOME/xdg"
45 export XDG_CACHE_HOME
46 # test behavior when XDG_CACHE_HOME is set
47 helper_test cache
49 test_expect_success "use custom XDG_CACHE_HOME if set and default sockets are not created" '
50 test_when_finished "git credential-cache exit" &&
51 test_path_is_socket "$XDG_CACHE_HOME/git/credential/socket" &&
52 test_path_is_missing "$HOME/.git-credential-cache/socket" &&
53 test_path_is_missing "$HOME/.cache/git/credential/socket"
55 unset XDG_CACHE_HOME
57 test_expect_success 'credential-cache --socket option overrides default location' '
58 test_when_finished "
59 git credential-cache exit --socket \"\$HOME/dir/socket\" &&
60 rmdir \"\$HOME/dir\"
61 " &&
62 check approve "cache --socket \"\$HOME/dir/socket\"" <<-\EOF &&
63 protocol=https
64 host=example.com
65 username=store-user
66 password=store-pass
67 EOF
68 test_path_is_socket "$HOME/dir/socket"
71 test_expect_success "use custom XDG_CACHE_HOME even if xdg socket exists" '
72 test_when_finished "
73 git credential-cache exit &&
74 sane_unset XDG_CACHE_HOME
75 " &&
76 check approve cache <<-\EOF &&
77 protocol=https
78 host=example.com
79 username=store-user
80 password=store-pass
81 EOF
82 test_path_is_socket "$HOME/.cache/git/credential/socket" &&
83 XDG_CACHE_HOME="$HOME/xdg" &&
84 export XDG_CACHE_HOME &&
85 check approve cache <<-\EOF &&
86 protocol=https
87 host=example.com
88 username=store-user
89 password=store-pass
90 EOF
91 test_path_is_socket "$XDG_CACHE_HOME/git/credential/socket"
94 test_expect_success 'use user socket if user directory exists' '
95 test_when_finished "
96 git credential-cache exit &&
97 rmdir \"\$HOME/.git-credential-cache/\"
98 " &&
99 mkdir -p "$HOME/.git-credential-cache/" &&
100 chmod 700 "$HOME/.git-credential-cache/" &&
101 check approve cache <<-\EOF &&
102 protocol=https
103 host=example.com
104 username=store-user
105 password=store-pass
107 test_path_is_socket "$HOME/.git-credential-cache/socket"
110 test_expect_success SYMLINKS 'use user socket if user directory is a symlink to a directory' '
111 test_when_finished "
112 git credential-cache exit &&
113 rmdir \"\$HOME/dir/\" &&
114 rm \"\$HOME/.git-credential-cache\"
115 " &&
116 mkdir -p -m 700 "$HOME/dir/" &&
117 ln -s "$HOME/dir" "$HOME/.git-credential-cache" &&
118 check approve cache <<-\EOF &&
119 protocol=https
120 host=example.com
121 username=store-user
122 password=store-pass
124 test_path_is_socket "$HOME/.git-credential-cache/socket"
127 helper_test_timeout cache --timeout=1
129 test_done