aboutsummaryrefslogtreecommitdiff
path: root/tests/root_test/root_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'tests/root_test/root_test.go')
-rw-r--r--tests/root_test/root_test.go91
1 files changed, 39 insertions, 52 deletions
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)
+ }
+}