diff options
Diffstat (limited to 'tests/root_test')
| -rw-r--r-- | tests/root_test/btrfs_test.go | 65 | ||||
| -rw-r--r-- | tests/root_test/issue893_test.go | 5 | ||||
| -rw-r--r-- | tests/root_test/root_test.go | 91 |
3 files changed, 106 insertions, 55 deletions
diff --git a/tests/root_test/btrfs_test.go b/tests/root_test/btrfs_test.go new file mode 100644 index 0000000..4f2527a --- /dev/null +++ b/tests/root_test/btrfs_test.go @@ -0,0 +1,65 @@ +package root_test + +import ( + "os" + "os/exec" + "path/filepath" + "syscall" + "testing" + + "github.com/rfjakob/gocryptfs/v2/internal/syscallcompat" + + "github.com/rfjakob/gocryptfs/v2/tests/test_helpers" +) + +// TestBtrfsQuirks needs root permissions because it creates a loop disk +func TestBtrfsQuirks(t *testing.T) { + if os.Getuid() != 0 { + t.Skip("must run as root") + } + + img := filepath.Join(test_helpers.TmpDir, t.Name()+".img") + f, err := os.Create(img) + if err != nil { + t.Fatal(err) + } + defer f.Close() + // minimum size for each btrfs device is 114294784 + err = f.Truncate(200 * 1024 * 1024) + if err != nil { + t.Fatal(err) + } + + // Format as Btrfs + _, err = exec.LookPath("mkfs.btrfs") + if err != nil { + t.Skip("mkfs.btrfs not found, skipping test") + } + cmd := exec.Command("mkfs.btrfs", img) + out, err := cmd.CombinedOutput() + if err != nil { + t.Logf("%q", cmd.Args) + t.Log(string(out)) + t.Fatal(err) + } + + // Mount + mnt := img + ".mnt" + err = os.Mkdir(mnt, 0600) + if err != nil { + t.Fatal(err) + } + cmd = exec.Command("mount", img, mnt) + out, err = cmd.CombinedOutput() + if err != nil { + t.Log(string(out)) + t.Fatal(err) + } + defer syscall.Unlink(img) + defer syscall.Unmount(mnt, 0) + + quirk := syscallcompat.DetectQuirks(mnt) + if quirk != syscallcompat.QuirkBrokenFalloc { + t.Errorf("wrong quirk: %v", quirk) + } +} diff --git a/tests/root_test/issue893_test.go b/tests/root_test/issue893_test.go index 6ad8e6d..2db0b19 100644 --- a/tests/root_test/issue893_test.go +++ b/tests/root_test/issue893_test.go @@ -4,7 +4,6 @@ package root_test import ( "fmt" - "io/ioutil" "os" "sync" "syscall" @@ -35,10 +34,10 @@ func TestConcurrentUserOps(t *testing.T) { if err = os.MkdirAll(d, 0700); err != nil { return } - if err = ioutil.WriteFile(d+"/foo", nil, 0400); err != nil { + if err = os.WriteFile(d+"/foo", nil, 0400); err != nil { return } - if err = ioutil.WriteFile(d+"/bar", []byte("aaaaaaaaaaaaaaaaaaaaa"), 0400); err != nil { + if err = os.WriteFile(d+"/bar", []byte("aaaaaaaaaaaaaaaaaaaaa"), 0400); err != nil { return } if err = syscall.Unlink(d + "/foo"); err != nil { diff --git a/tests/root_test/root_test.go b/tests/root_test/root_test.go index e432ce0..c531ebb 100644 --- a/tests/root_test/root_test.go +++ b/tests/root_test/root_test.go @@ -5,7 +5,6 @@ package root_test import ( - "io/ioutil" "os" "os/exec" "path/filepath" @@ -203,7 +202,7 @@ func TestDiskFull(t *testing.T) { } t.Logf("sz1=%d, sz2=%d", sz1, sz2) - foo1, err := ioutil.ReadFile(mnt + "/foo1") + foo1, err := os.ReadFile(mnt + "/foo1") if err != nil { t.Fatal(err) } @@ -211,7 +210,7 @@ func TestDiskFull(t *testing.T) { t.Fail() } - foo2, err := ioutil.ReadFile(mnt + "/foo2") + foo2, err := os.ReadFile(mnt + "/foo2") if err != nil { t.Fatal(err) } @@ -231,7 +230,7 @@ func TestAcl(t *testing.T) { defer test_helpers.UnmountPanic(pDir) f1 := pDir + "/f1" - if err := ioutil.WriteFile(f1, []byte("hello world\n"), 000); err != nil { + if err := os.WriteFile(f1, []byte("hello world\n"), 000); err != nil { t.Fatal(err) } @@ -301,54 +300,6 @@ func TestAcl(t *testing.T) { } } -// TestBtrfsQuirks needs root permissions because it creates a loop disk -func TestBtrfsQuirks(t *testing.T) { - if os.Getuid() != 0 { - t.Skip("must run as root") - } - - img := filepath.Join(test_helpers.TmpDir, t.Name()+".img") - f, err := os.Create(img) - if err != nil { - t.Fatal(err) - } - defer f.Close() - // minimum size for each btrfs device is 114294784 - err = f.Truncate(200 * 1024 * 1024) - if err != nil { - t.Fatal(err) - } - - // Format as Btrfs - cmd := exec.Command("mkfs.btrfs", img) - out, err := cmd.CombinedOutput() - if err != nil { - t.Logf("%q", cmd.Args) - t.Log(string(out)) - t.Fatal(err) - } - - // Mount - mnt := img + ".mnt" - err = os.Mkdir(mnt, 0600) - if err != nil { - t.Fatal(err) - } - cmd = exec.Command("mount", img, mnt) - out, err = cmd.CombinedOutput() - if err != nil { - t.Log(string(out)) - t.Fatal(err) - } - defer syscall.Unlink(img) - defer syscall.Unmount(mnt, 0) - - quirk := syscallcompat.DetectQuirks(mnt) - if quirk != syscallcompat.QuirkBrokenFalloc { - t.Errorf("wrong quirk: %v", quirk) - } -} - func TestOverlay(t *testing.T) { if os.Getuid() != 0 { t.Skip("must run as root") @@ -379,3 +330,39 @@ func TestOverlay(t *testing.T) { } defer syscall.Unmount(ovlMnt, 0) } + +// Check that mkdir and file create works with force_owner and runnung as root +// https://github.com/rfjakob/gocryptfs/issues/783 +func TestRootForceOwner(t *testing.T) { + if os.Getuid() != 0 { + t.Skip("must run as root") + } + cDir := test_helpers.InitFS(t) + pDir := cDir + ".mnt" + test_helpers.MountOrFatal(t, cDir, pDir, "-allow_other", "-extpass=echo test", "-force_owner=1234:1234") + defer test_helpers.UnmountPanic(pDir) + + err := asUser(1234, 1234, nil, func() error { + return os.Mkdir(pDir+"/dir1", 0700) + }) + if err != nil { + t.Error(err) + } + err = asUser(1234, 1234, nil, func() error { + f, err := os.Create(pDir + "/file1") + if err == nil { + f.Close() + } + return err + }) + if err != nil { + t.Error(err) + } + err = asUser(1234, 1234, nil, func() error { + sock := pDir + "/sock" + return syscall.Mknod(sock, syscall.S_IFSOCK|0600, 0) + }) + if err != nil { + t.Errorf("mknod: %v", err) + } +} |
