aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Unterwurzacher2025-06-20 21:07:57 +0200
committerJakob Unterwurzacher2025-07-09 19:28:09 +0200
commitac2493d0fb26155b17ecbe35751534e6f50dc548 (patch)
tree121d153396b081983261e75f87f21f374618700c
parent386232f39ede046d6453a0990ad40f2d86a26f53 (diff)
tests: reverse: add TestIssue927 exclude test
Also, run plaintextnames test first to make it easier to spot what's wrong. https://github.com/rfjakob/gocryptfs/issues/927
-rw-r--r--tests/reverse/exclude_test.go93
-rw-r--r--tests/reverse/main_test.go2
2 files changed, 94 insertions, 1 deletions
diff --git a/tests/reverse/exclude_test.go b/tests/reverse/exclude_test.go
index 645d267..ad6ade6 100644
--- a/tests/reverse/exclude_test.go
+++ b/tests/reverse/exclude_test.go
@@ -4,6 +4,7 @@ import (
"log"
"os"
"path/filepath"
+ "strings"
"testing"
"github.com/rfjakob/gocryptfs/v2/ctlsock"
@@ -196,3 +197,95 @@ func TestExcludeAllOnlyDir1(t *testing.T) {
}
doTestExcludeTestFs(t, "-exclude-wildcard", patterns, tree)
}
+
+// Test that the "exclude everything except" example
+// from https://git-scm.com/docs/gitignore works
+// (copied below):
+//
+// $ cat .gitignore
+// # exclude everything except directory foo/bar
+// /*
+// !/foo
+// /foo/*
+// !/foo/bar
+func TestGitignoreExampleExcludeEverythingExcept(t *testing.T) {
+ // --exclude-wildcard patterns, gitignore syntax
+ patterns := []string{
+ "/*",
+ "!/foo",
+ "/foo/*",
+ "!/foo/bar",
+ }
+ var tree directoryTree
+ // visible are plaintext paths that should be visible in the encrypted view
+ tree.visibleDirs = []string{
+ "foo",
+ "foo/bar",
+ }
+ tree.visibleFiles = []string{}
+ // hidden are plaintext paths that should be hidden in the encrypted view
+ tree.hiddenDirs = []string{
+ "baz",
+ }
+ tree.hiddenFiles = []string{
+ "boing",
+ }
+ doTestExcludeTestFs(t, "-exclude-wildcard", patterns, tree)
+}
+
+// Issue https://github.com/rfjakob/gocryptfs/issues/927
+//
+// Patterns ending with "/" are not handled correctly by
+// https://github.com/sabhiram/go-gitignore
+func TestIssue927(t *testing.T) {
+ patterns := strings.Split(`
+/*
+.gitignore
+.config/**
+!.config/
+.config/conky/*
+!.config/conky/
+!.config/conky/conkyrc
+
+.config/geany/*
+!.config/geany/
+.config/geany/colorschemes/*
+!.config/geany/colorschemes/
+!.config/geany/colorschemes/dark3.conf
+
+/.config/mpv/*
+!/.config/mpv/
+!/.config/mpv/config
+!/.config/mpv/scripts/
+!/.config/mpv/scripts/*
+.config/mpv/scripts/sub.lua
+!/.config/mpv/script-opts/
+!/.config/mpv/script-opts/*
+!/.config/mpv/input.conf
+`, "\n")
+ var tree directoryTree
+ // visible are plaintext paths that should be visible in the encrypted view
+ tree.visibleDirs = []string{
+ ".config",
+ ".config/conky",
+ }
+ tree.visibleFiles = []string{
+ ".config/conky/conkyrc",
+ ".config/geany/colorschemes/dark3.conf",
+ ".config/mpv/input.conf",
+ ".config/mpv/script-opts/hello",
+ }
+ // hidden are plaintext paths that should be hidden in the encrypted view
+ tree.hiddenDirs = []string{
+ "ddd",
+ ".config/conky/ddd",
+ }
+ tree.hiddenFiles = []string{
+ "fff",
+ ".config/conky/fff",
+ ".config/geany/colorschemes/fff",
+ ".config/mpv/fff",
+ ".config/mpv/scripts/sub.lua",
+ }
+ doTestExcludeTestFs(t, "-exclude-wildcard", patterns, tree)
+}
diff --git a/tests/reverse/main_test.go b/tests/reverse/main_test.go
index 6a3ed9b..62d9334 100644
--- a/tests/reverse/main_test.go
+++ b/tests/reverse/main_test.go
@@ -39,8 +39,8 @@ func TestMain(m *testing.M) {
plaintextnames bool
deterministic_names bool
}{
- {false, false},
{true, false},
+ {false, false},
{false, true},
}
for i, tc := range testcases {