]>
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 |
40220f48 | 42 | helper_test_authtype cache |
612c49e9 DL |
43 | |
44 | test_expect_success 'socket defaults to ~/.cache/git/credential/socket' ' | |
45 | test_when_finished " | |
46 | git credential-cache exit && | |
47 | rmdir -p .cache/git/credential/ | |
48 | " && | |
49 | test_path_is_missing "$HOME/.git-credential-cache" && | |
0fdcfa2f | 50 | test_path_is_socket "$HOME/.cache/git/credential/socket" |
612c49e9 DL |
51 | ' |
52 | ||
53 | XDG_CACHE_HOME="$HOME/xdg" | |
54 | export XDG_CACHE_HOME | |
55 | # test behavior when XDG_CACHE_HOME is set | |
56 | helper_test cache | |
57 | ||
58 | test_expect_success "use custom XDG_CACHE_HOME if set and default sockets are not created" ' | |
59 | test_when_finished "git credential-cache exit" && | |
0fdcfa2f | 60 | test_path_is_socket "$XDG_CACHE_HOME/git/credential/socket" && |
612c49e9 DL |
61 | test_path_is_missing "$HOME/.git-credential-cache/socket" && |
62 | test_path_is_missing "$HOME/.cache/git/credential/socket" | |
63 | ' | |
64 | unset XDG_CACHE_HOME | |
65 | ||
66 | test_expect_success 'credential-cache --socket option overrides default location' ' | |
67 | test_when_finished " | |
68 | git credential-cache exit --socket \"\$HOME/dir/socket\" && | |
69 | rmdir \"\$HOME/dir\" | |
70 | " && | |
71 | check approve "cache --socket \"\$HOME/dir/socket\"" <<-\EOF && | |
72 | protocol=https | |
73 | host=example.com | |
74 | username=store-user | |
75 | password=store-pass | |
76 | EOF | |
0fdcfa2f | 77 | test_path_is_socket "$HOME/dir/socket" |
612c49e9 DL |
78 | ' |
79 | ||
80 | test_expect_success "use custom XDG_CACHE_HOME even if xdg socket exists" ' | |
81 | test_when_finished " | |
82 | git credential-cache exit && | |
83 | sane_unset XDG_CACHE_HOME | |
84 | " && | |
85 | check approve cache <<-\EOF && | |
86 | protocol=https | |
87 | host=example.com | |
88 | username=store-user | |
89 | password=store-pass | |
90 | EOF | |
0fdcfa2f | 91 | test_path_is_socket "$HOME/.cache/git/credential/socket" && |
612c49e9 DL |
92 | XDG_CACHE_HOME="$HOME/xdg" && |
93 | export XDG_CACHE_HOME && | |
94 | check approve cache <<-\EOF && | |
95 | protocol=https | |
96 | host=example.com | |
97 | username=store-user | |
98 | password=store-pass | |
99 | EOF | |
0fdcfa2f | 100 | test_path_is_socket "$XDG_CACHE_HOME/git/credential/socket" |
612c49e9 DL |
101 | ' |
102 | ||
103 | test_expect_success 'use user socket if user directory exists' ' | |
104 | test_when_finished " | |
105 | git credential-cache exit && | |
106 | rmdir \"\$HOME/.git-credential-cache/\" | |
107 | " && | |
0fdcfa2f CMAB |
108 | mkdir -p "$HOME/.git-credential-cache/" && |
109 | chmod 700 "$HOME/.git-credential-cache/" && | |
612c49e9 DL |
110 | check approve cache <<-\EOF && |
111 | protocol=https | |
112 | host=example.com | |
113 | username=store-user | |
114 | password=store-pass | |
115 | EOF | |
0fdcfa2f | 116 | test_path_is_socket "$HOME/.git-credential-cache/socket" |
612c49e9 DL |
117 | ' |
118 | ||
119 | test_expect_success SYMLINKS 'use user socket if user directory is a symlink to a directory' ' | |
120 | test_when_finished " | |
121 | git credential-cache exit && | |
122 | rmdir \"\$HOME/dir/\" && | |
123 | rm \"\$HOME/.git-credential-cache\" | |
124 | " && | |
125 | mkdir -p -m 700 "$HOME/dir/" && | |
126 | ln -s "$HOME/dir" "$HOME/.git-credential-cache" && | |
127 | check approve cache <<-\EOF && | |
128 | protocol=https | |
129 | host=example.com | |
130 | username=store-user | |
131 | password=store-pass | |
132 | EOF | |
0fdcfa2f | 133 | test_path_is_socket "$HOME/.git-credential-cache/socket" |
612c49e9 DL |
134 | ' |
135 | ||
e2770979 JK |
136 | helper_test_timeout cache --timeout=1 |
137 | ||
e2770979 | 138 | test_done |