Skip to content

Commit

Permalink
test cases: complete porting to testify and remove goftp.v1 (#201)
Browse files Browse the repository at this point in the history
* test cases: complete porting to testify and remove goftp.v1

* add specific test cases for methods implicitly called in goftp.v1

* improve test coverage
  • Loading branch information
drakkan authored Dec 16, 2020
1 parent acbfda7 commit c84759b
Show file tree
Hide file tree
Showing 10 changed files with 434 additions and 476 deletions.
21 changes: 21 additions & 0 deletions client_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,24 @@ func isStringInSlice(s string, list []string) bool {

return false
}

func TestUnkowCommand(t *testing.T) {
s := NewTestServer(t, true)
conf := goftp.Config{
User: authUser,
Password: authPass,
}

c, err := goftp.DialConfig(conf, s.Addr())
require.NoError(t, err, "Couldn't connect")

defer func() { panicOnError(c.Close()) }()

raw, err := c.OpenRawConn()
require.NoError(t, err, "Couldn't open raw connection")

rc, response, err := raw.SendCommand("UNSUPPORTED")
require.NoError(t, err)
require.Equal(t, StatusSyntaxErrorNotRecognised, rc)
require.Equal(t, "Unknown command", response)
}
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ require (
github.com/secsy/goftp v0.0.0-20200609142545-aa2de14babf4
github.com/spf13/afero v1.5.1
github.com/stretchr/testify v1.6.1
golang.org/x/text v0.3.4 // indirect
gopkg.in/dutchcoders/goftp.v1 v1.0.0-20170301105846-ed59a591ce14
golang.org/x/text v0.3.4 // indirect
)

replace github.com/secsy/goftp => github.com/drakkan/goftp v0.0.0-20200916091733-843d4cca4bb2
3 changes: 0 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20191220142924-d4481acd189f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.4 h1:0YWbFKbhXG/wIiuHDSKpS0Iy7FSA+u45VtBMfQcFTTc=
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
Expand Down Expand Up @@ -347,8 +346,6 @@ gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLks
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
gopkg.in/dutchcoders/goftp.v1 v1.0.0-20170301105846-ed59a591ce14 h1:tHqNpm9sPaE6BSuMLXBzgTwukQLdBEt4OYU2coQjEQQ=
gopkg.in/dutchcoders/goftp.v1 v1.0.0-20170301105846-ed59a591ce14/go.mod h1:nzmlZQ+UqB5+55CRTV/dOaiK8OrPl6Co96Ob8lH4Wxw=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/gcfg.v1 v1.2.3/go.mod h1:yesOnuUOFQAhST5vPY4nbZsb/huCgGGXlipJsBn0b3o=
Expand Down
7 changes: 0 additions & 7 deletions handle_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package ftpserver

import (
"crypto/tls"
"fmt"
"net"
"testing"
"time"
Expand All @@ -17,12 +16,6 @@ func panicOnError(err error) {
}
}

func reportError(err error) {
if err != nil {
fmt.Println("Error reporting:", err)
}
}

func TestLoginSuccess(t *testing.T) {
s := NewTestServer(t, true)
// send a NOOP before the login, this doesn't seems possible using secsy/goftp so use the old way ...
Expand Down
8 changes: 4 additions & 4 deletions handle_dirs.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,6 @@ func (c *clientHandler) checkLISTArgs() {
}

func (c *clientHandler) handleLIST() error {
if !c.server.settings.DisableLISTArgs {
c.checkLISTArgs()
}

if files, err := c.getFileList(); err == nil || err == io.EOF {
if tr, errTr := c.TransferOpen(); errTr == nil {
err = c.dirTransferLIST(tr, files)
Expand Down Expand Up @@ -258,6 +254,10 @@ func (c *clientHandler) writeMLSxOutput(w io.Writer, file os.FileInfo) error {
}

func (c *clientHandler) getFileList() ([]os.FileInfo, error) {
if !c.server.settings.DisableLISTArgs {
c.checkLISTArgs()
}

directoryPath := c.absPath(c.param)

if fileList, ok := c.driver.(ClientDriverExtensionFileList); ok {
Expand Down
Loading

0 comments on commit c84759b

Please sign in to comment.