Skip to content

Commit c84759b

Browse files
authored
test cases: complete porting to testify and remove goftp.v1 (#201)
* test cases: complete porting to testify and remove goftp.v1 * add specific test cases for methods implicitly called in goftp.v1 * improve test coverage
1 parent acbfda7 commit c84759b

File tree

10 files changed

+434
-476
lines changed

10 files changed

+434
-476
lines changed

client_handler_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,24 @@ func isStringInSlice(s string, list []string) bool {
133133

134134
return false
135135
}
136+
137+
func TestUnkowCommand(t *testing.T) {
138+
s := NewTestServer(t, true)
139+
conf := goftp.Config{
140+
User: authUser,
141+
Password: authPass,
142+
}
143+
144+
c, err := goftp.DialConfig(conf, s.Addr())
145+
require.NoError(t, err, "Couldn't connect")
146+
147+
defer func() { panicOnError(c.Close()) }()
148+
149+
raw, err := c.OpenRawConn()
150+
require.NoError(t, err, "Couldn't open raw connection")
151+
152+
rc, response, err := raw.SendCommand("UNSUPPORTED")
153+
require.NoError(t, err)
154+
require.Equal(t, StatusSyntaxErrorNotRecognised, rc)
155+
require.Equal(t, "Unknown command", response)
156+
}

go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ require (
77
github.com/secsy/goftp v0.0.0-20200609142545-aa2de14babf4
88
github.com/spf13/afero v1.5.1
99
github.com/stretchr/testify v1.6.1
10-
golang.org/x/text v0.3.4 // indirect
11-
gopkg.in/dutchcoders/goftp.v1 v1.0.0-20170301105846-ed59a591ce14
10+
golang.org/x/text v0.3.4 // indirect
1211
)
1312

1413
replace github.com/secsy/goftp => github.com/drakkan/goftp v0.0.0-20200916091733-843d4cca4bb2

go.sum

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,6 @@ golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7w
304304
golang.org/x/sys v0.0.0-20191220142924-d4481acd189f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
305305
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
306306
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
307-
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
308307
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
309308
golang.org/x/text v0.3.4 h1:0YWbFKbhXG/wIiuHDSKpS0Iy7FSA+u45VtBMfQcFTTc=
310309
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
@@ -347,8 +346,6 @@ gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLks
347346
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
348347
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
349348
gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
350-
gopkg.in/dutchcoders/goftp.v1 v1.0.0-20170301105846-ed59a591ce14 h1:tHqNpm9sPaE6BSuMLXBzgTwukQLdBEt4OYU2coQjEQQ=
351-
gopkg.in/dutchcoders/goftp.v1 v1.0.0-20170301105846-ed59a591ce14/go.mod h1:nzmlZQ+UqB5+55CRTV/dOaiK8OrPl6Co96Ob8lH4Wxw=
352349
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
353350
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
354351
gopkg.in/gcfg.v1 v1.2.3/go.mod h1:yesOnuUOFQAhST5vPY4nbZsb/huCgGGXlipJsBn0b3o=

handle_auth_test.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package ftpserver
22

33
import (
44
"crypto/tls"
5-
"fmt"
65
"net"
76
"testing"
87
"time"
@@ -17,12 +16,6 @@ func panicOnError(err error) {
1716
}
1817
}
1918

20-
func reportError(err error) {
21-
if err != nil {
22-
fmt.Println("Error reporting:", err)
23-
}
24-
}
25-
2619
func TestLoginSuccess(t *testing.T) {
2720
s := NewTestServer(t, true)
2821
// send a NOOP before the login, this doesn't seems possible using secsy/goftp so use the old way ...

handle_dirs.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,6 @@ func (c *clientHandler) checkLISTArgs() {
111111
}
112112

113113
func (c *clientHandler) handleLIST() error {
114-
if !c.server.settings.DisableLISTArgs {
115-
c.checkLISTArgs()
116-
}
117-
118114
if files, err := c.getFileList(); err == nil || err == io.EOF {
119115
if tr, errTr := c.TransferOpen(); errTr == nil {
120116
err = c.dirTransferLIST(tr, files)
@@ -258,6 +254,10 @@ func (c *clientHandler) writeMLSxOutput(w io.Writer, file os.FileInfo) error {
258254
}
259255

260256
func (c *clientHandler) getFileList() ([]os.FileInfo, error) {
257+
if !c.server.settings.DisableLISTArgs {
258+
c.checkLISTArgs()
259+
}
260+
261261
directoryPath := c.absPath(c.param)
262262

263263
if fileList, ok := c.driver.(ClientDriverExtensionFileList); ok {

0 commit comments

Comments
 (0)