From fc819145f26200b443f5fef813170e2fee3c1f8f Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Thu, 7 Dec 2023 16:12:33 -0500 Subject: [PATCH] feat: add ssh lfs-transfer tests --- pkg/git/lfs.go | 2 - testscript/script_test.go | 1 - testscript/testdata/ssh-lfs.txtar | 76 +++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 testscript/testdata/ssh-lfs.txtar diff --git a/pkg/git/lfs.go b/pkg/git/lfs.go index 7dc4b8b35..4b0065f3e 100644 --- a/pkg/git/lfs.go +++ b/pkg/git/lfs.go @@ -159,8 +159,6 @@ func (t *lfsTransfer) StartUpload(oid string, r io.Reader, _ transfer.Args) (io. return nil, err } - t.logger.Infof("Object name: %s", obj.Name()) - return &uploadObject{ oid: oid, size: written, diff --git a/testscript/script_test.go b/testscript/script_test.go index 0b1b619e2..32ebe77c1 100644 --- a/testscript/script_test.go +++ b/testscript/script_test.go @@ -148,7 +148,6 @@ func TestScript(t *testing.T) { cfg.HTTP.PublicURL = "http://" + httpListen cfg.Stats.ListenAddr = statsListen cfg.LFS.Enabled = true - // cfg.LFS.SSHEnabled = true // Parse os SOFT_SERVE environment variables if err := cfg.ParseEnv(); err != nil { diff --git a/testscript/testdata/ssh-lfs.txtar b/testscript/testdata/ssh-lfs.txtar new file mode 100644 index 000000000..a3753b66a --- /dev/null +++ b/testscript/testdata/ssh-lfs.txtar @@ -0,0 +1,76 @@ +# vi: set ft=conf + +[windows] dos2unix err1.txt err2.txt err3.txt errauth.txt + +# enable ssh lfs transfer +env SOFT_SERVE_LFS_SSH_ENABLED=true +# start soft serve +exec soft serve & +# wait for server to start +waitforserver + +# create a user +soft user create foo --key "$USER1_AUTHORIZED_KEY" + +# create a repo +soft repo create repo1 +soft repo create repo1p -p +usoft repo create repo2 +usoft repo create repo2p -p + +# SSH Git LFS Transfer command +! soft git-lfs-transfer +cmp stderr err1.txt +! soft git-lfs-transfer repo1 +cmp stderr err2.txt +soft git-lfs-transfer repo1 download +stdout '000eversion=1\n000clocking\n0000' +soft git-lfs-transfer repo1 upload +stdout '000eversion=1\n000clocking\n0000' +usoft git-lfs-transfer repo1 download +stdout '000eversion=1\n000clocking\n0000' +! usoft git-lfs-transfer repo1 upload +cmp stderr errauth.txt + +# Unauthorized user +! usoft git-lfs-transfer +cmp stderr err1.txt +! usoft git-lfs-transfer repo1p +cmp stderr err2.txt +! usoft git-lfs-transfer repo1p download +cmp stderr errauth.txt +! usoft git-lfs-transfer repo1p upload +cmp stderr errauth.txt + +# push & create repo with some files, commits, tags... +mkdir ./repo1 +git -c init.defaultBranch=master -C repo1 init +mkfile ./repo1/README.md '# Project\nfoo' +mkfile ./repo1/foo.png 'foo' +mkfile ./repo1/bar.png 'bar' +git -C repo1 remote add origin ssh://localhost:$SSH_PORT/repo1 +git -C repo1 lfs install --local +git -C repo1 lfs track '*.png' +git -C repo1 add -A +git -C repo1 commit -m 'first' +git -C repo1 tag v0.1.0 +git -C repo1 push origin HEAD +git -C repo1 push origin HEAD --tags + +# clone repo with ssh lfs-transfer +git clone ssh://localhost:$SSH_PORT/repo1 repo1c +exists repo1c/README.md +exists repo1c/foo.png +exists repo1c/bar.png + +# stop the server +[windows] stopserver + +-- err1.txt -- +Error: accepts 2 arg(s), received 0 +-- err2.txt -- +Error: accepts 2 arg(s), received 1 +-- err3.txt -- +Error: invalid request +-- errauth.txt -- +Error: you are not authorized to do this