Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
fclairamb committed Mar 10, 2024
1 parent b48ecad commit f5571b7
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 28 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ linters:
- testifylint
# - testpackage -> too late for that
- thelper
- tparallel
- unconvert
- unparam
- unused
Expand Down
4 changes: 4 additions & 0 deletions client_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ func TestTransferOpenError(t *testing.T) {
}

func TestTLSMethods(t *testing.T) {
t.Parallel()

t.Run("without-tls", func(t *testing.T) {
t.Parallel()
cc := clientHandler{
server: NewTestServer(t, false),
}
Expand All @@ -125,6 +128,7 @@ func TestTLSMethods(t *testing.T) {
})

t.Run("with-implicit-tls", func(t *testing.T) {
t.Parallel()
s := NewTestServerWithTestDriver(t, &TestServerDriver{
Settings: &Settings{
TLSRequired: ImplicitEncryption,
Expand Down
1 change: 0 additions & 1 deletion driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ func (driver *TestServerDriver) Init() {

func NewTestServerWithTestDriver(t *testing.T, driver *TestServerDriver) *FtpServer {
t.Helper()
t.Parallel()

driver.Init()

Expand Down
4 changes: 4 additions & 0 deletions handle_dirs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,14 +484,18 @@ func TestDirListingBeforeLogin(t *testing.T) {
}

func TestListArgs(t *testing.T) {
t.Parallel()

t.Run("with-mlsd", func(t *testing.T) {
t.Parallel()
testListDirArgs(
t,
NewTestServer(t, false),
)
})

t.Run("without-mlsd", func(t *testing.T) {
t.Parallel()
testListDirArgs(
t,
NewTestServerWithTestDriver(t, &TestServerDriver{Debug: false, Settings: &Settings{DisableMLSD: true}}),
Expand Down
91 changes: 64 additions & 27 deletions transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,28 +184,47 @@ func ftpDelete(t *testing.T, ftp *goftp.Client, filename string) {
}

func TestTransferIPv6(t *testing.T) {
s := NewTestServerWithTestDriver(
t,
&TestServerDriver{
Debug: false,
Settings: &Settings{
ActiveTransferPortNon20: true,
ListenAddr: "[::1]:0",
t.Parallel()

createServer := func() *FtpServer {
s := NewTestServerWithTestDriver(
t,
&TestServerDriver{
Debug: false,
Settings: &Settings{
ActiveTransferPortNon20: true,
ListenAddr: "[::1]:0",
},
},
},
)
)

if s == nil {
t.Skip("IPv6 is not supported here")
}

if s == nil {
t.Skip("IPv6 is not supported here")
return s
}

t.Run("active", func(t *testing.T) { testTransferOnConnection(t, s, true, false, false) })
t.Run("passive", func(t *testing.T) { testTransferOnConnection(t, s, false, false, false) })
t.Run("active", func(t *testing.T) {
t.Parallel()

s := createServer()
testTransferOnConnection(t, s, true, false, false)
})
t.Run("passive", func(t *testing.T) {
t.Parallel()

s := createServer()
testTransferOnConnection(t, s, false, false, false)
})
}

// TestTransfer validates the upload of file in both active and passive mode
func TestTransfer(t *testing.T) {
t.Parallel()

t.Run("without-tls", func(t *testing.T) {
t.Parallel()
s := NewTestServerWithTestDriver(
t,
&TestServerDriver{
Expand All @@ -220,6 +239,7 @@ func TestTransfer(t *testing.T) {
testTransferOnConnection(t, s, true, false, false)
})
t.Run("with-tls", func(t *testing.T) {
t.Parallel()
s := NewTestServerWithTestDriver(
t,
&TestServerDriver{
Expand All @@ -236,6 +256,7 @@ func TestTransfer(t *testing.T) {
})

t.Run("with-implicit-tls", func(t *testing.T) {
t.Parallel()
s := NewTestServerWithTestDriver(t, &TestServerDriver{
Debug: false,
TLS: true,
Expand Down Expand Up @@ -397,35 +418,49 @@ func TestBogusTransferStart(t *testing.T) {
}

func TestFailingFileTransfer(t *testing.T) {
driver := &TestServerDriver{
Debug: false,
}
s := NewTestServerWithTestDriver(t, driver)
conf := goftp.Config{
User: authUser,
Password: authPass,
}
t.Parallel()

file := createTemporaryFile(t, 1*1024)
createClientOnServer := func(t *testing.T) (*goftp.Client, *os.File) {
t.Helper()

c, err := goftp.DialConfig(conf, s.Addr())
require.NoError(t, err)
driver := &TestServerDriver{
Debug: false,
}

defer func() { require.NoError(t, c.Close()) }()
s := NewTestServerWithTestDriver(t, driver)
conf := goftp.Config{
User: authUser,
Password: authPass,
}

file := createTemporaryFile(t, 1*1024)

c, err := goftp.DialConfig(conf, s.Addr())
require.NoError(t, err)
t.Cleanup(func() { panicOnError(c.Close()) })

return c, file
}

t.Run("on write", func(t *testing.T) {
err = c.Store("fail-to-write.bin", file)
t.Parallel()
c, file := createClientOnServer(t)
err := c.Store("fail-to-write.bin", file)
require.Error(t, err)
require.True(t, strings.Contains(err.Error(), errFailWrite.Error()), err)
})

t.Run("on close", func(t *testing.T) {
err = c.Store("fail-to-close.bin", file)
t.Parallel()
c, file := createClientOnServer(t)
err := c.Store("fail-to-close.bin", file)
require.Error(t, err)
require.True(t, strings.Contains(err.Error(), errFailClose.Error()), err)
})

t.Run("on seek", func(t *testing.T) {
t.Parallel()
c, _ := createClientOnServer(t)
initialData := []byte("initial data")
appendFile, err := os.CreateTemp("", "ftpserver")
require.NoError(t, err)
Expand Down Expand Up @@ -456,6 +491,8 @@ func TestFailingFileTransfer(t *testing.T) {
})

t.Run("check for sync", func(t *testing.T) {
t.Parallel()
c, file := createClientOnServer(t)
require.NoError(t, c.Store("ok", file))
})
}
Expand Down

0 comments on commit f5571b7

Please sign in to comment.