From da37a83741d17f552f92df5ff6100cdebbc3e9e9 Mon Sep 17 00:00:00 2001 From: risk danger olson Date: Tue, 17 Nov 2015 17:19:23 -0700 Subject: [PATCH] halt if creds are needed but not found --- lfs/client.go | 10 ++++++++++ test/test-credentials.sh | 26 +++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/lfs/client.go b/lfs/client.go index 9dbe5077..5f2c2da4 100644 --- a/lfs/client.go +++ b/lfs/client.go @@ -515,6 +515,16 @@ func doApiRequestWithRedirects(req *http.Request, via []*http.Request, useCreds var creds Creds if useCreds { c, err := getCredsForAPI(req) + if c == nil || len(c) < 1 { + errmsg := fmt.Sprintf("Git credentials for %s not found", req.URL) + if err != nil { + errmsg = errmsg + ":\n" + err.Error() + } else { + errmsg = errmsg + "." + } + return nil, errors.New(errmsg) + } + if err != nil { return nil, err } diff --git a/test/test-credentials.sh b/test/test-credentials.sh index 713a129d..00e43240 100755 --- a/test/test-credentials.sh +++ b/test/test-credentials.sh @@ -2,6 +2,30 @@ . "test/testlib.sh" +begin_test "attempt private access without credential helper" +( + set -e + + reponame="$(basename "$0" ".sh")" + setup_remote_repo "$reponame" + clone_repo "$reponame" without-creds + + git lfs track "*.dat" + echo "hi" > hi.dat + git add hi.dat + git add .gitattributes + git commit -m "initial commit" + + git config --unset credential.helper + git config --global --unset credential.helper + + GIT_TERMINAL_PROMPT=0 git push origin master 2>&1 | tee push.log + + repourl="$GITSERVER/$reponame.git/info/lfs/objects/batch" + grep "Git credentials for $repourl not found" push.log +) +end_test + begin_test "credentials without useHttpPath, with bad path password" ( set -e @@ -75,7 +99,7 @@ begin_test "credentials with useHttpPath, with correct password" git lfs track "*.dat" 2>&1 | tee track.log grep "Tracking \*.dat" track.log - # creating new branch does not re-sent any objects existing on other + # creating new branch does not re-send any objects existing on other # remote branches anymore, generate new object, different from prev tests contents="b" contents_oid=$(calc_oid "$contents")