tests: split example_filesystems into its own package
Running these tests from integration_tests' TestMain() was awkward because they were run twice with unchanged settings. integration_tests tests everything with OpenSSL and with native Go crypto, but this does not take affect for the example filesystems. To make this work, test_helpers is also split into its own package.
This commit is contained in:
parent
0f4d350136
commit
c2a5303eeb
@ -7,4 +7,4 @@ set -eu
|
||||
|
||||
source build.bash
|
||||
|
||||
go test ./integration_tests -bench=. -defaultonly
|
||||
go test ./tests/integration_tests -bench=. -defaultonly
|
@ -1,4 +1,4 @@
|
||||
package integration_tests
|
||||
package example_filesystems
|
||||
|
||||
// Mount example filesystems and check that the file "status.txt" is there
|
||||
|
||||
@ -7,10 +7,17 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/rfjakob/gocryptfs/tests/test_helpers"
|
||||
)
|
||||
|
||||
const statusTxtContent = "It works!\n"
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
test_helpers.ResetTmpDir(true)
|
||||
m.Run()
|
||||
}
|
||||
|
||||
// checkExampleFS - verify that "dir" contains the expected test files
|
||||
func checkExampleFS(t *testing.T, dir string) {
|
||||
// Read regular file
|
||||
@ -42,8 +49,8 @@ func checkExampleFS(t *testing.T, dir string) {
|
||||
t.Errorf("Unexpected link target: %s\n", target)
|
||||
}
|
||||
// Test directory operations
|
||||
testRename(t, dir)
|
||||
testMkdirRmdir(t, dir)
|
||||
test_helpers.TestRename(t, dir)
|
||||
test_helpers.TestMkdirRmdir(t, dir)
|
||||
}
|
||||
|
||||
// checkExampleFSLongnames - verify that "dir" contains the expected test files
|
||||
@ -70,19 +77,19 @@ func checkExampleFSLongnames(t *testing.T, dir string) {
|
||||
// Test example_filesystems/v0.4
|
||||
// with password mount and -masterkey mount
|
||||
func TestExampleFSv04(t *testing.T) {
|
||||
pDir := tmpDir + "TestExampleFsV04/"
|
||||
cDir := "example_filesystems/v0.4"
|
||||
pDir := test_helpers.TmpDir + "TestExampleFsV04/"
|
||||
cDir := "v0.4"
|
||||
err := os.Mkdir(pDir, 0777)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
mountOrFatal(t, cDir, pDir, "-extpass", "echo test")
|
||||
test_helpers.MountOrFatal(t, cDir, pDir, "-extpass", "echo test")
|
||||
checkExampleFS(t, pDir)
|
||||
unmount(pDir)
|
||||
mountOrFatal(t, cDir, pDir, "-masterkey", "74676e34-0b47c145-00dac61a-17a92316-"+
|
||||
test_helpers.Unmount(pDir)
|
||||
test_helpers.MountOrFatal(t, cDir, pDir, "-masterkey", "74676e34-0b47c145-00dac61a-17a92316-"+
|
||||
"bb57044c-e205b71f-65f4fdca-7cabd4b3", "-diriv=false", "-emenames=false", "-gcmiv128=false")
|
||||
checkExampleFS(t, pDir)
|
||||
unmount(pDir)
|
||||
test_helpers.Unmount(pDir)
|
||||
err = os.Remove(pDir)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
@ -92,19 +99,19 @@ func TestExampleFSv04(t *testing.T) {
|
||||
// Test example_filesystems/v0.5
|
||||
// with password mount and -masterkey mount
|
||||
func TestExampleFSv05(t *testing.T) {
|
||||
pDir := tmpDir + "TestExampleFsV05/"
|
||||
cDir := "example_filesystems/v0.5"
|
||||
pDir := test_helpers.TmpDir + "TestExampleFsV05/"
|
||||
cDir := "v0.5"
|
||||
err := os.Mkdir(pDir, 0777)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
mountOrFatal(t, cDir, pDir, "-extpass", "echo test")
|
||||
test_helpers.MountOrFatal(t, cDir, pDir, "-extpass", "echo test")
|
||||
checkExampleFS(t, pDir)
|
||||
unmount(pDir)
|
||||
mountOrFatal(t, cDir, pDir, "-masterkey", "199eae55-36bff4af-83b9a3a2-4fa16f65-"+
|
||||
test_helpers.Unmount(pDir)
|
||||
test_helpers.MountOrFatal(t, cDir, pDir, "-masterkey", "199eae55-36bff4af-83b9a3a2-4fa16f65-"+
|
||||
"1549ccdb-2d08d1f0-b1b26965-1b61f896", "-emenames=false", "-gcmiv128=false")
|
||||
checkExampleFS(t, pDir)
|
||||
unmount(pDir)
|
||||
test_helpers.Unmount(pDir)
|
||||
err = os.Remove(pDir)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
@ -114,19 +121,19 @@ func TestExampleFSv05(t *testing.T) {
|
||||
// Test example_filesystems/v0.6
|
||||
// with password mount and -masterkey mount
|
||||
func TestExampleFSv06(t *testing.T) {
|
||||
pDir := tmpDir + "TestExampleFsV06/"
|
||||
cDir := "example_filesystems/v0.6"
|
||||
pDir := test_helpers.TmpDir + "TestExampleFsV06/"
|
||||
cDir := "v0.6"
|
||||
err := os.Mkdir(pDir, 0777)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
mountOrFatal(t, cDir, pDir, "-extpass", "echo test")
|
||||
test_helpers.MountOrFatal(t, cDir, pDir, "-extpass", "echo test")
|
||||
checkExampleFS(t, pDir)
|
||||
unmount(pDir)
|
||||
mountOrFatal(t, cDir, pDir, "-masterkey", "7bc8deb0-5fc894ef-a093da43-61561a81-"+
|
||||
test_helpers.Unmount(pDir)
|
||||
test_helpers.MountOrFatal(t, cDir, pDir, "-masterkey", "7bc8deb0-5fc894ef-a093da43-61561a81-"+
|
||||
"0e8dee83-fdc056a4-937c37dd-9df5c520", "-gcmiv128=false")
|
||||
checkExampleFS(t, pDir)
|
||||
unmount(pDir)
|
||||
test_helpers.Unmount(pDir)
|
||||
err = os.Remove(pDir)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
@ -138,19 +145,19 @@ func TestExampleFSv06(t *testing.T) {
|
||||
// v0.6 changed the file name handling a lot, hence the explicit test case for
|
||||
// plaintextnames.
|
||||
func TestExampleFSv06PlaintextNames(t *testing.T) {
|
||||
pDir := tmpDir + "TestExampleFsV06PlaintextNames/"
|
||||
cDir := "example_filesystems/v0.6-plaintextnames"
|
||||
pDir := test_helpers.TmpDir + "TestExampleFsV06PlaintextNames/"
|
||||
cDir := "v0.6-plaintextnames"
|
||||
err := os.Mkdir(pDir, 0777)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
mountOrFatal(t, cDir, pDir, "-extpass", "echo test")
|
||||
test_helpers.MountOrFatal(t, cDir, pDir, "-extpass", "echo test")
|
||||
checkExampleFS(t, pDir)
|
||||
unmount(pDir)
|
||||
mountOrFatal(t, cDir, pDir, "-masterkey", "f4690202-595e4593-64c4f7e0-4dddd7d1-"+
|
||||
test_helpers.Unmount(pDir)
|
||||
test_helpers.MountOrFatal(t, cDir, pDir, "-masterkey", "f4690202-595e4593-64c4f7e0-4dddd7d1-"+
|
||||
"303147f9-0ca8aea2-966341a7-52ea8ae9", "-plaintextnames", "-gcmiv128=false")
|
||||
checkExampleFS(t, pDir)
|
||||
unmount(pDir)
|
||||
test_helpers.Unmount(pDir)
|
||||
err = os.Remove(pDir)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
@ -161,19 +168,19 @@ func TestExampleFSv06PlaintextNames(t *testing.T) {
|
||||
// with password mount and -masterkey mount
|
||||
// v0.7 adds 128 bit GCM IVs
|
||||
func TestExampleFSv07(t *testing.T) {
|
||||
pDir := tmpDir + "TestExampleFsV07/"
|
||||
cDir := "example_filesystems/v0.7"
|
||||
pDir := test_helpers.TmpDir + "TestExampleFsV07/"
|
||||
cDir := "v0.7"
|
||||
err := os.Mkdir(pDir, 0777)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
mountOrFatal(t, cDir, pDir, "-extpass", "echo test")
|
||||
test_helpers.MountOrFatal(t, cDir, pDir, "-extpass", "echo test")
|
||||
checkExampleFS(t, pDir)
|
||||
unmount(pDir)
|
||||
mountOrFatal(t, cDir, pDir, "-masterkey", "ed7f6d83-40cce86c-0e7d79c2-a9438710-"+
|
||||
test_helpers.Unmount(pDir)
|
||||
test_helpers.MountOrFatal(t, cDir, pDir, "-masterkey", "ed7f6d83-40cce86c-0e7d79c2-a9438710-"+
|
||||
"575221bf-30a0eb60-2821fa8f-7f3123bf")
|
||||
checkExampleFS(t, pDir)
|
||||
unmount(pDir)
|
||||
test_helpers.Unmount(pDir)
|
||||
err = os.Remove(pDir)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
@ -183,19 +190,19 @@ func TestExampleFSv07(t *testing.T) {
|
||||
// Test example_filesystems/v0.9
|
||||
// (gocryptfs v0.9 introduced long file name support)
|
||||
func TestExampleFSv09(t *testing.T) {
|
||||
cDir := "example_filesystems/v0.9"
|
||||
pDir := tmpDir + "TestExampleFsV09/"
|
||||
cDir := "v0.9"
|
||||
pDir := test_helpers.TmpDir + "TestExampleFsV09/"
|
||||
err := os.Mkdir(pDir, 0777)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
mountOrFatal(t, cDir, pDir, "-extpass", "echo test")
|
||||
test_helpers.MountOrFatal(t, cDir, pDir, "-extpass", "echo test")
|
||||
checkExampleFSLongnames(t, pDir)
|
||||
unmount(pDir)
|
||||
mountOrFatal(t, cDir, pDir, "-masterkey", "1cafe3f4-bc316466-2214c47c-ecd89bf3-"+
|
||||
test_helpers.Unmount(pDir)
|
||||
test_helpers.MountOrFatal(t, cDir, pDir, "-masterkey", "1cafe3f4-bc316466-2214c47c-ecd89bf3-"+
|
||||
"4e078fe4-f5faeea7-8b7cab02-884f5e1c")
|
||||
checkExampleFSLongnames(t, pDir)
|
||||
unmount(pDir)
|
||||
test_helpers.Unmount(pDir)
|
||||
err = os.Remove(pDir)
|
||||
if err != nil {
|
||||
t.Error(err)
|
@ -9,16 +9,18 @@ import (
|
||||
|
||||
"github.com/rfjakob/gocryptfs/internal/configfile"
|
||||
"github.com/rfjakob/gocryptfs/internal/nametransform"
|
||||
|
||||
"github.com/rfjakob/gocryptfs/tests/test_helpers"
|
||||
)
|
||||
|
||||
// Test -init flag
|
||||
func TestInit(t *testing.T) {
|
||||
dir := tmpDir + "TestInit/"
|
||||
dir := test_helpers.TmpDir + "TestInit/"
|
||||
err := os.Mkdir(dir, 0777)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cmd := exec.Command(gocryptfsBinary, "-init", "-extpass", "echo test", "-scryptn=10", dir)
|
||||
cmd := exec.Command(test_helpers.GocryptfsBinary, "-init", "-extpass", "echo test", "-scryptn=10", dir)
|
||||
if testing.Verbose() {
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
@ -33,7 +35,7 @@ func TestInit(t *testing.T) {
|
||||
}
|
||||
|
||||
// Test -passwd
|
||||
cmd2 := exec.Command(gocryptfsBinary, "-passwd", "-extpass", "echo test", dir)
|
||||
cmd2 := exec.Command(test_helpers.GocryptfsBinary, "-passwd", "-extpass", "echo test", dir)
|
||||
if testing.Verbose() {
|
||||
cmd2.Stdout = os.Stdout
|
||||
cmd2.Stderr = os.Stderr
|
||||
@ -46,13 +48,13 @@ func TestInit(t *testing.T) {
|
||||
|
||||
// Test -init & -config flag
|
||||
func TestInitConfig(t *testing.T) {
|
||||
dir := tmpDir + "TestInitConfig/"
|
||||
config := tmpDir + "TestInitConfig.conf"
|
||||
dir := test_helpers.TmpDir + "TestInitConfig/"
|
||||
config := test_helpers.TmpDir + "TestInitConfig.conf"
|
||||
err := os.Mkdir(dir, 0777)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cmd := exec.Command(gocryptfsBinary, "-init", "-extpass", "echo test",
|
||||
cmd := exec.Command(test_helpers.GocryptfsBinary, "-init", "-extpass", "echo test",
|
||||
"-config", config, "-scryptn=10", dir)
|
||||
if testing.Verbose() {
|
||||
cmd.Stdout = os.Stdout
|
||||
@ -68,7 +70,7 @@ func TestInitConfig(t *testing.T) {
|
||||
}
|
||||
|
||||
// Test -passwd & -config
|
||||
cmd2 := exec.Command(gocryptfsBinary, "-passwd", "-extpass", "echo test",
|
||||
cmd2 := exec.Command(test_helpers.GocryptfsBinary, "-passwd", "-extpass", "echo test",
|
||||
"-config", config, dir)
|
||||
if testing.Verbose() {
|
||||
cmd2.Stdout = os.Stdout
|
||||
@ -82,12 +84,12 @@ func TestInitConfig(t *testing.T) {
|
||||
|
||||
// Test -init -plaintextnames
|
||||
func TestInitPlaintextNames(t *testing.T) {
|
||||
dir := tmpDir + "TestInitPlaintextNames/"
|
||||
dir := test_helpers.TmpDir + "TestInitPlaintextNames/"
|
||||
err := os.Mkdir(dir, 0777)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cmd := exec.Command(gocryptfsBinary, "-init", "-extpass", "echo test",
|
||||
cmd := exec.Command(test_helpers.GocryptfsBinary, "-init", "-extpass", "echo test",
|
||||
"-scryptn=10", "-plaintextnames", dir)
|
||||
if testing.Verbose() {
|
||||
cmd.Stdout = os.Stdout
|
@ -14,6 +14,8 @@ import (
|
||||
"sync"
|
||||
"syscall"
|
||||
"testing"
|
||||
|
||||
"github.com/rfjakob/gocryptfs/tests/test_helpers"
|
||||
)
|
||||
|
||||
var plaintextNames bool
|
||||
@ -27,10 +29,10 @@ func TestMain(m *testing.M) {
|
||||
if testing.Verbose() {
|
||||
fmt.Println("***** Testing with OpenSSL")
|
||||
}
|
||||
resetTmpDir(false) // <- this also create gocryptfs.diriv
|
||||
mountOrExit(defaultCipherDir, defaultPlainDir, "--zerokey")
|
||||
test_helpers.ResetTmpDir(false) // <- this also create gocryptfs.diriv
|
||||
test_helpers.MountOrExit(test_helpers.DefaultCipherDir, test_helpers.DefaultPlainDir, "--zerokey")
|
||||
r := m.Run()
|
||||
unmount(defaultPlainDir)
|
||||
test_helpers.Unmount(test_helpers.DefaultPlainDir)
|
||||
|
||||
if r != 0 {
|
||||
os.Exit(r)
|
||||
@ -43,10 +45,10 @@ func TestMain(m *testing.M) {
|
||||
if testing.Verbose() {
|
||||
fmt.Println("***** Testing with native Go crypto")
|
||||
}
|
||||
resetTmpDir(false)
|
||||
mountOrExit(defaultCipherDir, defaultPlainDir, "--zerokey", "--openssl=false")
|
||||
test_helpers.ResetTmpDir(false)
|
||||
test_helpers.MountOrExit(test_helpers.DefaultCipherDir, test_helpers.DefaultPlainDir, "--zerokey", "--openssl=false")
|
||||
r = m.Run()
|
||||
unmount(defaultPlainDir)
|
||||
test_helpers.Unmount(test_helpers.DefaultPlainDir)
|
||||
|
||||
if r != 0 {
|
||||
os.Exit(r)
|
||||
@ -55,11 +57,11 @@ func TestMain(m *testing.M) {
|
||||
if testing.Verbose() {
|
||||
fmt.Println("***** Testing \"--plaintextnames\"")
|
||||
}
|
||||
resetTmpDir(true) // do not create gocryptfs.diriv
|
||||
mountOrExit(defaultCipherDir, defaultPlainDir, "--zerokey", "--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()
|
||||
unmount(defaultPlainDir)
|
||||
test_helpers.Unmount(test_helpers.DefaultPlainDir)
|
||||
|
||||
if r != 0 {
|
||||
os.Exit(r)
|
||||
@ -70,7 +72,7 @@ func TestMain(m *testing.M) {
|
||||
|
||||
// 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(defaultPlainDir + fn)
|
||||
file, err := os.Create(test_helpers.DefaultPlainDir + fn)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -85,12 +87,12 @@ func testWriteN(t *testing.T, fn string, n int) string {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
verifySize(t, defaultPlainDir+fn, n)
|
||||
test_helpers.VerifySize(t, test_helpers.DefaultPlainDir+fn, n)
|
||||
|
||||
bin := md5.Sum(d)
|
||||
hashWant := hex.EncodeToString(bin[:])
|
||||
|
||||
hashActual := md5fn(defaultPlainDir + fn)
|
||||
hashActual := test_helpers.Md5fn(test_helpers.DefaultPlainDir + fn)
|
||||
|
||||
if hashActual != hashWant {
|
||||
t.Errorf("Wrong content, hashWant=%s hashActual=%s", hashWant, hashActual)
|
||||
@ -116,7 +118,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(defaultPlainDir + "1M")
|
||||
hashActual := test_helpers.Md5fn(test_helpers.DefaultPlainDir + "1M")
|
||||
if hashActual != hashWant {
|
||||
fmt.Printf("Read corruption in loop # %d\n", i)
|
||||
t.FailNow()
|
||||
@ -127,39 +129,39 @@ func TestWrite1Mx100(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestTruncate(t *testing.T) {
|
||||
fn := defaultPlainDir + "truncate"
|
||||
fn := test_helpers.DefaultPlainDir + "truncate"
|
||||
file, err := os.Create(fn)
|
||||
if err != nil {
|
||||
t.FailNow()
|
||||
}
|
||||
// Grow to two blocks
|
||||
file.Truncate(7000)
|
||||
verifySize(t, fn, 7000)
|
||||
if md5fn(fn) != "95d4ec7038e3e4fdbd5f15c34c3f0b34" {
|
||||
test_helpers.VerifySize(t, fn, 7000)
|
||||
if test_helpers.Md5fn(fn) != "95d4ec7038e3e4fdbd5f15c34c3f0b34" {
|
||||
t.Errorf("wrong content")
|
||||
}
|
||||
// Shrink - needs RMW
|
||||
file.Truncate(6999)
|
||||
verifySize(t, fn, 6999)
|
||||
if md5fn(fn) != "35fd15873ec6c35380064a41b9b9683b" {
|
||||
test_helpers.VerifySize(t, fn, 6999)
|
||||
if test_helpers.Md5fn(fn) != "35fd15873ec6c35380064a41b9b9683b" {
|
||||
t.Errorf("wrong content")
|
||||
}
|
||||
// Shrink to one partial block
|
||||
file.Truncate(465)
|
||||
verifySize(t, fn, 465)
|
||||
if md5fn(fn) != "a1534d6e98a6b21386456a8f66c55260" {
|
||||
test_helpers.VerifySize(t, fn, 465)
|
||||
if test_helpers.Md5fn(fn) != "a1534d6e98a6b21386456a8f66c55260" {
|
||||
t.Errorf("wrong content")
|
||||
}
|
||||
// Grow to exactly one block
|
||||
file.Truncate(4096)
|
||||
verifySize(t, fn, 4096)
|
||||
if md5fn(fn) != "620f0b67a91f7f74151bc5be745b7110" {
|
||||
test_helpers.VerifySize(t, fn, 4096)
|
||||
if test_helpers.Md5fn(fn) != "620f0b67a91f7f74151bc5be745b7110" {
|
||||
t.Errorf("wrong content")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAppend(t *testing.T) {
|
||||
fn := defaultPlainDir + "append"
|
||||
fn := test_helpers.DefaultPlainDir + "append"
|
||||
file, err := os.Create(fn)
|
||||
if err != nil {
|
||||
t.FailNow()
|
||||
@ -172,7 +174,7 @@ func TestAppend(t *testing.T) {
|
||||
buf.Write(data)
|
||||
bin := md5.Sum(buf.Bytes())
|
||||
hashWant = hex.EncodeToString(bin[:])
|
||||
hashActual := md5fn(fn)
|
||||
hashActual := test_helpers.Md5fn(fn)
|
||||
if hashWant != hashActual {
|
||||
t.FailNow()
|
||||
}
|
||||
@ -183,7 +185,7 @@ func TestAppend(t *testing.T) {
|
||||
file.Seek(0, 0)
|
||||
for i := 0; i <= 500; i++ {
|
||||
file.Write(data)
|
||||
hashActual := md5fn(fn)
|
||||
hashActual := test_helpers.Md5fn(fn)
|
||||
if hashWant != hashActual {
|
||||
t.FailNow()
|
||||
}
|
||||
@ -193,7 +195,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 := defaultPlainDir + "fileholes"
|
||||
fn := test_helpers.DefaultPlainDir + "fileholes"
|
||||
file, err := os.Create(fn)
|
||||
if err != nil {
|
||||
t.Errorf("file create failed")
|
||||
@ -221,7 +223,7 @@ func TestRmwRace(t *testing.T) {
|
||||
|
||||
runtime.GOMAXPROCS(10)
|
||||
|
||||
fn := defaultPlainDir + "rmwrace"
|
||||
fn := test_helpers.DefaultPlainDir + "rmwrace"
|
||||
f1, err := os.Create(fn)
|
||||
if err != nil {
|
||||
t.Fatalf("file create failed")
|
||||
@ -274,7 +276,7 @@ func TestRmwRace(t *testing.T) {
|
||||
// [oooooossss]
|
||||
|
||||
buf, _ := ioutil.ReadFile(fn)
|
||||
m := md5hex(buf)
|
||||
m := test_helpers.Md5hex(buf)
|
||||
goodMd5[m] = goodMd5[m] + 1
|
||||
|
||||
/*
|
||||
@ -292,7 +294,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 := defaultPlainDir + "gocryptfs.conf"
|
||||
filteredFile := test_helpers.DefaultPlainDir + "gocryptfs.conf"
|
||||
file, err := os.Create(filteredFile)
|
||||
if plaintextNames == true && err == nil {
|
||||
t.Errorf("should have failed but didn't")
|
||||
@ -310,13 +312,13 @@ func TestFiltered(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestFilenameEncryption(t *testing.T) {
|
||||
file, err := os.Create(defaultPlainDir + "TestFilenameEncryption.txt")
|
||||
file, err := os.Create(test_helpers.DefaultPlainDir + "TestFilenameEncryption.txt")
|
||||
file.Close()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = os.Stat(defaultCipherDir + "TestFilenameEncryption.txt")
|
||||
_, 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 {
|
||||
@ -325,19 +327,19 @@ func TestFilenameEncryption(t *testing.T) {
|
||||
}
|
||||
|
||||
// Test Mkdir and Rmdir
|
||||
func TestMkdirRmdir(t *testing.T) {
|
||||
testMkdirRmdir(t, defaultPlainDir)
|
||||
func testMkdirRmdir(t *testing.T) {
|
||||
test_helpers.TestMkdirRmdir(t, test_helpers.DefaultPlainDir)
|
||||
}
|
||||
|
||||
// Test Rename
|
||||
func TestRename(t *testing.T) {
|
||||
testRename(t, defaultPlainDir)
|
||||
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 := defaultPlainDir + "DirOverwrite1"
|
||||
dir2 := defaultPlainDir + "DirOverwrite2"
|
||||
dir1 := test_helpers.DefaultPlainDir + "DirOverwrite1"
|
||||
dir2 := test_helpers.DefaultPlainDir + "DirOverwrite2"
|
||||
err := os.Mkdir(dir1, 0777)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@ -353,12 +355,12 @@ func TestDirOverwrite(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLongNames(t *testing.T) {
|
||||
fi, err := ioutil.ReadDir(defaultCipherDir)
|
||||
fi, err := ioutil.ReadDir(test_helpers.DefaultCipherDir)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cnt1 := len(fi)
|
||||
wd := defaultPlainDir
|
||||
wd := test_helpers.DefaultPlainDir
|
||||
// Create file with long name
|
||||
n255x := string(bytes.Repeat([]byte("x"), 255))
|
||||
f, err := os.Create(wd + n255x)
|
||||
@ -366,7 +368,7 @@ func TestLongNames(t *testing.T) {
|
||||
t.Fatalf("Could not create n255x: %v", err)
|
||||
}
|
||||
f.Close()
|
||||
if !verifyExistence(wd + n255x) {
|
||||
if !test_helpers.VerifyExistence(wd + n255x) {
|
||||
t.Errorf("n255x is not in directory listing")
|
||||
}
|
||||
// Rename long to long
|
||||
@ -375,7 +377,7 @@ func TestLongNames(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Could not rename n255x to n255y: %v", err)
|
||||
}
|
||||
if !verifyExistence(wd + n255y) {
|
||||
if !test_helpers.VerifyExistence(wd + n255y) {
|
||||
t.Errorf("n255y is not in directory listing")
|
||||
}
|
||||
// Rename long to short
|
||||
@ -383,7 +385,7 @@ func TestLongNames(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Could not rename n255y to short: %v", err)
|
||||
}
|
||||
if !verifyExistence(wd + "short") {
|
||||
if !test_helpers.VerifyExistence(wd + "short") {
|
||||
t.Errorf("short is not in directory listing")
|
||||
}
|
||||
// Rename short to long
|
||||
@ -391,7 +393,7 @@ func TestLongNames(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Could not rename short to n255x: %v", err)
|
||||
}
|
||||
if !verifyExistence(wd + n255x) {
|
||||
if !test_helpers.VerifyExistence(wd + n255x) {
|
||||
t.Errorf("255x is not in directory listing II")
|
||||
}
|
||||
// Unlink
|
||||
@ -399,7 +401,7 @@ func TestLongNames(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Could not unlink n255x: %v", err)
|
||||
}
|
||||
if verifyExistence(wd + n255x) {
|
||||
if test_helpers.VerifyExistence(wd + n255x) {
|
||||
t.Errorf("n255x still there after unlink")
|
||||
}
|
||||
// Long symlink
|
||||
@ -408,7 +410,7 @@ func TestLongNames(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !verifyExistence(wd + n255s) {
|
||||
if !test_helpers.VerifyExistence(wd + n255s) {
|
||||
t.Errorf("n255s is not in directory listing")
|
||||
}
|
||||
err = syscall.Unlink(wd + n255s)
|
||||
@ -426,7 +428,7 @@ func TestLongNames(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
// Check for orphaned files
|
||||
fi, err = ioutil.ReadDir(defaultCipherDir)
|
||||
fi, err = ioutil.ReadDir(test_helpers.DefaultCipherDir)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
@ -8,13 +8,15 @@ import (
|
||||
"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(defaultPlainDir + "BenchmarkWrite")
|
||||
file, err := os.Create(test_helpers.DefaultPlainDir + "BenchmarkWrite")
|
||||
if err != nil {
|
||||
t.FailNow()
|
||||
}
|
||||
@ -35,7 +37,7 @@ func BenchmarkStreamRead(t *testing.B) {
|
||||
buf := make([]byte, 1024*1024)
|
||||
t.SetBytes(int64(len(buf)))
|
||||
|
||||
fn := defaultPlainDir + "BenchmarkWrite"
|
||||
fn := test_helpers.DefaultPlainDir + "BenchmarkWrite"
|
||||
fi, err := os.Stat(fn)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@ -82,7 +84,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", defaultPlainDir, count, size)
|
||||
dir := fmt.Sprintf("%s/createFiles_%d_%d", test_helpers.DefaultPlainDir, count, size)
|
||||
err := os.Mkdir(dir, 0777)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
@ -1,4 +1,4 @@
|
||||
package integration_tests
|
||||
package test_helpers
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
@ -15,43 +15,43 @@ import (
|
||||
)
|
||||
|
||||
// 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 TmpDir = "/tmp/gocryptfs_main_test/"
|
||||
const DefaultPlainDir = TmpDir + "plain/"
|
||||
const DefaultCipherDir = TmpDir + "cipher/"
|
||||
|
||||
const gocryptfsBinary = "../gocryptfs"
|
||||
const GocryptfsBinary = "../../gocryptfs"
|
||||
|
||||
// resetTmpDir - delete old tmp dir, create new one, write gocryptfs.diriv
|
||||
func resetTmpDir(plaintextNames bool) {
|
||||
// ResetTmpDir - delete old tmp dir, create new one, write gocryptfs.diriv
|
||||
func ResetTmpDir(plaintextNames bool) {
|
||||
|
||||
// Try to unmount everything
|
||||
entries, err := ioutil.ReadDir(tmpDir)
|
||||
entries, err := ioutil.ReadDir(TmpDir)
|
||||
if err == nil {
|
||||
for _, e := range entries {
|
||||
fu := exec.Command("fusermount", "-z", "-u", filepath.Join(tmpDir, e.Name()))
|
||||
fu := exec.Command("fusermount", "-z", "-u", filepath.Join(TmpDir, e.Name()))
|
||||
fu.Run()
|
||||
}
|
||||
}
|
||||
|
||||
err = os.RemoveAll(tmpDir)
|
||||
err = os.RemoveAll(TmpDir)
|
||||
if err != nil {
|
||||
fmt.Println("resetTmpDir: RemoveAll:" + err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
err = os.MkdirAll(defaultPlainDir, 0777)
|
||||
err = os.MkdirAll(DefaultPlainDir, 0777)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
err = os.MkdirAll(defaultCipherDir, 0777)
|
||||
err = os.MkdirAll(DefaultCipherDir, 0777)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if !plaintextNames {
|
||||
err = nametransform.WriteDirIV(defaultCipherDir)
|
||||
err = nametransform.WriteDirIV(DefaultCipherDir)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
@ -59,8 +59,8 @@ func resetTmpDir(plaintextNames bool) {
|
||||
}
|
||||
}
|
||||
|
||||
// mount CIPHERDIR "c" on PLAINDIR "p"
|
||||
func mount(c string, p string, extraArgs ...string) error {
|
||||
// Mount CIPHERDIR "c" on PLAINDIR "p"
|
||||
func Mount(c string, p string, extraArgs ...string) error {
|
||||
var args []string
|
||||
args = append(args, extraArgs...)
|
||||
args = append(args, "-nosyslog", "-q", "-wpanic")
|
||||
@ -68,31 +68,33 @@ func mount(c string, p string, extraArgs ...string) error {
|
||||
//args = append(args, "-d")
|
||||
args = append(args, c)
|
||||
args = append(args, p)
|
||||
cmd := exec.Command(gocryptfsBinary, args...)
|
||||
cmd := exec.Command(GocryptfsBinary, args...)
|
||||
cmd.Stderr = os.Stderr
|
||||
if testing.Verbose() {
|
||||
cmd.Stdout = os.Stdout
|
||||
}
|
||||
return cmd.Run()
|
||||
}
|
||||
|
||||
// mountOrExit calls mount() and exits on failure.
|
||||
func mountOrExit(c string, p string, extraArgs ...string) {
|
||||
err := mount(c, p, extraArgs...)
|
||||
// MountOrExit calls mount() and exits on failure.
|
||||
func MountOrExit(c string, p string, extraArgs ...string) {
|
||||
err := Mount(c, p, extraArgs...)
|
||||
if err != nil {
|
||||
fmt.Printf("mount failed: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
// mountOrFatal calls mount() and calls t.Fatal() on failure.
|
||||
func mountOrFatal(t *testing.T, c string, p string, extraArgs ...string) {
|
||||
err := mount(c, p, extraArgs...)
|
||||
// MountOrFatal calls mount() and calls t.Fatal() on failure.
|
||||
func MountOrFatal(t *testing.T, c string, p string, extraArgs ...string) {
|
||||
err := Mount(c, p, extraArgs...)
|
||||
if err != nil {
|
||||
t.Fatal(fmt.Errorf("mount failed: %v", err))
|
||||
}
|
||||
}
|
||||
|
||||
// unmount PLAINDIR "p"
|
||||
func unmount(p string) error {
|
||||
// Unmount PLAINDIR "p"
|
||||
func Unmount(p string) error {
|
||||
fu := exec.Command("fusermount", "-u", "-z", p)
|
||||
fu.Stdout = os.Stdout
|
||||
fu.Stderr = os.Stderr
|
||||
@ -104,17 +106,17 @@ func unmount(p string) error {
|
||||
}
|
||||
|
||||
// Return md5 string for file "filename"
|
||||
func md5fn(filename string) string {
|
||||
func Md5fn(filename string) string {
|
||||
buf, err := ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
fmt.Printf("ReadFile: %v\n", err)
|
||||
return ""
|
||||
}
|
||||
return md5hex(buf)
|
||||
return Md5hex(buf)
|
||||
}
|
||||
|
||||
// Return md5 string for "buf"
|
||||
func md5hex(buf []byte) string {
|
||||
func Md5hex(buf []byte) string {
|
||||
rawHash := md5.Sum(buf)
|
||||
hash := hex.EncodeToString(rawHash[:])
|
||||
return hash
|
||||
@ -123,7 +125,7 @@ func md5hex(buf []byte) string {
|
||||
// Verify that the file size equals "want". This checks:
|
||||
// 1) Size reported by Stat()
|
||||
// 2) Number of bytes returned when reading the whole file
|
||||
func verifySize(t *testing.T, path string, want int) {
|
||||
func VerifySize(t *testing.T, path string, want int) {
|
||||
buf, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
t.Errorf("ReadFile failed: %v", err)
|
||||
@ -140,7 +142,7 @@ func verifySize(t *testing.T, path string, want int) {
|
||||
}
|
||||
|
||||
// Create and delete a directory
|
||||
func testMkdirRmdir(t *testing.T, plainDir string) {
|
||||
func TestMkdirRmdir(t *testing.T, plainDir string) {
|
||||
dir := plainDir + "dir1"
|
||||
err := os.Mkdir(dir, 0777)
|
||||
if err != nil {
|
||||
@ -187,7 +189,7 @@ func testMkdirRmdir(t *testing.T, plainDir string) {
|
||||
}
|
||||
|
||||
// Create and rename a file
|
||||
func testRename(t *testing.T, plainDir string) {
|
||||
func TestRename(t *testing.T, plainDir string) {
|
||||
file1 := plainDir + "rename1"
|
||||
file2 := plainDir + "rename2"
|
||||
err := ioutil.WriteFile(file1, []byte("content"), 0777)
|
||||
@ -203,7 +205,7 @@ func testRename(t *testing.T, plainDir string) {
|
||||
|
||||
// verifyExistence - check in 3 ways that "path" exists:
|
||||
// stat, open, readdir
|
||||
func verifyExistence(path string) bool {
|
||||
func VerifyExistence(path string) bool {
|
||||
|
||||
// Check that file can be stated
|
||||
_, err := os.Stat(path)
|
Loading…
Reference in New Issue
Block a user