tests: add example_filesystems, test password and -masterkey mount
This commit is contained in:
parent
296bdf3af2
commit
40882c6e49
Binary file not shown.
12
integration_tests/example_filesystems/normal/gocryptfs.conf
Normal file
12
integration_tests/example_filesystems/normal/gocryptfs.conf
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"EncryptedKey": "He757VFOKOWbMJqJ7HBs67SMSi3Vu8/2vgWNI6j1tVo4JBlNvrQSw6KkCh0lGrHrh6ICbPv4MyoyFdGa",
|
||||||
|
"ScryptObject": {
|
||||||
|
"Salt": "MeHSsxsnJwngAwptNzuXQlj7JtF1b0uzZuWvVV3cH3w=",
|
||||||
|
"N": 65536,
|
||||||
|
"R": 8,
|
||||||
|
"P": 1,
|
||||||
|
"KeyLen": 32
|
||||||
|
},
|
||||||
|
"Version": 2,
|
||||||
|
"FeatureFlags": null
|
||||||
|
}
|
46
integration_tests/example_filesystems_test.go
Normal file
46
integration_tests/example_filesystems_test.go
Normal file
@ -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)
|
||||||
|
}
|
||||||
|
}
|
@ -12,51 +12,63 @@ import (
|
|||||||
|
|
||||||
// Note: the code assumes that all have a trailing slash
|
// Note: the code assumes that all have a trailing slash
|
||||||
const tmpDir = "/tmp/gocryptfs_main_test/"
|
const tmpDir = "/tmp/gocryptfs_main_test/"
|
||||||
const plainDir = tmpDir + "plain/"
|
const defaultPlainDir = tmpDir + "plain/"
|
||||||
const cipherDir = tmpDir + "cipher/"
|
const defaultCipherDir = tmpDir + "cipher/"
|
||||||
|
|
||||||
const gocryptfsBinary = "../gocryptfs"
|
const gocryptfsBinary = "../gocryptfs"
|
||||||
|
|
||||||
func resetTmpDir() {
|
func resetTmpDir() {
|
||||||
fu := exec.Command("fusermount", "-z", "-u", plainDir)
|
fu := exec.Command("fusermount", "-z", "-u", defaultPlainDir)
|
||||||
fu.Run()
|
fu.Run()
|
||||||
|
|
||||||
os.RemoveAll(tmpDir)
|
err := os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
err := os.MkdirAll(plainDir, 0777)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("Could not create plainDir")
|
fmt.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = os.MkdirAll(cipherDir, 0777)
|
err = os.MkdirAll(defaultPlainDir, 0777)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("Could not create cipherDir")
|
fmt.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func mount(extraArgs ...string) {
|
err = os.MkdirAll(defaultCipherDir, 0777)
|
||||||
var args []string
|
|
||||||
args = append(args, extraArgs...)
|
|
||||||
//args = append(args, "--fusedebug")
|
|
||||||
args = append(args, cipherDir)
|
|
||||||
args = append(args, plainDir)
|
|
||||||
c := exec.Command(gocryptfsBinary, args...)
|
|
||||||
if testing.Verbose() {
|
|
||||||
c.Stdout = os.Stdout
|
|
||||||
c.Stderr = os.Stderr
|
|
||||||
}
|
|
||||||
err := c.Run()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func unmount() error {
|
// mount CIPHERDIR "c" on PLAINDIR "p"
|
||||||
fu := exec.Command("fusermount", "-z", "-u", plainDir)
|
func mount(c string, p string, extraArgs ...string) {
|
||||||
|
var args []string
|
||||||
|
args = append(args, extraArgs...)
|
||||||
|
//args = append(args, "--fusedebug")
|
||||||
|
args = append(args, c)
|
||||||
|
args = append(args, p)
|
||||||
|
cmd := exec.Command(gocryptfsBinary, args...)
|
||||||
|
if testing.Verbose() {
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
}
|
||||||
|
err := cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// unmount PLAINDIR "p"
|
||||||
|
func unmount(p string) error {
|
||||||
|
fu := exec.Command("fusermount", "-u", "-z", p)
|
||||||
fu.Stdout = os.Stdout
|
fu.Stdout = os.Stdout
|
||||||
fu.Stderr = os.Stderr
|
fu.Stderr = os.Stderr
|
||||||
return fu.Run()
|
err := fu.Run()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return md5 string for file "filename"
|
// Return md5 string for file "filename"
|
||||||
|
@ -25,9 +25,9 @@ func TestMain(m *testing.M) {
|
|||||||
fmt.Printf("***** Testing with OpenSSL\n")
|
fmt.Printf("***** Testing with OpenSSL\n")
|
||||||
}
|
}
|
||||||
resetTmpDir()
|
resetTmpDir()
|
||||||
mount("--zerokey")
|
mount(defaultCipherDir, defaultPlainDir, "--zerokey")
|
||||||
r := m.Run()
|
r := m.Run()
|
||||||
unmount()
|
unmount(defaultPlainDir)
|
||||||
|
|
||||||
if defaultonly {
|
if defaultonly {
|
||||||
os.Exit(r)
|
os.Exit(r)
|
||||||
@ -37,25 +37,25 @@ func TestMain(m *testing.M) {
|
|||||||
fmt.Printf("***** Testing with native Go crypto\n")
|
fmt.Printf("***** Testing with native Go crypto\n")
|
||||||
}
|
}
|
||||||
resetTmpDir()
|
resetTmpDir()
|
||||||
mount("--zerokey", "--openssl=false")
|
mount(defaultCipherDir, defaultPlainDir, "--zerokey", "--openssl=false")
|
||||||
r = m.Run()
|
r = m.Run()
|
||||||
unmount()
|
unmount(defaultPlainDir)
|
||||||
|
|
||||||
if testing.Verbose() {
|
if testing.Verbose() {
|
||||||
fmt.Printf("***** Testing \"--plaintextnames\"\n")
|
fmt.Printf("***** Testing \"--plaintextnames\"\n")
|
||||||
}
|
}
|
||||||
resetTmpDir()
|
resetTmpDir()
|
||||||
mount("--zerokey", "--plaintextnames")
|
mount(defaultCipherDir, defaultPlainDir, "--zerokey", "--plaintextnames")
|
||||||
plaintextNames = true
|
plaintextNames = true
|
||||||
r = m.Run()
|
r = m.Run()
|
||||||
unmount()
|
unmount(defaultPlainDir)
|
||||||
|
|
||||||
os.Exit(r)
|
os.Exit(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write "n" zero bytes to filename "fn", read again, compare hash
|
// Write "n" zero bytes to filename "fn", read again, compare hash
|
||||||
func testWriteN(t *testing.T, fn string, n int) string {
|
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 {
|
if err != nil {
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
}
|
}
|
||||||
@ -68,12 +68,12 @@ func testWriteN(t *testing.T, fn string, n int) string {
|
|||||||
}
|
}
|
||||||
file.Close()
|
file.Close()
|
||||||
|
|
||||||
verifySize(t, plainDir+fn, n)
|
verifySize(t, defaultPlainDir+fn, n)
|
||||||
|
|
||||||
bin := md5.Sum(d)
|
bin := md5.Sum(d)
|
||||||
hashWant := hex.EncodeToString(bin[:])
|
hashWant := hex.EncodeToString(bin[:])
|
||||||
|
|
||||||
hashActual := md5fn(plainDir + fn)
|
hashActual := md5fn(defaultPlainDir + fn)
|
||||||
|
|
||||||
if hashActual != hashWant {
|
if hashActual != hashWant {
|
||||||
t.Errorf("Wrong content, hashWant=%s hashActual=%s\n", hashWant, hashActual)
|
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
|
// Read and check 100 times to catch race conditions
|
||||||
var i int
|
var i int
|
||||||
for i = 0; i < 100; i++ {
|
for i = 0; i < 100; i++ {
|
||||||
hashActual := md5fn(plainDir + "1M")
|
hashActual := md5fn(defaultPlainDir + "1M")
|
||||||
if hashActual != hashWant {
|
if hashActual != hashWant {
|
||||||
fmt.Printf("Read corruption in loop # %d\n", i)
|
fmt.Printf("Read corruption in loop # %d\n", i)
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
@ -110,7 +110,7 @@ func TestWrite1Mx100(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestTruncate(t *testing.T) {
|
func TestTruncate(t *testing.T) {
|
||||||
fn := plainDir + "truncate"
|
fn := defaultPlainDir + "truncate"
|
||||||
file, err := os.Create(fn)
|
file, err := os.Create(fn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
@ -142,7 +142,7 @@ func TestTruncate(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAppend(t *testing.T) {
|
func TestAppend(t *testing.T) {
|
||||||
fn := plainDir + "append"
|
fn := defaultPlainDir + "append"
|
||||||
file, err := os.Create(fn)
|
file, err := os.Create(fn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
@ -176,7 +176,7 @@ func TestAppend(t *testing.T) {
|
|||||||
// Create a file with holes by writing to offset 0 (block #0) and
|
// Create a file with holes by writing to offset 0 (block #0) and
|
||||||
// offset 4096 (block #1).
|
// offset 4096 (block #1).
|
||||||
func TestFileHoles(t *testing.T) {
|
func TestFileHoles(t *testing.T) {
|
||||||
fn := plainDir + "fileholes"
|
fn := defaultPlainDir + "fileholes"
|
||||||
file, err := os.Create(fn)
|
file, err := os.Create(fn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("file create failed")
|
t.Errorf("file create failed")
|
||||||
@ -203,7 +203,7 @@ func TestRmwRace(t *testing.T) {
|
|||||||
|
|
||||||
runtime.GOMAXPROCS(10)
|
runtime.GOMAXPROCS(10)
|
||||||
|
|
||||||
fn := plainDir + "rmwrace"
|
fn := defaultPlainDir + "rmwrace"
|
||||||
f1, err := os.Create(fn)
|
f1, err := os.Create(fn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("file create failed")
|
t.Fatalf("file create failed")
|
||||||
@ -274,7 +274,7 @@ func TestRmwRace(t *testing.T) {
|
|||||||
// With "--plaintextnames", the name "/gocryptfs.conf" is reserved.
|
// With "--plaintextnames", the name "/gocryptfs.conf" is reserved.
|
||||||
// Otherwise there should be no restrictions.
|
// Otherwise there should be no restrictions.
|
||||||
func TestFiltered(t *testing.T) {
|
func TestFiltered(t *testing.T) {
|
||||||
filteredFile := plainDir + "gocryptfs.conf"
|
filteredFile := defaultPlainDir + "gocryptfs.conf"
|
||||||
file, err := os.Create(filteredFile)
|
file, err := os.Create(filteredFile)
|
||||||
if plaintextNames == true && err == nil {
|
if plaintextNames == true && err == nil {
|
||||||
t.Errorf("should have failed but didn't")
|
t.Errorf("should have failed but didn't")
|
||||||
@ -292,13 +292,13 @@ func TestFiltered(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFilenameEncryption(t *testing.T) {
|
func TestFilenameEncryption(t *testing.T) {
|
||||||
file, err := os.Create(plainDir + "TestFilenameEncryption.txt")
|
file, err := os.Create(defaultPlainDir + "TestFilenameEncryption.txt")
|
||||||
file.Close()
|
file.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = os.Stat(cipherDir + "TestFilenameEncryption.txt")
|
_, err = os.Stat(defaultCipherDir + "TestFilenameEncryption.txt")
|
||||||
if plaintextNames == true && err != nil {
|
if plaintextNames == true && err != nil {
|
||||||
t.Errorf("plaintextnames not working: %v", err)
|
t.Errorf("plaintextnames not working: %v", err)
|
||||||
} else if plaintextNames == false && err == nil {
|
} else if plaintextNames == false && err == nil {
|
||||||
|
@ -12,7 +12,7 @@ func BenchmarkStreamWrite(t *testing.B) {
|
|||||||
buf := make([]byte, 1024*1024)
|
buf := make([]byte, 1024*1024)
|
||||||
t.SetBytes(int64(len(buf)))
|
t.SetBytes(int64(len(buf)))
|
||||||
|
|
||||||
file, err := os.Create(plainDir + "BenchmarkWrite")
|
file, err := os.Create(defaultPlainDir + "BenchmarkWrite")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
}
|
}
|
||||||
@ -33,7 +33,7 @@ func BenchmarkStreamRead(t *testing.B) {
|
|||||||
buf := make([]byte, 1024*1024)
|
buf := make([]byte, 1024*1024)
|
||||||
t.SetBytes(int64(len(buf)))
|
t.SetBytes(int64(len(buf)))
|
||||||
|
|
||||||
fn := plainDir + "BenchmarkWrite"
|
fn := defaultPlainDir + "BenchmarkWrite"
|
||||||
fi, err := os.Stat(fn)
|
fi, err := os.Stat(fn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@ -80,7 +80,7 @@ func BenchmarkStreamRead(t *testing.B) {
|
|||||||
|
|
||||||
// createFiles - create "count" files of size "size" bytes each
|
// createFiles - create "count" files of size "size" bytes each
|
||||||
func createFiles(t *testing.B, count int, size int) {
|
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)
|
err := os.Mkdir(dir, 0777)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
Loading…
Reference in New Issue
Block a user