From 01df7536992af375a54bbedf45369a475953e372 Mon Sep 17 00:00:00 2001 From: Máximo Cuadros Date: Sun, 2 May 2021 23:40:08 +0200 Subject: *: use go-billy instead of os calls --- plumbing/transport/ssh/auth_method.go | 2 +- plumbing/transport/ssh/auth_method_test.go | 26 ++++++++++++++++++++------ plumbing/transport/ssh/upload_pack_test.go | 5 +++++ 3 files changed, 26 insertions(+), 7 deletions(-) (limited to 'plumbing/transport/ssh') diff --git a/plumbing/transport/ssh/auth_method.go b/plumbing/transport/ssh/auth_method.go index 568ec86..3514669 100644 --- a/plumbing/transport/ssh/auth_method.go +++ b/plumbing/transport/ssh/auth_method.go @@ -11,7 +11,7 @@ import ( "github.com/go-git/go-git/v5/plumbing/transport" "github.com/mitchellh/go-homedir" - "github.com/xanzy/ssh-agent" + sshagent "github.com/xanzy/ssh-agent" "golang.org/x/crypto/ssh" "golang.org/x/crypto/ssh/knownhosts" ) diff --git a/plumbing/transport/ssh/auth_method_test.go b/plumbing/transport/ssh/auth_method_test.go index ade344f..b275018 100644 --- a/plumbing/transport/ssh/auth_method_test.go +++ b/plumbing/transport/ssh/auth_method_test.go @@ -3,10 +3,12 @@ package ssh import ( "bufio" "fmt" - "io/ioutil" "os" + "runtime" "strings" + "github.com/go-git/go-billy/v5/osfs" + "github.com/go-git/go-billy/v5/util" "golang.org/x/crypto/ssh" "golang.org/x/crypto/ssh/testdata" @@ -108,6 +110,10 @@ func (s *SuiteCommon) TestPublicKeysCallbackString(c *C) { c.Assert(a.String(), Equals, fmt.Sprintf("user: test, name: %s", PublicKeysCallbackName)) } func (s *SuiteCommon) TestNewSSHAgentAuth(c *C) { + if runtime.GOOS == "js" { + c.Skip("tcp connections are not available in wasm") + } + if os.Getenv("SSH_AUTH_SOCK") == "" { c.Skip("SSH_AUTH_SOCK or SSH_TEST_PRIVATE_KEY are required") } @@ -153,12 +159,16 @@ func (*SuiteCommon) TestNewPublicKeysWithEncryptedEd25519PEM(c *C) { } func (*SuiteCommon) TestNewPublicKeysFromFile(c *C) { - f, err := ioutil.TempFile("", "ssh-test") + if runtime.GOOS == "js" { + c.Skip("not available in wasm") + } + + f, err := util.TempFile(osfs.Default, "", "ssh-test") c.Assert(err, IsNil) _, err = f.Write(testdata.PEMBytes["rsa"]) c.Assert(err, IsNil) c.Assert(f.Close(), IsNil) - defer os.RemoveAll(f.Name()) + defer osfs.Default.Remove(f.Name()) auth, err := NewPublicKeysFromFile("foo", f.Name(), "") c.Assert(err, IsNil) @@ -172,9 +182,13 @@ func (*SuiteCommon) TestNewPublicKeysWithInvalidPEM(c *C) { } func (*SuiteCommon) TestNewKnownHostsCallback(c *C) { + if runtime.GOOS == "js" { + c.Skip("not available in wasm") + } + var mock = mockKnownHosts{} - f, err := ioutil.TempFile("", "known-hosts") + f, err := util.TempFile(osfs.Default, "", "known-hosts") c.Assert(err, IsNil) _, err = f.Write(mock.knownHosts()) @@ -183,9 +197,9 @@ func (*SuiteCommon) TestNewKnownHostsCallback(c *C) { err = f.Close() c.Assert(err, IsNil) - defer os.RemoveAll(f.Name()) + defer util.RemoveAll(osfs.Default, f.Name()) - f, err = os.Open(f.Name()) + f, err = osfs.Default.Open(f.Name()) c.Assert(err, IsNil) defer f.Close() diff --git a/plumbing/transport/ssh/upload_pack_test.go b/plumbing/transport/ssh/upload_pack_test.go index 1bcb82b..e65e04a 100644 --- a/plumbing/transport/ssh/upload_pack_test.go +++ b/plumbing/transport/ssh/upload_pack_test.go @@ -9,6 +9,7 @@ import ( "os" "os/exec" "path/filepath" + "runtime" "strings" "sync" @@ -32,6 +33,10 @@ type UploadPackSuite struct { var _ = Suite(&UploadPackSuite{}) func (s *UploadPackSuite) SetUpSuite(c *C) { + if runtime.GOOS == "js" { + c.Skip("tcp connections are not available in wasm") + } + l, err := net.Listen("tcp", "localhost:0") c.Assert(err, IsNil) -- cgit