tests: add InitFS helper
This commit is contained in:
parent
c76c952c19
commit
305e9c1045
@ -3,7 +3,6 @@ package integration_tests
|
|||||||
// Test CLI operations like "-init", "-password" etc
|
// Test CLI operations like "-init", "-password" etc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -17,18 +16,8 @@ import (
|
|||||||
|
|
||||||
// Test -init flag
|
// Test -init flag
|
||||||
func TestInit(t *testing.T) {
|
func TestInit(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir(test_helpers.TmpDir, "TestInit")
|
dir := test_helpers.InitFS(t)
|
||||||
if err != nil {
|
_, err := os.Stat(filepath.Join(dir, configfile.ConfDefaultName))
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
cmd := exec.Command(test_helpers.GocryptfsBinary, "-q", "-init", "-extpass", "echo test", "-scryptn=10", dir)
|
|
||||||
cmd.Stdout = os.Stdout
|
|
||||||
cmd.Stderr = os.Stderr
|
|
||||||
err = cmd.Run()
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
_, err = os.Stat(filepath.Join(dir, configfile.ConfDefaultName))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -37,22 +26,12 @@ func TestInit(t *testing.T) {
|
|||||||
// Test -passwd flag
|
// Test -passwd flag
|
||||||
func TestPasswd(t *testing.T) {
|
func TestPasswd(t *testing.T) {
|
||||||
// Create FS
|
// Create FS
|
||||||
dir, err := ioutil.TempDir(test_helpers.TmpDir, "TestPasswd")
|
dir := test_helpers.InitFS(t)
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
cmd := exec.Command(test_helpers.GocryptfsBinary, "-q", "-init", "-extpass", "echo test", "-scryptn=10", dir)
|
|
||||||
cmd.Stdout = os.Stdout
|
|
||||||
cmd.Stderr = os.Stderr
|
|
||||||
err = cmd.Run()
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
// Change password using "-extpass"
|
// Change password using "-extpass"
|
||||||
cmd = exec.Command(test_helpers.GocryptfsBinary, "-q", "-passwd", "-extpass", "echo test", dir)
|
cmd := exec.Command(test_helpers.GocryptfsBinary, "-q", "-passwd", "-extpass", "echo test", dir)
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
err = cmd.Run()
|
err := cmd.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
@ -81,21 +60,10 @@ func TestPasswd(t *testing.T) {
|
|||||||
|
|
||||||
// Test -init & -config flag
|
// Test -init & -config flag
|
||||||
func TestInitConfig(t *testing.T) {
|
func TestInitConfig(t *testing.T) {
|
||||||
dir := test_helpers.TmpDir + "TestInitConfig/"
|
|
||||||
config := test_helpers.TmpDir + "TestInitConfig.conf"
|
config := test_helpers.TmpDir + "TestInitConfig.conf"
|
||||||
err := os.Mkdir(dir, 0777)
|
dir := test_helpers.InitFS(t, "-config="+config)
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
_, err := os.Stat(config)
|
||||||
}
|
|
||||||
cmd := exec.Command(test_helpers.GocryptfsBinary, "-q", "-init", "-extpass", "echo test",
|
|
||||||
"-config", config, "-scryptn=10", dir)
|
|
||||||
cmd.Stdout = os.Stdout
|
|
||||||
cmd.Stderr = os.Stderr
|
|
||||||
err = cmd.Run()
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
_, err = os.Stat(config)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -113,20 +81,9 @@ func TestInitConfig(t *testing.T) {
|
|||||||
|
|
||||||
// Test -init -plaintextnames
|
// Test -init -plaintextnames
|
||||||
func TestInitPlaintextNames(t *testing.T) {
|
func TestInitPlaintextNames(t *testing.T) {
|
||||||
dir := test_helpers.TmpDir + "TestInitPlaintextNames/"
|
dir := test_helpers.InitFS(t, "-plaintextnames")
|
||||||
err := os.Mkdir(dir, 0777)
|
dir = dir + "/"
|
||||||
if err != nil {
|
_, err := os.Stat(dir + configfile.ConfDefaultName)
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
cmd := exec.Command(test_helpers.GocryptfsBinary, "-q", "-init", "-extpass", "echo test",
|
|
||||||
"-scryptn=10", "-plaintextnames", dir)
|
|
||||||
cmd.Stdout = os.Stdout
|
|
||||||
cmd.Stderr = os.Stderr
|
|
||||||
err = cmd.Run()
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
_, err = os.Stat(dir + configfile.ConfDefaultName)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,12 @@ const DefaultCipherDir = TmpDir + "cipher/"
|
|||||||
|
|
||||||
const GocryptfsBinary = "../../gocryptfs"
|
const GocryptfsBinary = "../../gocryptfs"
|
||||||
|
|
||||||
// ResetTmpDir - delete old tmp dir, create new one, write gocryptfs.diriv
|
// ResetTmpDir - delete TmpDir, create new dir tree:
|
||||||
|
//
|
||||||
|
// TmpDir
|
||||||
|
// |-- DefaultPlainDir
|
||||||
|
// *-- DefaultCipherDir
|
||||||
|
// *-- gocryptfs.diriv
|
||||||
func ResetTmpDir(plaintextNames bool) {
|
func ResetTmpDir(plaintextNames bool) {
|
||||||
|
|
||||||
// Try to unmount everything
|
// Try to unmount everything
|
||||||
@ -59,7 +64,33 @@ func ResetTmpDir(plaintextNames bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InitFS calls "gocryptfs -init" on a new directory in TmpDir, passing
|
||||||
|
// "extraArgs" in addition to practical defaults.
|
||||||
|
// The returned "dir" has NO trailing slash.
|
||||||
|
func InitFS(t *testing.T, extraArgs ...string) string {
|
||||||
|
dir, err := ioutil.TempDir(TmpDir, "")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
args := []string{"-q", "-init", "-extpass", "echo test", "-scryptn=10"}
|
||||||
|
args = append(args, extraArgs...)
|
||||||
|
args = append(args, dir)
|
||||||
|
|
||||||
|
cmd := exec.Command(GocryptfsBinary, args...)
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
|
||||||
|
err = cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("InitFS with args %v failed: %v", args, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return dir
|
||||||
|
}
|
||||||
|
|
||||||
// Mount CIPHERDIR "c" on PLAINDIR "p"
|
// Mount CIPHERDIR "c" on PLAINDIR "p"
|
||||||
|
// Creates "p" if it does not exist.
|
||||||
func Mount(c string, p string, extraArgs ...string) error {
|
func Mount(c string, p string, extraArgs ...string) error {
|
||||||
var args []string
|
var args []string
|
||||||
args = append(args, extraArgs...)
|
args = append(args, extraArgs...)
|
||||||
@ -68,11 +99,17 @@ func Mount(c string, p string, extraArgs ...string) error {
|
|||||||
//args = append(args, "-d")
|
//args = append(args, "-d")
|
||||||
args = append(args, c)
|
args = append(args, c)
|
||||||
args = append(args, p)
|
args = append(args, p)
|
||||||
|
|
||||||
|
if _, err := os.Stat(p); err != nil {
|
||||||
|
err = os.Mkdir(p, 0777)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cmd := exec.Command(GocryptfsBinary, args...)
|
cmd := exec.Command(GocryptfsBinary, args...)
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
if testing.Verbose() {
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stdout = os.Stdout
|
|
||||||
}
|
|
||||||
return cmd.Run()
|
return cmd.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user