From 02b6d3067d502bcc063965a5a9d75aa693125e1b Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Thu, 30 Jun 2016 00:57:14 +0200 Subject: test: split up integration_tests ...into "matrix" and "normal". Also: * Make running multiple packages in parallel safe, see http://stackoverflow.com/questions/23715302/go-how-to-run-tests-for-multiple-packages * Don't depent on test_helper.TmpDir and friends to have a terminating slash --- test.bash | 5 + .../example_filesystems_test.go | 47 +-- tests/integration_tests/cli_test.go | 97 ----- tests/integration_tests/main_test.go | 455 --------------------- tests/integration_tests/performance_test.go | 131 ------ tests/matrix/matrix_test.go | 436 ++++++++++++++++++++ tests/normal/cli_test.go | 105 +++++ tests/normal/performance_test.go | 131 ++++++ tests/plaintextnames/plaintextnames_test.go | 4 +- tests/test_helpers/helpers.go | 71 ++-- 10 files changed, 738 insertions(+), 744 deletions(-) delete mode 100644 tests/integration_tests/cli_test.go delete mode 100644 tests/integration_tests/main_test.go delete mode 100644 tests/integration_tests/performance_test.go create mode 100644 tests/matrix/matrix_test.go create mode 100644 tests/normal/cli_test.go create mode 100644 tests/normal/performance_test.go diff --git a/test.bash b/test.bash index c8f209a..2a565b7 100755 --- a/test.bash +++ b/test.bash @@ -8,4 +8,9 @@ source build.bash go test ./... $* +# Clean up after ourself, but don't descend into maybe still mounted +# example filesystems +# The tests cannot to this themselves as they are run in parallel +rm -Rf --one-file-system /tmp/gocryptfs-test-parent + go tool vet -shadow=true . diff --git a/tests/example_filesystems/example_filesystems_test.go b/tests/example_filesystems/example_filesystems_test.go index 6e0ab66..13aa941 100644 --- a/tests/example_filesystems/example_filesystems_test.go +++ b/tests/example_filesystems/example_filesystems_test.go @@ -15,20 +15,23 @@ import ( const statusTxtContent = "It works!\n" -var opensslOpt = "-openssl=false" +var opensslOpt string func TestMain(m *testing.M) { - test_helpers.ResetTmpDir(true) - r := m.Run() - opensslOpt = "-openssl=true" - r2 := m.Run() - os.Exit(r + r2) + for _, opensslOpt = range []string{"-openssl=false", "-openssl=true"} { + test_helpers.ResetTmpDir(true) + r := m.Run() + if r != 0 { + os.Exit(r) + } + } + os.Exit(0) } // This filesystem is not supported anymore. func TestExampleFSv04(t *testing.T) { cDir := "v0.4" - pDir := test_helpers.TmpDir + cDir + pDir := test_helpers.TmpDir + "/" + cDir err := test_helpers.Mount(cDir, pDir, false, "-extpass", "echo test", opensslOpt) if err == nil { t.Errorf("Mounting too old FS should fail") @@ -38,7 +41,7 @@ func TestExampleFSv04(t *testing.T) { // This filesystem is not supported anymore. func TestExampleFSv05(t *testing.T) { cDir := "v0.5" - pDir := test_helpers.TmpDir + cDir + pDir := test_helpers.TmpDir + "/" + cDir err := test_helpers.Mount(cDir, pDir, false, "-extpass", "echo test", opensslOpt) if err == nil { t.Errorf("Mounting too old FS should fail") @@ -48,7 +51,7 @@ func TestExampleFSv05(t *testing.T) { // This filesystem is not supported anymore. func TestExampleFSv06(t *testing.T) { cDir := "v0.6" - pDir := test_helpers.TmpDir + cDir + pDir := test_helpers.TmpDir + "/" + cDir err := test_helpers.Mount(cDir, pDir, false, "-extpass", "echo test", opensslOpt) if err == nil { t.Errorf("Mounting too old FS should fail") @@ -58,7 +61,7 @@ func TestExampleFSv06(t *testing.T) { // This filesystem is not supported anymore. func TestExampleFSv06PlaintextNames(t *testing.T) { cDir := "v0.6-plaintextnames" - pDir := test_helpers.TmpDir + cDir + pDir := test_helpers.TmpDir + "/" + cDir err := test_helpers.Mount(cDir, pDir, false, "-extpass", "echo test", opensslOpt) if err == nil { t.Errorf("Mounting too old FS should fail") @@ -69,8 +72,8 @@ func TestExampleFSv06PlaintextNames(t *testing.T) { // with password mount and -masterkey mount // v0.7 adds 128 bit GCM IVs func TestExampleFSv07(t *testing.T) { - pDir := test_helpers.TmpDir + "TestExampleFsV07/" cDir := "v0.7" + pDir := test_helpers.TmpDir + "/" + cDir err := os.Mkdir(pDir, 0777) if err != nil { t.Fatal(err) @@ -83,38 +86,31 @@ func TestExampleFSv07(t *testing.T) { opensslOpt) checkExampleFS(t, pDir, true) test_helpers.Unmount(pDir) - err = os.Remove(pDir) - if err != nil { - t.Error(err) - } } // gocryptfs v0.7 filesystem created with "-plaintextnames" func TestExampleFSv07PlaintextNames(t *testing.T) { cDir := "v0.7-plaintextnames" - pDir := test_helpers.TmpDir + cDir + ".mnt" + pDir := test_helpers.TmpDir + "/" + cDir + ".mnt" test_helpers.MountOrFatal(t, cDir, pDir, "-extpass", "echo test", opensslOpt) checkExampleFS(t, pDir, true) test_helpers.Unmount(pDir) - + // The actual unmount takes some time, this causes weird problems. Just don't + // reuse the mountpoint. + pDir = pDir + ".2" test_helpers.MountOrFatal(t, cDir, pDir, "-plaintextnames", "-masterkey", "6d96397b-585631e1-c7cba69d-61e738b6-4d5ad2c2-e21f0fb3-52f60d3a-b08526f7", opensslOpt) checkExampleFS(t, pDir, true) test_helpers.Unmount(pDir) - - err := os.Remove(pDir) - if err != nil { - t.Error(err) - } } // Test example_filesystems/v0.9 // (gocryptfs v0.9 introduced long file name support) func TestExampleFSv09(t *testing.T) { cDir := "v0.9" - pDir := test_helpers.TmpDir + "TestExampleFsV09/" + pDir := test_helpers.TmpDir + "/" + cDir err := os.Mkdir(pDir, 0777) if err != nil { t.Fatal(err) @@ -122,13 +118,10 @@ func TestExampleFSv09(t *testing.T) { test_helpers.MountOrFatal(t, cDir, pDir, "-extpass", "echo test", opensslOpt) checkExampleFSLongnames(t, pDir) test_helpers.Unmount(pDir) + pDir = pDir + ".2" test_helpers.MountOrFatal(t, cDir, pDir, "-masterkey", "1cafe3f4-bc316466-2214c47c-ecd89bf3-4e078fe4-f5faeea7-8b7cab02-884f5e1c", opensslOpt) checkExampleFSLongnames(t, pDir) test_helpers.Unmount(pDir) - err = os.Remove(pDir) - if err != nil { - t.Error(err) - } } diff --git a/tests/integration_tests/cli_test.go b/tests/integration_tests/cli_test.go deleted file mode 100644 index 679a5c1..0000000 --- a/tests/integration_tests/cli_test.go +++ /dev/null @@ -1,97 +0,0 @@ -package integration_tests - -// Test CLI operations like "-init", "-password" etc - -import ( - "os" - "os/exec" - "path/filepath" - "testing" - - "github.com/rfjakob/gocryptfs/internal/configfile" - - "github.com/rfjakob/gocryptfs/tests/test_helpers" -) - -// Test -init flag -func TestInit(t *testing.T) { - dir := test_helpers.InitFS(t) - _, err := os.Stat(filepath.Join(dir, configfile.ConfDefaultName)) - if err != nil { - t.Fatal(err) - } -} - -// Test -passwd flag -func TestPasswd(t *testing.T) { - // Create FS - dir := test_helpers.InitFS(t) - // Change password using "-extpass" - cmd := exec.Command(test_helpers.GocryptfsBinary, "-q", "-passwd", "-extpass", "echo test", dir) - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - err := cmd.Run() - if err != nil { - t.Error(err) - } - // Change password using stdin - cmd = exec.Command(test_helpers.GocryptfsBinary, "-q", "-passwd", dir) - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - p, err := cmd.StdinPipe() - if err != nil { - t.Fatal(err) - } - err = cmd.Start() - if err != nil { - t.Error(err) - } - // Old password - p.Write([]byte("test\n")) - // New password - p.Write([]byte("newpasswd\n")) - p.Close() - err = cmd.Wait() - if err != nil { - t.Error(err) - } -} - -// Test -init & -config flag -func TestInitConfig(t *testing.T) { - config := test_helpers.TmpDir + "TestInitConfig.conf" - dir := test_helpers.InitFS(t, "-config="+config) - - _, err := os.Stat(config) - if err != nil { - t.Fatal(err) - } - - // Test -passwd & -config - cmd2 := exec.Command(test_helpers.GocryptfsBinary, "-q", "-passwd", "-extpass", "echo test", - "-config", config, dir) - cmd2.Stdout = os.Stdout - cmd2.Stderr = os.Stderr - err = cmd2.Run() - if err != nil { - t.Error(err) - } -} - -// Test -ro -func TestRo(t *testing.T) { - dir := test_helpers.InitFS(t) - mnt := dir + ".mnt" - test_helpers.MountOrFatal(t, dir, mnt, "-ro", "-extpass=echo test") - defer test_helpers.Unmount(mnt) - - file := mnt + "/file" - err := os.Mkdir(file, 0777) - if err == nil { - t.Errorf("Mkdir should have failed") - } - _, err = os.Create(file) - if err == nil { - t.Errorf("Create should have failed") - } -} diff --git a/tests/integration_tests/main_test.go b/tests/integration_tests/main_test.go deleted file mode 100644 index 17f9d9d..0000000 --- a/tests/integration_tests/main_test.go +++ /dev/null @@ -1,455 +0,0 @@ -package integration_tests - -// File reading, writing, modification, truncate - -import ( - "bytes" - "crypto/md5" - "encoding/hex" - "flag" - "fmt" - "io/ioutil" - "os" - "runtime" - "sync" - "syscall" - "testing" - - "github.com/rfjakob/gocryptfs/tests/test_helpers" -) - -var plaintextNames bool - -// This is the entry point for the tests -func TestMain(m *testing.M) { - var defaultonly bool - flag.BoolVar(&defaultonly, "defaultonly", false, "Only test default configuration (openssl=true, plaintextnames=false)") - flag.Parse() - - if testing.Verbose() { - fmt.Println("***** Testing with OpenSSL") - } - test_helpers.ResetTmpDir(false) // <- this also create gocryptfs.diriv - test_helpers.MountOrExit(test_helpers.DefaultCipherDir, test_helpers.DefaultPlainDir, "--zerokey") - r := m.Run() - test_helpers.Unmount(test_helpers.DefaultPlainDir) - - if r != 0 { - os.Exit(r) - } - - if defaultonly { - os.Exit(r) - } - - if testing.Verbose() { - fmt.Println("***** Testing with native Go crypto") - } - test_helpers.ResetTmpDir(false) - test_helpers.MountOrExit(test_helpers.DefaultCipherDir, test_helpers.DefaultPlainDir, "--zerokey", "--openssl=false") - r = m.Run() - test_helpers.Unmount(test_helpers.DefaultPlainDir) - - if r != 0 { - os.Exit(r) - } - - if testing.Verbose() { - fmt.Println("***** Testing \"--plaintextnames\"") - } - test_helpers.ResetTmpDir(true) // do not create gocryptfs.diriv - test_helpers.MountOrExit(test_helpers.DefaultCipherDir, test_helpers.DefaultPlainDir, "--zerokey", "--plaintextnames") - plaintextNames = true - r = m.Run() - test_helpers.Unmount(test_helpers.DefaultPlainDir) - - if r != 0 { - os.Exit(r) - } - - 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(test_helpers.DefaultPlainDir + fn) - if err != nil { - t.Fatal(err) - } - - d := make([]byte, n) - written, err := file.Write(d) - if err != nil || written != len(d) { - t.Errorf("err=\"%s\", written=%d", err, written) - } - err = file.Close() - if err != nil { - t.Error(err) - } - - test_helpers.VerifySize(t, test_helpers.DefaultPlainDir+fn, n) - - bin := md5.Sum(d) - hashWant := hex.EncodeToString(bin[:]) - - hashActual := test_helpers.Md5fn(test_helpers.DefaultPlainDir + fn) - - if hashActual != hashWant { - t.Errorf("Wrong content, hashWant=%s hashActual=%s", hashWant, hashActual) - } - - return hashActual -} - -func TestWrite10(t *testing.T) { - testWriteN(t, "10", 10) -} - -func TestWrite100(t *testing.T) { - testWriteN(t, "100", 100) -} - -func TestWrite1M(t *testing.T) { - testWriteN(t, "1M", 1024*1024) -} - -func TestWrite1Mx100(t *testing.T) { - hashWant := testWriteN(t, "1Mx100", 1024*1024) - // Read and check 100 times to catch race conditions - var i int - for i = 0; i < 100; i++ { - hashActual := test_helpers.Md5fn(test_helpers.DefaultPlainDir + "1M") - if hashActual != hashWant { - fmt.Printf("Read corruption in loop # %d\n", i) - t.FailNow() - } else { - //fmt.Print(".") - } - } -} - -func TestTruncate(t *testing.T) { - fn := test_helpers.DefaultPlainDir + "truncate" - file, err := os.Create(fn) - if err != nil { - t.FailNow() - } - // Grow to two blocks - file.Truncate(7000) - test_helpers.VerifySize(t, fn, 7000) - if test_helpers.Md5fn(fn) != "95d4ec7038e3e4fdbd5f15c34c3f0b34" { - t.Errorf("wrong content") - } - // Shrink - needs RMW - file.Truncate(6999) - test_helpers.VerifySize(t, fn, 6999) - if test_helpers.Md5fn(fn) != "35fd15873ec6c35380064a41b9b9683b" { - t.Errorf("wrong content") - } - // Shrink to one partial block - file.Truncate(465) - test_helpers.VerifySize(t, fn, 465) - if test_helpers.Md5fn(fn) != "a1534d6e98a6b21386456a8f66c55260" { - t.Errorf("wrong content") - } - // Grow to exactly one block - file.Truncate(4096) - test_helpers.VerifySize(t, fn, 4096) - if test_helpers.Md5fn(fn) != "620f0b67a91f7f74151bc5be745b7110" { - t.Errorf("wrong content") - } -} - -func TestAppend(t *testing.T) { - fn := test_helpers.DefaultPlainDir + "append" - file, err := os.Create(fn) - if err != nil { - t.FailNow() - } - data := []byte("testdata123456789") // length 17 - var buf bytes.Buffer - var hashWant string - for i := 0; i <= 500; i++ { - file.Write(data) - buf.Write(data) - bin := md5.Sum(buf.Bytes()) - hashWant = hex.EncodeToString(bin[:]) - hashActual := test_helpers.Md5fn(fn) - if hashWant != hashActual { - t.FailNow() - } - } - - // Overwrite with the same data - // Hash must stay the same - file.Seek(0, 0) - for i := 0; i <= 500; i++ { - file.Write(data) - hashActual := test_helpers.Md5fn(fn) - if hashWant != hashActual { - t.FailNow() - } - } -} - -// Create a file with holes by writing to offset 0 (block #0) and -// offset 4096 (block #1). -func TestFileHoles(t *testing.T) { - fn := test_helpers.DefaultPlainDir + "fileholes" - file, err := os.Create(fn) - if err != nil { - t.Errorf("file create failed") - } - foo := []byte("foo") - file.Write(foo) - file.WriteAt(foo, 4096) - _, err = ioutil.ReadFile(fn) - if err != nil { - t.Error(err) - } -} - -// sContains - does the slice of strings "haystack" contain "needle"? -func sContains(haystack []string, needle string) bool { - for _, element := range haystack { - if element == needle { - return true - } - } - return false -} - -func TestRmwRace(t *testing.T) { - - runtime.GOMAXPROCS(10) - - fn := test_helpers.DefaultPlainDir + "rmwrace" - f1, err := os.Create(fn) - if err != nil { - t.Fatalf("file create failed") - } - f2, err := os.Create(fn) - if err != nil { - t.Fatalf("file create failed") - } - - oldBlock := bytes.Repeat([]byte("o"), 4096) - - newBlock := bytes.Repeat([]byte("n"), 4096) - - shortBlock := bytes.Repeat([]byte("s"), 16) - - mergedBlock := make([]byte, 4096) - copy(mergedBlock, newBlock) - copy(mergedBlock[4080:], shortBlock) - - goodMd5 := make(map[string]int) - - for i := 0; i < 1000; i++ { - // Reset to [ooooooooo] - _, err = f1.WriteAt(oldBlock, 0) - if err != nil { - t.Fatalf("Write failed") - } - - var wg sync.WaitGroup - wg.Add(2) - - // Write to the end of the file, [....ssss] - go func() { - f1.WriteAt(shortBlock, 4080) - wg.Done() - }() - - // Overwrite to [nnnnnnn] - go func() { - f2.WriteAt(newBlock, 0) - wg.Done() - }() - - wg.Wait() - - // The file should be either: - // [nnnnnnnnnn] (md5: 6c1660fdabccd448d1359f27b3db3c99) or - // [nnnnnnssss] (md5: da885006a6a284530a427c73ce1e5c32) - // but it must not be - // [oooooossss] - - buf, _ := ioutil.ReadFile(fn) - m := test_helpers.Md5hex(buf) - goodMd5[m] = goodMd5[m] + 1 - - /* - if m == "6c1660fdabccd448d1359f27b3db3c99" { - fmt.Println(hex.Dump(buf)) - t.FailNow() - } - */ - } - if testing.Verbose() { - fmt.Println(goodMd5) - } -} - -// With "--plaintextnames", the name "/gocryptfs.conf" is reserved. -// Otherwise there should be no restrictions. -func TestFiltered(t *testing.T) { - filteredFile := test_helpers.DefaultPlainDir + "gocryptfs.conf" - file, err := os.Create(filteredFile) - if plaintextNames == true && err == nil { - t.Errorf("should have failed but didn't") - } else if plaintextNames == false && err != nil { - t.Error(err) - } - file.Close() - - err = os.Remove(filteredFile) - if plaintextNames == true && err == nil { - t.Errorf("should have failed but didn't") - } else if plaintextNames == false && err != nil { - t.Error(err) - } -} - -func TestFilenameEncryption(t *testing.T) { - file, err := os.Create(test_helpers.DefaultPlainDir + "TestFilenameEncryption.txt") - file.Close() - if err != nil { - t.Fatal(err) - } - - _, err = os.Stat(test_helpers.DefaultCipherDir + "TestFilenameEncryption.txt") - if plaintextNames == true && err != nil { - t.Errorf("plaintextnames not working: %v", err) - } else if plaintextNames == false && err == nil { - t.Errorf("file name encryption not working") - } -} - -// Test Mkdir and Rmdir -func testMkdirRmdir(t *testing.T) { - test_helpers.TestMkdirRmdir(t, test_helpers.DefaultPlainDir) -} - -// Test Rename -func testRename(t *testing.T) { - test_helpers.TestRename(t, test_helpers.DefaultPlainDir) -} - -// Overwrite an empty directory with another directory -func TestDirOverwrite(t *testing.T) { - dir1 := test_helpers.DefaultPlainDir + "DirOverwrite1" - dir2 := test_helpers.DefaultPlainDir + "DirOverwrite2" - err := os.Mkdir(dir1, 0777) - if err != nil { - t.Fatal(err) - } - err = os.Mkdir(dir2, 0777) - if err != nil { - t.Fatal(err) - } - err = os.Rename(dir1, dir2) - if err != nil { - t.Fatal(err) - } -} - -func TestLongNames(t *testing.T) { - fi, err := ioutil.ReadDir(test_helpers.DefaultCipherDir) - if err != nil { - t.Fatal(err) - } - cnt1 := len(fi) - wd := test_helpers.DefaultPlainDir - // Create file with long name - n255x := string(bytes.Repeat([]byte("x"), 255)) - f, err := os.Create(wd + n255x) - if err != nil { - t.Fatalf("Could not create n255x: %v", err) - } - f.Close() - if !test_helpers.VerifyExistence(wd + n255x) { - t.Errorf("n255x is not in directory listing") - } - // Rename long to long - n255y := string(bytes.Repeat([]byte("y"), 255)) - err = os.Rename(wd+n255x, wd+n255y) - if err != nil { - t.Fatalf("Could not rename n255x to n255y: %v", err) - } - if !test_helpers.VerifyExistence(wd + n255y) { - t.Errorf("n255y is not in directory listing") - } - // Rename long to short - err = os.Rename(wd+n255y, wd+"short") - if err != nil { - t.Fatalf("Could not rename n255y to short: %v", err) - } - if !test_helpers.VerifyExistence(wd + "short") { - t.Errorf("short is not in directory listing") - } - // Rename short to long - err = os.Rename(wd+"short", wd+n255x) - if err != nil { - t.Fatalf("Could not rename short to n255x: %v", err) - } - if !test_helpers.VerifyExistence(wd + n255x) { - t.Errorf("255x is not in directory listing II") - } - // Unlink - err = syscall.Unlink(wd + n255x) - if err != nil { - t.Fatalf("Could not unlink n255x: %v", err) - } - if test_helpers.VerifyExistence(wd + n255x) { - t.Errorf("n255x still there after unlink") - } - // Long symlink - n255s := string(bytes.Repeat([]byte("s"), 255)) - err = os.Symlink("/etc/motd", wd+n255s) - if err != nil { - t.Fatal(err) - } - if !test_helpers.VerifyExistence(wd + n255s) { - t.Errorf("n255s is not in directory listing") - } - err = syscall.Unlink(wd + n255s) - if err != nil { - t.Error(err) - } - // Long dir - n255d := string(bytes.Repeat([]byte("d"), 255)) - err = os.Mkdir(wd+n255d, 0777) - if err != nil { - t.Fatal(err) - } - err = syscall.Rmdir(wd + n255d) - if err != nil { - t.Error(err) - } - // Check for orphaned files - fi, err = ioutil.ReadDir(test_helpers.DefaultCipherDir) - if err != nil { - t.Fatal(err) - } - cnt2 := len(fi) - if cnt1 != cnt2 { - t.Errorf("Leftover files, cnt1=%d cnt2=%d", cnt1, cnt2) - } -} - -func TestLchown(t *testing.T) { - name := test_helpers.DefaultPlainDir + "symlink" - err := os.Symlink("/target/does/not/exist", name) - if err != nil { - t.Fatal(err) - } - err = os.Chown(name, os.Getuid(), os.Getgid()) - if err == nil { - t.Error("Chown on dangling symlink should fail") - } - err = os.Lchown(name, os.Getuid(), os.Getgid()) - if err != nil { - t.Error(err) - } -} diff --git a/tests/integration_tests/performance_test.go b/tests/integration_tests/performance_test.go deleted file mode 100644 index 67f0b28..0000000 --- a/tests/integration_tests/performance_test.go +++ /dev/null @@ -1,131 +0,0 @@ -package integration_tests - -// Benchmarks - -import ( - "fmt" - "io" - "io/ioutil" - "os" - "testing" - - "github.com/rfjakob/gocryptfs/tests/test_helpers" -) - -func BenchmarkStreamWrite(t *testing.B) { - buf := make([]byte, 1024*1024) - t.SetBytes(int64(len(buf))) - - file, err := os.Create(test_helpers.DefaultPlainDir + "BenchmarkWrite") - if err != nil { - t.FailNow() - } - - t.ResetTimer() - var i int - for i = 0; i < t.N; i++ { - written, err := file.Write(buf) - if err != nil { - fmt.Printf("err=\"%s\", written=%d\n", err.Error(), written) - t.FailNow() - } - } - file.Close() -} - -func BenchmarkStreamRead(t *testing.B) { - buf := make([]byte, 1024*1024) - t.SetBytes(int64(len(buf))) - - fn := test_helpers.DefaultPlainDir + "BenchmarkWrite" - fi, err := os.Stat(fn) - if err != nil { - t.Fatal(err) - } - mb := int(fi.Size() / 1024 / 1024) - - if t.N > mb { - // Grow file so we can satisfy the test - //fmt.Printf("Growing file to %d MB... ", t.N) - var f2 *os.File - f2, err = os.OpenFile(fn, os.O_WRONLY|os.O_APPEND, 0666) - if err != nil { - fmt.Println(err) - t.FailNow() - } - for h := 0; h < t.N-mb; h++ { - _, err = f2.Write(buf) - if err != nil { - fmt.Println(err) - t.FailNow() - } - } - f2.Close() - } - - file, err := os.Open(fn) - if err != nil { - t.FailNow() - } - t.ResetTimer() - var i int - for i = 0; i < t.N; i++ { - _, err := file.Read(buf) - if err == io.EOF { - fmt.Println("Test file too small") - t.SkipNow() - } else if err != nil { - fmt.Println(err) - t.FailNow() - } - } - file.Close() -} - -// 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", test_helpers.DefaultPlainDir, count, size) - err := os.Mkdir(dir, 0777) - if err != nil { - t.Fatal(err) - } - buf := make([]byte, size) - t.SetBytes(int64(len(buf))) - t.ResetTimer() - var i int - for i = 0; i < count; i++ { - file := fmt.Sprintf("%s/%d", dir, i) - if size > 0 { - err = ioutil.WriteFile(file, buf, 0666) - } else { - var fh *os.File - fh, err = os.Create(file) - fh.Close() - } - if err != nil { - t.Fatal(err) - } - } - t.StopTimer() - os.RemoveAll(dir) -} - -func BenchmarkCreate0B(t *testing.B) { - createFiles(t, t.N, 0) -} - -func BenchmarkCreate1B(t *testing.B) { - createFiles(t, t.N, 1) -} - -func BenchmarkCreate100B(t *testing.B) { - createFiles(t, t.N, 100) -} - -func BenchmarkCreate4kB(t *testing.B) { - createFiles(t, t.N, 4*1024) -} - -func BenchmarkCreate10kB(t *testing.B) { - createFiles(t, t.N, 10*1024) -} diff --git a/tests/matrix/matrix_test.go b/tests/matrix/matrix_test.go new file mode 100644 index 0000000..eb49d59 --- /dev/null +++ b/tests/matrix/matrix_test.go @@ -0,0 +1,436 @@ +package matrix + +// File reading, writing, modification, truncate +// +// Runs everything four times, for all combinations of +// "-plaintextnames" and "-openssl". +// +// Test Matrix: +// openssl=true openssl=false +// plaintextnames=false X X +// plaintextnames=true X X + +import ( + "bytes" + "crypto/md5" + "encoding/hex" + "flag" + "fmt" + "io/ioutil" + "os" + "runtime" + "sync" + "syscall" + "testing" + + "github.com/rfjakob/gocryptfs/tests/test_helpers" +) + +// Several tests need to be aware if plaintextnames is active or not, so make this +// a global variable +var plaintextnames bool + +// This is the entry point for the tests +func TestMain(m *testing.M) { + // Make "testing.Verbose()" return the correct value + flag.Parse() + for _, openssl := range []bool{true, false} { + for _, plaintextnames = range []bool{true, false} { + if testing.Verbose() { + fmt.Printf("Testing openssl=%v plaintextnames=%v\n", openssl, plaintextnames) + + } + test_helpers.ResetTmpDir(plaintextnames) + opts := []string{"--zerokey"} + opts = append(opts, fmt.Sprintf("-openssl=%v", openssl)) + opts = append(opts, fmt.Sprintf("-plaintextnames=%v", plaintextnames)) + test_helpers.MountOrExit(test_helpers.DefaultCipherDir, test_helpers.DefaultPlainDir, opts...) + r := m.Run() + test_helpers.Unmount(test_helpers.DefaultPlainDir) + if r != 0 { + os.Exit(r) + } + } + } + os.Exit(0) +} + +// 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(test_helpers.DefaultPlainDir + "/" + fn) + if err != nil { + t.Fatal(err) + } + + d := make([]byte, n) + written, err := file.Write(d) + if err != nil || written != len(d) { + t.Errorf("err=\"%s\", written=%d", err, written) + } + err = file.Close() + if err != nil { + t.Error(err) + } + + test_helpers.VerifySize(t, test_helpers.DefaultPlainDir+"/"+fn, n) + + bin := md5.Sum(d) + hashWant := hex.EncodeToString(bin[:]) + + hashActual := test_helpers.Md5fn(test_helpers.DefaultPlainDir + "/" + fn) + + if hashActual != hashWant { + t.Errorf("Wrong content, hashWant=%s hashActual=%s", hashWant, hashActual) + } + + return hashActual +} + +func TestWrite10(t *testing.T) { + testWriteN(t, "10", 10) +} + +func TestWrite100(t *testing.T) { + testWriteN(t, "100", 100) +} + +func TestWrite1M(t *testing.T) { + testWriteN(t, "1M", 1024*1024) +} + +func TestWrite100x100(t *testing.T) { + hashWant := testWriteN(t, "100x100", 100) + // Read and check 100 times to catch race conditions + var i int + for i = 0; i < 100; i++ { + hashActual := test_helpers.Md5fn(test_helpers.DefaultPlainDir + "/100") + if hashActual != hashWant { + fmt.Printf("Read corruption in loop #%d\n", i) + t.FailNow() + } else { + //fmt.Print(".") + } + } +} + +func TestTruncate(t *testing.T) { + fn := test_helpers.DefaultPlainDir + "/truncate" + file, err := os.Create(fn) + if err != nil { + t.FailNow() + } + // Grow to two blocks + file.Truncate(7000) + test_helpers.VerifySize(t, fn, 7000) + if test_helpers.Md5fn(fn) != "95d4ec7038e3e4fdbd5f15c34c3f0b34" { + t.Errorf("wrong content") + } + // Shrink - needs RMW + file.Truncate(6999) + test_helpers.VerifySize(t, fn, 6999) + if test_helpers.Md5fn(fn) != "35fd15873ec6c35380064a41b9b9683b" { + t.Errorf("wrong content") + } + // Shrink to one partial block + file.Truncate(465) + test_helpers.VerifySize(t, fn, 465) + if test_helpers.Md5fn(fn) != "a1534d6e98a6b21386456a8f66c55260" { + t.Errorf("wrong content") + } + // Grow to exactly one block + file.Truncate(4096) + test_helpers.VerifySize(t, fn, 4096) + if test_helpers.Md5fn(fn) != "620f0b67a91f7f74151bc5be745b7110" { + t.Errorf("wrong content") + } +} + +func TestAppend(t *testing.T) { + fn := test_helpers.DefaultPlainDir + "/append" + file, err := os.Create(fn) + if err != nil { + t.FailNow() + } + data := []byte("testdata123456789") // length 17 + var buf bytes.Buffer + var hashWant string + for i := 0; i <= 500; i++ { + file.Write(data) + buf.Write(data) + bin := md5.Sum(buf.Bytes()) + hashWant = hex.EncodeToString(bin[:]) + hashActual := test_helpers.Md5fn(fn) + if hashWant != hashActual { + t.FailNow() + } + } + + // Overwrite with the same data + // Hash must stay the same + file.Seek(0, 0) + for i := 0; i <= 500; i++ { + file.Write(data) + hashActual := test_helpers.Md5fn(fn) + if hashWant != hashActual { + t.FailNow() + } + } +} + +// Create a file with holes by writing to offset 0 (block #0) and +// offset 4096 (block #1). +func TestFileHoles(t *testing.T) { + fn := test_helpers.DefaultPlainDir + "/fileholes" + file, err := os.Create(fn) + if err != nil { + t.Errorf("file create failed") + } + foo := []byte("foo") + file.Write(foo) + file.WriteAt(foo, 4096) + _, err = ioutil.ReadFile(fn) + if err != nil { + t.Error(err) + } +} + +// sContains - does the slice of strings "haystack" contain "needle"? +func sContains(haystack []string, needle string) bool { + for _, element := range haystack { + if element == needle { + return true + } + } + return false +} + +func TestRmwRace(t *testing.T) { + + runtime.GOMAXPROCS(10) + + fn := test_helpers.DefaultPlainDir + "/rmwrace" + f1, err := os.Create(fn) + if err != nil { + t.Fatalf("file create failed") + } + f2, err := os.Create(fn) + if err != nil { + t.Fatalf("file create failed") + } + + oldBlock := bytes.Repeat([]byte("o"), 4096) + + newBlock := bytes.Repeat([]byte("n"), 4096) + + shortBlock := bytes.Repeat([]byte("s"), 16) + + mergedBlock := make([]byte, 4096) + copy(mergedBlock, newBlock) + copy(mergedBlock[4080:], shortBlock) + + goodMd5 := make(map[string]int) + + for i := 0; i < 1000; i++ { + // Reset to [ooooooooo] + _, err = f1.WriteAt(oldBlock, 0) + if err != nil { + t.Fatalf("Write failed") + } + + var wg sync.WaitGroup + wg.Add(2) + + // Write to the end of the file, [....ssss] + go func() { + f1.WriteAt(shortBlock, 4080) + wg.Done() + }() + + // Overwrite to [nnnnnnn] + go func() { + f2.WriteAt(newBlock, 0) + wg.Done() + }() + + wg.Wait() + + // The file should be either: + // [nnnnnnnnnn] (md5: 6c1660fdabccd448d1359f27b3db3c99) or + // [nnnnnnssss] (md5: da885006a6a284530a427c73ce1e5c32) + // but it must not be + // [oooooossss] + + buf, _ := ioutil.ReadFile(fn) + m := test_helpers.Md5hex(buf) + goodMd5[m] = goodMd5[m] + 1 + + /* + if m == "6c1660fdabccd448d1359f27b3db3c99" { + fmt.Println(hex.Dump(buf)) + t.FailNow() + } + */ + } +} + +// With "--plaintextnames", the name "/gocryptfs.conf" is reserved. +// Otherwise there should be no restrictions. +func TestFiltered(t *testing.T) { + filteredFile := test_helpers.DefaultPlainDir + "/gocryptfs.conf" + file, err := os.Create(filteredFile) + if plaintextnames == true && err == nil { + t.Errorf("should have failed but didn't") + } else if plaintextnames == false && err != nil { + t.Error(err) + } + file.Close() + + err = os.Remove(filteredFile) + if plaintextnames == true && err == nil { + t.Errorf("should have failed but didn't") + } else if plaintextnames == false && err != nil { + t.Error(err) + } +} + +func TestFilenameEncryption(t *testing.T) { + file, err := os.Create(test_helpers.DefaultPlainDir + "/TestFilenameEncryption.txt") + file.Close() + if err != nil { + t.Fatal(err) + } + _, err = os.Stat(test_helpers.DefaultCipherDir + "/TestFilenameEncryption.txt") + if plaintextnames == true && err != nil { + t.Errorf("plaintextnames not working: %v", err) + } else if plaintextnames == false && err == nil { + t.Errorf("file name encryption not working") + } +} + +// Test Mkdir and Rmdir +func testMkdirRmdir(t *testing.T) { + test_helpers.TestMkdirRmdir(t, test_helpers.DefaultPlainDir) +} + +// Test Rename +func testRename(t *testing.T) { + test_helpers.TestRename(t, test_helpers.DefaultPlainDir) +} + +// Overwrite an empty directory with another directory +func TestDirOverwrite(t *testing.T) { + dir1 := test_helpers.DefaultPlainDir + "/DirOverwrite1" + dir2 := test_helpers.DefaultPlainDir + "/DirOverwrite2" + err := os.Mkdir(dir1, 0777) + if err != nil { + t.Fatal(err) + } + err = os.Mkdir(dir2, 0777) + if err != nil { + t.Fatal(err) + } + err = os.Rename(dir1, dir2) + if err != nil { + t.Fatal(err) + } +} + +func TestLongNames(t *testing.T) { + fi, err := ioutil.ReadDir(test_helpers.DefaultCipherDir) + if err != nil { + t.Fatal(err) + } + cnt1 := len(fi) + wd := test_helpers.DefaultPlainDir + "/" + // Create file with long name + n255x := string(bytes.Repeat([]byte("x"), 255)) + f, err := os.Create(wd + n255x) + if err != nil { + t.Fatalf("Could not create n255x: %v", err) + } + f.Close() + if !test_helpers.VerifyExistence(wd + n255x) { + t.Errorf("n255x is not in directory listing") + } + // Rename long to long + n255y := string(bytes.Repeat([]byte("y"), 255)) + err = os.Rename(wd+n255x, wd+n255y) + if err != nil { + t.Fatalf("Could not rename n255x to n255y: %v", err) + } + if !test_helpers.VerifyExistence(wd + n255y) { + t.Errorf("n255y is not in directory listing") + } + // Rename long to short + err = os.Rename(wd+n255y, wd+"short") + if err != nil { + t.Fatalf("Could not rename n255y to short: %v", err) + } + if !test_helpers.VerifyExistence(wd + "short") { + t.Errorf("short is not in directory listing") + } + // Rename short to long + err = os.Rename(wd+"short", wd+n255x) + if err != nil { + t.Fatalf("Could not rename short to n255x: %v", err) + } + if !test_helpers.VerifyExistence(wd + n255x) { + t.Errorf("255x is not in directory listing II") + } + // Unlink + err = syscall.Unlink(wd + n255x) + if err != nil { + t.Fatalf("Could not unlink n255x: %v", err) + } + if test_helpers.VerifyExistence(wd + n255x) { + t.Errorf("n255x still there after unlink") + } + // Long symlink + n255s := string(bytes.Repeat([]byte("s"), 255)) + err = os.Symlink("/etc/motd", wd+n255s) + if err != nil { + t.Fatal(err) + } + if !test_helpers.VerifyExistence(wd + n255s) { + t.Errorf("n255s is not in directory listing") + } + err = syscall.Unlink(wd + n255s) + if err != nil { + t.Error(err) + } + // Long dir + n255d := string(bytes.Repeat([]byte("d"), 255)) + err = os.Mkdir(wd+n255d, 0777) + if err != nil { + t.Fatal(err) + } + err = syscall.Rmdir(wd + n255d) + if err != nil { + t.Error(err) + } + // Check for orphaned files + fi, err = ioutil.ReadDir(test_helpers.DefaultCipherDir) + if err != nil { + t.Fatal(err) + } + cnt2 := len(fi) + if cnt1 != cnt2 { + t.Errorf("Leftover files, cnt1=%d cnt2=%d", cnt1, cnt2) + } +} + +func TestLchown(t *testing.T) { + name := test_helpers.DefaultPlainDir + "/symlink" + err := os.Symlink("/target/does/not/exist", name) + if err != nil { + t.Fatal(err) + } + err = os.Chown(name, os.Getuid(), os.Getgid()) + if err == nil { + t.Error("Chown on dangling symlink should fail") + } + err = os.Lchown(name, os.Getuid(), os.Getgid()) + if err != nil { + t.Error(err) + } +} diff --git a/tests/normal/cli_test.go b/tests/normal/cli_test.go new file mode 100644 index 0000000..4c634f2 --- /dev/null +++ b/tests/normal/cli_test.go @@ -0,0 +1,105 @@ +package normal + +// Test CLI operations like "-init", "-password" etc + +import ( + "os" + "os/exec" + "path/filepath" + "testing" + + "github.com/rfjakob/gocryptfs/internal/configfile" + + "github.com/rfjakob/gocryptfs/tests/test_helpers" +) + +func TestMain(m *testing.M) { + test_helpers.ResetTmpDir(false) + test_helpers.MountOrExit(test_helpers.DefaultCipherDir, test_helpers.DefaultPlainDir, "--zerokey") + r := m.Run() + test_helpers.Unmount(test_helpers.DefaultPlainDir) + os.Exit(r) +} + +// Test -init flag +func TestInit(t *testing.T) { + dir := test_helpers.InitFS(t) + _, err := os.Stat(filepath.Join(dir, configfile.ConfDefaultName)) + if err != nil { + t.Fatal(err) + } +} + +// Test -passwd flag +func TestPasswd(t *testing.T) { + // Create FS + dir := test_helpers.InitFS(t) + // Change password using "-extpass" + cmd := exec.Command(test_helpers.GocryptfsBinary, "-q", "-passwd", "-extpass", "echo test", dir) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + err := cmd.Run() + if err != nil { + t.Error(err) + } + // Change password using stdin + cmd = exec.Command(test_helpers.GocryptfsBinary, "-q", "-passwd", dir) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + p, err := cmd.StdinPipe() + if err != nil { + t.Fatal(err) + } + err = cmd.Start() + if err != nil { + t.Error(err) + } + // Old password + p.Write([]byte("test\n")) + // New password + p.Write([]byte("newpasswd\n")) + p.Close() + err = cmd.Wait() + if err != nil { + t.Error(err) + } +} + +// Test -init & -config flag +func TestInitConfig(t *testing.T) { + config := test_helpers.TmpDir + "/TestInitConfig.conf" + dir := test_helpers.InitFS(t, "-config="+config) + + _, err := os.Stat(config) + if err != nil { + t.Fatal(err) + } + + // Test -passwd & -config + cmd2 := exec.Command(test_helpers.GocryptfsBinary, "-q", "-passwd", "-extpass", "echo test", + "-config", config, dir) + cmd2.Stdout = os.Stdout + cmd2.Stderr = os.Stderr + err = cmd2.Run() + if err != nil { + t.Error(err) + } +} + +// Test -ro +func TestRo(t *testing.T) { + dir := test_helpers.InitFS(t) + mnt := dir + ".mnt" + test_helpers.MountOrFatal(t, dir, mnt, "-ro", "-extpass=echo test") + defer test_helpers.Unmount(mnt) + + file := mnt + "/file" + err := os.Mkdir(file, 0777) + if err == nil { + t.Errorf("Mkdir should have failed") + } + _, err = os.Create(file) + if err == nil { + t.Errorf("Create should have failed") + } +} diff --git a/tests/normal/performance_test.go b/tests/normal/performance_test.go new file mode 100644 index 0000000..78ecf41 --- /dev/null +++ b/tests/normal/performance_test.go @@ -0,0 +1,131 @@ +package normal + +// Benchmarks + +import ( + "fmt" + "io" + "io/ioutil" + "os" + "testing" + + "github.com/rfjakob/gocryptfs/tests/test_helpers" +) + +func BenchmarkStreamWrite(t *testing.B) { + buf := make([]byte, 1024*1024) + t.SetBytes(int64(len(buf))) + + file, err := os.Create(test_helpers.DefaultPlainDir + "BenchmarkWrite") + if err != nil { + t.FailNow() + } + + t.ResetTimer() + var i int + for i = 0; i < t.N; i++ { + written, err := file.Write(buf) + if err != nil { + fmt.Printf("err=\"%s\", written=%d\n", err.Error(), written) + t.FailNow() + } + } + file.Close() +} + +func BenchmarkStreamRead(t *testing.B) { + buf := make([]byte, 1024*1024) + t.SetBytes(int64(len(buf))) + + fn := test_helpers.DefaultPlainDir + "BenchmarkWrite" + fi, err := os.Stat(fn) + if err != nil { + t.Fatal(err) + } + mb := int(fi.Size() / 1024 / 1024) + + if t.N > mb { + // Grow file so we can satisfy the test + //fmt.Printf("Growing file to %d MB... ", t.N) + var f2 *os.File + f2, err = os.OpenFile(fn, os.O_WRONLY|os.O_APPEND, 0666) + if err != nil { + fmt.Println(err) + t.FailNow() + } + for h := 0; h < t.N-mb; h++ { + _, err = f2.Write(buf) + if err != nil { + fmt.Println(err) + t.FailNow() + } + } + f2.Close() + } + + file, err := os.Open(fn) + if err != nil { + t.FailNow() + } + t.ResetTimer() + var i int + for i = 0; i < t.N; i++ { + _, err := file.Read(buf) + if err == io.EOF { + fmt.Println("Test file too small") + t.SkipNow() + } else if err != nil { + fmt.Println(err) + t.FailNow() + } + } + file.Close() +} + +// 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", test_helpers.DefaultPlainDir, count, size) + err := os.Mkdir(dir, 0777) + if err != nil { + t.Fatal(err) + } + buf := make([]byte, size) + t.SetBytes(int64(len(buf))) + t.ResetTimer() + var i int + for i = 0; i < count; i++ { + file := fmt.Sprintf("%s/%d", dir, i) + if size > 0 { + err = ioutil.WriteFile(file, buf, 0666) + } else { + var fh *os.File + fh, err = os.Create(file) + fh.Close() + } + if err != nil { + t.Fatal(err) + } + } + t.StopTimer() + os.RemoveAll(dir) +} + +func BenchmarkCreate0B(t *testing.B) { + createFiles(t, t.N, 0) +} + +func BenchmarkCreate1B(t *testing.B) { + createFiles(t, t.N, 1) +} + +func BenchmarkCreate100B(t *testing.B) { + createFiles(t, t.N, 100) +} + +func BenchmarkCreate4kB(t *testing.B) { + createFiles(t, t.N, 4*1024) +} + +func BenchmarkCreate10kB(t *testing.B) { + createFiles(t, t.N, 10*1024) +} diff --git a/tests/plaintextnames/plaintextnames_test.go b/tests/plaintextnames/plaintextnames_test.go index 7e7db7c..6c6d272 100644 --- a/tests/plaintextnames/plaintextnames_test.go +++ b/tests/plaintextnames/plaintextnames_test.go @@ -20,7 +20,9 @@ func TestMain(m *testing.M) { cDir = test_helpers.InitFS(nil, "-plaintextnames") pDir = cDir + ".mnt" test_helpers.MountOrExit(cDir, pDir, "-extpass", "echo test") - os.Exit(m.Run()) + r := m.Run() + test_helpers.Unmount(pDir) + os.Exit(r) } // Only the PlaintextNames feature flag should be set diff --git a/tests/test_helpers/helpers.go b/tests/test_helpers/helpers.go index 88ef039..a6c2b7d 100644 --- a/tests/test_helpers/helpers.go +++ b/tests/test_helpers/helpers.go @@ -10,17 +10,31 @@ import ( "path/filepath" "syscall" "testing" + "time" "github.com/rfjakob/gocryptfs/internal/nametransform" ) -// Note: the code assumes that all have a trailing slash -const TmpDir = "/tmp/gocryptfs_main_test/" -const DefaultPlainDir = TmpDir + "plain/" -const DefaultCipherDir = TmpDir + "cipher/" - +const testParentDir = "/tmp/gocryptfs-test-parent" const GocryptfsBinary = "../../gocryptfs" +// "go test" runs package tests in parallel! We must create a unique TmpDir on +// startup or the tests will interfere horribly +var TmpDir string +var DefaultPlainDir string +var DefaultCipherDir string + +func init() { + os.MkdirAll(testParentDir, 0700) + var err error + TmpDir, err = ioutil.TempDir(testParentDir, "") + if err != nil { + panic(err) + } + DefaultPlainDir = TmpDir + "/default-plain" + DefaultCipherDir = TmpDir + "/default-cipher" +} + // ResetTmpDir - delete TmpDir, create new dir tree: // // TmpDir @@ -28,38 +42,31 @@ const GocryptfsBinary = "../../gocryptfs" // *-- DefaultCipherDir // *-- gocryptfs.diriv func ResetTmpDir(plaintextNames bool) { - - // Try to unmount everything + // Try to unmount and delete everything entries, err := ioutil.ReadDir(TmpDir) if err == nil { for _, e := range entries { - fu := exec.Command("fusermount", "-z", "-u", filepath.Join(TmpDir, e.Name())) - fu.Run() + d := filepath.Join(TmpDir, e.Name()) + err = os.Remove(d) + if err != nil { + fu := exec.Command("fusermount", "-z", "-u", d) + fu.Run() + os.RemoveAll(d) + } } } - - err = os.RemoveAll(TmpDir) + err = os.Mkdir(DefaultPlainDir, 0700) if err != nil { - fmt.Println("resetTmpDir: RemoveAll:" + err.Error()) - os.Exit(1) + panic(err) } - - err = os.MkdirAll(DefaultPlainDir, 0777) + err = os.Mkdir(DefaultCipherDir, 0700) if err != nil { - fmt.Println(err) - os.Exit(1) - } - - err = os.MkdirAll(DefaultCipherDir, 0777) - if err != nil { - fmt.Println(err) - os.Exit(1) + panic(err) } if !plaintextNames { err = nametransform.WriteDirIV(DefaultCipherDir) if err != nil { - fmt.Println(err) - os.Exit(1) + panic(err) } } } @@ -73,7 +80,6 @@ func InitFS(t *testing.T, extraArgs ...string) string { if err != nil { t.Fatal(err) } - args := []string{"-q", "-init", "-extpass", "echo test", "-scryptn=10"} args = append(args, extraArgs...) args = append(args, dir) @@ -95,7 +101,7 @@ func InitFS(t *testing.T, extraArgs ...string) string { func Mount(c string, p string, showOutput bool, extraArgs ...string) error { var args []string args = append(args, extraArgs...) - args = append(args, "-nosyslog", "-q", "-wpanic") + args = append(args, "-q", "-wpanic") //args = append(args, "-fusedebug") //args = append(args, "-d") args = append(args, c) @@ -142,7 +148,9 @@ func Unmount(p string) error { err := fu.Run() if err != nil { fmt.Println(err) + panic(err) } + time.Sleep(10 * time.Millisecond) return err } @@ -184,7 +192,7 @@ func VerifySize(t *testing.T, path string, want int) { // Create and delete a directory func TestMkdirRmdir(t *testing.T, plainDir string) { - dir := plainDir + "dir1" + dir := plainDir + "/dir1" err := os.Mkdir(dir, 0777) if err != nil { t.Fatal(err) @@ -231,8 +239,8 @@ func TestMkdirRmdir(t *testing.T, plainDir string) { // Create and rename a file func TestRename(t *testing.T, plainDir string) { - file1 := plainDir + "rename1" - file2 := plainDir + "rename2" + file1 := plainDir + "/rename1" + file2 := plainDir + "/rename2" err := ioutil.WriteFile(file1, []byte("content"), 0777) if err != nil { t.Fatal(err) @@ -247,14 +255,12 @@ func TestRename(t *testing.T, plainDir string) { // verifyExistence - check in 3 ways that "path" exists: // stat, open, readdir func VerifyExistence(path string) bool { - // Check that file can be stated _, err := os.Stat(path) if err != nil { //t.Log(err) return false } - // Check that file can be opened fd, err := os.Open(path) if err != nil { @@ -262,7 +268,6 @@ func VerifyExistence(path string) bool { return false } fd.Close() - // Check that file shows up in directory listing dir := filepath.Dir(path) name := filepath.Base(path) -- cgit v1.2.3