From 356795f8b0a575bd83aa8ece55fda57c6bfa313e Mon Sep 17 00:00:00 2001 From: Nicola Murino Date: Sat, 22 Jun 2024 19:23:02 +0200 Subject: [PATCH] add a test case for listing files with long names Signed-off-by: Nicola Murino --- internal/sftpd/sftpd_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/internal/sftpd/sftpd_test.go b/internal/sftpd/sftpd_test.go index 9279b4a7..6e6a4b16 100644 --- a/internal/sftpd/sftpd_test.go +++ b/internal/sftpd/sftpd_test.go @@ -23,6 +23,7 @@ import ( "crypto/sha512" "encoding/base64" "encoding/binary" + "encoding/hex" "encoding/json" "errors" "fmt" @@ -782,6 +783,34 @@ func TestSFTPFsEscapeHomeDir(t *testing.T) { assert.NoError(t, err) } +func TestReadDirLongNames(t *testing.T) { + usePubKey := true + user, _, err := httpdtest.AddUser(getTestUser(usePubKey), http.StatusCreated) + assert.NoError(t, err) + + conn, client, err := getSftpClient(user, usePubKey) + if assert.NoError(t, err) { + defer conn.Close() + defer client.Close() + + numFiles := 1000 + for i := 0; i < 1000; i++ { + fPath := filepath.Join(user.GetHomeDir(), hex.EncodeToString(util.GenerateRandomBytes(127))) + err = os.WriteFile(fPath, util.GenerateRandomBytes(30), 0666) + assert.NoError(t, err) + } + + entries, err := client.ReadDir("/") + assert.NoError(t, err) + assert.Len(t, entries, numFiles) + } + + _, err = httpdtest.RemoveUser(user, http.StatusOK) + assert.NoError(t, err) + err = os.RemoveAll(user.GetHomeDir()) + assert.NoError(t, err) +} + func TestGroupSettingsOverride(t *testing.T) { usePubKey := true g := getTestGroup()