]>
Commit | Line | Data |
---|---|---|
e2770979 JK |
1 | #!/bin/sh |
2 | ||
3 | test_description='credential-cache tests' | |
4 | . ./test-lib.sh | |
5 | . "$TEST_DIRECTORY"/lib-credential.sh | |
6 | ||
6320358e JS |
7 | test -z "$NO_UNIX_SOCKETS" || { |
8 | skip_all='skipping credential-cache tests, unix sockets not available' | |
9 | test_done | |
10 | } | |
2406bf5f MA |
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 | |
17 | } | |
18 | fi | |
6320358e | 19 | |
0fdcfa2f CMAB |
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" | |
26 | } | |
27 | ;; | |
28 | *) | |
29 | test_path_is_socket () { | |
30 | test -S "$1" | |
31 | } | |
32 | ;; | |
33 | esac | |
34 | ||
e2770979 | 35 | # don't leave a stale daemon running |
3bc2702b | 36 | test_atexit 'git credential-cache exit' |
e2770979 | 37 | |
612c49e9 | 38 | # test that the daemon works with no special setup |
e2770979 | 39 | helper_test cache |
0ce02e2f | 40 | helper_test_password_expiry_utc cache |
a5c76569 | 41 | helper_test_oauth_refresh_token cache |
612c49e9 DL |
42 | |
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" && | |
0fdcfa2f | 49 | test_path_is_socket "$HOME/.cache/git/credential/socket" |
612c49e9 DL |
50 | ' |
51 | ||
52 | XDG_CACHE_HOME="$HOME/xdg" | |
53 | export XDG_CACHE_HOME | |
54 | # test behavior when XDG_CACHE_HOME is set | |
55 | helper_test cache | |
56 | ||
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" && | |
0fdcfa2f | 59 | test_path_is_socket "$XDG_CACHE_HOME/git/credential/socket" && |
612c49e9 DL |
60 | test_path_is_missing "$HOME/.git-credential-cache/socket" && |
61 | test_path_is_missing "$HOME/.cache/git/credential/socket" | |
62 | ' | |
63 | unset XDG_CACHE_HOME | |
64 | ||
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 | |
0fdcfa2f | 76 | test_path_is_socket "$HOME/dir/socket" |
612c49e9 DL |
77 | ' |
78 | ||
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 | |
0fdcfa2f | 90 | test_path_is_socket "$HOME/.cache/git/credential/socket" && |
612c49e9 DL |
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 | |
0fdcfa2f | 99 | test_path_is_socket "$XDG_CACHE_HOME/git/credential/socket" |
612c49e9 DL |
100 | ' |
101 | ||
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 | " && | |
0fdcfa2f CMAB |
107 | mkdir -p "$HOME/.git-credential-cache/" && |
108 | chmod 700 "$HOME/.git-credential-cache/" && | |
612c49e9 DL |
109 | check approve cache <<-\EOF && |
110 | protocol=https | |
111 | host=example.com | |
112 | username=store-user | |
113 | password=store-pass | |
114 | EOF | |
0fdcfa2f | 115 | test_path_is_socket "$HOME/.git-credential-cache/socket" |
612c49e9 DL |
116 | ' |
117 | ||
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 | |
131 | EOF | |
0fdcfa2f | 132 | test_path_is_socket "$HOME/.git-credential-cache/socket" |
612c49e9 DL |
133 | ' |
134 | ||
e2770979 JK |
135 | helper_test_timeout cache --timeout=1 |
136 | ||
e2770979 | 137 | test_done |