]> git.ipfire.org Git - thirdparty/git.git/blob - t/t0301-credential-cache.sh
Merge branch 'jc/doc-add-placeholder-fix' into HEAD
[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_password_expiry_utc cache
33 helper_test_oauth_refresh_token cache
34
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"
42 '
43
44 XDG_CACHE_HOME="$HOME/xdg"
45 export XDG_CACHE_HOME
46 # test behavior when XDG_CACHE_HOME is set
47 helper_test cache
48
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"
54 '
55 unset XDG_CACHE_HOME
56
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"
69 '
70
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"
92 '
93
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
106 EOF
107 test_path_is_socket "$HOME/.git-credential-cache/socket"
108 '
109
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
123 EOF
124 test_path_is_socket "$HOME/.git-credential-cache/socket"
125 '
126
127 helper_test_timeout cache --timeout=1
128
129 test_done