Start the 2.46 cycle
[alt-git.git] / t / t0301-credential-cache.sh
blobf2c146fa2a1dd79fd68bd0c71f836667d5c55cf3
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
11 if test_have_prereq MINGW
12 then
13 service_running=$(sc query afunix | grep "4 RUNNING")
14 test -z "$service_running" || {
15 skip_all='skipping credential-cache tests, unix sockets not available'
16 test_done
20 uname_s=$(uname -s)
21 case $uname_s in
22 *MINGW*)
23 test_path_is_socket () {
24 # `test -S` cannot detect Win10's Unix sockets
25 test_path_exists "$1"
29 test_path_is_socket () {
30 test -S "$1"
33 esac
35 # don't leave a stale daemon running
36 test_atexit 'git credential-cache exit'
38 # test that the daemon works with no special setup
39 helper_test cache
40 helper_test_password_expiry_utc cache
41 helper_test_oauth_refresh_token cache
43 test_expect_success 'socket defaults to ~/.cache/git/credential/socket' '
44 test_when_finished "
45 git credential-cache exit &&
46 rmdir -p .cache/git/credential/
47 " &&
48 test_path_is_missing "$HOME/.git-credential-cache" &&
49 test_path_is_socket "$HOME/.cache/git/credential/socket"
52 XDG_CACHE_HOME="$HOME/xdg"
53 export XDG_CACHE_HOME
54 # test behavior when XDG_CACHE_HOME is set
55 helper_test cache
57 test_expect_success "use custom XDG_CACHE_HOME if set and default sockets are not created" '
58 test_when_finished "git credential-cache exit" &&
59 test_path_is_socket "$XDG_CACHE_HOME/git/credential/socket" &&
60 test_path_is_missing "$HOME/.git-credential-cache/socket" &&
61 test_path_is_missing "$HOME/.cache/git/credential/socket"
63 unset XDG_CACHE_HOME
65 test_expect_success 'credential-cache --socket option overrides default location' '
66 test_when_finished "
67 git credential-cache exit --socket \"\$HOME/dir/socket\" &&
68 rmdir \"\$HOME/dir\"
69 " &&
70 check approve "cache --socket \"\$HOME/dir/socket\"" <<-\EOF &&
71 protocol=https
72 host=example.com
73 username=store-user
74 password=store-pass
75 EOF
76 test_path_is_socket "$HOME/dir/socket"
79 test_expect_success "use custom XDG_CACHE_HOME even if xdg socket exists" '
80 test_when_finished "
81 git credential-cache exit &&
82 sane_unset XDG_CACHE_HOME
83 " &&
84 check approve cache <<-\EOF &&
85 protocol=https
86 host=example.com
87 username=store-user
88 password=store-pass
89 EOF
90 test_path_is_socket "$HOME/.cache/git/credential/socket" &&
91 XDG_CACHE_HOME="$HOME/xdg" &&
92 export XDG_CACHE_HOME &&
93 check approve cache <<-\EOF &&
94 protocol=https
95 host=example.com
96 username=store-user
97 password=store-pass
98 EOF
99 test_path_is_socket "$XDG_CACHE_HOME/git/credential/socket"
102 test_expect_success 'use user socket if user directory exists' '
103 test_when_finished "
104 git credential-cache exit &&
105 rmdir \"\$HOME/.git-credential-cache/\"
106 " &&
107 mkdir -p "$HOME/.git-credential-cache/" &&
108 chmod 700 "$HOME/.git-credential-cache/" &&
109 check approve cache <<-\EOF &&
110 protocol=https
111 host=example.com
112 username=store-user
113 password=store-pass
115 test_path_is_socket "$HOME/.git-credential-cache/socket"
118 test_expect_success SYMLINKS 'use user socket if user directory is a symlink to a directory' '
119 test_when_finished "
120 git credential-cache exit &&
121 rmdir \"\$HOME/dir/\" &&
122 rm \"\$HOME/.git-credential-cache\"
123 " &&
124 mkdir -p -m 700 "$HOME/dir/" &&
125 ln -s "$HOME/dir" "$HOME/.git-credential-cache" &&
126 check approve cache <<-\EOF &&
127 protocol=https
128 host=example.com
129 username=store-user
130 password=store-pass
132 test_path_is_socket "$HOME/.git-credential-cache/socket"
135 helper_test_timeout cache --timeout=1
137 test_done