2016-06-06 23:57:42 +02:00
|
|
|
package example_filesystems
|
2015-11-15 15:05:15 +01:00
|
|
|
|
2016-06-27 23:43:43 +02:00
|
|
|
// Mount example filesystems, check that the example content (normal file, symlinks)
|
|
|
|
// is there and test mkdir and rmdir
|
|
|
|
//
|
|
|
|
// Runs all the tests twice, once with "-openssl=false" and once with
|
|
|
|
// "-openssl=true".
|
2015-11-15 15:05:15 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
2016-06-06 23:57:42 +02:00
|
|
|
|
|
|
|
"github.com/rfjakob/gocryptfs/tests/test_helpers"
|
2015-11-15 15:05:15 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
const statusTxtContent = "It works!\n"
|
|
|
|
|
2016-06-30 00:57:14 +02:00
|
|
|
var opensslOpt string
|
2016-06-27 23:43:43 +02:00
|
|
|
|
2016-06-06 23:57:42 +02:00
|
|
|
func TestMain(m *testing.M) {
|
2016-06-30 00:57:14 +02:00
|
|
|
for _, opensslOpt = range []string{"-openssl=false", "-openssl=true"} {
|
|
|
|
test_helpers.ResetTmpDir(true)
|
|
|
|
r := m.Run()
|
|
|
|
if r != 0 {
|
|
|
|
os.Exit(r)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
os.Exit(0)
|
2016-06-06 23:57:42 +02:00
|
|
|
}
|
|
|
|
|
2016-06-23 22:02:31 +02:00
|
|
|
// This filesystem is not supported anymore.
|
2015-12-10 20:02:18 +01:00
|
|
|
func TestExampleFSv04(t *testing.T) {
|
2016-06-06 23:57:42 +02:00
|
|
|
cDir := "v0.4"
|
2016-06-30 00:57:14 +02:00
|
|
|
pDir := test_helpers.TmpDir + "/" + cDir
|
2016-06-27 23:43:43 +02:00
|
|
|
err := test_helpers.Mount(cDir, pDir, false, "-extpass", "echo test", opensslOpt)
|
2016-06-23 21:29:00 +02:00
|
|
|
if err == nil {
|
2016-06-23 22:02:31 +02:00
|
|
|
t.Errorf("Mounting too old FS should fail")
|
2015-11-15 15:05:15 +01:00
|
|
|
}
|
|
|
|
}
|
2015-11-28 20:31:01 +01:00
|
|
|
|
2016-06-23 22:02:31 +02:00
|
|
|
// This filesystem is not supported anymore.
|
2015-12-10 20:02:18 +01:00
|
|
|
func TestExampleFSv05(t *testing.T) {
|
2016-06-06 23:57:42 +02:00
|
|
|
cDir := "v0.5"
|
2016-06-30 00:57:14 +02:00
|
|
|
pDir := test_helpers.TmpDir + "/" + cDir
|
2016-06-27 23:43:43 +02:00
|
|
|
err := test_helpers.Mount(cDir, pDir, false, "-extpass", "echo test", opensslOpt)
|
2016-06-19 20:01:29 +02:00
|
|
|
if err == nil {
|
2016-06-23 22:02:31 +02:00
|
|
|
t.Errorf("Mounting too old FS should fail")
|
2016-06-19 20:01:29 +02:00
|
|
|
}
|
2015-11-28 20:31:01 +01:00
|
|
|
}
|
2015-12-08 16:17:19 +01:00
|
|
|
|
2016-06-23 22:10:19 +02:00
|
|
|
// This filesystem is not supported anymore.
|
2015-12-10 20:02:18 +01:00
|
|
|
func TestExampleFSv06(t *testing.T) {
|
2016-06-06 23:57:42 +02:00
|
|
|
cDir := "v0.6"
|
2016-06-30 00:57:14 +02:00
|
|
|
pDir := test_helpers.TmpDir + "/" + cDir
|
2016-06-27 23:43:43 +02:00
|
|
|
err := test_helpers.Mount(cDir, pDir, false, "-extpass", "echo test", opensslOpt)
|
2016-06-19 20:01:29 +02:00
|
|
|
if err == nil {
|
2016-06-23 22:10:19 +02:00
|
|
|
t.Errorf("Mounting too old FS should fail")
|
2015-12-08 16:17:19 +01:00
|
|
|
}
|
|
|
|
}
|
2015-12-10 19:50:45 +01:00
|
|
|
|
2016-06-23 22:10:19 +02:00
|
|
|
// This filesystem is not supported anymore.
|
2015-12-10 20:02:18 +01:00
|
|
|
func TestExampleFSv06PlaintextNames(t *testing.T) {
|
2016-06-06 23:57:42 +02:00
|
|
|
cDir := "v0.6-plaintextnames"
|
2016-06-30 00:57:14 +02:00
|
|
|
pDir := test_helpers.TmpDir + "/" + cDir
|
2016-06-27 23:43:43 +02:00
|
|
|
err := test_helpers.Mount(cDir, pDir, false, "-extpass", "echo test", opensslOpt)
|
2016-06-19 20:01:29 +02:00
|
|
|
if err == nil {
|
2016-06-23 22:10:19 +02:00
|
|
|
t.Errorf("Mounting too old FS should fail")
|
2015-12-19 14:41:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test example_filesystems/v0.7
|
|
|
|
// with password mount and -masterkey mount
|
|
|
|
// v0.7 adds 128 bit GCM IVs
|
|
|
|
func TestExampleFSv07(t *testing.T) {
|
2016-06-06 23:57:42 +02:00
|
|
|
cDir := "v0.7"
|
2016-06-30 00:57:14 +02:00
|
|
|
pDir := test_helpers.TmpDir + "/" + cDir
|
2015-12-19 14:41:39 +01:00
|
|
|
err := os.Mkdir(pDir, 0777)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-06-27 23:43:43 +02:00
|
|
|
test_helpers.MountOrFatal(t, cDir, pDir, "-extpass", "echo test", opensslOpt)
|
2016-06-16 23:24:32 +02:00
|
|
|
checkExampleFS(t, pDir, true)
|
2016-06-06 23:57:42 +02:00
|
|
|
test_helpers.Unmount(pDir)
|
2016-06-27 23:43:43 +02:00
|
|
|
test_helpers.MountOrFatal(t, cDir, pDir, "-masterkey",
|
|
|
|
"ed7f6d83-40cce86c-0e7d79c2-a9438710-575221bf-30a0eb60-2821fa8f-7f3123bf",
|
|
|
|
opensslOpt)
|
2016-06-16 23:24:32 +02:00
|
|
|
checkExampleFS(t, pDir, true)
|
2016-06-06 23:57:42 +02:00
|
|
|
test_helpers.Unmount(pDir)
|
2015-12-10 19:50:45 +01:00
|
|
|
}
|
2016-06-04 14:57:01 +02:00
|
|
|
|
2016-06-23 20:53:14 +02:00
|
|
|
// gocryptfs v0.7 filesystem created with "-plaintextnames"
|
|
|
|
func TestExampleFSv07PlaintextNames(t *testing.T) {
|
|
|
|
cDir := "v0.7-plaintextnames"
|
2016-06-30 00:57:14 +02:00
|
|
|
pDir := test_helpers.TmpDir + "/" + cDir + ".mnt"
|
2016-06-23 20:53:14 +02:00
|
|
|
|
2016-06-27 23:43:43 +02:00
|
|
|
test_helpers.MountOrFatal(t, cDir, pDir, "-extpass", "echo test", opensslOpt)
|
2016-06-23 20:53:14 +02:00
|
|
|
checkExampleFS(t, pDir, true)
|
|
|
|
test_helpers.Unmount(pDir)
|
2016-06-30 00:57:14 +02:00
|
|
|
// The actual unmount takes some time, this causes weird problems. Just don't
|
|
|
|
// reuse the mountpoint.
|
|
|
|
pDir = pDir + ".2"
|
2016-06-23 20:53:14 +02:00
|
|
|
test_helpers.MountOrFatal(t, cDir, pDir, "-plaintextnames", "-masterkey",
|
2016-06-27 23:43:43 +02:00
|
|
|
"6d96397b-585631e1-c7cba69d-61e738b6-4d5ad2c2-e21f0fb3-52f60d3a-b08526f7",
|
|
|
|
opensslOpt)
|
2016-06-23 20:53:14 +02:00
|
|
|
checkExampleFS(t, pDir, true)
|
|
|
|
test_helpers.Unmount(pDir)
|
|
|
|
}
|
|
|
|
|
2016-06-04 14:57:01 +02:00
|
|
|
// Test example_filesystems/v0.9
|
|
|
|
// (gocryptfs v0.9 introduced long file name support)
|
|
|
|
func TestExampleFSv09(t *testing.T) {
|
2016-06-06 23:57:42 +02:00
|
|
|
cDir := "v0.9"
|
2016-06-30 00:57:14 +02:00
|
|
|
pDir := test_helpers.TmpDir + "/" + cDir
|
2016-06-04 14:57:01 +02:00
|
|
|
err := os.Mkdir(pDir, 0777)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-06-27 23:43:43 +02:00
|
|
|
test_helpers.MountOrFatal(t, cDir, pDir, "-extpass", "echo test", opensslOpt)
|
2016-06-04 14:57:01 +02:00
|
|
|
checkExampleFSLongnames(t, pDir)
|
2016-06-06 23:57:42 +02:00
|
|
|
test_helpers.Unmount(pDir)
|
2016-06-30 00:57:14 +02:00
|
|
|
pDir = pDir + ".2"
|
2016-06-27 23:43:43 +02:00
|
|
|
test_helpers.MountOrFatal(t, cDir, pDir, "-masterkey",
|
|
|
|
"1cafe3f4-bc316466-2214c47c-ecd89bf3-4e078fe4-f5faeea7-8b7cab02-884f5e1c",
|
|
|
|
opensslOpt)
|
2016-06-04 14:57:01 +02:00
|
|
|
checkExampleFSLongnames(t, pDir)
|
2016-06-06 23:57:42 +02:00
|
|
|
test_helpers.Unmount(pDir)
|
2016-06-04 14:57:01 +02:00
|
|
|
}
|