aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Unterwurzacher2025-06-05 19:19:53 +0200
committerJakob Unterwurzacher2025-06-05 19:22:54 +0200
commite55a637512131c21a7eb16574aba799abd2a336f (patch)
tree7fe5c3f6c74b03cbc1a2e8902c4ca3e21d7e4a92
parent16ed08caf78951bf6bb92945c3e729bb06111f6f (diff)
tests: add TestRootForceOwner
$ make root_test [...] === RUN TestRootForceOwner root_test.go:398: mkdir /var/tmp/gocryptfs-test-parent-0/3816769547/TestRootForceOwner.2366169656.mnt/dir1: permission denied root_test.go:408: open /var/tmp/gocryptfs-test-parent-0/3816769547/TestRootForceOwner.2366169656.mnt/file1: permission denied root_test.go:415: mknod: permission denied --- FAIL: TestRootForceOwner (0.04s) https://github.com/rfjakob/gocryptfs/issues/783
-rw-r--r--tests/root_test/root_test.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/root_test/root_test.go b/tests/root_test/root_test.go
index e432ce0..9ce1f4b 100644
--- a/tests/root_test/root_test.go
+++ b/tests/root_test/root_test.go
@@ -379,3 +379,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)
+ }
+}