]> git.ipfire.org Git - thirdparty/git.git/blob - t/t0301-credential-cache.sh
Merge branch 'jc/commit-new-underscore-index-fix' into maint-2.42
[thirdparty/git.git] / t / t0301-credential-cache.sh
1 #!/bin/sh
2
3 test_description='credential-cache tests'
4 . ./test-lib.sh
5 . "$TEST_DIRECTORY"/lib-credential.sh
6
7 test -z "$NO_UNIX_SOCKETS" || {
8 skip_all='skipping credential-cache tests, unix sockets not available'
9 test_done
10 }
11
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"
18 }
19 ;;
20 *)
21 test_path_is_socket () {
22 test -S "$1"
23 }
24 ;;
25 esac
26
27 # don't leave a stale daemon running
28 test_atexit 'git credential-cache exit'
29
30 # test that the daemon works with no special setup
31 helper_test cache
32 helper_test_oauth_refresh_token cache
33
34 test_expect_success 'socket defaults to ~/.cache/git/credential/socket' '
35 test_when_finished "
36 git credential-cache exit &&
37 rmdir -p .cache/git/credential/
38 " &&
39 test_path_is_missing "$HOME/.git-credential-cache" &&
40 test_path_is_socket "$HOME/.cache/git/credential/socket"
41 '
42
43 XDG_CACHE_HOME="$HOME/xdg"
44 export XDG_CACHE_HOME
45 # test behavior when XDG_CACHE_HOME is set
46 helper_test cache
47
48 test_expect_success "use custom XDG_CACHE_HOME if set and default sockets are not created" '
49 test_when_finished "git credential-cache exit" &&
50 test_path_is_socket "$XDG_CACHE_HOME/git/credential/socket" &&
51 test_path_is_missing "$HOME/.git-credential-cache/socket" &&
52 test_path_is_missing "$HOME/.cache/git/credential/socket"
53 '
54 unset XDG_CACHE_HOME
55
56 test_expect_success 'credential-cache --socket option overrides default location' '
57 test_when_finished "
58 git credential-cache exit --socket \"\$HOME/dir/socket\" &&
59 rmdir \"\$HOME/dir\"
60 " &&
61 check approve "cache --socket \"\$HOME/dir/socket\"" <<-\EOF &&
62 protocol=https
63 host=example.com
64 username=store-user
65 password=store-pass
66 EOF
67 test_path_is_socket "$HOME/dir/socket"
68 '
69
70 test_expect_success "use custom XDG_CACHE_HOME even if xdg socket exists" '
71 test_when_finished "
72 git credential-cache exit &&
73 sane_unset XDG_CACHE_HOME
74 " &&
75 check approve cache <<-\EOF &&
76 protocol=https
77 host=example.com
78 username=store-user
79 password=store-pass
80 EOF
81 test_path_is_socket "$HOME/.cache/git/credential/socket" &&
82 XDG_CACHE_HOME="$HOME/xdg" &&
83 export XDG_CACHE_HOME &&
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 "$XDG_CACHE_HOME/git/credential/socket"
91 '
92
93 test_expect_success 'use user socket if user directory exists' '
94 test_when_finished "
95 git credential-cache exit &&
96 rmdir \"\$HOME/.git-credential-cache/\"
97 " &&
98 mkdir -p "$HOME/.git-credential-cache/" &&
99 chmod 700 "$HOME/.git-credential-cache/" &&
100 check approve cache <<-\EOF &&
101 protocol=https
102 host=example.com
103 username=store-user
104 password=store-pass
105 EOF
106 test_path_is_socket "$HOME/.git-credential-cache/socket"
107 '
108
109 test_expect_success SYMLINKS 'use user socket if user directory is a symlink to a directory' '
110 test_when_finished "
111 git credential-cache exit &&
112 rmdir \"\$HOME/dir/\" &&
113 rm \"\$HOME/.git-credential-cache\"
114 " &&
115 mkdir -p -m 700 "$HOME/dir/" &&
116 ln -s "$HOME/dir" "$HOME/.git-credential-cache" &&
117 check approve cache <<-\EOF &&
118 protocol=https
119 host=example.com
120 username=store-user
121 password=store-pass
122 EOF
123 test_path_is_socket "$HOME/.git-credential-cache/socket"
124 '
125
126 helper_test_timeout cache --timeout=1
127
128 test_done