aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJose M Perez2021-08-12 22:48:34 +0200
committerJakob Unterwurzacher2021-08-19 18:05:54 +0200
commit8f94083a2114c3aef4bc0320065e0374c420ea4a (patch)
treed6b56a31e58a99e8a46b4663d6d63b0c3be425b8 /tests
parent02c91d73ce2c63f999f2c29cf61d55caef19c67b (diff)
Flag -zerodiriv to create all diriv as all zero byte files
Diffstat (limited to 'tests')
-rw-r--r--tests/test_helpers/helpers.go2
-rw-r--r--tests/zerodiriv/zerodiriv_test.go85
2 files changed, 86 insertions, 1 deletions
diff --git a/tests/test_helpers/helpers.go b/tests/test_helpers/helpers.go
index 87dba0a..f78c59c 100644
--- a/tests/test_helpers/helpers.go
+++ b/tests/test_helpers/helpers.go
@@ -110,7 +110,7 @@ func ResetTmpDir(createDirIV bool) {
// Open cipherdir (following symlinks)
dirfd, err := syscall.Open(DefaultCipherDir, syscall.O_DIRECTORY|syscallcompat.O_PATH, 0)
if err == nil {
- err = nametransform.WriteDirIVAt(dirfd)
+ err = nametransform.WriteDirIVAt(dirfd, true)
syscall.Close(dirfd)
}
if err != nil {
diff --git a/tests/zerodiriv/zerodiriv_test.go b/tests/zerodiriv/zerodiriv_test.go
new file mode 100644
index 0000000..3fbbf47
--- /dev/null
+++ b/tests/zerodiriv/zerodiriv_test.go
@@ -0,0 +1,85 @@
+package zerodiriv
+
+// integration tests that target zerodiriv specifically
+
+import (
+ "bytes"
+ "path/filepath"
+ "io/ioutil"
+ "os"
+ "testing"
+
+ "github.com/rfjakob/gocryptfs/tests/test_helpers"
+)
+
+var cDir string
+var pDir string
+
+var testPw = []byte("test")
+
+// Create and mount "-zerodiriv" fs
+func TestMain(m *testing.M) {
+ cDir = test_helpers.InitFS(nil, "-zerodiriv")
+ pDir = cDir + ".mnt"
+ test_helpers.MountOrExit(cDir, pDir, "-zerodiriv", "-extpass", "echo test")
+ r := m.Run()
+ test_helpers.UnmountPanic(pDir)
+ os.Exit(r)
+}
+
+// diriv should be all-zero on newly created dirs
+func TestZeroDirIV(t *testing.T) {
+ // Create /dir1, move it and create it again
+ var dirPath = pDir+"/dir1"
+ var err = os.Mkdir(dirPath, 0777)
+ if err != nil {
+ t.Error(err)
+ }
+ err = os.Rename(dirPath, dirPath + ".bak")
+ if err != nil {
+ t.Error(err)
+ }
+ err = os.Mkdir(dirPath, 0777)
+ if err != nil {
+ t.Error(err)
+ }
+
+ var matches []string
+ matches, err = filepath.Glob(cDir+"/*/gocryptfs.diriv")
+ if err != nil {
+ t.Error(err)
+ }
+
+ // The contents of the both diriv files must be the same
+ var diriv0 []byte
+ diriv0, err = ioutil.ReadFile(matches[0])
+ if err != nil {
+ t.Error(err)
+ }
+ var diriv1 []byte
+ diriv1, err = ioutil.ReadFile(matches[1])
+ if err != nil {
+ t.Error(err)
+ }
+ if !bytes.Equal(diriv0, diriv1) {
+ t.Errorf("both dirivs should have the same value")
+ }
+ // And equal to zero
+ zerodiriv := make([]byte, len(diriv0))
+ if !bytes.Equal(diriv0, zerodiriv) {
+ t.Errorf("both dirivs should be all-zero")
+ }
+}
+
+// root diriv should be all-zero
+func TestZeroRootDirIV(t *testing.T) {
+ // The contents of the diriv file must be zero
+ diriv, err := ioutil.ReadFile(cDir+"/gocryptfs.diriv")
+ if err != nil {
+ t.Error(err)
+ }
+ zerodiriv := make([]byte, len(diriv))
+ if !bytes.Equal(diriv, zerodiriv) {
+ t.Errorf("root diriv should be all-zero")
+ }
+}