summaryrefslogtreecommitdiff
path: root/internal/fusefrontend/openbackingdir_test.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2019-01-02 21:52:52 +0100
committerJakob Unterwurzacher2019-01-02 21:52:52 +0100
commit352f3147c5f1260cf729692d945c87e210cb1ad8 (patch)
tree7678cd13a18f1d4bf2c4f24c2e15df0c7fc85f6f /internal/fusefrontend/openbackingdir_test.go
parent2b12bba274ba75f76ac8c2af3790e4190b32396f (diff)
fusefrontend: move openBackingDir into its own file
This function is in all fastpaths, will get a cache, and needs its own file. renamed: internal/fusefrontend/names.go -> internal/fusefrontend/openbackingdir.go renamed: internal/fusefrontend/names_test.go -> internal/fusefrontend/openbackingdir_test.go
Diffstat (limited to 'internal/fusefrontend/openbackingdir_test.go')
-rw-r--r--internal/fusefrontend/openbackingdir_test.go152
1 files changed, 152 insertions, 0 deletions
diff --git a/internal/fusefrontend/openbackingdir_test.go b/internal/fusefrontend/openbackingdir_test.go
new file mode 100644
index 0000000..8453e52
--- /dev/null
+++ b/internal/fusefrontend/openbackingdir_test.go
@@ -0,0 +1,152 @@
+package fusefrontend
+
+import (
+ "strings"
+ "syscall"
+ "testing"
+
+ "golang.org/x/sys/unix"
+
+ "github.com/rfjakob/gocryptfs/internal/syscallcompat"
+ "github.com/rfjakob/gocryptfs/tests/test_helpers"
+)
+
+func TestOpenBackingDir(t *testing.T) {
+ cipherdir := test_helpers.InitFS(t)
+ args := Args{
+ Cipherdir: cipherdir,
+ }
+ fs := newTestFS(args)
+
+ code := fs.Mkdir("dir1", 0700, nil)
+ if !code.Ok() {
+ t.Fatal(code)
+ }
+ code = fs.Mkdir("dir1/dir2", 0700, nil)
+ if !code.Ok() {
+ t.Fatal(code)
+ }
+
+ 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 == "" {
+ 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 = fs.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.Error(err)
+ }
+ syscall.Close(dirfd)
+
+ n255 := strings.Repeat("n", 255)
+ path := "dir1/" + n255
+ fs.Mkdir(path, 0700, nil)
+ dirfd, cName, err = fs.openBackingDir(path)
+ 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.Error(err)
+ }
+ syscall.Close(dirfd)
+}
+
+func TestOpenBackingDirPlaintextNames(t *testing.T) {
+ cipherdir := test_helpers.InitFS(t, "-plaintextnames")
+ args := Args{
+ Cipherdir: cipherdir,
+ PlaintextNames: true,
+ }
+ fs := newTestFS(args)
+
+ code := fs.Mkdir("dir1", 0700, nil)
+ if !code.Ok() {
+ t.Fatal(code)
+ }
+ code = fs.Mkdir("dir1/dir2", 0700, nil)
+ if !code.Ok() {
+ t.Fatal(code)
+ }
+
+ 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)
+}