From c6feebf3dc896b0bac99dee70b06ae7302f250be Mon Sep 17 00:00:00 2001 From: risk danger olson Date: Wed, 4 Jan 2017 11:16:07 -0700 Subject: [PATCH 1/3] Add test for ssh auth --- test/cmd/ssh-echo.go | 34 ++++++++++++++++++++++++++++++++++ test/test-batch-transfer.sh | 21 +++++++++++++++++++++ test/testenv.sh | 2 ++ 3 files changed, 57 insertions(+) create mode 100644 test/cmd/ssh-echo.go diff --git a/test/cmd/ssh-echo.go b/test/cmd/ssh-echo.go new file mode 100644 index 00000000..1092be1d --- /dev/null +++ b/test/cmd/ssh-echo.go @@ -0,0 +1,34 @@ +// +build testtools + +package main + +import ( + "encoding/json" + "fmt" + "os" + "strings" +) + +type sshResponse struct { + Href string `json:"href"` + Header map[string]string `json:"header"` +} + +func main() { + // expect args: + // ssh-echo -p PORT git@127.0.0.1 git-lfs-authenticate REPO OPERATION + if len(os.Args) != 5 { + fmt.Fprintf(os.Stderr, "got %d args: %v", len(os.Args), os.Args) + os.Exit(1) + } + + // just "git-lfs-authenticate REPO OPERATION" + authLine := strings.Split(os.Args[4], " ") + if len(authLine) < 13 { + fmt.Fprintf(os.Stderr, "bad git-lfs-authenticate line: %s\nargs: %v", authLine, os.Args) + } + + json.NewEncoder(os.Stdout).Encode(sshResponse{ + Href: fmt.Sprintf("http://127.0.0.1:%s/%s.git/info/lfs", os.Args[2], authLine[1]), + }) +} diff --git a/test/test-batch-transfer.sh b/test/test-batch-transfer.sh index 52d1455a..48366ba4 100755 --- a/test/test-batch-transfer.sh +++ b/test/test-batch-transfer.sh @@ -101,3 +101,24 @@ begin_test "batch transfers occur in reverse order by size" ) end_test +begin_test "batch transfers with ssh endpoint" +( + set -e + + reponame="batch-ssh" + setup_remote_repo "$reponame" + clone_repo "$reponame" "$reponame" + + sshurl="${GITSERVER/http:\/\//ssh://git@}/$reponame" + git config lfs.url "$sshurl" + git lfs env + + oid="$(calc_oid "test")" + git lfs track "*.dat" + printf "test" > test.dat + git add .gitattributes test.dat + git commit -m "initial commit" + + git push origin master 2>&1 +) +end_test diff --git a/test/testenv.sh b/test/testenv.sh index 3c041e92..b71a19e9 100644 --- a/test/testenv.sh +++ b/test/testenv.sh @@ -110,9 +110,11 @@ TESTHOME="$REMOTEDIR/home" GIT_CONFIG_NOSYSTEM=1 GIT_TERMINAL_PROMPT=0 +GIT_SSH=ssh-echo export CREDSDIR export GIT_CONFIG_NOSYSTEM +export GIT_SSH mkdir -p "$TMPDIR" mkdir -p "$TRASHDIR" From 0951c698ad22a53c04d8d5d98a100f18f6e3993a Mon Sep 17 00:00:00 2001 From: risk danger olson Date: Wed, 4 Jan 2017 12:24:07 -0700 Subject: [PATCH 2/3] test: env test should look for GIT_SSH too --- test/test-env.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test-env.sh b/test/test-env.sh index e005ca01..8d2f6ad9 100755 --- a/test/test-env.sh +++ b/test/test-env.sh @@ -686,7 +686,8 @@ begin_test "env with multiple ssh remotes" expected='Endpoint=https://git-server.com/user/repo.git/info/lfs (auth=none) SSH=git@git-server.com:user/repo.git Endpoint (other)=https://other-git-server.com/user/repo.git/info/lfs (auth=none) - SSH=git@other-git-server.com:user/repo.git' + SSH=git@other-git-server.com:user/repo.git +GIT_SSH=ssh-echo' contains_same_elements "$expected" "$(git lfs env | grep -e "Endpoint" -e "SSH=")" ) From 32244d92a44aaf24b144312bc1327ac7b4664d2e Mon Sep 17 00:00:00 2001 From: risk danger olson Date: Wed, 4 Jan 2017 13:27:05 -0700 Subject: [PATCH 3/3] lfs: fix issue that grabs env vars with 'GIT_' in the value Fixes an issue with 'APPVEYOR_REPO_COMMIT_MESSAGE' being included, causing test-env.sh failures --- lfs/lfs.go | 2 +- test/testenv.sh | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lfs/lfs.go b/lfs/lfs.go index cbf48117..eb1f459c 100644 --- a/lfs/lfs.go +++ b/lfs/lfs.go @@ -109,7 +109,7 @@ func Environ(cfg *config.Configuration, manifest *tq.Manifest) []string { } for _, e := range osEnviron { - if !strings.Contains(e, "GIT_") { + if !strings.Contains(strings.SplitN(e, "=", 2)[0], "GIT_") { continue } env = append(env, e) diff --git a/test/testenv.sh b/test/testenv.sh index b71a19e9..1e591d35 100644 --- a/test/testenv.sh +++ b/test/testenv.sh @@ -111,10 +111,12 @@ TESTHOME="$REMOTEDIR/home" GIT_CONFIG_NOSYSTEM=1 GIT_TERMINAL_PROMPT=0 GIT_SSH=ssh-echo +APPVEYOR_REPO_COMMIT_MESSAGE="test: env test should look for GIT_SSH too" export CREDSDIR export GIT_CONFIG_NOSYSTEM export GIT_SSH +export APPVEYOR_REPO_COMMIT_MESSAGE mkdir -p "$TMPDIR" mkdir -p "$TRASHDIR"