2016-06-06 23:57:42 +02:00
|
|
|
package example_filesystems
|
2015-11-15 15:05:15 +01:00
|
|
|
|
|
|
|
// Mount example filesystems and check that the file "status.txt" is there
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
2015-11-29 21:55:20 +01:00
|
|
|
"path/filepath"
|
2015-11-15 15:05:15 +01:00
|
|
|
"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-06 23:57:42 +02:00
|
|
|
func TestMain(m *testing.M) {
|
|
|
|
test_helpers.ResetTmpDir(true)
|
|
|
|
m.Run()
|
|
|
|
}
|
|
|
|
|
2016-06-04 14:57:01 +02:00
|
|
|
// checkExampleFS - verify that "dir" contains the expected test files
|
2015-12-10 20:02:18 +01:00
|
|
|
func checkExampleFS(t *testing.T, dir string) {
|
|
|
|
// Read regular file
|
2015-11-28 20:21:06 +01:00
|
|
|
statusFile := filepath.Join(dir, "status.txt")
|
|
|
|
contentBytes, err := ioutil.ReadFile(statusFile)
|
2015-11-15 15:05:15 +01:00
|
|
|
if err != nil {
|
2015-11-27 21:50:11 +01:00
|
|
|
t.Fatal(err)
|
2015-11-15 15:05:15 +01:00
|
|
|
}
|
|
|
|
content := string(contentBytes)
|
|
|
|
if content != statusTxtContent {
|
|
|
|
t.Errorf("Unexpected content: %s\n", content)
|
|
|
|
}
|
2015-12-10 20:02:18 +01:00
|
|
|
// Read relative symlink
|
2015-11-28 20:21:06 +01:00
|
|
|
symlink := filepath.Join(dir, "rel")
|
|
|
|
target, err := os.Readlink(symlink)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if target != "status.txt" {
|
|
|
|
t.Errorf("Unexpected link target: %s\n", target)
|
|
|
|
}
|
2015-12-10 20:02:18 +01:00
|
|
|
// Read absolute symlink
|
2015-11-28 20:21:06 +01:00
|
|
|
symlink = filepath.Join(dir, "abs")
|
|
|
|
target, err = os.Readlink(symlink)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if target != "/a/b/c/d" {
|
|
|
|
t.Errorf("Unexpected link target: %s\n", target)
|
|
|
|
}
|
2015-12-10 20:02:18 +01:00
|
|
|
// Test directory operations
|
2016-06-06 23:57:42 +02:00
|
|
|
test_helpers.TestRename(t, dir)
|
|
|
|
test_helpers.TestMkdirRmdir(t, dir)
|
2015-11-15 15:05:15 +01:00
|
|
|
}
|
|
|
|
|
2016-06-04 14:57:01 +02:00
|
|
|
// checkExampleFSLongnames - verify that "dir" contains the expected test files
|
|
|
|
// plus the long file name test file
|
|
|
|
func checkExampleFSLongnames(t *testing.T, dir string) {
|
|
|
|
// regular tests
|
|
|
|
checkExampleFS(t, dir)
|
|
|
|
// long name test file
|
|
|
|
longname := "longname_255_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" +
|
|
|
|
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" +
|
|
|
|
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" +
|
|
|
|
"xxxxxxxxxxxxxxxxxxxxxxxx"
|
|
|
|
contentBytes, err := ioutil.ReadFile(filepath.Join(dir, longname))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
content := string(contentBytes)
|
|
|
|
if content != statusTxtContent {
|
|
|
|
t.Errorf("longname_255: unexpected content: %s\n", content)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-11-28 20:31:01 +01:00
|
|
|
// Test example_filesystems/v0.4
|
2015-11-15 15:05:15 +01:00
|
|
|
// with password mount and -masterkey mount
|
2015-12-10 20:02:18 +01:00
|
|
|
func TestExampleFSv04(t *testing.T) {
|
2016-06-06 23:57:42 +02:00
|
|
|
pDir := test_helpers.TmpDir + "TestExampleFsV04/"
|
|
|
|
cDir := "v0.4"
|
2015-11-15 15:05:15 +01:00
|
|
|
err := os.Mkdir(pDir, 0777)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-06-06 23:57:42 +02:00
|
|
|
test_helpers.MountOrFatal(t, cDir, pDir, "-extpass", "echo test")
|
2015-12-10 20:02:18 +01:00
|
|
|
checkExampleFS(t, pDir)
|
2016-06-06 23:57:42 +02:00
|
|
|
test_helpers.Unmount(pDir)
|
|
|
|
test_helpers.MountOrFatal(t, cDir, pDir, "-masterkey", "74676e34-0b47c145-00dac61a-17a92316-"+
|
2015-12-19 14:41:39 +01:00
|
|
|
"bb57044c-e205b71f-65f4fdca-7cabd4b3", "-diriv=false", "-emenames=false", "-gcmiv128=false")
|
2015-12-10 20:02:18 +01:00
|
|
|
checkExampleFS(t, pDir)
|
2016-06-06 23:57:42 +02:00
|
|
|
test_helpers.Unmount(pDir)
|
2015-11-15 15:05:15 +01:00
|
|
|
err = os.Remove(pDir)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|
2015-11-28 20:31:01 +01:00
|
|
|
|
|
|
|
// Test example_filesystems/v0.5
|
|
|
|
// with password mount and -masterkey mount
|
2015-12-10 20:02:18 +01:00
|
|
|
func TestExampleFSv05(t *testing.T) {
|
2016-06-06 23:57:42 +02:00
|
|
|
pDir := test_helpers.TmpDir + "TestExampleFsV05/"
|
|
|
|
cDir := "v0.5"
|
2015-11-28 20:31:01 +01:00
|
|
|
err := os.Mkdir(pDir, 0777)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-06-06 23:57:42 +02:00
|
|
|
test_helpers.MountOrFatal(t, cDir, pDir, "-extpass", "echo test")
|
2015-12-10 20:02:18 +01:00
|
|
|
checkExampleFS(t, pDir)
|
2016-06-06 23:57:42 +02:00
|
|
|
test_helpers.Unmount(pDir)
|
|
|
|
test_helpers.MountOrFatal(t, cDir, pDir, "-masterkey", "199eae55-36bff4af-83b9a3a2-4fa16f65-"+
|
2015-12-19 14:41:39 +01:00
|
|
|
"1549ccdb-2d08d1f0-b1b26965-1b61f896", "-emenames=false", "-gcmiv128=false")
|
2015-12-10 20:02:18 +01:00
|
|
|
checkExampleFS(t, pDir)
|
2016-06-06 23:57:42 +02:00
|
|
|
test_helpers.Unmount(pDir)
|
2015-11-28 20:31:01 +01:00
|
|
|
err = os.Remove(pDir)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|
2015-12-08 16:17:19 +01:00
|
|
|
|
|
|
|
// Test example_filesystems/v0.6
|
|
|
|
// with password mount and -masterkey mount
|
2015-12-10 20:02:18 +01:00
|
|
|
func TestExampleFSv06(t *testing.T) {
|
2016-06-06 23:57:42 +02:00
|
|
|
pDir := test_helpers.TmpDir + "TestExampleFsV06/"
|
|
|
|
cDir := "v0.6"
|
2015-12-08 16:17:19 +01:00
|
|
|
err := os.Mkdir(pDir, 0777)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-06-06 23:57:42 +02:00
|
|
|
test_helpers.MountOrFatal(t, cDir, pDir, "-extpass", "echo test")
|
2015-12-10 20:02:18 +01:00
|
|
|
checkExampleFS(t, pDir)
|
2016-06-06 23:57:42 +02:00
|
|
|
test_helpers.Unmount(pDir)
|
|
|
|
test_helpers.MountOrFatal(t, cDir, pDir, "-masterkey", "7bc8deb0-5fc894ef-a093da43-61561a81-"+
|
2015-12-19 14:41:39 +01:00
|
|
|
"0e8dee83-fdc056a4-937c37dd-9df5c520", "-gcmiv128=false")
|
2015-12-10 20:02:18 +01:00
|
|
|
checkExampleFS(t, pDir)
|
2016-06-06 23:57:42 +02:00
|
|
|
test_helpers.Unmount(pDir)
|
2015-12-08 16:17:19 +01:00
|
|
|
err = os.Remove(pDir)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|
2015-12-10 19:50:45 +01:00
|
|
|
|
2015-12-19 14:41:39 +01:00
|
|
|
// Test example_filesystems/v0.6-plaintextnames
|
2015-12-10 19:50:45 +01:00
|
|
|
// with password mount and -masterkey mount
|
2015-12-19 14:41:39 +01:00
|
|
|
// v0.6 changed the file name handling a lot, hence the explicit test case for
|
|
|
|
// plaintextnames.
|
2015-12-10 20:02:18 +01:00
|
|
|
func TestExampleFSv06PlaintextNames(t *testing.T) {
|
2016-06-06 23:57:42 +02:00
|
|
|
pDir := test_helpers.TmpDir + "TestExampleFsV06PlaintextNames/"
|
|
|
|
cDir := "v0.6-plaintextnames"
|
2015-12-10 19:50:45 +01:00
|
|
|
err := os.Mkdir(pDir, 0777)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-06-06 23:57:42 +02:00
|
|
|
test_helpers.MountOrFatal(t, cDir, pDir, "-extpass", "echo test")
|
2015-12-10 20:02:18 +01:00
|
|
|
checkExampleFS(t, pDir)
|
2016-06-06 23:57:42 +02:00
|
|
|
test_helpers.Unmount(pDir)
|
|
|
|
test_helpers.MountOrFatal(t, cDir, pDir, "-masterkey", "f4690202-595e4593-64c4f7e0-4dddd7d1-"+
|
2015-12-19 14:41:39 +01:00
|
|
|
"303147f9-0ca8aea2-966341a7-52ea8ae9", "-plaintextnames", "-gcmiv128=false")
|
|
|
|
checkExampleFS(t, pDir)
|
2016-06-06 23:57:42 +02:00
|
|
|
test_helpers.Unmount(pDir)
|
2015-12-19 14:41:39 +01:00
|
|
|
err = os.Remove(pDir)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
pDir := test_helpers.TmpDir + "TestExampleFsV07/"
|
|
|
|
cDir := "v0.7"
|
2015-12-19 14:41:39 +01:00
|
|
|
err := os.Mkdir(pDir, 0777)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-06-06 23:57:42 +02:00
|
|
|
test_helpers.MountOrFatal(t, cDir, pDir, "-extpass", "echo test")
|
2015-12-19 14:41:39 +01:00
|
|
|
checkExampleFS(t, pDir)
|
2016-06-06 23:57:42 +02:00
|
|
|
test_helpers.Unmount(pDir)
|
|
|
|
test_helpers.MountOrFatal(t, cDir, pDir, "-masterkey", "ed7f6d83-40cce86c-0e7d79c2-a9438710-"+
|
2016-06-04 15:20:22 +02:00
|
|
|
"575221bf-30a0eb60-2821fa8f-7f3123bf")
|
2015-12-10 20:02:18 +01:00
|
|
|
checkExampleFS(t, pDir)
|
2016-06-06 23:57:42 +02:00
|
|
|
test_helpers.Unmount(pDir)
|
2015-12-10 19:50:45 +01:00
|
|
|
err = os.Remove(pDir)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|
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"
|
|
|
|
pDir := test_helpers.TmpDir + "TestExampleFsV09/"
|
2016-06-04 14:57:01 +02:00
|
|
|
err := os.Mkdir(pDir, 0777)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-06-06 23:57:42 +02:00
|
|
|
test_helpers.MountOrFatal(t, cDir, pDir, "-extpass", "echo test")
|
2016-06-04 14:57:01 +02:00
|
|
|
checkExampleFSLongnames(t, pDir)
|
2016-06-06 23:57:42 +02:00
|
|
|
test_helpers.Unmount(pDir)
|
|
|
|
test_helpers.MountOrFatal(t, cDir, pDir, "-masterkey", "1cafe3f4-bc316466-2214c47c-ecd89bf3-"+
|
2016-06-04 14:57:01 +02:00
|
|
|
"4e078fe4-f5faeea7-8b7cab02-884f5e1c")
|
|
|
|
checkExampleFSLongnames(t, pDir)
|
2016-06-06 23:57:42 +02:00
|
|
|
test_helpers.Unmount(pDir)
|
2016-06-04 14:57:01 +02:00
|
|
|
err = os.Remove(pDir)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|