2018-01-16 14:20:59 +01:00
|
|
|
package sftp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestRequestPflags(t *testing.T) {
|
2018-06-17 18:59:12 +02:00
|
|
|
pflags := newFileOpenFlags(ssh_FXF_READ | ssh_FXF_WRITE | ssh_FXF_APPEND)
|
2018-01-16 14:20:59 +01:00
|
|
|
assert.True(t, pflags.Read)
|
|
|
|
assert.True(t, pflags.Write)
|
|
|
|
assert.True(t, pflags.Append)
|
|
|
|
assert.False(t, pflags.Creat)
|
|
|
|
assert.False(t, pflags.Trunc)
|
|
|
|
assert.False(t, pflags.Excl)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRequestAflags(t *testing.T) {
|
2018-06-17 18:59:12 +02:00
|
|
|
aflags := newFileAttrFlags(
|
|
|
|
ssh_FILEXFER_ATTR_SIZE | ssh_FILEXFER_ATTR_UIDGID)
|
2018-01-16 14:20:59 +01:00
|
|
|
assert.True(t, aflags.Size)
|
|
|
|
assert.True(t, aflags.UidGid)
|
|
|
|
assert.False(t, aflags.Acmodtime)
|
|
|
|
assert.False(t, aflags.Permissions)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRequestAttributes(t *testing.T) {
|
|
|
|
// UID/GID
|
2018-06-17 18:59:12 +02:00
|
|
|
fa := FileStat{UID: 1, GID: 2}
|
2018-01-16 14:20:59 +01:00
|
|
|
fl := uint32(ssh_FILEXFER_ATTR_UIDGID)
|
|
|
|
at := []byte{}
|
|
|
|
at = marshalUint32(at, 1)
|
|
|
|
at = marshalUint32(at, 2)
|
|
|
|
test_fs, _ := getFileStat(fl, at)
|
2018-06-17 18:59:12 +02:00
|
|
|
assert.Equal(t, fa, *test_fs)
|
2018-01-16 14:20:59 +01:00
|
|
|
// Size and Mode
|
2018-06-17 18:59:12 +02:00
|
|
|
fa = FileStat{Mode: 700, Size: 99}
|
2018-01-16 14:20:59 +01:00
|
|
|
fl = uint32(ssh_FILEXFER_ATTR_SIZE | ssh_FILEXFER_ATTR_PERMISSIONS)
|
|
|
|
at = []byte{}
|
|
|
|
at = marshalUint64(at, 99)
|
|
|
|
at = marshalUint32(at, 700)
|
|
|
|
test_fs, _ = getFileStat(fl, at)
|
2018-06-17 18:59:12 +02:00
|
|
|
assert.Equal(t, fa, *test_fs)
|
2018-01-16 14:20:59 +01:00
|
|
|
// FileMode
|
2018-06-17 18:59:12 +02:00
|
|
|
assert.True(t, test_fs.FileMode().IsRegular())
|
|
|
|
assert.False(t, test_fs.FileMode().IsDir())
|
|
|
|
assert.Equal(t, test_fs.FileMode().Perm(), os.FileMode(700).Perm())
|
2018-01-16 14:20:59 +01:00
|
|
|
}
|