add a test case for listing files with long names

Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
Nicola Murino 2024-06-22 19:23:02 +02:00
parent 3efcd94e14
commit 356795f8b0
No known key found for this signature in database
GPG key ID: 935D2952DEC4EECF

View file

@ -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()