From ee59b5269be45154107dc6840c7bf810aed18ae2 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sat, 26 Jun 2021 16:22:37 +0200 Subject: fusefrontend: convert openBackingDir tests to prepareAtSyscall openBackingDir will be removed. --- internal/fusefrontend/openbackingdir_test.go | 170 ------------------------- internal/fusefrontend/prepare_syscall_test.go | 172 ++++++++++++++++++++++++++ 2 files changed, 172 insertions(+), 170 deletions(-) delete mode 100644 internal/fusefrontend/openbackingdir_test.go create mode 100644 internal/fusefrontend/prepare_syscall_test.go (limited to 'internal') diff --git a/internal/fusefrontend/openbackingdir_test.go b/internal/fusefrontend/openbackingdir_test.go deleted file mode 100644 index ba4014f..0000000 --- a/internal/fusefrontend/openbackingdir_test.go +++ /dev/null @@ -1,170 +0,0 @@ -package fusefrontend - -import ( - "strings" - "syscall" - "testing" - - "golang.org/x/sys/unix" - - "github.com/hanwen/go-fuse/v2/fuse" - - "github.com/rfjakob/gocryptfs/internal/syscallcompat" - "github.com/rfjakob/gocryptfs/tests/test_helpers" -) - -func TestOpenBackingDir(t *testing.T) { - cipherdir := test_helpers.InitFS(t) - t.Logf("cipherdir = %q", cipherdir) - args := Args{ - Cipherdir: cipherdir, - } - rn := newTestFS(args) - out := &fuse.EntryOut{} - - child, errno := rn.Mkdir(nil, "dir1", 0700, out) - if errno != 0 { - t.Fatal(errno) - } - rn.AddChild("dir1", child, false) - dir1 := toNode(child.Operations()) - _, errno = dir1.Mkdir(nil, "dir2", 0700, out) - if errno != 0 { - t.Fatal(errno) - } - - dirfd, cName, err := rn.openBackingDir("") - if err != nil { - t.Fatal(err) - } - 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, err = rn.openBackingDir("") - if err != nil { - t.Fatal(err) - } - 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, err = rn.openBackingDir("dir1") - if err != nil { - t.Fatal(err) - } - 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, err = rn.openBackingDir("dir1/dir2") - if err != nil { - t.Fatal(err) - } - 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, err = rn.openBackingDir("dir1/" + n255) - if err != nil { - t.Fatal(err) - } - 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 TestOpenBackingDirPlaintextNames(t *testing.T) { - cipherdir := test_helpers.InitFS(t, "-plaintextnames") - args := Args{ - Cipherdir: cipherdir, - PlaintextNames: true, - } - fs := newTestFS(args) - out := &fuse.EntryOut{} - - _, errno := fs.Mkdir(nil, "dir1", 0700, out) - if errno != 0 { - t.Fatal(errno) - } - _, errno = fs.Mkdir(nil, "dir1/dir2", 0700, out) - if errno != 0 { - t.Fatal(errno) - } - - dirfd, cName, err := fs.openBackingDir("") - if err != nil { - t.Fatal(err) - } - 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, err = fs.openBackingDir("dir1") - if err != nil { - t.Fatal(err) - } - 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, err = fs.openBackingDir("dir1/dir2") - if err != nil { - t.Fatal(err) - } - 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) -} diff --git a/internal/fusefrontend/prepare_syscall_test.go b/internal/fusefrontend/prepare_syscall_test.go new file mode 100644 index 0000000..28e655c --- /dev/null +++ b/internal/fusefrontend/prepare_syscall_test.go @@ -0,0 +1,172 @@ +package fusefrontend + +import ( + "strings" + "syscall" + "testing" + + "golang.org/x/sys/unix" + + "github.com/hanwen/go-fuse/v2/fuse" + + "github.com/rfjakob/gocryptfs/internal/syscallcompat" + "github.com/rfjakob/gocryptfs/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) + out := &fuse.EntryOut{} + + child, errno := rn.Mkdir(nil, "dir1", 0700, out) + if errno != 0 { + t.Fatal(errno) + } + rn.AddChild("dir1", child, false) + dir1 := toNode(child.Operations()) + _, errno = dir1.Mkdir(nil, "dir2", 0700, out) + 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") + if err != nil { + t.Fatal(err) + } + 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) + out := &fuse.EntryOut{} + + child, errno := rn.Mkdir(nil, "dir1", 0700, out) + if errno != 0 { + t.Fatal(errno) + } + rn.AddChild("dir1", child, false) + dir1 := toNode(child.Operations()) + _, errno = dir1.Mkdir(nil, "dir2", 0700, out) + 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) +} -- cgit v1.2.3