sftpd: fix the max upload file size check for overwrites

improved test case too
This commit is contained in:
Nicola Murino 2020-10-25 08:52:31 +01:00
parent 5ff8f75917
commit 975a2f3632
No known key found for this signature in database
GPG key ID: 2F1FB59433D5A8CB
4 changed files with 15 additions and 3 deletions

View file

@ -824,6 +824,11 @@ func TestUploadMaxSize(t *testing.T) {
assert.Error(t, err)
err = ftpUploadFile(testFilePath, testFileName, testFileSize, client, 0)
assert.NoError(t, err)
// now test overwrite an existing file with a size bigger than the allowed one
err = createTestFile(filepath.Join(user.GetHomeDir(), testFileName1), testFileSize1)
assert.NoError(t, err)
err = ftpUploadFile(testFilePath1, testFileName1, testFileSize1, client, 0)
assert.Error(t, err)
err = client.Quit()
assert.NoError(t, err)
}

View file

@ -391,9 +391,6 @@ func (c *Connection) handleSFTPUploadToExistingFile(pflags sftp.FileOpenFlags, r
} else {
initialSize = fileSize
}
if maxWriteSize > 0 && isTruncate {
maxWriteSize += fileSize
}
}
vfs.SetPathPermissions(c.Fs, filePath, c.User.GetUID(), c.User.GetGID())

View file

@ -2482,6 +2482,11 @@ func TestUploadMaxSize(t *testing.T) {
assert.Error(t, err)
err = sftpUploadFile(testFilePath, testFileName, testFileSize, client)
assert.NoError(t, err)
// now test overwrite an existing file with a size bigger than the allowed one
err = createTestFile(filepath.Join(user.GetHomeDir(), testFileName1), testFileSize1)
assert.NoError(t, err)
err = sftpUploadFile(testFilePath1, testFileName1, testFileSize1, client)
assert.Error(t, err)
}
err = os.Remove(testFilePath)
assert.NoError(t, err)

View file

@ -701,6 +701,11 @@ func TestUploadMaxSize(t *testing.T) {
assert.Error(t, err)
err = uploadFile(testFilePath, testFileName, testFileSize, client)
assert.NoError(t, err)
// now test overwrite an existing file with a size bigger than the allowed one
err = createTestFile(filepath.Join(user.GetHomeDir(), testFileName1), testFileSize1)
assert.NoError(t, err)
err = uploadFile(testFilePath1, testFileName1, testFileSize1, client)
assert.Error(t, err)
err = os.Remove(testFilePath)
assert.NoError(t, err)