mirror of
https://github.com/git/git.git
synced 2024-12-04 23:44:14 +08:00
89a70b80eb
When cleaning up files in the $HOME directory, it really makes sense to quote the path, especially in Git's test suite, where the HOME directory is *guaranteed* to contain spaces in its name. It would appear that those two tests pass even without cleaning up the files, but really more by pure chance than by design (the cleanup seems not actually to be necessary). However, if anybody would have a left-over `trash/` directory in Git's `t/` directory, these tests would fail, because they would all of a sudden try to delete that directory, but without the `-r` (recursive) flag. That is how this issue was found. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Reviewed-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
124 lines
3.3 KiB
Bash
Executable File
124 lines
3.3 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
test_description='credential-store tests'
|
|
. ./test-lib.sh
|
|
. "$TEST_DIRECTORY"/lib-credential.sh
|
|
|
|
helper_test store
|
|
|
|
test_expect_success 'when xdg file does not exist, xdg file not created' '
|
|
test_path_is_missing "$HOME/.config/git/credentials" &&
|
|
test -s "$HOME/.git-credentials"
|
|
'
|
|
|
|
test_expect_success 'setup xdg file' '
|
|
rm -f "$HOME/.git-credentials" &&
|
|
mkdir -p "$HOME/.config/git" &&
|
|
>"$HOME/.config/git/credentials"
|
|
'
|
|
|
|
helper_test store
|
|
|
|
test_expect_success 'when xdg file exists, home file not created' '
|
|
test -s "$HOME/.config/git/credentials" &&
|
|
test_path_is_missing "$HOME/.git-credentials"
|
|
'
|
|
|
|
test_expect_success 'setup custom xdg file' '
|
|
rm -f "$HOME/.git-credentials" &&
|
|
rm -f "$HOME/.config/git/credentials" &&
|
|
mkdir -p "$HOME/xdg/git" &&
|
|
>"$HOME/xdg/git/credentials"
|
|
'
|
|
|
|
XDG_CONFIG_HOME="$HOME/xdg"
|
|
export XDG_CONFIG_HOME
|
|
helper_test store
|
|
unset XDG_CONFIG_HOME
|
|
|
|
test_expect_success 'if custom xdg file exists, home and xdg files not created' '
|
|
test_when_finished "rm -f \"$HOME/xdg/git/credentials\"" &&
|
|
test -s "$HOME/xdg/git/credentials" &&
|
|
test_path_is_missing "$HOME/.git-credentials" &&
|
|
test_path_is_missing "$HOME/.config/git/credentials"
|
|
'
|
|
|
|
test_expect_success 'get: use home file if both home and xdg files have matches' '
|
|
echo "https://home-user:home-pass@example.com" >"$HOME/.git-credentials" &&
|
|
mkdir -p "$HOME/.config/git" &&
|
|
echo "https://xdg-user:xdg-pass@example.com" >"$HOME/.config/git/credentials" &&
|
|
check fill store <<-\EOF
|
|
protocol=https
|
|
host=example.com
|
|
--
|
|
protocol=https
|
|
host=example.com
|
|
username=home-user
|
|
password=home-pass
|
|
--
|
|
EOF
|
|
'
|
|
|
|
test_expect_success 'get: use xdg file if home file has no matches' '
|
|
>"$HOME/.git-credentials" &&
|
|
mkdir -p "$HOME/.config/git" &&
|
|
echo "https://xdg-user:xdg-pass@example.com" >"$HOME/.config/git/credentials" &&
|
|
check fill store <<-\EOF
|
|
protocol=https
|
|
host=example.com
|
|
--
|
|
protocol=https
|
|
host=example.com
|
|
username=xdg-user
|
|
password=xdg-pass
|
|
--
|
|
EOF
|
|
'
|
|
|
|
test_expect_success POSIXPERM,SANITY 'get: use xdg file if home file is unreadable' '
|
|
echo "https://home-user:home-pass@example.com" >"$HOME/.git-credentials" &&
|
|
chmod -r "$HOME/.git-credentials" &&
|
|
mkdir -p "$HOME/.config/git" &&
|
|
echo "https://xdg-user:xdg-pass@example.com" >"$HOME/.config/git/credentials" &&
|
|
check fill store <<-\EOF
|
|
protocol=https
|
|
host=example.com
|
|
--
|
|
protocol=https
|
|
host=example.com
|
|
username=xdg-user
|
|
password=xdg-pass
|
|
--
|
|
EOF
|
|
'
|
|
|
|
test_expect_success 'store: if both xdg and home files exist, only store in home file' '
|
|
>"$HOME/.git-credentials" &&
|
|
mkdir -p "$HOME/.config/git" &&
|
|
>"$HOME/.config/git/credentials" &&
|
|
check approve store <<-\EOF &&
|
|
protocol=https
|
|
host=example.com
|
|
username=store-user
|
|
password=store-pass
|
|
EOF
|
|
echo "https://store-user:store-pass@example.com" >expected &&
|
|
test_cmp expected "$HOME/.git-credentials" &&
|
|
test_must_be_empty "$HOME/.config/git/credentials"
|
|
'
|
|
|
|
|
|
test_expect_success 'erase: erase matching credentials from both xdg and home files' '
|
|
echo "https://home-user:home-pass@example.com" >"$HOME/.git-credentials" &&
|
|
mkdir -p "$HOME/.config/git" &&
|
|
echo "https://xdg-user:xdg-pass@example.com" >"$HOME/.config/git/credentials" &&
|
|
check reject store <<-\EOF &&
|
|
protocol=https
|
|
host=example.com
|
|
EOF
|
|
test_must_be_empty "$HOME/.git-credentials" &&
|
|
test_must_be_empty "$HOME/.config/git/credentials"
|
|
'
|
|
|
|
test_done
|