t: make credential helper handle local URLs

The lfstest credential helper provides credentials found by reading a
file on the system.  Currently, it expects that there is a colon in the
URL followed by one or more slashes.  If there is not (say, because
we're using a file:/// or cert:/// URL), it fails to concatenate the
path properly, and instead of looking in the credentials directory,
looks for a different file one directory higher.  This occurs because
filepath.Join strips off a trailing slash if the second argument passed
to it is empty.

This, of course, makes the credential helper fail to work and the tests
hang waiting for input.  Insert an additional slash in the environment
variable and handle the empty string case properly so that credentials
for local paths can be looked up properly.
This commit is contained in:
brian m. carlson 2018-09-17 18:38:16 +00:00
parent 4500e2008b
commit 1790168bd5
No known key found for this signature in database
GPG Key ID: 2D0C9BC12F82B3A1
2 changed files with 12 additions and 2 deletions

@ -89,7 +89,17 @@ func fill() {
}
func credsForHostAndPath(host, path string) (string, string, error) {
hostFilename := filepath.Join(credsDir, host)
var hostFilename string
// We need hostFilename to end in a slash so that our credentials all
// end up in the same directory. credsDir will come in from the
// testsuite with a slash, but filepath.Join will strip it off if host
// is empty, such as when we have a file:/// or cert:/// URL.
if host != "" {
hostFilename = filepath.Join(credsDir, host)
} else {
hostFilename = credsDir
}
if len(path) > 0 {
pathFilename := fmt.Sprintf("%s--%s", hostFilename, strings.Replace(path, "/", "-", -1))

@ -90,7 +90,7 @@ REMOTEDIR="$ROOTDIR/t/remote"
# # stores the credentials for http://git-server.com
# $CREDSDIR/git-server.com
#
CREDSDIR="$REMOTEDIR/creds"
CREDSDIR="$REMOTEDIR/creds/"
# This is the prefix for Git config files. See the "Test Suite" section in
# t/README.md