aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/normal/cli_test.go59
-rw-r--r--tests/reverse/correctness_test.go17
-rw-r--r--tests/reverse/longname_perf_test.go45
-rw-r--r--tests/reverse/main_test.go32
4 files changed, 112 insertions, 41 deletions
diff --git a/tests/normal/cli_test.go b/tests/normal/cli_test.go
index ed3111b..62ad217 100644
--- a/tests/normal/cli_test.go
+++ b/tests/normal/cli_test.go
@@ -5,7 +5,6 @@ package normal
import (
"os"
"os/exec"
- "path/filepath"
"testing"
"github.com/rfjakob/gocryptfs/internal/configfile"
@@ -24,18 +23,45 @@ func TestMain(m *testing.M) {
// Test -init flag
func TestInit(t *testing.T) {
dir := test_helpers.InitFS(t)
- _, err := os.Stat(filepath.Join(dir, configfile.ConfDefaultName))
+ _, c, err := configfile.LoadConfFile(dir+"/"+configfile.ConfDefaultName, "test")
if err != nil {
t.Fatal(err)
}
+ if c.IsFeatureFlagSet(configfile.FlagGCMSIV) {
+ t.Error("GCMSIV flag should not be set")
+ }
}
-// Test -passwd flag
-func TestPasswd(t *testing.T) {
- // Create FS
- dir := test_helpers.InitFS(t)
+// Test -init with -gcmsiv
+func TestInitGcmsiv(t *testing.T) {
+ dir := test_helpers.InitFS(t, "-gcmsiv")
+ _, c, err := configfile.LoadConfFile(dir+"/"+configfile.ConfDefaultName, "test")
+ if err != nil {
+ t.Fatal(err)
+ }
+ if !c.IsFeatureFlagSet(configfile.FlagGCMSIV) {
+ t.Error("GCMSIV flag should be set but is not")
+ }
+}
+
+// Test -init with -reverse
+func TestInitReverse(t *testing.T) {
+ dir := test_helpers.InitFS(t, "-reverse")
+ _, c, err := configfile.LoadConfFile(dir+"/"+configfile.ConfReverseName, "test")
+ if err != nil {
+ t.Fatal(err)
+ }
+ if !c.IsFeatureFlagSet(configfile.FlagGCMSIV) {
+ t.Error("GCMSIV flag should be set but is not")
+ }
+}
+
+func testPasswd(t *testing.T, dir string, extraArgs ...string) {
// Change password using "-extpass"
- cmd := exec.Command(test_helpers.GocryptfsBinary, "-q", "-passwd", "-extpass", "echo test", dir)
+ args := []string{"-q", "-passwd", "-extpass", "echo test"}
+ args = append(args, extraArgs...)
+ args = append(args, dir)
+ cmd := exec.Command(test_helpers.GocryptfsBinary, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
@@ -43,7 +69,10 @@ func TestPasswd(t *testing.T) {
t.Error(err)
}
// Change password using stdin
- cmd = exec.Command(test_helpers.GocryptfsBinary, "-q", "-passwd", dir)
+ args = []string{"-q", "-passwd", "-extpass", "echo test"}
+ args = append(args, extraArgs...)
+ args = append(args, dir)
+ cmd = exec.Command(test_helpers.GocryptfsBinary, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
p, err := cmd.StdinPipe()
@@ -65,6 +94,20 @@ func TestPasswd(t *testing.T) {
}
}
+// Test -passwd flag
+func TestPasswd(t *testing.T) {
+ // Create FS
+ dir := test_helpers.InitFS(t)
+ testPasswd(t, dir)
+}
+
+// Test -passwd with -reverse
+func TestPasswdReverse(t *testing.T) {
+ // Create FS
+ dir := test_helpers.InitFS(t, "-reverse")
+ testPasswd(t, dir, "-reverse")
+}
+
// Test -init & -config flag
func TestInitConfig(t *testing.T) {
config := test_helpers.TmpDir + "/TestInitConfig.conf"
diff --git a/tests/reverse/correctness_test.go b/tests/reverse/correctness_test.go
new file mode 100644
index 0000000..e268815
--- /dev/null
+++ b/tests/reverse/correctness_test.go
@@ -0,0 +1,17 @@
+package reverse_test
+
+import (
+ "os"
+ "testing"
+)
+
+func TestLongnameStat(t *testing.T) {
+ _, err := os.Stat(dirA + "/" + "")
+ if err != nil {
+ t.Error(err)
+ }
+ _, err = os.Stat(dirA + "/" + "")
+ if err != nil {
+ t.Error(err)
+ }
+}
diff --git a/tests/reverse/longname_perf_test.go b/tests/reverse/longname_perf_test.go
index 43acd25..f170ad7 100644
--- a/tests/reverse/longname_perf_test.go
+++ b/tests/reverse/longname_perf_test.go
@@ -5,34 +5,17 @@ import (
"fmt"
"os"
"testing"
-
- "github.com/rfjakob/gocryptfs/tests/test_helpers"
)
-var dirA, dirB, x240 string
-
-func TestMain(m *testing.M) {
- x240 = string(bytes.Repeat([]byte("x"), 240))
- dirA = test_helpers.TmpDir + "/a"
- dirB = test_helpers.TmpDir + "/b"
- os.Mkdir(dirA, 0700)
- os.Mkdir(dirB, 0700)
- generateFiles(dirA)
- test_helpers.MountOrExit(dirA, dirB, "-zerokey", "-reverse")
- r := m.Run()
- test_helpers.UnmountPanic(dirB)
- os.RemoveAll(test_helpers.TmpDir)
- os.Exit(r)
-}
-
-func genName(i int) string {
- return fmt.Sprintf("%04d.%s", i, x240)
+func genName(i int, postfix string) string {
+ return fmt.Sprintf("%04d.%s", i, postfix)
}
// Create 10000 files with long names
-func generateFiles(dir string) {
+func generateLongnameFiles(dir string) {
+ x240 := string(bytes.Repeat([]byte("x"), 240))
for i := 0; i < 100000; i++ {
- n := genName(i)
+ n := genName(i, x240)
f, err := os.Create(dir + "/" + n)
if err != nil {
panic(err)
@@ -41,18 +24,9 @@ func generateFiles(dir string) {
}
}
-func TestLongnameStat(t *testing.T) {
- _, err := os.Stat(dirA + "/" + genName(0))
- if err != nil {
- t.Error(err)
- }
- _, err = os.Stat(dirA + "/" + genName(9999))
- if err != nil {
- t.Error(err)
- }
-}
-
func BenchmarkLongnameStat(b *testing.B) {
+ // Setup
+ generateLongnameFiles(dirA)
dirFd, err := os.Open(dirB)
if err != nil {
b.Fatal(err)
@@ -63,6 +37,7 @@ func BenchmarkLongnameStat(b *testing.B) {
}
l := len(encryptedNames)
dirFd.Close()
+ // Benchmark
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := os.Stat(dirB + "/" + encryptedNames[i%l])
@@ -70,4 +45,8 @@ func BenchmarkLongnameStat(b *testing.B) {
b.Fatal(err)
}
}
+ // Cleanup
+ b.StopTimer()
+ os.RemoveAll(dirA)
+ os.Mkdir(dirA, 0700)
}
diff --git a/tests/reverse/main_test.go b/tests/reverse/main_test.go
new file mode 100644
index 0000000..3d10750
--- /dev/null
+++ b/tests/reverse/main_test.go
@@ -0,0 +1,32 @@
+package reverse_test
+
+import (
+ "os"
+ "testing"
+
+ "github.com/rfjakob/gocryptfs/tests/test_helpers"
+)
+
+var dirA, dirB, dirC string
+
+func TestMain(m *testing.M) {
+ dirA = test_helpers.TmpDir + "/a"
+ dirB = test_helpers.TmpDir + "/b"
+ dirC = test_helpers.TmpDir + "/c"
+ if err := os.Mkdir(dirA, 0700); err != nil {
+ panic(err)
+ }
+ if err := os.Mkdir(dirB, 0700); err != nil {
+ panic(err)
+ }
+ if err := os.Mkdir(dirC, 0700); err != nil {
+ panic(err)
+ }
+ test_helpers.MountOrExit(dirA, dirB, "-zerokey", "-reverse")
+ test_helpers.MountOrExit(dirB, dirC, "-zerokey", "-gcmsiv")
+ r := m.Run()
+ test_helpers.UnmountPanic(dirC)
+ test_helpers.UnmountPanic(dirB)
+ os.RemoveAll(test_helpers.TmpDir)
+ os.Exit(r)
+}