Jeff King | e277097 | 2011-12-10 05:34:14 -0500 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='credential-cache tests' |
| 4 | . ./test-lib.sh |
| 5 | . "$TEST_DIRECTORY"/lib-credential.sh |
| 6 | |
Johannes Sixt | 6320358 | 2011-12-12 22:12:56 +0100 | [diff] [blame] | 7 | test -z "$NO_UNIX_SOCKETS" || { |
| 8 | skip_all='skipping credential-cache tests, unix sockets not available' |
| 9 | test_done |
| 10 | } |
| 11 | |
Carlo Marcelo Arenas Belón | 0fdcfa2 | 2021-09-14 00:25:58 -0700 | [diff] [blame] | 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 | |
Jeff King | e277097 | 2011-12-10 05:34:14 -0500 | [diff] [blame] | 27 | # don't leave a stale daemon running |
SZEDER Gábor | 3bc2702 | 2019-03-13 13:24:14 +0100 | [diff] [blame] | 28 | test_atexit 'git credential-cache exit' |
Jeff King | e277097 | 2011-12-10 05:34:14 -0500 | [diff] [blame] | 29 | |
Devin Lehmacher | 612c49e | 2017-03-17 08:36:34 -0400 | [diff] [blame] | 30 | # test that the daemon works with no special setup |
Jeff King | e277097 | 2011-12-10 05:34:14 -0500 | [diff] [blame] | 31 | helper_test cache |
M Hickford | a5c7656 | 2023-04-21 09:47:59 +0000 | [diff] [blame] | 32 | helper_test_oauth_refresh_token cache |
Devin Lehmacher | 612c49e | 2017-03-17 08:36:34 -0400 | [diff] [blame] | 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" && |
Carlo Marcelo Arenas Belón | 0fdcfa2 | 2021-09-14 00:25:58 -0700 | [diff] [blame] | 40 | test_path_is_socket "$HOME/.cache/git/credential/socket" |
Devin Lehmacher | 612c49e | 2017-03-17 08:36:34 -0400 | [diff] [blame] | 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" && |
Carlo Marcelo Arenas Belón | 0fdcfa2 | 2021-09-14 00:25:58 -0700 | [diff] [blame] | 50 | test_path_is_socket "$XDG_CACHE_HOME/git/credential/socket" && |
Devin Lehmacher | 612c49e | 2017-03-17 08:36:34 -0400 | [diff] [blame] | 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 |
Carlo Marcelo Arenas Belón | 0fdcfa2 | 2021-09-14 00:25:58 -0700 | [diff] [blame] | 67 | test_path_is_socket "$HOME/dir/socket" |
Devin Lehmacher | 612c49e | 2017-03-17 08:36:34 -0400 | [diff] [blame] | 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 |
Carlo Marcelo Arenas Belón | 0fdcfa2 | 2021-09-14 00:25:58 -0700 | [diff] [blame] | 81 | test_path_is_socket "$HOME/.cache/git/credential/socket" && |
Devin Lehmacher | 612c49e | 2017-03-17 08:36:34 -0400 | [diff] [blame] | 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 |
Carlo Marcelo Arenas Belón | 0fdcfa2 | 2021-09-14 00:25:58 -0700 | [diff] [blame] | 90 | test_path_is_socket "$XDG_CACHE_HOME/git/credential/socket" |
Devin Lehmacher | 612c49e | 2017-03-17 08:36:34 -0400 | [diff] [blame] | 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 | " && |
Carlo Marcelo Arenas Belón | 0fdcfa2 | 2021-09-14 00:25:58 -0700 | [diff] [blame] | 98 | mkdir -p "$HOME/.git-credential-cache/" && |
| 99 | chmod 700 "$HOME/.git-credential-cache/" && |
Devin Lehmacher | 612c49e | 2017-03-17 08:36:34 -0400 | [diff] [blame] | 100 | check approve cache <<-\EOF && |
| 101 | protocol=https |
| 102 | host=example.com |
| 103 | username=store-user |
| 104 | password=store-pass |
| 105 | EOF |
Carlo Marcelo Arenas Belón | 0fdcfa2 | 2021-09-14 00:25:58 -0700 | [diff] [blame] | 106 | test_path_is_socket "$HOME/.git-credential-cache/socket" |
Devin Lehmacher | 612c49e | 2017-03-17 08:36:34 -0400 | [diff] [blame] | 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 |
Carlo Marcelo Arenas Belón | 0fdcfa2 | 2021-09-14 00:25:58 -0700 | [diff] [blame] | 123 | test_path_is_socket "$HOME/.git-credential-cache/socket" |
Devin Lehmacher | 612c49e | 2017-03-17 08:36:34 -0400 | [diff] [blame] | 124 | ' |
| 125 | |
Jeff King | e277097 | 2011-12-10 05:34:14 -0500 | [diff] [blame] | 126 | helper_test_timeout cache --timeout=1 |
| 127 | |
Jeff King | e277097 | 2011-12-10 05:34:14 -0500 | [diff] [blame] | 128 | test_done |