Merge branch 'po/git-help-on-git-itself'
[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 # don't leave a stale daemon running
13 test_atexit 'git credential-cache exit'
14
15 # test that the daemon works with no special setup
16 helper_test cache
17
18 test_expect_success 'socket defaults to ~/.cache/git/credential/socket' '
19         test_when_finished "
20                 git credential-cache exit &&
21                 rmdir -p .cache/git/credential/
22         " &&
23         test_path_is_missing "$HOME/.git-credential-cache" &&
24         test -S "$HOME/.cache/git/credential/socket"
25 '
26
27 XDG_CACHE_HOME="$HOME/xdg"
28 export XDG_CACHE_HOME
29 # test behavior when XDG_CACHE_HOME is set
30 helper_test cache
31
32 test_expect_success "use custom XDG_CACHE_HOME if set and default sockets are not created" '
33         test_when_finished "git credential-cache exit" &&
34         test -S "$XDG_CACHE_HOME/git/credential/socket" &&
35         test_path_is_missing "$HOME/.git-credential-cache/socket" &&
36         test_path_is_missing "$HOME/.cache/git/credential/socket"
37 '
38 unset XDG_CACHE_HOME
39
40 test_expect_success 'credential-cache --socket option overrides default location' '
41         test_when_finished "
42                 git credential-cache exit --socket \"\$HOME/dir/socket\" &&
43                 rmdir \"\$HOME/dir\"
44         " &&
45         check approve "cache --socket \"\$HOME/dir/socket\"" <<-\EOF &&
46         protocol=https
47         host=example.com
48         username=store-user
49         password=store-pass
50         EOF
51         test -S "$HOME/dir/socket"
52 '
53
54 test_expect_success "use custom XDG_CACHE_HOME even if xdg socket exists" '
55         test_when_finished "
56                 git credential-cache exit &&
57                 sane_unset XDG_CACHE_HOME
58         " &&
59         check approve cache <<-\EOF &&
60         protocol=https
61         host=example.com
62         username=store-user
63         password=store-pass
64         EOF
65         test -S "$HOME/.cache/git/credential/socket" &&
66         XDG_CACHE_HOME="$HOME/xdg" &&
67         export XDG_CACHE_HOME &&
68         check approve cache <<-\EOF &&
69         protocol=https
70         host=example.com
71         username=store-user
72         password=store-pass
73         EOF
74         test -S "$XDG_CACHE_HOME/git/credential/socket"
75 '
76
77 test_expect_success 'use user socket if user directory exists' '
78         test_when_finished "
79                 git credential-cache exit &&
80                 rmdir \"\$HOME/.git-credential-cache/\"
81         " &&
82         mkdir -p -m 700 "$HOME/.git-credential-cache/" &&
83         check approve cache <<-\EOF &&
84         protocol=https
85         host=example.com
86         username=store-user
87         password=store-pass
88         EOF
89         test -S "$HOME/.git-credential-cache/socket"
90 '
91
92 test_expect_success SYMLINKS 'use user socket if user directory is a symlink to a directory' '
93         test_when_finished "
94                 git credential-cache exit &&
95                 rmdir \"\$HOME/dir/\" &&
96                 rm \"\$HOME/.git-credential-cache\"
97         " &&
98         mkdir -p -m 700 "$HOME/dir/" &&
99         ln -s "$HOME/dir" "$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 -S "$HOME/.git-credential-cache/socket"
107 '
108
109 helper_test_timeout cache --timeout=1
110
111 test_done