aboutsummaryrefslogtreecommitdiff
path: root/internal/fusefrontend_reverse/rfs_test.go
diff options
context:
space:
mode:
authorEduardo M KALINOWSKI2019-02-16 18:55:54 -0200
committerJakob Unterwurzacher2019-03-26 20:56:37 +0100
commit3bc100aeb3f0763f78c8b3a70165b9f8aaa52db5 (patch)
tree19b1576b0ee8e74612c29b0ff4cec4f3cecf2b29 /internal/fusefrontend_reverse/rfs_test.go
parent73f9e2374dab47374dc479911a9be5cfebf89378 (diff)
reverse mode: support wildcard exclude (--exclude-wildcard)
This adds support for gitignore-like wildcards and exclude patters in reverse mode. It (somewhat) fixes #273: no regexp support, but the syntax should be powerful enough to satisfy most needs. Also, since adding a lot of --exclude options can be tedious, it adds the --exclude-from option to read patterns from a file (or files).
Diffstat (limited to 'internal/fusefrontend_reverse/rfs_test.go')
-rw-r--r--internal/fusefrontend_reverse/rfs_test.go124
1 files changed, 124 insertions, 0 deletions
diff --git a/internal/fusefrontend_reverse/rfs_test.go b/internal/fusefrontend_reverse/rfs_test.go
new file mode 100644
index 0000000..eccaab9
--- /dev/null
+++ b/internal/fusefrontend_reverse/rfs_test.go
@@ -0,0 +1,124 @@
+package fusefrontend_reverse
+
+import (
+ "testing"
+
+ "github.com/rfjakob/gocryptfs/internal/configfile"
+ "github.com/rfjakob/gocryptfs/internal/nametransform"
+)
+
+func TestShouldDetectDirIV(t *testing.T) {
+ var rfs ReverseFS
+ ftype := rfs.getFileType("some/path/" + nametransform.DirIVFilename)
+ if ftype != typeDiriv {
+ t.Errorf("Expecting %d, got %d\n", typeDiriv, ftype)
+ }
+}
+
+func TestShouldDetectNameFile(t *testing.T) {
+ var rfs ReverseFS
+ ftype := rfs.getFileType("dir1/dir2/gocryptfs.longname.URrM8kgxTKYMgCk4hKk7RO9Lcfr30XQof4L_5bD9Iro=" + nametransform.LongNameSuffix)
+ if ftype != typeName {
+ t.Errorf("Expecting %d, got %d\n", typeName, ftype)
+ }
+}
+
+func TestShouldDetectConfigFile(t *testing.T) {
+ var rfs ReverseFS
+ ftype := rfs.getFileType(configfile.ConfDefaultName)
+ if ftype != typeConfig {
+ t.Errorf("Expecting %d, got %d\n", typeConfig, ftype)
+ }
+}
+
+func TestShouldDetectRegularFile(t *testing.T) {
+ var rfs ReverseFS
+ ftype := rfs.getFileType("documents/text_file.txt")
+ if ftype != typeRegular {
+ t.Errorf("Expecting %d, got %d\n", typeRegular, ftype)
+ }
+}
+
+// Note: For path exclusion, see also the integration tests in
+// tests/reverse/exclude_test.go
+func TestShouldNotCallIgnoreParserForTranslatedConfig(t *testing.T) {
+ rfs, ignorerMock := createRFSWithMocks()
+
+ ftype, excluded, _, err := rfs.getFileInfo(configfile.ConfDefaultName)
+ if err != nil {
+ t.Errorf("Unexpected error %q\n", err)
+ }
+ if ftype != typeConfig {
+ t.Errorf("Wrong file type, expecting %d, got %d\n", typeConfig, ftype)
+ }
+ if excluded {
+ t.Error("Should not exclude translated config")
+ }
+ if ignorerMock.calledWith != "" {
+ t.Error("Should not call IgnoreParser for translated config")
+ }
+}
+
+func TestShouldCheckIfParentIsExcludedForDirIV(t *testing.T) {
+ rfs, ignorerMock := createRFSWithMocks()
+ path := "dir"
+ ignorerMock.toExclude = "mockdecrypt_dir"
+ dirIV := path + "/" + nametransform.DirIVFilename
+
+ ftype, excluded, _, err := rfs.getFileInfo(dirIV)
+ if err != nil {
+ t.Errorf("Unexpected error %q\n", err)
+ }
+ if ftype != typeDiriv {
+ t.Errorf("Wrong file type, expecting %d, got %d\n", typeDiriv, ftype)
+ }
+ if !excluded {
+ t.Error("Should have excluded DirIV based on parent")
+ }
+ if ignorerMock.calledWith != "mockdecrypt_dir" {
+ t.Errorf("Should have checked parent dir, checked %q", ignorerMock.calledWith)
+ }
+}
+
+func TestShouldCheckIfParentIsExcludedForLongName(t *testing.T) {
+ rfs, ignorerMock := createRFSWithMocks()
+ path := "parent"
+ ignorerMock.toExclude = "mockdecrypt_parent"
+ dirIV := path + "/" + "gocryptfs.longname.fake.name"
+
+ ftype, excluded, _, err := rfs.getFileInfo(dirIV)
+ if err != nil {
+ t.Errorf("Unexpected error %q\n", err)
+ }
+ if ftype != typeName {
+ t.Errorf("Wrong file type, expecting %d, got %d\n", typeName, ftype)
+ }
+ if !excluded {
+ t.Error("Should have excluded LongName based on parent")
+ }
+ if ignorerMock.calledWith != "mockdecrypt_parent" {
+ t.Errorf("Should have checked parent dir, checked %q", ignorerMock.calledWith)
+ }
+}
+
+func TestShouldDecryptPathAndReturnTrueForExcludedPath(t *testing.T) {
+ rfs, ignorerMock := createRFSWithMocks()
+ ignorerMock.toExclude = "mockdecrypt_file.txt"
+
+ ftype, excluded, pPath, err := rfs.getFileInfo("file.txt")
+ if err != nil {
+ t.Errorf("Unexpected error %q\n", err)
+ }
+ if ftype != typeRegular {
+ t.Errorf("Wrong file type, expecting %d, got %d\n", typeRegular, ftype)
+ }
+ if !excluded {
+ t.Error("Should have excluded")
+ }
+ if pPath != "mockdecrypt_file.txt" {
+ t.Errorf("Wrong pPath returned, got %q\n", pPath)
+ }
+ if ignorerMock.calledWith != "mockdecrypt_file.txt" {
+ t.Error("Didn't call IgnoreParser with decrypted path")
+ }
+}