aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Unterwurzacher2015-11-15 15:05:15 +0100
committerJakob Unterwurzacher2015-11-15 15:05:15 +0100
commit40882c6e49186510a8adc6ae4b41a879c5d3278f (patch)
tree789510deb01d2a1fa7db5bd0d44f998b11860399
parent296bdf3af21a8964dcb884ff41ea7556cc811e9a (diff)
tests: add example_filesystems, test password and -masterkey mount
-rw-r--r--integration_tests/example_filesystems/normal/3-HZSwv99agoWgTErV0YFQ==bin0 -> 56 bytes
-rw-r--r--integration_tests/example_filesystems/normal/gocryptfs.conf12
-rw-r--r--integration_tests/example_filesystems_test.go46
-rw-r--r--integration_tests/helpers.go48
-rw-r--r--integration_tests/main_test.go34
-rw-r--r--integration_tests/performance_test.go6
6 files changed, 108 insertions, 38 deletions
diff --git a/integration_tests/example_filesystems/normal/3-HZSwv99agoWgTErV0YFQ== b/integration_tests/example_filesystems/normal/3-HZSwv99agoWgTErV0YFQ==
new file mode 100644
index 0000000..5d0af82
--- /dev/null
+++ b/integration_tests/example_filesystems/normal/3-HZSwv99agoWgTErV0YFQ==
Binary files differ
diff --git a/integration_tests/example_filesystems/normal/gocryptfs.conf b/integration_tests/example_filesystems/normal/gocryptfs.conf
new file mode 100644
index 0000000..354b4bb
--- /dev/null
+++ b/integration_tests/example_filesystems/normal/gocryptfs.conf
@@ -0,0 +1,12 @@
+{
+ "EncryptedKey": "He757VFOKOWbMJqJ7HBs67SMSi3Vu8/2vgWNI6j1tVo4JBlNvrQSw6KkCh0lGrHrh6ICbPv4MyoyFdGa",
+ "ScryptObject": {
+ "Salt": "MeHSsxsnJwngAwptNzuXQlj7JtF1b0uzZuWvVV3cH3w=",
+ "N": 65536,
+ "R": 8,
+ "P": 1,
+ "KeyLen": 32
+ },
+ "Version": 2,
+ "FeatureFlags": null
+} \ No newline at end of file
diff --git a/integration_tests/example_filesystems_test.go b/integration_tests/example_filesystems_test.go
new file mode 100644
index 0000000..b208d39
--- /dev/null
+++ b/integration_tests/example_filesystems_test.go
@@ -0,0 +1,46 @@
+package integration_tests
+
+// Mount example filesystems and check that the file "status.txt" is there
+
+import (
+ "io/ioutil"
+ "os"
+ "testing"
+)
+
+const statusTxtContent = "It works!\n"
+
+// checkStatusTxt - read file "filename" and verify that it contains
+// "It works!\n"
+func checkStatusTxt(t *testing.T, filename string) {
+ contentBytes, err := ioutil.ReadFile(filename)
+ if err != nil {
+ t.Error(err)
+ }
+ content := string(contentBytes)
+ if content != statusTxtContent {
+ t.Errorf("Unexpected content: %s\n", content)
+ }
+}
+
+// Test example_filesystems/normal
+// with password mount and -masterkey mount
+func TestExampleFsNormal(t *testing.T) {
+ pDir := tmpDir + "TestExampleFsNormal/"
+ cDir := "example_filesystems/normal"
+ err := os.Mkdir(pDir, 0777)
+ if err != nil {
+ t.Fatal(err)
+ }
+ mount(cDir, pDir, "-extpass", "echo test")
+ checkStatusTxt(t, pDir + "status.txt")
+ unmount(pDir)
+ mount(cDir, pDir, "-masterkey", "74676e34-0b47c145-00dac61a-17a92316-"+
+ "bb57044c-e205b71f-65f4fdca-7cabd4b3")
+ checkStatusTxt(t, pDir + "status.txt")
+ unmount(pDir)
+ err = os.Remove(pDir)
+ if err != nil {
+ t.Error(err)
+ }
+}
diff --git a/integration_tests/helpers.go b/integration_tests/helpers.go
index 3ab1d21..87e133b 100644
--- a/integration_tests/helpers.go
+++ b/integration_tests/helpers.go
@@ -12,51 +12,63 @@ import (
// Note: the code assumes that all have a trailing slash
const tmpDir = "/tmp/gocryptfs_main_test/"
-const plainDir = tmpDir + "plain/"
-const cipherDir = tmpDir + "cipher/"
+const defaultPlainDir = tmpDir + "plain/"
+const defaultCipherDir = tmpDir + "cipher/"
const gocryptfsBinary = "../gocryptfs"
func resetTmpDir() {
- fu := exec.Command("fusermount", "-z", "-u", plainDir)
+ fu := exec.Command("fusermount", "-z", "-u", defaultPlainDir)
fu.Run()
- os.RemoveAll(tmpDir)
+ err := os.RemoveAll(tmpDir)
+ if err != nil {
+ fmt.Println(err)
+ os.Exit(1)
+ }
- err := os.MkdirAll(plainDir, 0777)
+ err = os.MkdirAll(defaultPlainDir, 0777)
if err != nil {
- panic("Could not create plainDir")
+ fmt.Println(err)
+ os.Exit(1)
}
- err = os.MkdirAll(cipherDir, 0777)
+ err = os.MkdirAll(defaultCipherDir, 0777)
if err != nil {
- panic("Could not create cipherDir")
+ fmt.Println(err)
+ os.Exit(1)
}
}
-func mount(extraArgs ...string) {
+// mount CIPHERDIR "c" on PLAINDIR "p"
+func mount(c string, p string, extraArgs ...string) {
var args []string
args = append(args, extraArgs...)
//args = append(args, "--fusedebug")
- args = append(args, cipherDir)
- args = append(args, plainDir)
- c := exec.Command(gocryptfsBinary, args...)
+ args = append(args, c)
+ args = append(args, p)
+ cmd := exec.Command(gocryptfsBinary, args...)
if testing.Verbose() {
- c.Stdout = os.Stdout
- c.Stderr = os.Stderr
+ cmd.Stdout = os.Stdout
+ cmd.Stderr = os.Stderr
}
- err := c.Run()
+ err := cmd.Run()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}
-func unmount() error {
- fu := exec.Command("fusermount", "-z", "-u", plainDir)
+// unmount PLAINDIR "p"
+func unmount(p string) error {
+ fu := exec.Command("fusermount", "-u", "-z", p)
fu.Stdout = os.Stdout
fu.Stderr = os.Stderr
- return fu.Run()
+ err := fu.Run()
+ if err != nil {
+ fmt.Println(err)
+ }
+ return err
}
// Return md5 string for file "filename"
diff --git a/integration_tests/main_test.go b/integration_tests/main_test.go
index 6049646..b1e1ac5 100644
--- a/integration_tests/main_test.go
+++ b/integration_tests/main_test.go
@@ -25,9 +25,9 @@ func TestMain(m *testing.M) {
fmt.Printf("***** Testing with OpenSSL\n")
}
resetTmpDir()
- mount("--zerokey")
+ mount(defaultCipherDir, defaultPlainDir, "--zerokey")
r := m.Run()
- unmount()
+ unmount(defaultPlainDir)
if defaultonly {
os.Exit(r)
@@ -37,25 +37,25 @@ func TestMain(m *testing.M) {
fmt.Printf("***** Testing with native Go crypto\n")
}
resetTmpDir()
- mount("--zerokey", "--openssl=false")
+ mount(defaultCipherDir, defaultPlainDir, "--zerokey", "--openssl=false")
r = m.Run()
- unmount()
+ unmount(defaultPlainDir)
if testing.Verbose() {
fmt.Printf("***** Testing \"--plaintextnames\"\n")
}
resetTmpDir()
- mount("--zerokey", "--plaintextnames")
+ mount(defaultCipherDir, defaultPlainDir, "--zerokey", "--plaintextnames")
plaintextNames = true
r = m.Run()
- unmount()
+ unmount(defaultPlainDir)
os.Exit(r)
}
// Write "n" zero bytes to filename "fn", read again, compare hash
func testWriteN(t *testing.T, fn string, n int) string {
- file, err := os.Create(plainDir + fn)
+ file, err := os.Create(defaultPlainDir + fn)
if err != nil {
t.FailNow()
}
@@ -68,12 +68,12 @@ func testWriteN(t *testing.T, fn string, n int) string {
}
file.Close()
- verifySize(t, plainDir+fn, n)
+ verifySize(t, defaultPlainDir+fn, n)
bin := md5.Sum(d)
hashWant := hex.EncodeToString(bin[:])
- hashActual := md5fn(plainDir + fn)
+ hashActual := md5fn(defaultPlainDir + fn)
if hashActual != hashWant {
t.Errorf("Wrong content, hashWant=%s hashActual=%s\n", hashWant, hashActual)
@@ -99,7 +99,7 @@ func TestWrite1Mx100(t *testing.T) {
// Read and check 100 times to catch race conditions
var i int
for i = 0; i < 100; i++ {
- hashActual := md5fn(plainDir + "1M")
+ hashActual := md5fn(defaultPlainDir + "1M")
if hashActual != hashWant {
fmt.Printf("Read corruption in loop # %d\n", i)
t.FailNow()
@@ -110,7 +110,7 @@ func TestWrite1Mx100(t *testing.T) {
}
func TestTruncate(t *testing.T) {
- fn := plainDir + "truncate"
+ fn := defaultPlainDir + "truncate"
file, err := os.Create(fn)
if err != nil {
t.FailNow()
@@ -142,7 +142,7 @@ func TestTruncate(t *testing.T) {
}
func TestAppend(t *testing.T) {
- fn := plainDir + "append"
+ fn := defaultPlainDir + "append"
file, err := os.Create(fn)
if err != nil {
t.FailNow()
@@ -176,7 +176,7 @@ func TestAppend(t *testing.T) {
// Create a file with holes by writing to offset 0 (block #0) and
// offset 4096 (block #1).
func TestFileHoles(t *testing.T) {
- fn := plainDir + "fileholes"
+ fn := defaultPlainDir + "fileholes"
file, err := os.Create(fn)
if err != nil {
t.Errorf("file create failed")
@@ -203,7 +203,7 @@ func TestRmwRace(t *testing.T) {
runtime.GOMAXPROCS(10)
- fn := plainDir + "rmwrace"
+ fn := defaultPlainDir + "rmwrace"
f1, err := os.Create(fn)
if err != nil {
t.Fatalf("file create failed")
@@ -274,7 +274,7 @@ func TestRmwRace(t *testing.T) {
// With "--plaintextnames", the name "/gocryptfs.conf" is reserved.
// Otherwise there should be no restrictions.
func TestFiltered(t *testing.T) {
- filteredFile := plainDir + "gocryptfs.conf"
+ filteredFile := defaultPlainDir + "gocryptfs.conf"
file, err := os.Create(filteredFile)
if plaintextNames == true && err == nil {
t.Errorf("should have failed but didn't")
@@ -292,13 +292,13 @@ func TestFiltered(t *testing.T) {
}
func TestFilenameEncryption(t *testing.T) {
- file, err := os.Create(plainDir + "TestFilenameEncryption.txt")
+ file, err := os.Create(defaultPlainDir + "TestFilenameEncryption.txt")
file.Close()
if err != nil {
t.Fatal(err)
}
- _, err = os.Stat(cipherDir + "TestFilenameEncryption.txt")
+ _, err = os.Stat(defaultCipherDir + "TestFilenameEncryption.txt")
if plaintextNames == true && err != nil {
t.Errorf("plaintextnames not working: %v", err)
} else if plaintextNames == false && err == nil {
diff --git a/integration_tests/performance_test.go b/integration_tests/performance_test.go
index b24474c..c77c79d 100644
--- a/integration_tests/performance_test.go
+++ b/integration_tests/performance_test.go
@@ -12,7 +12,7 @@ func BenchmarkStreamWrite(t *testing.B) {
buf := make([]byte, 1024*1024)
t.SetBytes(int64(len(buf)))
- file, err := os.Create(plainDir + "BenchmarkWrite")
+ file, err := os.Create(defaultPlainDir + "BenchmarkWrite")
if err != nil {
t.FailNow()
}
@@ -33,7 +33,7 @@ func BenchmarkStreamRead(t *testing.B) {
buf := make([]byte, 1024*1024)
t.SetBytes(int64(len(buf)))
- fn := plainDir + "BenchmarkWrite"
+ fn := defaultPlainDir + "BenchmarkWrite"
fi, err := os.Stat(fn)
if err != nil {
t.Fatal(err)
@@ -80,7 +80,7 @@ func BenchmarkStreamRead(t *testing.B) {
// createFiles - create "count" files of size "size" bytes each
func createFiles(t *testing.B, count int, size int) {
- dir := fmt.Sprintf("%s/createFiles_%d_%d", plainDir, count, size)
+ dir := fmt.Sprintf("%s/createFiles_%d_%d", defaultPlainDir, count, size)
err := os.Mkdir(dir, 0777)
if err != nil {
t.Fatal(err)