aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/cli/cli_test.go6
-rw-r--r--tests/reverse/correctness_test.go8
-rw-r--r--tests/reverse/inomap_test.go6
-rw-r--r--tests/reverse/main_test.go23
-rw-r--r--tests/reverse/one_file_system_test.go29
5 files changed, 45 insertions, 27 deletions
diff --git a/tests/cli/cli_test.go b/tests/cli/cli_test.go
index f4162f8..85a8006 100644
--- a/tests/cli/cli_test.go
+++ b/tests/cli/cli_test.go
@@ -995,9 +995,3 @@ func TestMountCreat(t *testing.T) {
test_helpers.UnmountPanic(mnt)
}
}
-
-// Test -init -deterministic-names
-func TestInitDeterministicNames(t *testing.T) {
- dir := test_helpers.InitFS(t, "-deterministic-names")
-
-}
diff --git a/tests/reverse/correctness_test.go b/tests/reverse/correctness_test.go
index 9d7a1c8..87d2f12 100644
--- a/tests/reverse/correctness_test.go
+++ b/tests/reverse/correctness_test.go
@@ -119,10 +119,10 @@ func TestConfigMapping(t *testing.T) {
}
}
-// Check that the access() syscall works on virtual files
-func TestAccessVirtual(t *testing.T) {
- if plaintextnames {
- t.Skip("test makes no sense for plaintextnames")
+// Check that the access() syscall works on virtual gocryptfs.diriv files
+func TestAccessVirtualDirIV(t *testing.T) {
+ if plaintextnames || deterministic_names {
+ t.Skip("test makes no sense for plaintextnames or deterministic_names")
}
var R_OK uint32 = 4
var W_OK uint32 = 2
diff --git a/tests/reverse/inomap_test.go b/tests/reverse/inomap_test.go
index e6fc525..d5544c8 100644
--- a/tests/reverse/inomap_test.go
+++ b/tests/reverse/inomap_test.go
@@ -130,8 +130,10 @@ func TestVirtualFileIno(t *testing.T) {
}
// Lower 48 bits should come from the backing file
const mask = 0xffffffffffff
- if origInos.parent&mask != cipherInos.diriv&mask {
- t.Errorf("diriv ino mismatch: %#x vs %#x", origInos.parent, cipherInos.diriv)
+ if !deterministic_names { // no diriv files with -deterministic-names
+ if origInos.parent&mask != cipherInos.diriv&mask {
+ t.Errorf("diriv ino mismatch: %#x vs %#x", origInos.parent, cipherInos.diriv)
+ }
}
if origInos.child != cipherInos.child {
t.Errorf("child ino mismatch: %d vs %d", origInos.child, cipherInos.child)
diff --git a/tests/reverse/main_test.go b/tests/reverse/main_test.go
index 3425289..3b9e7d0 100644
--- a/tests/reverse/main_test.go
+++ b/tests/reverse/main_test.go
@@ -2,6 +2,7 @@ package reverse_test
import (
"bytes"
+ "fmt"
"os"
"testing"
@@ -9,8 +10,13 @@ import (
)
var x240 = string(bytes.Repeat([]byte("x"), 240))
+
+// plaintextnames is true when the currently running test has -plaintextnames active
var plaintextnames bool
+// deterministic_names is true when the currently running test has -deterministic-names active
+var deterministic_names bool
+
// dirA is a normal directory
var dirA string
@@ -24,10 +30,22 @@ var dirC string
// to "dirC".
func TestMain(m *testing.M) {
var r int
- for _, plaintextnames = range []bool{false, true} {
+
+ testcases := []struct {
+ plaintextnames bool
+ deterministic_names bool
+ }{
+ {false, false},
+ {true, false},
+ {false, true},
+ }
+ for i, tc := range testcases {
argsA := []string{"-reverse"}
- if plaintextnames {
+ plaintextnames, deterministic_names = tc.plaintextnames, tc.deterministic_names
+ if tc.plaintextnames {
argsA = append(argsA, "-plaintextnames")
+ } else if tc.deterministic_names {
+ argsA = append(argsA, "-deterministic-names")
}
dirA = test_helpers.InitFS(nil, argsA...)
dirB = test_helpers.TmpDir + "/b"
@@ -49,6 +67,7 @@ func TestMain(m *testing.M) {
os.RemoveAll(dirC)
if r != 0 {
+ fmt.Printf("testcases[%d] = %#v failed\n", i, tc)
os.Exit(r)
}
}
diff --git a/tests/reverse/one_file_system_test.go b/tests/reverse/one_file_system_test.go
index 61fdb61..a3e441f 100644
--- a/tests/reverse/one_file_system_test.go
+++ b/tests/reverse/one_file_system_test.go
@@ -1,8 +1,9 @@
-package reverse
+package reverse_test
import (
"io/ioutil"
"net/url"
+ "os"
"runtime"
"syscall"
"testing"
@@ -10,7 +11,10 @@ import (
"github.com/rfjakob/gocryptfs/tests/test_helpers"
)
-func doTestOneFileSystem(t *testing.T, plaintextnames bool) {
+func TestOneFileSystem(t *testing.T) {
+ if runtime.GOOS != "linux" {
+ t.Skip("only works on linux")
+ }
// Let's not explode with "TempDir: pattern contains path separator"
myEscapedName := url.PathEscape(t.Name())
mnt, err := ioutil.TempDir(test_helpers.TmpDir, myEscapedName)
@@ -20,6 +24,8 @@ func doTestOneFileSystem(t *testing.T, plaintextnames bool) {
cliArgs := []string{"-reverse", "-zerokey", "-one-file-system"}
if plaintextnames {
cliArgs = append(cliArgs, "-plaintextnames")
+ } else if deterministic_names {
+ cliArgs = append(cliArgs, "-deterministic-names")
}
test_helpers.MountOrFatal(t, "/", mnt, cliArgs...)
defer test_helpers.UnmountErr(mnt)
@@ -48,25 +54,22 @@ func doTestOneFileSystem(t *testing.T, plaintextnames bool) {
t.Skip("no mountpoints found, nothing to test")
}
for _, m := range mountpoints {
- e, err := ioutil.ReadDir(mnt + "/" + m)
+ dir, err := os.Open(mnt + "/" + m)
+ if err != nil {
+ t.Error(err)
+ }
+ defer dir.Close()
+ e, err := dir.Readdirnames(-1)
if err != nil {
t.Error(err)
}
expected := 1
- if plaintextnames {
+ if plaintextnames || deterministic_names {
expected = 0
}
if len(e) != expected {
- t.Errorf("mountpoint %q does not look empty: %v", m, e)
+ t.Errorf("mountpoint %q should have %d entries, actually has: %v", m, expected, e)
}
}
t.Logf("tested %d mountpoints: %v", len(mountpoints), mountpoints)
}
-
-func TestOneFileSystem(t *testing.T) {
- if runtime.GOOS != "linux" {
- t.Skip("only works on linux")
- }
- t.Run("normal", func(t *testing.T) { doTestOneFileSystem(t, false) })
- t.Run("plaintextnames", func(t *testing.T) { doTestOneFileSystem(t, true) })
-}