[PATCH 2/2] tests: test credential-store XDG support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



* "helper_test store" is run for when $XDG_CONFIG_HOME/git/credentials
  exists and ~/.git-credentials does not and the other way around.
* Test that credentials are stored in XDG file if both XDG and HOME
  files exist.
* Test that credentials from XDG file are used if matching credentials
  are found in both XDG and HOME files.
* Test that credentials from HOME file are used if a matching credential
  could not be found in the XDG file.
* Test that when erasing credentials, matching credentials in both the
  XDG and HOME files are erase.d

Signed-off-by: Paul Tan <pyokagan@xxxxxxxxx>
---
 t/t0302-credential-store.sh | 74 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)

diff --git a/t/t0302-credential-store.sh b/t/t0302-credential-store.sh
index f61b40c..80893b9 100755
--- a/t/t0302-credential-store.sh
+++ b/t/t0302-credential-store.sh
@@ -4,6 +4,80 @@ test_description='credential-store tests'
 . ./test-lib.sh
 . "$TEST_DIRECTORY"/lib-credential.sh
 
+# Tests for when ~/.git-credentials exists but
+# $XDG_CONFIG_HOME/git/credentials does not
 helper_test store
+test_expect_success '~/.git-credentials is written to when XDG git-credentials does not exist' '
+	test -s "$HOME/.git-credentials"
+'
+test_expect_success 'XDG credentials will not be created if it does not exist' '
+	test ! -e "${XDG_CONFIG_HOME:-$HOME/.config}/git/credentials"
+'
+
+# Tests for when $XDG_CONFIG_HOME/git/credentials exists but
+# ~/.git-credentials does not.
+rm "$HOME/.git-credentials"
+mkdir -p "${XDG_CONFIG_HOME:-$HOME/.config}/git"
+echo '' > "${XDG_CONFIG_HOME:-$HOME/.config}/git/credentials"
+helper_test store
+test_expect_success '~/.git-credentials will not be created if XDG git-credentials exist' '
+	test ! -e "$HOME/.git-credentials"
+'
+test_expect_success 'XDG credentials will be written to if it exists' '
+	test -s "${XDG_CONFIG_HOME:-$HOME/.config}/git/credentials"
+'
+
+# Tests for when both $XDG_CONFIG_HOME/git/credentials and
+# ~/.git-credentials exists.
+echo '' > "$HOME/.git-credentials"
+echo '' > "${XDG_CONFIG_HOME:-$HOME/.config}/git/credentials"
+test_expect_success 'Credentials are stored in XDG file if both XDG and HOME files exist' '
+	check approve store <<-\EOF
+	protocol=https
+	host=example.com
+	username=store-user
+	password=store-pass
+	EOF
+	read contents < "${XDG_CONFIG_HOME:-$HOME/.config}/git/credentials"
+	test ! -z "$contents"
+	read contents < "$HOME/.git-credentials"
+	test -z "$contents"
+'
+test_expect_success 'Credentials from XDG file are used if the credentials exist in both XDG and HOME files' '
+	echo "https://baduser:badpass@xxxxxxxxxxx"; > "$HOME/.git-credentials"
+	check fill store <<-\EOF
+	protocol=https
+	host=example.com
+	--
+	protocol=https
+	host=example.com
+	username=store-user
+	password=store-pass
+	--
+	EOF
+'
+test_expect_success 'Credentials from HOME file are used if the XDG files does not have them' '
+	echo "" > "${XDG_CONFIG_HOME:-$HOME/.config}/git/credentials"
+	check fill store <<-\EOF
+	protocol=https
+	host=example.com
+	--
+	protocol=https
+	host=example.com
+	username=baduser
+	password=badpass
+	--
+	EOF
+'
+test_expect_success 'Credentials from both XDG and HOME files meeting the criteria are erased' '
+	check reject $HELPER <<-\EOF &&
+	protocol=https
+	host=example.com
+	EOF
+	read contents < "${XDG_CONFIG_HOME:-$HOME/.config}/git/credentials"
+	test -z "$contents"
+	read contents < "$HOME/.git-credentials"
+	test -z "$contents"
+'
 
 test_done
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]