tests: give "-plaintextnames" its own test package
...and add tests for checking that gocryptfs.diriv does not get created. The main "integration_tests" package has become quite big and convoluted over time. This small separate package should make writing tests for "-plaintextnames" easier. As seen in "fusefrontend: fix PlaintextNames versions of Mkdir, Rmdir", we need more of them.
This commit is contained in:
parent
c400aca5cf
commit
2720cd7b0d
@ -9,7 +9,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/rfjakob/gocryptfs/internal/configfile"
|
||||
"github.com/rfjakob/gocryptfs/internal/nametransform"
|
||||
|
||||
"github.com/rfjakob/gocryptfs/tests/test_helpers"
|
||||
)
|
||||
@ -79,30 +78,6 @@ func TestInitConfig(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Test -init -plaintextnames
|
||||
func TestInitPlaintextNames(t *testing.T) {
|
||||
dir := test_helpers.InitFS(t, "-plaintextnames")
|
||||
dir = dir + "/"
|
||||
_, err := os.Stat(dir + configfile.ConfDefaultName)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = os.Stat(dir + nametransform.DirIVFilename)
|
||||
if err == nil {
|
||||
t.Errorf("gocryptfs.diriv should not have been created with -plaintextnames")
|
||||
}
|
||||
_, cf, err := configfile.LoadConfFile(dir+configfile.ConfDefaultName, "test")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !cf.IsFeatureFlagSet(configfile.FlagPlaintextNames) {
|
||||
t.Error("PlaintextNames flag should be set but isnt")
|
||||
}
|
||||
if cf.IsFeatureFlagSet(configfile.FlagEMENames) || cf.IsFeatureFlagSet(configfile.FlagDirIV) {
|
||||
t.Error("FlagEMENames and FlagDirIV should be not set")
|
||||
}
|
||||
}
|
||||
|
||||
// Test -ro
|
||||
func TestRo(t *testing.T) {
|
||||
dir := test_helpers.InitFS(t)
|
||||
|
82
tests/plaintextnames/plaintextnames_test.go
Normal file
82
tests/plaintextnames/plaintextnames_test.go
Normal file
@ -0,0 +1,82 @@
|
||||
package plaintextnames
|
||||
|
||||
// integration tests that target plaintextnames specifically
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/rfjakob/gocryptfs/internal/configfile"
|
||||
|
||||
"github.com/rfjakob/gocryptfs/tests/test_helpers"
|
||||
)
|
||||
|
||||
var cDir string
|
||||
var pDir string
|
||||
|
||||
// Create and mount "-plaintextnames" fs
|
||||
func TestMain(m *testing.M) {
|
||||
cDir = test_helpers.InitFS(nil, "-plaintextnames")
|
||||
pDir = cDir + ".mnt"
|
||||
test_helpers.MountOrExit(cDir, pDir, "-extpass", "echo test")
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
// Only the PlaintextNames feature flag should be set
|
||||
func TestFlags(t *testing.T) {
|
||||
_, cf, err := configfile.LoadConfFile(cDir+"/gocryptfs.conf", "test")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !cf.IsFeatureFlagSet(configfile.FlagPlaintextNames) {
|
||||
t.Error("PlaintextNames flag should be set but isnt")
|
||||
}
|
||||
if cf.IsFeatureFlagSet(configfile.FlagEMENames) || cf.IsFeatureFlagSet(configfile.FlagDirIV) {
|
||||
t.Error("FlagEMENames and FlagDirIV should be not set")
|
||||
}
|
||||
}
|
||||
|
||||
// gocryptfs.diriv should NOT be created
|
||||
func TestDirIV(t *testing.T) {
|
||||
_, err := os.Stat(cDir + "/gocryptfs.diriv")
|
||||
if err == nil {
|
||||
t.Errorf("gocryptfs.diriv should not be created in the top directory")
|
||||
}
|
||||
err = os.Mkdir(pDir+"/dir1", 0777)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
_, err = os.Stat(pDir + "/dir1/gocryptfs.diriv")
|
||||
if err == nil {
|
||||
t.Errorf("gocryptfs.diriv should not be created in a subdirectory")
|
||||
}
|
||||
}
|
||||
|
||||
// With "-plaintextnames", the name "/gocryptfs.conf" is reserved, but everything
|
||||
// else should work.
|
||||
func TestFiltered(t *testing.T) {
|
||||
filteredFile := pDir + "/gocryptfs.conf"
|
||||
err := ioutil.WriteFile(filteredFile, []byte("foo"), 0777)
|
||||
if err == nil {
|
||||
t.Errorf("should have failed but didn't")
|
||||
}
|
||||
err = os.Remove(filteredFile)
|
||||
if err == nil {
|
||||
t.Errorf("should have failed but didn't")
|
||||
}
|
||||
err = ioutil.WriteFile(pDir+"/gocryptfs.diriv", []byte("foo"), 0777)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
subDir, err := ioutil.TempDir(pDir, "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fd, err := os.Create(subDir + "/gocryptfs.conf")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else {
|
||||
fd.Close()
|
||||
}
|
||||
}
|
@ -66,7 +66,8 @@ 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.
|
||||
//
|
||||
// The returned cipherdir has NO trailing slash.
|
||||
func InitFS(t *testing.T, extraArgs ...string) string {
|
||||
dir, err := ioutil.TempDir(TmpDir, "")
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user