aboutsummaryrefslogtreecommitdiff
path: root/tests/defaults/main_test.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2017-07-11 23:19:58 +0200
committerJakob Unterwurzacher2017-07-11 23:19:58 +0200
commit3062de6187990f9b4f669ecd9dffdd48ee0d778f (patch)
treef62274c8d0497a1fec068f75d8519fbf0263247d /tests/defaults/main_test.go
parent849ec10081c0eb04535017f8845501ae799ac477 (diff)
fusefronted: enable writing to write-only files
Due to RMW, we always need read permissions on the backing file. This is a problem if the file permissions do not allow reading (i.e. 0200 permissions). This patch works around that problem by chmod'ing the file, obtaining a fd, and chmod'ing it back. Test included. Issue reported at: https://github.com/rfjakob/gocryptfs/issues/125
Diffstat (limited to 'tests/defaults/main_test.go')
-rw-r--r--tests/defaults/main_test.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/defaults/main_test.go b/tests/defaults/main_test.go
index ca11b43..5c6bb84 100644
--- a/tests/defaults/main_test.go
+++ b/tests/defaults/main_test.go
@@ -4,6 +4,7 @@ package defaults
import (
"bytes"
"io"
+ "io/ioutil"
"os"
"os/exec"
"runtime"
@@ -161,3 +162,32 @@ func TestXfs124(t *testing.T) {
wg.Wait()
}
+
+func TestWrite0200File(t *testing.T) {
+ fn := test_helpers.DefaultPlainDir + "/TestWrite0200File"
+ err := ioutil.WriteFile(fn, nil, 0200)
+ if err != nil {
+ t.Fatalf("creating empty file failed: %v", err)
+ }
+ fd, err := os.OpenFile(fn, os.O_WRONLY, 0)
+ if err != nil {
+ t.Fatal(err)
+ }
+ fi, err := fd.Stat()
+ if err != nil {
+ t.Fatal(err)
+ }
+ perms := fi.Mode().Perm()
+ if perms != 0200 {
+ t.Fatal("wrong initial permissions")
+ }
+ defer fd.Close()
+ _, err = fd.Write(make([]byte, 10))
+ if err != nil {
+ t.Fatal(err)
+ }
+ perms = fi.Mode().Perm()
+ if perms != 0200 {
+ t.Fatal("wrong restored permissions")
+ }
+}