libgocryptfs/internal/fusefrontend/prepare_syscall_test.go

173 lines
3.6 KiB
Go
Raw Normal View History

package fusefrontend
import (
"strings"
"syscall"
"testing"
"golang.org/x/sys/unix"
2020-07-11 20:15:47 +02:00
"github.com/hanwen/go-fuse/v2/fuse"
"github.com/rfjakob/gocryptfs/v2/internal/syscallcompat"
"github.com/rfjakob/gocryptfs/v2/tests/test_helpers"
)
func TestPrepareAtSyscall(t *testing.T) {
cipherdir := test_helpers.InitFS(t)
t.Logf("cipherdir = %q", cipherdir)
args := Args{
Cipherdir: cipherdir,
}
rn := newTestFS(args)
2020-07-11 20:15:47 +02:00
out := &fuse.EntryOut{}
child, errno := rn.Mkdir(nil, "dir1", 0700, out)
2020-07-11 20:15:47 +02:00
if errno != 0 {
t.Fatal(errno)
}
rn.AddChild("dir1", child, false)
dir1 := toNode(child.Operations())
_, errno = dir1.Mkdir(nil, "dir2", 0700, out)
2020-07-11 20:15:47 +02:00
if errno != 0 {
t.Fatal(errno)
}
dirfd, cName, errno := rn.prepareAtSyscallMyself()
if errno != 0 {
t.Fatal(errno)
}
if cName != "." {
t.Fatal("cName should be .")
}
syscall.Close(dirfd)
// Again, but populate the cache for "" by looking up a non-existing file
rn.Lookup(nil, "xyz1234", &fuse.EntryOut{})
dirfd, cName, errno = rn.prepareAtSyscallMyself()
if errno != 0 {
t.Fatal(errno)
}
if cName != "." {
t.Fatal("cName should be .")
}
err := syscallcompat.Faccessat(dirfd, cName, unix.R_OK)
if err != nil {
t.Error(err)
}
err = syscallcompat.Faccessat(dirfd, ".", unix.R_OK)
if err != nil {
t.Error(err)
}
syscall.Close(dirfd)
dirfd, cName, errno = rn.prepareAtSyscall("dir1")
Fix issues found by ineffassign gocryptfs$ ineffassign ./... /home/jakob/go/src/github.com/rfjakob/gocryptfs/internal/configfile/config_file.go:243:2: ineffectual assignment to scryptHash /home/jakob/go/src/github.com/rfjakob/gocryptfs/internal/configfile/config_file.go:272:2: ineffectual assignment to scryptHash /home/jakob/go/src/github.com/rfjakob/gocryptfs/internal/fusefrontend/file.go:285:3: ineffectual assignment to fileID /home/jakob/go/src/github.com/rfjakob/gocryptfs/internal/fusefrontend/node.go:367:3: ineffectual assignment to err /home/jakob/go/src/github.com/rfjakob/gocryptfs/internal/fusefrontend/node_open_create.go:68:2: ineffectual assignment to fd /home/jakob/go/src/github.com/rfjakob/gocryptfs/mount.go:308:2: ineffectual assignment to masterkey /home/jakob/go/src/github.com/rfjakob/gocryptfs/gocryptfs-xray/xray_main.go:156:13: ineffectual assignment to err /home/jakob/go/src/github.com/rfjakob/gocryptfs/internal/fusefrontend/prepare_syscall_test.go:65:16: ineffectual assignment to errno /home/jakob/go/src/github.com/rfjakob/gocryptfs/internal/syscallcompat/open_nofollow_test.go:34:2: ineffectual assignment to fd /home/jakob/go/src/github.com/rfjakob/gocryptfs/tests/defaults/acl_test.go:111:6: ineffectual assignment to err /home/jakob/go/src/github.com/rfjakob/gocryptfs/tests/defaults/acl_test.go:181:2: ineffectual assignment to sz /home/jakob/go/src/github.com/rfjakob/gocryptfs/tests/defaults/acl_test.go:198:2: ineffectual assignment to sz /home/jakob/go/src/github.com/rfjakob/gocryptfs/tests/defaults/main_test.go:365:8: ineffectual assignment to err /home/jakob/go/src/github.com/rfjakob/gocryptfs/tests/xattr/xattr_fd_test.go:30:6: ineffectual assignment to err /home/jakob/go/src/github.com/rfjakob/gocryptfs/tests/xattr/xattr_fd_test.go:66:6: ineffectual assignment to err
2021-08-18 15:47:17 +02:00
if errno != 0 {
t.Fatal(errno)
}
if cName == "" {
t.Fatal("cName should not be empty")
}
err = syscallcompat.Faccessat(dirfd, cName, unix.R_OK)
if err != nil {
t.Error(err)
}
syscall.Close(dirfd)
dirfd, cName, errno = dir1.prepareAtSyscall("dir2")
if errno != 0 {
t.Fatal(errno)
}
if cName == "" {
t.Fatal("cName should not be empty")
}
err = syscallcompat.Faccessat(dirfd, cName, unix.R_OK)
if err != nil {
t.Errorf("Faccessat(%d, %q): %v", dirfd, cName, err)
}
syscall.Close(dirfd)
n255 := strings.Repeat("n", 255)
dir1.Mkdir(nil, n255, 0700, out)
dirfd, cName, errno = dir1.prepareAtSyscall(n255)
if errno != 0 {
t.Fatal(errno)
}
if cName == "" {
t.Fatal("cName should not be empty")
}
if len(cName) >= 255 {
t.Fatalf("cName is too long: %q", cName)
}
err = syscallcompat.Faccessat(dirfd, cName, unix.R_OK)
if err != nil {
t.Errorf("Faccessat(%d, %q): %v", dirfd, cName, err)
}
syscall.Close(dirfd)
}
func TestPrepareAtSyscallPlaintextnames(t *testing.T) {
cipherdir := test_helpers.InitFS(t, "-plaintextnames")
args := Args{
Cipherdir: cipherdir,
PlaintextNames: true,
}
rn := newTestFS(args)
2020-07-11 20:15:47 +02:00
out := &fuse.EntryOut{}
child, errno := rn.Mkdir(nil, "dir1", 0700, out)
2020-07-11 20:15:47 +02:00
if errno != 0 {
t.Fatal(errno)
}
rn.AddChild("dir1", child, false)
dir1 := toNode(child.Operations())
_, errno = dir1.Mkdir(nil, "dir2", 0700, out)
2020-07-11 20:15:47 +02:00
if errno != 0 {
t.Fatal(errno)
}
dirfd, cName, errno := rn.prepareAtSyscallMyself()
if errno != 0 {
t.Fatal(errno)
}
if cName != "." {
t.Fatal("cName should be .")
}
err := syscallcompat.Faccessat(dirfd, cName, unix.R_OK)
if err != nil {
t.Error(err)
}
err = syscallcompat.Faccessat(dirfd, ".", unix.R_OK)
if err != nil {
t.Error(err)
}
syscall.Close(dirfd)
dirfd, cName, errno = rn.prepareAtSyscall("dir1")
if errno != 0 {
t.Fatal(errno)
}
if cName != "dir1" {
t.Fatalf("wrong cName: %q", cName)
}
err = syscallcompat.Faccessat(dirfd, cName, unix.R_OK)
if err != nil {
t.Error(err)
}
syscall.Close(dirfd)
dirfd, cName, errno = dir1.prepareAtSyscall("dir2")
if errno != 0 {
t.Fatal(errno)
}
if cName != "dir2" {
t.Fatalf("wrong cName: %q", cName)
}
err = syscallcompat.Faccessat(dirfd, cName, unix.R_OK)
if err != nil {
t.Error(err)
}
syscall.Close(dirfd)
}