sftpd: test case for SetStat
SetStat is silently ignored. Ownership and permissions are configured globally or per account
This commit is contained in:
parent
eb18e30a65
commit
aaa4c22911
1 changed files with 52 additions and 4 deletions
|
@ -159,10 +159,6 @@ func TestBasicSFTPHandling(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Errorf("file upload error: %v", err)
|
||||
}
|
||||
err = client.Chown(testFileName, 1000, 1000)
|
||||
if err != nil {
|
||||
t.Errorf("chown error: %v", err)
|
||||
}
|
||||
localDownloadPath := filepath.Join(homeBasePath, "test_download.dat")
|
||||
err = sftpDownloadFile(testFileName, localDownloadPath, testFileSize, client)
|
||||
if err != nil {
|
||||
|
@ -299,6 +295,58 @@ func TestSymlink(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestSetStat(t *testing.T) {
|
||||
usePubKey := false
|
||||
user, err := api.AddUser(getTestUser(usePubKey), http.StatusOK)
|
||||
if err != nil {
|
||||
t.Errorf("unable to add user: %v", err)
|
||||
}
|
||||
client, err := getSftpClient(user, usePubKey)
|
||||
if err != nil {
|
||||
t.Errorf("unable to create sftp client: %v", err)
|
||||
} else {
|
||||
defer client.Close()
|
||||
testFileName := "test_file.dat"
|
||||
testFilePath := filepath.Join(homeBasePath, testFileName)
|
||||
testFileSize := int64(65535)
|
||||
err = createTestFile(testFilePath, testFileSize)
|
||||
if err != nil {
|
||||
t.Errorf("unable to create test file: %v", err)
|
||||
}
|
||||
err = sftpUploadFile(testFilePath, testFileName, testFileSize, client)
|
||||
if err != nil {
|
||||
t.Errorf("file upload error: %v", err)
|
||||
}
|
||||
fi, err := client.Lstat(testFileName)
|
||||
if err != nil {
|
||||
t.Errorf("stat error: %v", err)
|
||||
}
|
||||
err = client.Chown(testFileName, 1000, 1000)
|
||||
if err != nil {
|
||||
t.Errorf("chown error: %v", err)
|
||||
}
|
||||
err = client.Chmod(testFileName, 0600)
|
||||
if err != nil {
|
||||
t.Errorf("chmod error: %v", err)
|
||||
}
|
||||
newFi, err := client.Lstat(testFileName)
|
||||
if err != nil {
|
||||
t.Errorf("stat error: %v", err)
|
||||
}
|
||||
if fi.Mode().Perm() != newFi.Mode().Perm() {
|
||||
t.Errorf("stat must remain unchanged")
|
||||
}
|
||||
err = client.Remove(testFileName)
|
||||
if err != nil {
|
||||
t.Errorf("error removing uploaded file: %v", err)
|
||||
}
|
||||
}
|
||||
err = api.RemoveUser(user, http.StatusOK)
|
||||
if err != nil {
|
||||
t.Errorf("unable to remove user: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// basic tests to verify virtual chroot, should be improved to cover more cases ...
|
||||
func TestEscapeHomeDir(t *testing.T) {
|
||||
usePubKey := true
|
||||
|
|
Loading…
Reference in a new issue